is un-XChat haxor

Posted by - April 9, 08

Well, for those who were in the #animeblogger IRC earlier today, I apologize for activating a test echo script in XChat, which apparently went ballistic (I wasn’t physically watching the channel and was totally unaware). The trouble was that this script was activated on another server window and in another [empty] channel, but it was handling every event, no matter the server. I just want to put my two-cents out there for anyone who is going to write a python module for XChat, and what NOT to do.

Teh Scriptz

echo like a monkey:

__module_name__ = "testing"
__module_version__ = "0.0"
__module_description__ = "Test mod"

import xchat

def echo_cb(word, word_eol, userdata):
	# DO STUFF HERE, I was doing xchat.command('say ' + word[1])
	return xchat.EAT_NONE

xchat.hook_print("Channel Message", echo_cb)

In the above code, I added a hook (event handler) to the print, for Channel Message. This only means, echo_cb is going to be called on the channel message event, great. The earlier problem arose because echo_cb doesn’t check it’s context, it just goes. I was under the impression that the plugin was context partitioned. Rather, xchat-python is global, so any loaded module will handle any event in xchat. This is good I guess, but I really wish I would have known about that (it isn’t in the doc).

a better method:

For those that may test stuff out, here is a better way to create handlers, so that they stay in “context” and not run amok.

__module_name__ = "testing"
__module_version__ = "0.0"
__module_description__ = "Test mod"

import xchat

def echo_cb(nick,channel):
	def f(word, word_eol, userdata):
		if xchat.get_info('channel')==channel and  xchat.get_info('nick')==nick:
		#DO STUFF HERE
		return xchat.EAT_NONE
	return f

xchat.prnt("Loading module for " + xchat.get_info('nick'))
xchat.hook_print( "Channel Message", echo_cb( 'YOUR NICK', "#CHANNEL TO ACTIVATE" ) )

What this manages is a small part of declarative programming; I am calling echo_cb with a nick and channel name, and echo_cb is returning the handler (f is an inner function being returned). The good news is that even on any channel message event, that if statement will prevent action unless it is from the channel specified and you are using the nick specified.

Had I used the second of these methods, there would not have been a problem since I wasn’t activating the module in AB or on IrcHighway. So, a good lesson.

Ryan A

ps. I wanted to write this earlier, but alas, school, which also made me miss the two UEFA Champions League matches ;.;

5 Comments on is un-XChat haxor

Respond | Trackback

  1. Michael says:

    You almost got banned for this. :V

  2. aloe says:

    Yea, it happens. This online mishaps was gained a little ground on my usual RL ones (which blow everything out of the water). ^^

  3. totali says:

    LOL damn, I wish I was there to see that.

  4. aloe says:

    Best part [for me] was how I had no clue what was going on, until opened the channel window and see me [my nick] echoing shit all over the place. It was scary, like waking up in a moving vehicle, but… eh, there’s no driver….. D:

    … must be careful around here, people will ghost ride their vehicle into a tree… with you still inside… I’ve seen it first hand.

  5. [...] 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 [...]

Respond

Comments

Comments