def on_pubmsg(self, c, e): #print e.arguments()[0] global lastUpdated if file_get_contents('hook.txt') != lastUpdated: lastUpdated = file_get_contents('hook.txt') system('git pull') out = self.prolog.communicate("['hedgehogbot.pl'].") print 'Git updated! Reloaded prolog scripts...' print out a = e.arguments()[0].split(":", 1) if len(a) > 1 and irc_lower(a[0]) == irc_lower( self.connection.get_nickname()): self.do_command(c, e, a[1].strip()) elif e.arguments()[0][:3] == "!pl": if nm_to_n(e.source()).lower() in self.admins: self.eval_command(c, e, e.arguments()[0][3:]) elif e.arguments()[0][:4] == "!say": c.privmsg(self.channel, e.arguments()[0][5:]) elif e.arguments()[0].startswith("!restart"): if nm_to_n(e.source()).lower() in self.admins: #c.privmsg("Restarting prolog side...") print "Restarting prolog side..." self.prolog.restart() elif e.arguments()[0][:5] == "!fact": fact = "assert(fact(" + e.arguments()[0][6:] + ")). remember." self.eval_command(c, e, fact) elif "om" in e.arguments()[0] and "nom" in e.arguments()[0]: c.privmsg(self.channel, simpl.omnom()) return
def on_pubmsg(self, c, e): #print e.arguments()[0] global lastUpdated if file_get_contents('hook.txt') != lastUpdated: lastUpdated = file_get_contents('hook.txt') system('git pull') out = self.prolog.communicate("['hedgehogbot.pl'].") print 'Git updated! Reloaded prolog scripts...' print out a = e.arguments()[0].split(":", 1) if len(a) > 1 and irc_lower(a[0]) == irc_lower(self.connection.get_nickname()): self.do_command(c, e, a[1].strip()) elif e.arguments()[0][:3] == "!pl": if nm_to_n(e.source()).lower() in self.admins: self.eval_command(c, e, e.arguments()[0][3:]) elif e.arguments()[0][:4] == "!say": c.privmsg(self.channel, e.arguments()[0][5:]) elif e.arguments()[0].startswith("!restart"): if nm_to_n(e.source()).lower() in self.admins: #c.privmsg("Restarting prolog side...") print "Restarting prolog side..." self.prolog.restart() elif e.arguments()[0][:5] == "!fact": fact = "assert(fact("+e.arguments()[0][6:]+")). remember." self.eval_command(c, e, fact) elif "om" in e.arguments()[0] and "nom" in e.arguments()[0]: c.privmsg(self.channel, simpl.omnom()) return
def on_ctcp(self, c, e): """Default handler for ctcp events. Replies to VERSION and PING requests and relays DCC requests to the on_dccchat method. """ if e.arguments()[0] == "VERSION": c.ctcp_reply(nm_to_n(e.source()), "VERSION " + self.get_version()) elif e.arguments()[0] == "PING": if len(e.arguments()) > 1: c.ctcp_reply(nm_to_n(e.source()), "PING " + e.arguments()[1]) elif e.arguments()[0] == "DCC" and e.arguments()[1].split(" ", 1)[0] == "CHAT": self.on_dccchat(c, e)
def do_command(self, e, cmd): nick = nm_to_n(e.source()) c = self.connection if cmd == "disconnect": self.disconnect() elif cmd == "die": self.die() elif cmd == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = chobj.users() users.sort() c.notice(nick, "Users: " + ", ".join(users)) opers = chobj.opers() opers.sort() c.notice(nick, "Opers: " + ", ".join(opers)) voiced = chobj.voiced() voiced.sort() c.notice(nick, "Voiced: " + ", ".join(voiced)) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp("DCC", nick, "CHAT chat %s %d" % ( ip_quad_to_numstr(dcc.localaddress), dcc.localport)) else: c.notice(nick, "Not understood: " + cmd)
def _on_part(self, c, e): nick = nm_to_n(e.source()) channel = e.target() if nick == c.get_nickname(): del self.channels[channel] else: self.channels[channel].remove_user(nick)
def on_pubmsg(self, c, e): arguments = e.arguments()[0] should_respond = False try: test_str = arguments.decode('ascii') if arguments.startswith(('stack', self.nickname)): should_respond = True except UnicodeDecodeError: should_respond = False if (should_respond): # Make sure they were talking to us, and then print # their stack to the channel. user = nm_to_n(e.source()) self.do_command(arguments, c, user, self.channel)
def do_command(self, c, e, cmd): nick = nm_to_n(e.source()) c = self.connection if nick.lower() in config.BOT_IGNORE: return elif nick.lower() in self.ignore: c.privmsg(self.channel, nick + ": EAT A DICK") return if cmd == "disconnect": self.prolog.terminate() self.disconnect() elif cmd == "die": self.prolog.terminate() self.die() elif cmd[:5] == "admin": self.admins.update([cmd[6:].lower()]) elif cmd[:6] == "ignore": print cmd[:6], '-', cmd[7:].lower() self.ignore.update([cmd[7:].lower()]) elif cmd == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = chobj.users() users.sort() c.notice(nick, "Users: " + ", ".join(users)) opers = chobj.opers() opers.sort() c.notice(nick, "Opers: " + ", ".join(opers)) voiced = chobj.voiced() voiced.sort() c.notice(nick, "Voiced: " + ", ".join(voiced)) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp( "DCC", nick, "CHAT chat %s %d" % (ip_quad_to_numstr(dcc.localaddress), dcc.localport)) elif cmd[:8] == "unignore": self.ignore.discard(cmd[9:].lower()) else: out = self.prolog.communicate("single. \"" + cmd + "\".") if (len(out) >= 1): print nick, '-', out c.privmsg(self.channel, nick + ": " + out)
def do_command(self, c, e, cmd): nick = nm_to_n(e.source()) c = self.connection if nick.lower() in config.BOT_IGNORE: return elif nick.lower() in self.ignore: c.privmsg(self.channel, nick+": EAT A DICK") return if cmd == "disconnect": self.prolog.terminate() self.disconnect() elif cmd == "die": self.prolog.terminate() self.die() elif cmd[:5] == "admin": self.admins.update([cmd[6:].lower()]) elif cmd[:6] == "ignore": print cmd[:6], '-', cmd[7:].lower() self.ignore.update([cmd[7:].lower()]) elif cmd == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = chobj.users() users.sort() c.notice(nick, "Users: " + ", ".join(users)) opers = chobj.opers() opers.sort() c.notice(nick, "Opers: " + ", ".join(opers)) voiced = chobj.voiced() voiced.sort() c.notice(nick, "Voiced: " + ", ".join(voiced)) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp("DCC", nick, "CHAT chat %s %d" % ( ip_quad_to_numstr(dcc.localaddress), dcc.localport)) elif cmd[:8] == "unignore": self.ignore.discard(cmd[9:].lower()) else: out = self.prolog.communicate("single. \""+cmd+"\".") if(len(out) >= 1): print nick,'-',out c.privmsg(self.channel, nick+": "+out)
def eval_command(self, c, e, cmd): nick = nm_to_n(e.source()).lower() c = self.connection if len(cmd) <= 1: return if cmd[-1] == '.': if nick in self.cmdbuffer.keys(): cmd = ''.join(self.cmdbuffer[nick]) + cmd self.cmdbuffer[nick] = [] else: self.cmdbuffer[nick] = [] out = self.prolog.communicate(cmd) print nick, '-', out c.privmsg(self.channel, nick + ": " + out) else: if nick in self.cmdbuffer.keys(): self.cmdbuffer[nick].append(cmd) else: self.cmdbuffer[nick] = [] self.cmdbuffer[nick].append(cmd)
def eval_command(self,c, e, cmd): nick = nm_to_n(e.source()).lower() c = self.connection if len(cmd) <= 1: return if cmd[-1] == '.': if nick in self.cmdbuffer.keys(): cmd = ''.join(self.cmdbuffer[nick]) + cmd self.cmdbuffer[nick] = [] else: self.cmdbuffer[nick] = [] out = self.prolog.communicate(cmd) print nick,'-',out c.privmsg(self.channel, nick+": "+out) else: if nick in self.cmdbuffer.keys(): self.cmdbuffer[nick].append(cmd) else: self.cmdbuffer[nick] = [] self.cmdbuffer[nick].append(cmd)
def do_command(self, e): cmd = e.arguments()[0].strip() c = self.connection nick = nm_to_n(e.source()) if "cups" in nick.lower(): return channel = e.target() # note that this might be a private query if channel[:1] not in ['#', '&', '+', '!']: channel = nick pass if re.search("c+u+p", cmd.lower()) == None: return print '(' + channel + ')' + "< " + nick + "> " + cmd if len(cmd) > 1 and cmd[0] == '!': self.load_db() to_add = cmd[1:].upper().strip() if to_add not in self.db: with open(self.dblocat, 'w') as f: self.db.append(to_add) cPickle.dump(self.db, f) pass c.privmsg(channel, nick + ": reply added!") pass else: c.privmsg( channel, nick + ": your cups-foo is strong. BUT MINE IS STRONGER!") pass return else: if len(self.db) == 0: # db is not loaded self.load_db() pass c.privmsg(channel, random.choice(self.db)) return pass
def do_command(self, e): cmd = e.arguments()[0].strip() c = self.connection nick = nm_to_n(e.source()) if "cups" in nick.lower(): return channel = e.target() # note that this might be a private query if channel[:1] not in ['#', '&', '+', '!']: channel = nick pass if re.search("c+u+p", cmd.lower()) == None: return print '(' + channel + ')' + "< " + nick + "> " + cmd if len(cmd) > 1 and cmd[0] == '!': self.load_db() to_add = cmd[1:].upper().strip() if to_add not in self.db: with open(self.dblocat, 'w') as f: self.db.append(to_add) cPickle.dump(self.db, f) pass c.privmsg(channel, nick + ": reply added!") pass else: c.privmsg(channel, nick + ": your cups-foo is strong. BUT MINE IS STRONGER!") pass return else: if len(self.db) == 0: # db is not loaded self.load_db() pass c.privmsg(channel, random.choice(self.db)) return pass
def getSource(self, event): return irclib.nm_to_n(event.source())
def _on_join(self, c, e): ch = e.target() nick = nm_to_n(e.source()) if nick == c.get_nickname(): self.channels[ch] = Channel() self.channels[ch].add_user(nick)
def _on_nick(self, c, e): before = nm_to_n(e.source()) after = e.target() for ch in self.channels.values(): if ch.has_user(before): ch.change_nick(before, after)
def _on_quit(self, c, e): nick = nm_to_n(e.source()) for ch in self.channels.values(): if ch.has_user(nick): ch.remove_user(nick)
def replyChannel(self, event, reply): Nick = irclib.nm_to_n(event.source()) Channel = event.target() if Nick != None: self.say(Channel, ": ".join([Nick, reply])) return
def inform_webusers(self, c, e): nick = nm_to_n(e.source()) if nick.startswith("fsiWeb"): c.privmsg(nick, "Wenn du dich auf der Fachschaftsseite anmeldest, kannst du in deinen Einstellungen einen Nick für den Webchat festlegen.")
def parseMessage(self, c, e, type): nick = nm_to_n(e.source()) if nick.lower() == "nickserv" and type == "private": if "This nickname is registered." in e.arguments()[0]: self.identify() return # Splitting the string into command and arguments args = e.arguments()[0].split() # Check if message is empty if len(args) == 0: return cmd = args[0].lower() args.pop(0) if self.DEBUG: self.log("Parsing " + str(type) + " command '" + str(cmd) + "' with '" + str(args) + "' from '" + str(nick) + "'") # Hardcoded oper commands if self.isOper(nick): if cmd == "!say": self.sendPublicMessage(str(' '.join(args))) return if cmd == "!mod": if len(args) < 1: self.sendPrivateMessage(nick, "Usage: !mod option [module]") self.sendPrivateMessage(nick, "option: list, add, rm") return if args[0].lower() == "list": self.sendPrivateMessage(nick, "List of modules:") active = [] for mod in self.activeModules: active.append(mod.__class__.__name__) available = self.getAvailableModules() for mod in available: status = "[ ]" if mod in active: status = "[*]" self.sendPrivateMessage(nick, status + " " + mod) return if args[0].lower() == "add": if len(args) < 2: self.sendPrivateMessage(nick, "Usage: !mod add module") return addmod = "" available = self.getAvailableModules() for mod in available: if mod.lower() == args[1].lower() or mod.lower() == args[1].lower() + "module": addmod = mod if addmod is "": self.sendPrivateMessage(nick, "No module added, check spelling.") return for mod in self.activeModules: modname = mod.__class__.__name__ if modname == addmod: self.sendPrivateMessage(nick, "Module already active.") return try: self.addModule(addmod) self.sendPrivateMessage(nick, "Module '" + addmod + "' added.") self.log(nick + " added module '" + addmod + "'") except Exception as e: self.sendPrivateMessage(nick, "Exception returned: " + str(e)) return if args[0].lower() == "rm" or args[0].lower() == "remove": if len(args) < 2: self.sendPrivateMessage(nick, "Usage: !mod rm module") return index = -1 rmmod = args[1].lower() for i, mod in enumerate(self.activeModules): modname = mod.__class__.__name__ if modname.lower() == rmmod or modname.lower() == rmmod + "module": index = i rmmod = modname if index != -1: del self.activeModules[index] self.sendPrivateMessage(nick, "Module '" + rmmod + "' removed.") self.log(nick + " removed module '" + rmmod + "'") else: self.sendPrivateMessage(nick, "No module removed.") return return if cmd == "!reload": self.log(nick + " triggered reload.") self.sendPrivateMessage(nick, "Reloading " + str(len(self.activeModules)) + " modules...") self.reload() self.sendPrivateMessage(nick, "done.") return if cmd == "!restart": self.log(nick + " triggered restart.") self.restart() return # Contact information for fsi if cmd == "!kontakt": self.sendPrivateMessage(nick, "E-Mail: [email protected] :: Tel: 0721 925-1448") return # User requested help. Send introduction string, then all help strings from all modules # Also, hardcoded strings. if cmd == "!help": self.sendPrivateMessage(nick, "Hallo " + nick + ", ich bin der Bot der Fachschaft Informatik. Hier sind meine Befehle:") self.sendPrivateMessage(nick, "!kontakt - Zeigt dir Kontaktinformationen zur Fachschaft an.") for module in self.activeModules: module.help(nick) if self.isOper(nick): self.sendPrivateMessage(nick, "Befehle für Ops:") self.sendPrivateMessage(nick, "!reload - Lädt alle aktiven Module neu") self.sendPrivateMessage(nick, "!restart - Startet den Bot neu (nützlich nach einem Upgrade)") self.sendPrivateMessage(nick, "!mod - Modulverwaltung") return # every string that starts with an '!' is considered to be an command for module in self.activeModules: try: if cmd.startswith("!"): newType = BotCommand.UNKNOWN if type == 'public': newType = BotCommand.PUBLIC if type == 'private': newType = BotCommand.PRIVATE module.command(BotCommand(self, nick, newType, cmd, args)) #module.command(nick, cmd, args, type) else: module.onMessage(type, e.arguments()[0]) except Exception as e: self.sendPublicMessage("Module '" + str(module) + "' crashed with '" + str(e) + "', removing.") print traceback.format_exc() del self.activeModules[self.activeModules.index(module)]
def on_privmsg(self, c, e): # If this was a private message, just send the stack # to that user. user = nm_to_n(e.source()) self.do_command(e.arguments()[0], c, user, user)
def replyMsg(self, event, reply): self.msg(irclib.nm_to_n(event.source()), reply) return