def is_reload(self, e): cmd = e.arguments[0].strip() if not cmd: return None cmd = misc.get_cmdchar(self.config, self.connection, cmd, e.type) cmdchar = self.config['core']['cmdchar'] if cmd.split()[0] == '%sreload' % cmdchar or cmd.split()[0] == '%sr' % cmdchar: return cmd else: return None
def is_reload(self, e): cmd = e.arguments[0].strip() if not cmd: return None cmd = misc.get_cmdchar(self.config, self.connection, cmd, e.type) cmdchar = self.config['core']['cmdchar'] if cmd.split()[0] == '%sreload' % cmdchar: return cmd else: return None
def check_reload(self, target, c, e, msgtype): cmd = e.arguments[0].strip() if not cmd: return cmd = misc.get_cmdchar(self.config, c, cmd, msgtype) cmdchar = self.config['core']['cmdchar'] if cmd.split()[0] == '%sreload' % cmdchar: admins = [x.strip() for x in self.config['auth']['admins'].split(',')] if e.source.nick not in admins: c.privmsg(target, "Nope, not gonna do it.") else: cmdargs = cmd[len('%sreload' % cmdchar) + 1:] self.do_reload(c, target, cmdargs)
def handle_msg(self, msgtype, c, e): """The Heart and Soul of IrcBot.""" # actions don't have the nick attr for some reason if msgtype == 'action': nick = e.source.split('!')[0] else: nick = e.source.nick # modes have separate arguments, everything else just one if msgtype == 'mode' or msgtype == 'nick' or msgtype == 'join': msg = " ".join(e.arguments) else: msg = e.arguments[0].strip() # Send the response to private messages to the sending nick. if msgtype == 'privmsg' or msgtype == 'privnotice': target = nick else: target = e.target send = lambda msg, mtype='privmsg', target=target: self.send(target, self.config['core']['nick'], msg, mtype) if msgtype == 'privnotice': if not hasattr(self, 'connection'): return if nick == 'NickServ': admin.set_admin(msg, self) return if self.config['feature'].getboolean('hooks') and nick not in self.ignored: for hook in self.hooks: realargs = self.do_args(hook.args, send, nick, target, e.source, c, hook, msgtype) hook.run(send, msg, msgtype, self, target, realargs) if msgtype == 'nick': if e.target in self.admins: c.privmsg('NickServ', 'ACC %s' % e.target) if identity.handle_nick(self, e): for x in misc.get_channels(self.channels, e.target): self.do_kick(send, x, e.target, "identity crisis") return # must come after set_admin to prevent spam self.do_log(target, nick, msg, msgtype) if msgtype == 'mode': self.do_mode(target, msg, nick, send) return if msgtype == 'join': if nick == c.real_nickname: send("Joined channel %s" % target, target=self.config['core']['ctrlchan']) return # ignore empty messages if not msg: return if e.target == self.config['core']['ctrlchan']: control.handle_ctrlchan(self, msg, c, send) if not self.is_admin(send, nick, False) and nick in self.ignored: return msg = misc.get_cmdchar(self.config, c, msg, msgtype) cmd = msg.split()[0] cmdchar = self.config['core']['cmdchar'] admins = [x.strip() for x in self.config['auth']['admins'].split(',')] # handle !s cmdlen = len(cmd) + 1 if cmd.startswith('%ss' % cmdchar): match = re.match('%ss(\W)' % cmdchar, cmd) if match: cmd = cmd.split(match.group(1))[0] cmdlen = len(cmd) cmdargs = msg[cmdlen:] found = False if cmd.startswith(cmdchar): cmd_name = cmd[len(cmdchar):] if command.is_registered(cmd_name): found = True cmd_obj = command.get_command(cmd_name) if cmd_obj.is_limited() and self.abusecheck(send, nick, target, cmd_obj.limit, cmd[len(cmdchar):]): return # Duplicate command if command.check_command(self.db.get(), nick, msg, target): return args = self.do_args(cmd_obj.args, send, nick, target, e.source, c, cmd_name, msgtype) cmd_obj.run(send, cmdargs, args, cmd_name, nick, target, self) # special commands if cmd.startswith(cmdchar): if cmd[len(cmdchar):] == 'reload': if nick in admins: found = True self.do_reload() send("Aye Aye Capt'n") # everything below this point requires admin if not found and self.is_admin(send, nick): self.do_admin(c, cmd[len(cmdchar):], cmdargs, send, nick, msgtype, target)
def handle_msg(self, msgtype, c, e): """The Heart and Soul of IrcBot.""" # actions don't have the nick attr for some reason if msgtype == 'action': nick = e.source.split('!')[0] else: nick = e.source.nick # modes have separate arguments, everything else just one if msgtype == 'mode' or msgtype == 'nick' or msgtype == 'join': msg = " ".join(e.arguments) else: msg = e.arguments[0].strip() # Send the response to private messages to the sending nick. if msgtype == 'privmsg' or msgtype == 'privnotice': target = nick else: target = e.target send = lambda msg, mtype='privmsg', target=target: self.send(target, self.config['core']['nick'], msg, mtype) if msgtype == 'privnotice': # FIXME: come up with a better way to prevent admin abuse. if nick == 'NickServ': admin.set_admin(msg, self) return if msgtype == 'pubnotice': return if self.config['feature'].getboolean('hooks') and nick not in self.ignored: for h in self.hooks: realargs = self.do_args(h.args, send, nick, target, e.source, c, h, msgtype) try: h.run(send, msg, msgtype, self, target, realargs) except InternalError: self.db.rollback() if msgtype == 'nick': if e.target in self.admins: c.send_raw('NS ACC %s' % e.target) if identity.handle_nick(self, e): for x in misc.get_channels(self.channels, e.target): self.do_kick(send, x, e.target, "identity crisis") return # must come after set_admin to prevent spam self.do_log(target, nick, msg, msgtype) if msgtype == 'mode': self.do_mode(target, msg, nick, send) return if msgtype == 'join': if nick == c.real_nickname: send("Joined channel %s" % target, target=self.config['core']['ctrlchan']) return # ignore empty messages if not msg: return if e.target == self.config['core']['ctrlchan']: control.handle_ctrlchan(self, msg, c, send) if not self.is_admin(send, nick, False) and nick in self.ignored: return msg = misc.get_cmdchar(self.config, c, msg, msgtype) cmd = msg.split()[0] cmdchar = self.config['core']['cmdchar'] admins = [x.strip() for x in self.config['auth']['admins'].split(',')] # handle !s cmdlen = len(cmd) + 1 if cmd.startswith('%ss' % cmdchar): match = re.match('%ss(\W)' % cmdchar, cmd) if match: cmd = cmd.split(match.group(1))[0] cmdlen = len(cmd) cmdargs = msg[cmdlen:] found = False if cmd.startswith(cmdchar): cmd_name = cmd[len(cmdchar):] if command.is_registered(cmd_name): found = True cmd_obj = command.get_command(cmd_name) if cmd_obj.is_limited() and self.abusecheck(send, nick, target, cmd_obj.limit, cmd[len(cmdchar):]): return try: # Duplicate command if command.check_command(self.db.get(), nick, msg, target): return args = self.do_args(cmd_obj.args, send, nick, target, e.source, c, cmd_name, msgtype) cmd_obj.run(send, cmdargs, args, cmd_name, nick, target, self) except InternalError: self.db.rollback() # special commands if cmd.startswith(cmdchar): if cmd[len(cmdchar):] == 'reload': if nick in admins: found = True self.do_reload() send("Aye Aye Capt'n") # everything below this point requires admin if not found and self.is_admin(send, nick): self.do_admin(c, cmd[len(cmdchar):], cmdargs, send, nick, msgtype, target)
def handle_msg(self, c, e): """The Heart and Soul of IrcBot.""" if e.type not in ['authenticate', 'join', 'part', 'quit']: nick = e.source.nick else: nick = e.source # cap and kick have multiple arguments. if e.type in ['cap', 'kick']: msg = " ".join(e.arguments).strip() elif e.arguments: msg = e.arguments[0].strip() else: # join and nick don't have any arguments. msg = "" # Send the response to private messages to the sending nick. target = nick if e.type == 'privmsg' else e.target def send(msg, mtype='privmsg', target=target, ignore_length=False): self.send(target, self.connection.real_nickname, msg, mtype, ignore_length) if e.type in ['authenticate', 'bannedfromchan', 'cap', 'ctcpreply', 'error', 'nosuchnick', 'nick', 'nicknameinuse', 'privnotice', 'welcome']: self.handle_event(msg, send, c, e) return # ignore empty messages if not msg and e.type != 'join': return self.do_log(target, nick, msg, e.type) if e.type == 'mode': self.do_mode(target, msg, nick, send) return if e.type == 'join': if nick == c.real_nickname: send("Joined channel %s" % target, target=self.config['core']['ctrlchan']) return if e.type == 'part': if nick == c.real_nickname: send("Parted channel %s" % target, target=self.config['core']['ctrlchan']) return if e.type == 'kick': if nick == c.real_nickname: send("Kicked from channel %s" % target, target=self.config['core']['ctrlchan']) # Auto-rejoin after 5 seconds. self.workers.defer(5, False, self.connection.join, target) return if e.target == self.config['core']['ctrlchan'] and self.is_admin(None, nick): control.handle_ctrlchan(self, msg, send) if self.is_ignored(nick) and not self.is_admin(None, nick): return if self.config['feature'].getboolean('hooks'): for h in hook.get_hook_objects(): realargs = self.do_args(h.args, send, nick, target, e.source, h, e.type) h.run(send, msg, e.type, self, target, realargs) msg = misc.get_cmdchar(self.config, c, msg, e.type) cmd = msg.split()[0] cmdchar = self.config['core']['cmdchar'] admins = [x.strip() for x in self.config['auth']['admins'].split(',')] cmdlen = len(cmd) + 1 # FIXME: figure out a better way to handle !s if cmd.startswith('%ss' % cmdchar): # escape special regex chars raw_cmdchar = '\\' + cmdchar if re.match(r'[\[\].^$*+?]', cmdchar) else cmdchar match = re.match(r'%ss(\W)' % raw_cmdchar, cmd) if match: cmd = cmd.split(match.group(1))[0] cmdlen = len(cmd) cmdargs = msg[cmdlen:] cmd_name = cmd[len(cmdchar):] if cmd.startswith(cmdchar) else None cmdargs, filtersend = self.get_filtered_send(cmdargs, send, target) if filtersend is None: send(cmdargs) return if command.is_registered(cmd_name): cmd_obj = command.get_command(cmd_name) if cmd_obj.is_limited() and self.abusecheck(send, nick, target, cmd_obj.limit, cmd[len(cmdchar):]): return if cmd_obj.requires_admin() and not self.is_admin(send, nick): send("This command requires admin privileges.") return args = self.do_args(cmd_obj.args, send, nick, target, e.source, cmd_name, e.type) cmd_obj.run(filtersend, cmdargs, args, cmd_name, nick, target, self) # special commands elif cmd[len(cmdchar):] == 'reload' or cmd[len(cmdchar):] == 'r': if nick in admins: send("Aye Aye Capt'n")
def handle_msg(self, msgtype, c, e): """The Heart and Soul of IrcBot.""" nick = e.source.nick # modes have separate arguments, everything else just one if msgtype == 'mode' or msgtype == 'nick' or msgtype == 'join': msg = " ".join(e.arguments) else: msg = e.arguments[0].strip() # ignore empty messages if not msg: return # Send the response to private messages to the sending nick. if msgtype == 'privmsg' or msgtype == 'privnotice': target = nick else: target = e.target def send(msg, mtype='privmsg', target=target): self.send(target, self.connection.real_nickname, msg, mtype) if msgtype == 'privnotice': # FIXME: come up with a better way to prevent admin abuse. if nick == 'NickServ': admin.set_admin(msg, self) return if self.config['feature'].getboolean('hooks') and not self.is_ignored(nick): for h in self.hooks.values(): realargs = self.do_args(h.args, send, nick, target, e.source, h, msgtype) h.run(send, msg, msgtype, self, target, realargs) if msgtype == 'nick': if self.config['feature'].getboolean('nickserv') and e.target in self.admins: c.send_raw('NS ACC %s' % e.target) if identity.handle_nick(self, e): for x in misc.get_channels(self.channels, e.target): self.do_kick(send, x, e.target, "identity crisis") return # must come after set_admin to prevent spam from all the NickServ ACC responses # We log nick changes in bot.py so that they show up for all channels. self.do_log(target, nick, msg, msgtype) if msgtype == 'mode': self.do_mode(target, msg, nick, send) return if msgtype == 'join': if nick == c.real_nickname: send("Joined channel %s" % target, target=self.config['core']['ctrlchan']) return if e.target == self.config['core']['ctrlchan'] and self.is_admin(None, nick): control.handle_ctrlchan(self, msg, send) if self.is_ignored(nick) and not self.is_admin(None, nick): return msg = misc.get_cmdchar(self.config, c, msg, msgtype) cmd = msg.split()[0] cmdchar = self.config['core']['cmdchar'] admins = [x.strip() for x in self.config['auth']['admins'].split(',')] # handle !s cmdlen = len(cmd) + 1 if cmd.startswith('%ss' % cmdchar): # escape special regex chars raw_cmdchar = '\\' + cmdchar if re.match(r'[\[\].^$*+?]', cmdchar) else cmdchar match = re.match(r'%ss(\W)' % raw_cmdchar, cmd) if match: cmd = cmd.split(match.group(1))[0] cmdlen = len(cmd) cmdargs = msg[cmdlen:] if cmd.startswith(cmdchar) and not msgtype == 'action': cmd_name = cmd[len(cmdchar):] if command.is_registered(cmd_name): cmd_obj = command.get_command(cmd_name) if cmd_obj.is_limited() and self.abusecheck(send, nick, target, cmd_obj.limit, cmd[len(cmdchar):]): return if cmd_obj.requires_admin() and not self.is_admin(send, nick): send("This command requires admin privileges.") return args = self.do_args(cmd_obj.args, send, nick, target, e.source, cmd_name, msgtype) cmd_obj.run(send, cmdargs, args, cmd_name, nick, target, self) # special commands elif cmd[len(cmdchar):] == 'reload': if nick in admins: send("Aye Aye Capt'n")
def handle_msg(self, c, e): """The Heart and Soul of IrcBot.""" if e.type not in ['authenticate', 'join', 'part', 'quit']: nick = e.source.nick else: nick = e.source # cap and kick have multiple arguments. if e.type in ['cap', 'kick']: msg = " ".join(e.arguments).strip() elif e.arguments: msg = e.arguments[0].strip() else: # join and nick don't have any arguments. msg = "" # Send the response to private messages to the sending nick. target = nick if e.type == 'privmsg' else e.target def send(msg, mtype='privmsg', target=target, ignore_length=False): self.send(target, self.connection.real_nickname, msg, mtype, ignore_length) if e.type in ['903', 'authenticate', 'bannedfromchan', 'cap', 'ctcpreply', 'error', 'nosuchnick', 'nick', 'nicknameinuse', 'privnotice', 'welcome']: self.handle_event(msg, send, c, e) return # ignore empty messages if not msg and e.type != 'join': return self.do_log(target, nick, msg, e.type) if e.type == 'mode': self.do_mode(target, msg, nick, send) return if e.type == 'join': if nick == c.real_nickname: send("Joined channel %s" % target, target=self.config['core']['ctrlchan']) return if e.type == 'part': if nick == c.real_nickname: send("Parted channel %s" % target, target=self.config['core']['ctrlchan']) return if e.type == 'kick': if nick == c.real_nickname: send("Kicked from channel %s" % target, target=self.config['core']['ctrlchan']) # Auto-rejoin after 5 seconds. self.workers.defer(5, False, self.connection.join, target) return if e.target == self.config['core']['ctrlchan'] and self.is_admin(None, nick): control.handle_ctrlchan(self, msg, send) if self.is_ignored(nick) and not self.is_admin(None, nick): return if self.config['feature'].getboolean('hooks'): for h in hook.get_hook_objects(): realargs = self.do_args(h.args, send, nick, target, e.source, h, e.type) h.run(send, msg, e.type, self, target, realargs) msg = misc.get_cmdchar(self.config, c, msg, e.type) cmd = msg.split()[0] cmdchar = self.config['core']['cmdchar'] admins = [x.strip() for x in self.config['auth']['admins'].split(',')] cmdlen = len(cmd) + 1 # FIXME: figure out a better way to handle !s if cmd.startswith('%ss' % cmdchar): # escape special regex chars raw_cmdchar = '\\' + cmdchar if re.match(r'[\[\].^$*+?]', cmdchar) else cmdchar match = re.match(r'%ss(\W)' % raw_cmdchar, cmd) if match: cmd = cmd.split(match.group(1))[0] cmdlen = len(cmd) cmdargs = msg[cmdlen:] cmd_name = cmd[len(cmdchar):] if cmd.startswith(cmdchar) else None cmdargs, filtersend = self.get_filtered_send(cmdargs, send, target) if filtersend is None: send(cmdargs) return if command.is_registered(cmd_name): cmd_obj = command.get_command(cmd_name) if cmd_obj.is_limited() and self.abusecheck(send, nick, target, cmd_obj.limit, cmd[len(cmdchar):]): return if cmd_obj.requires_admin() and not self.is_admin(send, nick): send("This command requires admin privileges.") return args = self.do_args(cmd_obj.args, send, nick, target, e.source, cmd_name, e.type) cmd_obj.run(filtersend, cmdargs, args, cmd_name, nick, target, self) # special commands elif cmd[len(cmdchar):] == 'reload': if nick in admins: send("Aye Aye Capt'n")