__module_name__ = "chattr" __module_version__ = "0.1" __module_description__ = "Allows the usr to speak in flickr or similr dialect easily" __module_author__ = "Maciej Katafiasz " import xchat, re help_msg = """Speak in flickr dialect Usage: /chattr [on|off|kill] on -- enable chattr for current channel off -- disable chattr for current channel kill -- disable for all channels call with no arguments to see current status """ channels = {} class ChannelInfo: def __init__(self, enabled): self.enabled = enabled self.in_loop = False def load_settings(): global channels try: setup = open(xchat.get_info("xchatdir") + "/chattr.conf", "r") except: print "Chattr: can't load settings" return for line in setup: try: chan, on = line.split(" ", 1) if bool(on): channels[chan] = ChannelInfo(True) except: continue def write_settings(w): global channels try: setup = open(xchat.get_info("xchatdir") + "/chattr.conf", "w") except: print "Chattr: can't save settings" for chan, info in channels.items(): if info.enabled: setup.write(chan + " " + str(info.enabled)) def channel_id(ct): return (ct.get_info("network") or ct.get_info("server")) + "@" + ct.get_info("channel") def chattr_set(word, word_eol, userdata): global channels ct = xchat.get_context() key = channel_id(ct) if len(word) == 1: try: info = channels[key] print "Chattr enabled for current channel" except: print "Chattr disabled for current channel" elif len(word) == 2: if word[1] == "kill": channels = {} elif word[1] == "off": try: del(channels[key]) except: pass print "Chattr is now disabled for current channel" elif word[1] == "on": channels[key] = ChannelInfo(True) print "Chattr is now enabled for current channel" else: print help_msg else: print help_msg return xchat.EAT_ALL def chattrify(text): return re.sub("([^aiueo])[aiueo](r[^aiueo]?)\\b", "\\1\\2", text) def codec_cb(word, word_eol, userdata): global channels event, send = userdata try: ct = xchat.get_context() info = channels[channel_id(ct)] if info.in_loop: info.in_loop = False return None else: if info.enabled and send: info.in_loop = True if event: text = word_eol[1] else: event = "say" text = word_eol[0] ct.command(event + " " + chattrify(text)) else: return None except Exception, e: return None return xchat.EAT_ALL EVENTS = [ "Channel Action", "Channel Action Hilight", "Channel Message", "Channel Msg Hilight", "Channel Notice", "Generic Message", "Kick", "Killed", "Motd", "Notice", "Part with Reason", "Private Message", "Private Message to Dialog", "Quit", "Receive Wallops", "Server Notice", "Server Text", "Topic", "Topic Change", "Your Message" ] load_settings() xchat.hook_command("chattr", chattr_set, help=help_msg) xchat.hook_command("", codec_cb, ("", True)) xchat.hook_command("topic", codec_cb, ("topic", True)) xchat.hook_command("me", codec_cb, ("me", True)) xchat.hook_unload(write_settings) for event in EVENTS: xchat.hook_print(event, codec_cb, (event, False)) print "Plugin Chattr loaded."