Code :: PleasurePoker

Posted by - April 25, 08

This is going to be a day late, but wow that was a long day. Fridays are code days. Personally, I think Fridays are a bit slow in the anime blogosphere, I mean its Friday, time to shed those weekly ambitions and let is ride. It goes without saying that I don’t expect much reading or feedback on these posts, there won’t be pretty pictures. It goes without saying there should be a disclaimer on any code I bring out on Fridays, as it is merely prototype-level stuff. Of course, I wouldn’t mind touching up some hacks if there is a need for it… personally I can work with hacks [and meta-hacks]. Hopefully, the relations to anime, or animeblogging, will be apparent.

Pleasure Poking and Bongo Party

Today’s code is quite simple/redundant, and for anyone that doesn’t want to look at code, I’ll just say what it does. It is a python XChat script (yes, that crazy stuff), which merely listens for the triggers: !bongos or !pokeme, and does a /me command based on the calling nick. Lame right?

pleasure

This has no intention of being an end script, but it does give some insight into useful XChat events, in case anyone wants to do this sort of thing, but doesn’t want to spend 4 hours looking at the documentation. Here is the code:


__module_name__ = "BongoPoke"
__module_version__ = "0.0"
__module_description__ = "Shakes bongos, and pokes for pleasurez"

import xchat, re

def pleasurepoke(word, word_eol, userdata):
	if xchat.get_info('nick')=='PleasurePoker' and re.search("^!pokeme$", word[1])!=None:
		xchat.command("me pokes "+ word[0] +" with pleasurez *ehew*")
		return xchat.EAT_ALL
	return xchat.EAT_NONE

def bongos( word ):
	if re.search("^!bongos$", word[1] ) != None:
		xchat.command("me shakes the bongos for "+ word[0]  +" ~()~");
		return 1
	else:
		return None

def echo_cb(nickchan):
	def f(word, word_eol, userdata):
		if xchat.get_info('nick')+xchat.get_info('channel')==nickchan:
		    res=bongos( word )
		    if res == 1:
		    	return xchat.EAT_ALL
		    else:
		    	return xchat.EAT_NONE
	return f

xchat.prnt("Loading module for " + xchat.get_info('nick') + " in " + xchat.get_info('channel') )
xchat.hook_print( "Channel Message", echo_cb( xchat.get_info('nick')+xchat.get_info('channel') ) )
xchat.hook_print( "Channel Message", pleasurepoke )

The Technicals

So here we have two handlers, pleasurepoke and bongos, which merely do some checking of the word data (state) and execute the xchat.command “me” (action command, we all know this one, the one to not use is say). The third function, echo_cb, is slightly more complex, it creates a function f, based on nickchan and returns the function f, the handler (here it is passing stuff to bongos). In this way, echo_cb is a mini “function factory” which abstracts the flow control that chooses to execute the handler or not. ( This simply means we can restrict the handlers to certain channels, nicks, servers, etc )

Well, I think it is straightforward, so I’ll stop here. Also, some of this is repeated from a previous XChat python post. One step closer to being l33t in all those anime IRC channels right!? This is pretty general use though :p

Ryan A

3 Comments on Code :: PleasurePoker

Respond | Trackback

  1. Michael says:

    I wish I understood this post. :V

  2. aloe says:

    Code = possibilities. It isn’t really about reading code or coding ideas, but the more general things; possibilities. What is possible….

    … is possible, but there are things which are possible, yet very difficult to achieve. Possibilities can lead other to “innovation”, something that may be useful if it worked in a given way. Innovation does not require coding, only ideas. ^^

  3. Michael says:

    That was so cryptic, Ry. But I agree, innovation only needs ideas. Implemented ones, though.

Respond

Comments

Comments