def chanmessage(word, word_eol, userdata): nick = word[0] message = word[1] if (xchat.nickcmp(xchat.strip(nick), "B") == 0 or xchat.nickcmp(xchat.strip(nick), "BridgeBabe") == 0) and message.startswith("("): name = "." + message[1:message.index(')')] message = message[message.index(')') + 2:] mode = name[1] if name[1] in "@+&~%" else "" xchat.emit_print(userdata, name, message, mode) return xchat.EAT_ALL return xchat.EAT_NONE
def msg(word, word_eol, userdata): if xchat.nickcmp(word[1], pirate_host) == 0: xchat.prnt("They are the same!") #xchat.prnt(', '.join(word_eol)) #userlist = context.get_list("users") #xchat.prnt(word) return xchat.EAT_NONE
def bcast(users, p2p, msg): ''' Send a message to all users in a channel ''' print msg for x in users: if not xchat.nickcmp(x.nick, xchat.get_prefs("irc_nick1")) == 0: xchat.command("msg " + x.nick + " " + msg) return xchat.EAT_ALL
def isop(): _isop = False mynick = xchat.get_info('nick') for user in xchat.get_list('users'): if xchat.nickcmp(user.nick, mynick) == 0: if user.prefix == "@": _isop = True return _isop
def friendhook(self, word, word_eol, userdata): if len(word) < 2: xchat.command("help friend") else: command = word[1].lower() if command == "list": print self.friends elif command == "add" and len(word) == 3: addnick = word[2] found = False for nick in self.friends: if xchat.nickcmp(nick, addnick) == 0: found = True print "Nick was already added as " + nick break if not found: self.friends.append(addnick) self.savefriends() print addnick + " has been added as a friend" elif (command == "del" or command == "delete") and len(word) == 3: delnick = word[2] found = False for nick in self.friends: if xchat.nickcmp(nick, delnick) == 0: found = nick break if found: self.friends.remove(found) self.savefriends() #delete stored public key self.conversations.get(found)["publickey"] = None self.keys.pop(found, None) self.savekeys() print found + " has been deleted from friends list" else: print delnick + " was not on friends list" else: xchat.command("help friend") return xchat.EAT_XCHAT
def checkmessage_cb(word, word_eol, userdata): if xchat.nickcmp(xchat.get_info("channel"), "#news") == 0: nick = word[0][1:] while len(nick) > 0 and nick[0].isdigit(): nick = nick[1:] if nick.lower() == "thekey": if "NSFW" in word[1]: return xchat.EAT_ALL return xchat.EAT_NONE
def identifycb(word, word_eol, userdata): c = xchat.get_context() match = NICKPATTERN.match(word[0]) matchtxt = "This nickname is registered and protected." if not match or xchat.nickcmp(match.group(1), 'NickServ') != 0: return xchat.EAT_NONE if matchtxt in word_eol[0]: c.command("msg nickserv identify " + c.get_info('nickserv')) return xchat.EAT_NONE
def checkmessage_cb(word, word_eol, userdata): if xchat.nickcmp(xchat.get_info("channel"), "#news") == 0: if word[1][1:5] == "find": return xchat.EAT_ALL elif word[1][0:5] == "!loli" or word[1][0:5] == "!futa": return xchat.EAT_ALL else: return xchat.EAT_NONE return xchat.EAT_NONE
def join_cb(word, word_eol, userdata): global joined global channel_name if xchat.nickcmp(xchat.get_info("channel"), channel_name) != 0: return xchat.EAT_NONE joined.append(xchat.strip(word[0])) return xchat.EAT_NONE
def checkterror_cb(word, word_eol, userdata): if xchat.nickcmp(xchat.get_info("channel"), "#commie-subs") == 0: if "EUZUBILLAHIMINE" in word[1]: nick = word[0][1:] while len(nick) > 0 and nick[0].isdigit(): nick = nick[1:] xchat.command("kickban " + nick) return xchat.EAT_NONE return xchat.EAT_NONE
def banned_callback(word, word_eol, userdata): # this now works on a basic level, will possibly be improved nick = xchat.get_info('nick') for user in xchat.get_list('users'): if xchat.nickcmp(nick, user.nick) == 0: userhost = user.host hostip = re.split('@', userhost)[1] if re.search(nick, word[1]) or re.search(hostip, word[1]): growlnotify('Banned', 'You have been banned by ' + word[0])
def filter_match(self, user, channel, message, nick): retval = False for rule in self.rules: rslt = {} for name, test in rule.iteritems(): # Is one of users if name == 'users': rslt.setdefault('users', False) for usr in test: if xchat.nickcmp(usr, user) == 0 or usr == '*': rslt['users'] = True continue elif name == 'str': if message.find(test) > -1: rslt['str'] = True else: rslt['str'] = False elif name == 'channels': rslt.setdefault('channels', False) for chan in test: if xchat.nickcmp(chan, channel) == 0: rslt['channels'] = True continue elif name == 'mention': rslt['mention'] = False if message.find(nick) > -1: rslt['mention'] = True continue if 'bool' in rule: if rule['bool'] == 'or' and any(rslt.values()): retval = rule break elif all(rslt.values()): retval = rule break if retval: return retval else: return None
def notbot_cb(word, word_eol, userdata): if xchat.nickcmp(xchat.get_info("nick"), "Mafuyu-chan") == 0: chan = xchat.find_context(channel="#commie-subs") if chan is None: return xchat.EAT_NONE if str.lower(word[1][0:4]) == "xdcc" or str.lower(word[1][0:5]) == "!find": test = "SAY MAFUYU-CHAN IS NOT A BOT " + str.upper(word[0]) + " MAFUYU-CHAN IS NOT 。・゚・(ノД`)・゚・。 " chan.command(test) penis = "kick " + word[0] chan.command(penis) return xchat.EAT_NONE return xchat.EAT_NONE
def setup(): global acceptlist global userlist global m acceptlist = [] userlist = xchat.get_list("users") m.SetInfo(xchat.get_info("server"), xchat.get_info("channel"), xchat.get_prefs("irc_nick1")) for x in userlist: if xchat.nickcmp(x.nick, xchat.get_prefs("irc_nick1")) == 0: acceptlist.append([x, 1]) else: acceptlist.append([x, 0])
def banned_callback(word, word_eol, userdata): # this now works on a basic level, will possibly be improved nick = xchat.get_info('nick') for user in xchat.get_list('users'): if xchat.nickcmp(nick, user.nick) == 0: userhost = user.host if not userhost: return None hostip = userhost.split('@')[1] if nick in word[1] or hostip in word[1]: growlnotify('Banned', 'You have been banned by ' + word[0])
def encrypted_broadcast(users, msg, key): global FLAG iv = crypto.GetIV() file = m.path f = open(file, 'a') f.write("\n" + time.strftime("%b") + " " + time.strftime("%a") + " " + time.strftime("%d") + " " + time.strftime("%X") + " <" + xchat.get_prefs("irc_nick1") + "> " + msg) encMsg = crypto.AES_Encrypt(b64encode(key), b64encode(iv), b64encode(msg)) sendMsg = b64encode(iv) + encMsg for x in users: if not xchat.nickcmp(x.nick, xchat.get_prefs("irc_nick1")) == 0: xchat.command("msg " + x.nick + " " + sendMsg) FLAG = 0 return xchat.EAT_ALL
def nicklist(text): _text = [] _nicklist = [ user.nick for user in xchat.get_list('users') if xchat.nickcmp(user.nick, my_nick) != 0 ] longest_nick_len = len(max(_nicklist, key=len)) for txt in text: _nick = random.choice(_nicklist) space = longest_nick_len - len(_nick) txt = "%s%s %s" % (_nick, " " * (space), txt) _text.append(txt) return _text
def quithook(self, word, word_eol, userdata): #print "quithook:", word[0] nick = word[0] sigue = False for friend in self.friends: if xchat.nickcmp(nick, friend) == 0: sigue = True break if sigue: #Reset the quitting-friend conversation self.conversations.reset(nick) return xchat.EAT_NONE
def noticecb(word, word_eol, userdata): match = NICKPATTERN.match(word[0]) matchtxt = 'Ghost with your nick has been killed.' if not match or xchat.nickcmp(match.group(1), 'NickServ') != 0: return xchat.EAT_NONE if word_eol[-2][1:] == 'Access denied.': xchat.unhook(userdata["hook"]) elif len(word_eol) > 7 and word_eol[-7][1:] == matchtxt: u = {} u.update(userdata) c = u["context"] c.command("nick " + u["nick"]) u["hook"] = xchat.hook_server("", identifycb, userdata=u) xchat.unhook(userdata["hook"]) return xchat.EAT_NONE
def encode(self, word, word_eol, userdata): #print "encode", word, word_eol interlocutor = xchat.get_context().get_info("channel") sigue = False for friend in self.friends: if xchat.nickcmp(interlocutor, friend) == 0: sigue = True if not sigue: #Send text as it comes (unencrypted to a no-friend) return xchat.EAT_NONE prefix = word_eol[0][0:PREFIXSIZE] conversation = self.conversations.get(interlocutor) if prefix in PREFIXES.itervalues(): #Send text as it comes (formated for a friend) return xchat.EAT_NONE if conversation["sndpublickey"]: #Send public key, invisible to user (raw) MsgWrapper.wrap("pub", self.pubKey, interlocutor) conversation["sndpublickey"] = False if self.keys.has_key(interlocutor): text = word_eol[0] txtKey, encryptedTxt = self.cipher(text, interlocutor) if txtKey is not None: txtSignature = self.sign(txtKey) #Send key pubkey = None if conversation["publickey"] is not None: pubkey = conversation["publickey"] else: pubkey = self.keys[interlocutor] MsgWrapper.wrap("key", pubkey.encrypt(txtKey, "")[0], interlocutor) #Send signature MsgWrapper.wrap("sig", txtSignature[0], interlocutor) #Send real message encrypted raw MsgWrapper.wrap("enc", encryptedTxt, interlocutor) #Show real message unencrypted on chat screen xchat.emit_print("Your Message", self.KEY_SYMBOL + xchat.get_info("nick"), text) return xchat.EAT_ALL else: return xchat.EAT_NONE
def weapon_continue(ctx): context = ctx['context'] channel = context.get_info('channel') for user in context.get_list('users'): for nick in ctx['nicks']: if xchat.nickcmp(user.nick, nick) == 0: username, hostname = user.host.split("@") if hostname.startswith("gateway/"): mask = "*!*%s@gateway/*" % username.lstrip("~") else: mask = "*!*@%s" % hostname context.command("mode %s +%s %s" % (channel, ctx["banmode"], mask)) if ctx["kick"]: context.command("kick %s" % user.nick) if not ctx["wasop"] and isop(): xchat.command("mode %s -o %s" % (xchat.get_info('channel'), xchat.get_info('nick')))
def spam(currenttime, currentnick): # Highlight and PM now have spam protection which previously could hang XChat global lasttime global lastnick if xchat.nickcmp(lastnick, currentnick) != 0: lasttime = time() lastnick = currentnick return False elif lasttime + 3 < currenttime: lasttime = time() return False else: lasttime = time() return True
def on_target_message(word, word_eol, userdata): global TARGET_HOST, TARGET_CHAN if TARGET_HOST and TARGET_CHAN: ctx = xchat.find_context(channel=TARGET_CHAN) if ctx: nick = word[0] host = [ user.host for user in ctx.get_list("users") if xchat.nickcmp(user.nick, nick) != 0 ] if host: if host[0] == TARGET_HOST: message = word[1] ctx.command("say %s" % message) else: error("Missing context for %s" % TARGET_CHAN) return xchat.EAT_NONE
def getLocationCB(word, word_eol, userdata): if len(word) < 2: xchat.emit_print("Server Error", __module_name__.upper() + " :Not enough parameters") else: channel = xchat.get_info("channel") if channel.startswith("#"): users = xchat.get_list('users') found = False for user in users: if not xchat.nickcmp(user.nick, word[1]): found = True loc = user.host.split('@')[1] printLocationLine(word[1], loc) if not found: xchat.emit_print("Server Error", "Can't find user %s" % word[1]) else: xchat.command('whois %s' % word[1]) return xchat.EAT_ALL
def cloudtobutt(word, word_eol, userdata): """ Callback for message printing events. Scans contents of a message for both URLs and nicks and colorizes them. This colorized output is sent along to the client """ try: nick = word[0] message = word_eol[1] except IndexError: return xchat.EAT_NONE # Prevent recursive crap and don't replace my messages if message.count('cloud') == 0 or xchat.nickcmp(nick, xchat.get_info('nick')) == 0: return xchat.EAT_NONE xchat.emit_print(userdata, word[0], message.replace('cloud', 'butt')) return xchat.EAT_ALL
def check_and_send(config_name): config_path = os.path.join(config_dir, config_name + ".conf") if not os.path.isfile(config_path): print("Cannot find " + config_path) return config = parse_config(config_path) if config is None: print(config_path + " has an invalid format") return chan = xchat.get_info("channel") if chan is None or chan != config.get('irc', 'channel'): print("Wrong channel. Expected " + config.get('irc', 'channel') + ", currently in " + str(chan)) return bot = config.get('irc', 'bot') found_bot = False for user in xchat.get_list('users'): if xchat.nickcmp(bot, user.nick) == 0: found_bot = True break if not found_bot: print("Failed to find " + bot + " in current channel") return history = parse_downloads() matched_files = get_packlist_matches(config) # Remove files we've already downloaded before matched_files = [file for file in matched_files if not file[0] in history] if len(matched_files) == 0: print("No new files to download") for idx, file in enumerate(matched_files): xchat.hook_timer(idx * 5000, xdcc_send, userdata=(config, file)) history.append(file[0]) save_downloads(history)
def getLocationCB(word, word_eol, userdata): all_users = not len(word) > 1 channel = xchat.get_info("channel") if channel.startswith("#"): users = xchat.get_list('users') found = False or all_users for user in users: loc = user.host.split('@')[1] if not all_users and not xchat.nickcmp(user.nick, word[1]): found = True if found: printLocationLine(user.nick, loc) if found and not all_users: break if not found: xchat.emit_print("Server Error", "Can't find user %s" % word[1]) elif not all_users: xchat.command('whois %s' % word[1]) else: xchat.emit_print("Generic Message", "@", "no username given or not in a channel") return xchat.EAT_ALL
def mimic(word, word_eol, userdata): global TARGET_HOST, TARGET_CHAN try: target_nick = word[1] target_chan = word[2] except IndexError: error("Missing target arguments!") else: ctx = xchat.find_context(channel=target_chan) if ctx: target_host = [ user.host for user in ctx.get_list("users") if xchat.nickcmp(user.nick, target_nick) != 0 ] if target_host: TARGET_HOST = target_host[0] TARGET_CHAN = target_chan else: error("Missing host for %s" % target_nick) else: error("Missing context for %s" % target_chan) return xchat.EAT_ALL
def italy_cb(word, word_eol, userdata): global joined global ciao global channel_name if xchat.nickcmp(xchat.get_info("channel"), channel_name) != 0: return xchat.EAT_NONE chan = xchat.find_context(channel=channel_name) if not (xchat.strip(word[0]) in joined or xchat.strip(word[0]) in ciao): return xchat.EAT_NONE if xchat.strip(word[0]) in joined: joined.remove(xchat.strip(word[0])) if word[1] == "ciao": ciao.append(xchat.strip(word[0])) return xchat.EAT_NONE if xchat.strip(word[0]) in ciao: ciao.remove(xchat.strip(word[0])) if word[1] == "!list": chan.command("kickban " + xchat.strip(word[0]) + " Italians aren't real people") return xchat.EAT_NONE
def get(self, nick): for i in self.iterkeys(): if xchat.nickcmp(nick, i) == 0: nick = i if not self.has_key(nick): super(Conversations, self).__setitem__(nick, { #RSA public key of this interlocutor currently in use "publickey": None, #AES object for incoming messages "txtkey": None, #key + initial IV pair of incoming messages "keyiv": None, #signature of initial incoming message "signature": None, #AES object for outcoming messages "sndtxtkey": None, #boolean: we need to send our public key to this interlocutor "sndpublickey": True, #buffer for multipart incoming message "multipart": "", }) return super(Conversations, self).get(nick)
def nick_to_prefix(nick): " john -> @ " userlist = xchat.get_list('users') for i in userlist: if xchat.nickcmp(nick, i.nick) == 0 : return i.prefix
def onconnectcb(word, word_eol, userdata): c = xchat.get_context() if xchat.nickcmp(c.get_info('nick'), xchat.get_prefs('irc_nick1')) != 0: c.command('nick ' + xchat.get_prefs('irc_nick1'))
def nick_to_fullname(nick): " john -> [email protected] " userlist = xchat.get_list('users') for i in userlist: if xchat.nickcmp(nick, i.nick) == 0 : return "%s!%s" % (i.nick, i.host)
def _get_channels(self, nick): return [i.context for i in xchat.get_list('channels') if i.type == 3 and 0 == xchat.nickcmp(i.channel, nick)]
def fb(word, word_eol, userdata): nicklist = [ user.nick for user in xchat.get_list('users') if xchat.nickcmp(user.nick, my_nick) != 0 ] if len(nicklist) < 1: error("No users in channel!") else: try: mode = word[1] if not mode in '1 2 3 4 5': error("Invalid mode argument!") except IndexError: error("Missing mode argument! (e.g. /fb 1, 2, 3, 4, or 5)") else: if mode in '1 2 3 4': if mode == '1': if len(word) < 4 or not '$n' in word_eol: error("Not enough arguments!") else: cmd = word[2] message = word_eol[3] for nick in nicklist: xchat.command("%s %s" % (cmd, message.replace('$n', nick))) elif mode in '2 3 4': if len(word) < 3: error("Not enough arguments!") else: message = word_eol[2] if mode == '2': message = ' '.join( [nick + ' ' + message for nick in nicklist]) xchat.command("say %s" % message) else: placeholder = [] for nick in nicklist: usr_code = color() msg_code = color() placeholder.append( "%s%s%s %s" % (usr_code, nick, msg_code, message)) if mode == '3': for line in placeholder: xchat.command("say %s" % line) else: message = ''.join(placeholder) xchat.command("say %s" % message) else: x = True for nick in nicklist: if x: message = "01,08/!\08,01* *FLASHING BAR* *01,08/!\\" x = False else: message = "08,01/!\01,08* *FLASHING BAR* *08,01/!\\" x = True space = 65 - (len(message) + len(nick)) new_msg = "%s %s> %s" % (nick, "-" * (space - 1), message) xchat.command("say %s" % new_msg) return xchat.EAT_ALL
def _get_channels(self, nick): return [ i.context for i in xchat.get_list('channels') if i.type == 3 and 0 == xchat.nickcmp(i.channel, nick) ]
def pop(self, nick, value): result = nick for i in self.iterkeys(): if xchat.nickcmp(nick, i) == 0: result = i return super(Keys, self).pop(result, value)
def decode(self, word, word_eol, userdata): #print "decode", word, word_eol, userdata interlocutor = xchat.get_info("channel") sigue = False for friend in self.friends: if xchat.nickcmp(interlocutor, friend) == 0: sigue = True break if not sigue: #Take as it comes (from no-friend) return xchat.EAT_NONE conversation = self.conversations.get(interlocutor) datatype, data = MsgWrapper.unwrap(word_eol[1] + conversation["multipart"]) #First, check for a multipart message if datatype == "mul": conversation["multipart"] = data #print "mul:", conversation["multipart"] return xchat.EAT_XCHAT else: conversation["multipart"] = "" #Check for a "public key" type message if datatype == "pub": try: pubKey = data # print pubKey assert isinstance(pubKey, RSA._RSAobj) possibleimpostor = False #Caution: negative comparation "!=" doesn't work for RSA #objects. It's always True, so you must use "not ==" instead. if self.keys.has_key(interlocutor) and \ not self.keys.get(interlocutor) == pubKey: possibleimpostor = True self.warn("Your interlocutor's public key has changed. " "She may be an impostor!! If you are sure she isn't, " "use \"/FRIEND DEL <nick>\" and then \"/FRIEND ADD " "<nick>\" commands to restore trusting. Otherwise, " "you'll keep receiving warning messages.") if not possibleimpostor: self.keys[interlocutor] = pubKey self.savekeys() conversation["publickey"] = pubKey self.conversations.reset(interlocutor) return xchat.EAT_XCHAT except Exception as inst: print inst elif datatype == "key": decoded = self.privKey.decrypt(data) key, iv = decoded[:32], decoded[32:] conversation["txtkey"] = AES.new(key, AES.MODE_CBC, iv) conversation["keyiv"] = decoded return xchat.EAT_XCHAT elif datatype == "sig": try: verified = False conversation["signature"] = (data, ) if self.verify(conversation["keyiv"], conversation["signature"], interlocutor): verified = True except Exception as inst: self.conversations.reset(interlocutor) print inst if verified: conversation["signature"] = None conversation["keyiv"] = None else: self.warn("Bad signature. " \ "Your interlocutor may be an impostor!!") return xchat.EAT_XCHAT elif datatype == "enc": try: if conversation["txtkey"] == None: exceptionmsg = "It's not possible to decrypt " \ "your interlocutor's message. She's using unkown conversation key. Send her a message to resynchronize." self.warn(exceptionmsg) raise Exception(exceptionmsg) decoded = self.decipher(conversation["txtkey"], data) xchat.emit_print(userdata, self.KEY_SYMBOL + word[0], decoded) # Decrypted correctly, so the interlocutor already has your pubkey conversation["sndpublickey"] = False return xchat.EAT_XCHAT except Exception as inst: self.conversations.reset(interlocutor) print inst return xchat.EAT_NONE
def kick_cb(word, eol, userdata): if xchat.nickcmp(word[3], xchat.get_info('nick')) == 0: xchat.command("JOIN "+word[2])