def help(self, user, chan, args): if args: topic = args.split()[0] self.fire(sendmessage(chan, '{}: {}'.format(user, self.help_msg[topic]))) else: self.fire(sendmessage(chan, user + ': ' + self.create_generic_help().format(user)))
def last_cmd(self, user, chan, args): last = user_controller.get_last_message(chan, args) if last: self.fire(sendmessage(chan, str(last))) else: if args: self.fire(sendmessage(chan, '{}: No message found for {}.'.format(user.nick, args))) else: self.fire(sendmessage(chan, '{}: No message found.'.format(user.nick)))
def stats_cmd(self, user, chan, args): func, labels = self.stat(args) if not func: self.fire( sendmessage( chan, '{}: No stats found for given labels.'.format(user.nick))) else: self.fire( sendmessage(chan, '{}: {}'.format('/'.join(labels), func())))
def help(self, user, chan, args): if args: topic = args.split()[0] self.fire( sendmessage(chan, '{}: {}'.format(user, self.help_msg[topic]))) else: self.fire( sendmessage( chan, user + ': ' + self.create_generic_help().format(user)))
def learn_factoid(self, source, channel, msg): arcuser = arcuser_controller.get_or_create_arcuser(source) for regex in regex_teach: match = regex.search(msg) if match: trigger = match.group('trigger') reply = match.group('reply') verb = match.group('verb') factoid = factoid_controller.save_factoid(arcuser, channel, trigger, reply, verb) self.fire(sendmessage(channel, '{}: Okay! Learned factoid #{} for {}'.format(source.nick, factoid.id, trigger))) return self.fire(sendmessage(channel, "{}: Sorry, I couldn't understand that factoid. Remember to include a verb!" .format(source.nick)))
def game_trigger(self, user, chan, args): cmd = args.split()[0] if len(args.split()) > 0 else 'help' args = args.split(None, 1)[1] if len(args.split()) > 1 else [] private = not chan.startswith('#') if cmd == 'help': self.help(user.nick, chan, args) elif cmd == 'join' and not private: coerce_controller.handle_join(chan, user.nick, self.send_func) elif cmd == 'quit' and not private: coerce_controller.handle_quit(chan, user.nick, self.send_func) elif cmd == 'start' and not private: coerce_controller.start_game(chan, self.send_func) elif cmd == 'score' and not private: coerce_controller.print_score(chan, user.nick, args, self.send_func) elif cmd == 'top' and not private: coerce_controller.print_top(chan, user.nick, args, self.send_func) elif cmd == 'status': #self.games[chan].player_status(user.nick) coerce_controller.print_status(chan, user.nick, self.send_func) elif cmd == 'reset' and user.admin: coerce_controller.reset_game(chan) elif cmd == 'end' and user.admin: coerce_controller.finish_game(chan, self.send_func) elif cmd == 'kick' and user.admin: coerce_controller.handle_quit(chan, args, self.send_func) else: self.fire(sendmessage(chan, '{}: Please include a command. Did you mean "help"?'.format(user.nick)))
def give_item(self, user, channel, args): arcuser = arcuser_controller.get_or_create_arcuser(user) if not args: self.fire(sendmessage(channel, '{}: What item did you want to give me?'.format(arcuser.base.nick))) return item = item_controller.add_item(creator=arcuser, channel=channel, name=args) self.fire(sendaction(channel, 'puts {} in his pocket.'.format(item.name)))
def eightball(self, user, channel, message): if message[-1] == '?': self.fire( sendmessage( channel, '{}: {}'.format(user.nick, random.choice(eightball_responses))))
def command(self, user, channel, cmd, args): if cmd == self._name: try: self._function(user, channel, args) except Exception as err: self.fire(sendmessage(channel, '{}: Error defining: {}'.format(user.nick, err))) raise
def game_trigger(self, user, chan, args): cmd = args.split()[0] if len(args.split()) > 0 else 'help' args = args.split(None, 1)[1] if len(args.split()) > 1 else [] private = not chan.startswith('#') if cmd == 'help': self.help(user.nick, chan, args) elif cmd == 'join' and not private: coerce_controller.handle_join(chan, user.nick, self.send_func) elif cmd == 'quit' and not private: coerce_controller.handle_quit(chan, user.nick, self.send_func) elif cmd == 'start' and not private: coerce_controller.start_game(chan, self.send_func) elif cmd == 'score' and not private: coerce_controller.print_score(chan, user.nick, args, self.send_func) elif cmd == 'top' and not private: coerce_controller.print_top(chan, user.nick, args, self.send_func) elif cmd == 'status': #self.games[chan].player_status(user.nick) coerce_controller.print_status(chan, user.nick, self.send_func) elif cmd == 'reset' and user.admin: coerce_controller.reset_game(chan) elif cmd == 'end' and user.admin: coerce_controller.finish_game(chan, self.send_func) elif cmd == 'kick' and user.admin: coerce_controller.handle_quit(chan, args, self.send_func) else: self.fire( sendmessage( chan, '{}: Please include a command. Did you mean "help"?'. format(user.nick)))
def print_factoid_info(self, user, channel, factoid): self.fire( sendmessage( channel, '{}: Factoid #{} was set by {} with trigger {}.'.format( user.nick, factoid.id, factoid.creator.base.nick, factoid.trigger)))
def main(): bot = IRCBot(host="irc.sudo-rmrf.net", port=6667, channel="#bot", nick="testbot") h = Help("Intro", "Outro").register(bot) UserTracker().register(bot) LastMessage().register(bot) IRCCommand('boop', lambda user, chan, args: bot.fire(sendmessage(chan, user.nick + ': bop'))).register(bot) d = Debugger().register(bot) bot.run()
def generalmessage(self, user, channel, args): if user.bot: return False if regex_bandname.fullmatch(args) and random.randint(1, 2) is 1: name = inflection.titleize(args) self.fire( sendmessage(channel, '{} would make a good band name.'.format(name)))
def last_factoid(self, user, channel, args): args = args.split() if len(args) == 0: if self.last: factoid = factoid_controller.get_factoid(self.last) self.print_factoid_info(user, channel, factoid) else: self.fire(sendmessage(channel, '{}: No recent factoid found.'.format(user.nick))) elif len(args) == 1: factoid = factoid_controller.get_factoid(int(args[0])) if factoid: self.print_factoid_info(user, channel, factoid) else: self.fire(sendmessage(channel, '{}: Could not find factoid #{}.'.format(user.nick, args[0]))) elif len(args) > 1: cmd = args[0] id = int(args[1]) if cmd == 'delete': factoid = factoid_controller.get_factoid(id) if not factoid: self.fire(sendmessage(channel, '{}: Factoid {} does not exist.'.format(user.nick, id))) elif user.admin or factoid.creator.base.id == user.id: if factoid_controller.delete_factoid(id): self.fire(sendmessage(channel, '{}: Deleted factoid #{}.'.format(user.nick, id))) else: self.fire(sendmessage(channel, '{}: Could not delete factoid #{}.'.format(user.nick, id))) else: self.fire(sendmessage(channel, "{}: Only admins can delete other users' factoids." .format(user.nick))) else: self.fire(sendmessage(channel, '{}: Command {} not available.'.format(user.nick, cmd)))
def main(): bot = IRCBot(host="irc.sudo-rmrf.net", port=6667, channel="#bot", nick="testbot") h = Help("Intro", "Outro").register(bot) UserTracker().register(bot) LastMessage().register(bot) Stats().register(bot) IRCCommand('boop', lambda user, chan, args: bot.fire(sendmessage(chan, user.nick + ': bop'))).register(bot) d = Debugger().register(bot) bot.run()
def command(self, user, channel, cmd, args): if cmd == self._name: try: self._function(user, channel, args) except Exception as err: self.fire( sendmessage( channel, '{}: Error defining: {}'.format(user.nick, err))) raise
def directmessage(self, source, channel, msg): arcuser = arcuser_controller.get_or_create_arcuser(source) for regex in regex_learn: match = regex.search(msg) if match: trigger = match.group('trigger') reply = match.group('reply') verb = match.group('verb') factoid = factoid_controller.save_factoid(arcuser, channel, trigger, reply, verb) self.fire(sendmessage(channel, '{}: Okay! Learned factoid #{} for {}'.format(source.nick, factoid.id, trigger))) return
def admin_cmd(self, user, channel, args): if not user.admin: self.fire(sendmessage(channel, '{}: You are not an admin.'.format(user.nick))) return False cmd_args = cmd_regex.match(args) if not cmd_args: self.fire(sendmessage(channel, '{}: Could not parse command.'.format(user.nick))) return False nick = cmd_args.group('nick') attribute = cmd_args.group('attribute') value = cmd_args.group('value') if user_controller.set_attribute(nick, attribute, value): self.fire(sendmessage(channel, '{}: Attribute set successfully.'.format(user.nick))) return True else: self.fire(sendmessage(channel, '{}: Attribute not set.'.format(user.nick))) return False
def last_factoid(self, user, channel, args): args = args.split() if len(args) > 0: if len(args) > 1: if user.admin: cmd = args[0] id = int(args[1]) if cmd == 'delete': if factoid_controller.delete_factoid(id): self.fire(sendmessage(channel, '{}: Deleted factoid #{}.'.format(user.nick, id))) else: self.fire(sendmessage(channel, '{}: Could not delete factoid #{}.'.format(user.nick, id))) else: self.fire(sendmessage(channel, '{}: Command {} not available.'.format(user.nick, cmd))) else: self.fire(sendmessage(channel, '{}: You are not an admin.'.format(user.nick))) else: factoid = factoid_controller.get_factoid(int(args[0])) if factoid: self.print_factoid_info(user, channel, factoid) else: self.fire(sendmessage(channel, '{}: Could not find factoid #{}.'.format(user.nick, args[0]))) else: if self.last: factoid = factoid_controller.get_factoid(self.last) self.print_factoid_info(user, channel, factoid) else: self.fire(sendmessage(channel, '{}: No recent factoid found.'.format(user.nick)))
def link_trigger(self, user, chan, args): user = user.nick if args: args = args.split() if args[0] in ['delete', 'remove']: if user.lower() == 'arctem': if args[1] in self.links: self.links.remove(args[1]) self.save() self.fire( sendmessage(chan, '{}: Link {}d.'.format(user, args[0]))) else: self.fire( sendmessage( chan, '{}: Could not find {} in links.'.format( user, args[1]))) else: self.fire( sendmessage( chan, '{}: You do not have permission to {} links.'. format(user, args[0]))) elif args[0] in self.links: self.fire( sendmessage(chan, '{}: Link already in database.'.format(user))) else: valid = Link.valid_link(args[0]) if valid == True: self.links.append(args[0]) self.save() self.fire(sendmessage(chan, '{}: Link added.'.format(user))) else: self.fire( sendmessage( chan, '{}: Could not add link: {}'.format(user, valid))) else: if self.links: self.fire( sendmessage( chan, '{}: {}'.format(user, random.choice(self.links)))) else: self.fire( sendmessage(chan, '{}: No links available.'.format(user)))
def learn_factoid(self, source, channel, msg): arcuser = arcuser_controller.get_or_create_arcuser(source) for regex in regex_teach: match = regex.search(msg) if match: trigger = match.group('trigger') reply = match.group('reply') verb = match.group('verb') factoid = factoid_controller.save_factoid( arcuser, channel, trigger, reply, verb) self.fire( sendmessage( channel, '{}: Okay! Learned factoid #{} for {}'.format( source.nick, factoid.id, trigger))) break
def generalmessage(self, user, channel, args): if user.bot: return False phrase = nltk.word_tokenize(args) tagged = nltk.pos_tag(phrase) if random.randint(0, self.count) > 100 and len(phrase) > 10: try: orig_word, new_word = self.get_replacement(tagged) new_phrase = args.replace(orig_word, new_word) self.fire(sendmessage(channel, new_phrase)) self.clean_data() except NoSwapError: self.fire(debugout("Could not swap {}.".format(tagged))) else: self.add_data(tagged) self.count += 1
def last_factoid(self, user, channel, args): args = args.split() if len(args) > 0: if len(args) > 1: if user.admin: cmd = args[0] id = int(args[1]) if cmd == 'delete': if factoid_controller.delete_factoid(id): self.fire( sendmessage( channel, '{}: Deleted factoid #{}.'.format( user.nick, id))) else: self.fire( sendmessage( channel, '{}: Could not delete factoid #{}.'.format( user.nick, id))) else: self.fire( sendmessage( channel, '{}: Command {} not available.'.format( user.nick, cmd))) else: self.fire( sendmessage( channel, '{}: You are not an admin.'.format(user.nick))) else: factoid = factoid_controller.get_factoid(int(args[0])) if factoid: self.print_factoid_info(user, channel, factoid) else: self.fire( sendmessage( channel, '{}: Could not find factoid #{}.'.format( user.nick, args[0]))) else: if self.last: factoid = factoid_controller.get_factoid(self.last) self.print_factoid_info(user, channel, factoid) else: self.fire( sendmessage( channel, '{}: No recent factoid found.'.format(user.nick)))
def choose_one(self, user, channel, message): options = choose_regex.match(message) if not options: return False options = list(options.groups()) if options[0]: #exclude the last element of options[0] because it's always blank options = options[0].split(', ')[:-1] + options[1:] else: options = options[1:] if random.randint(1, 500) == 500: if len(options) == 2: choice = 'Both.' else: choice = ' and '.join(random.sample(map(str,options), 2)) + '.' else: choice = random.choice(options) self.fire(sendmessage(channel, '{}: {}'.format(user.nick, choice))) return True
def choose_one(self, user, channel, message): options = choose_regex.match(message) if not options: return False options = list(options.groups()) if options[0]: #exclude the last element of options[0] because it's always blank options = options[0].split(', ')[:-1] + options[1:] else: options = options[1:] if random.randint(1, 500) == 500: if len(options) == 2: choice = 'Both.' else: choice = ' and '.join(random.sample(map(str, options), 2)) + '.' else: choice = random.choice(options) self.fire(sendmessage(channel, '{}: {}'.format(user.nick, choice))) return True
def generalmessage(self, user, channel, orig): if user.bot: return False matches = self.reg.findall(orig) if not matches: return False else: for m in set(matches): the, f*****g = m.split(' ') out = ['f*****g', 'the'] if the == the.upper(): out[0] = 'F*****G' elif the[0] == the[0].upper(): out[0] = 'F*****g' else: out[0] = ('f' if the[0] is 't' else 'F') + f*****g[1:] if f*****g == f*****g.upper(): out[1] = 'THE' elif f*****g[0] == f*****g[0].upper(): out[1] = 'The' else: out[1] = ('t' if f*****g[0] is 'f' else 'T') + the[1:] orig = orig.replace(m, ' '.join(out)) self.fire(sendmessage(channel, orig))
def send_func(self, chan, msg): self.fire(sendmessage(chan, msg))
def make_output(self, user, chan, args): msg = self.get_string(user.nick, args.split() or None) self.fire(sendmessage(chan, msg))
def fun(self, user, chan, args): response = phrase_maker.make(self.phrase, args or user.nick) self.fire(sendmessage(chan, response))
def generalmessage(self, user, channel, args): if user.bot: return False if regex_bandname.fullmatch(args) and random.randint(1, 2) is 1: name = inflection.titleize(args) self.fire(sendmessage(channel, '{} would make a good band name.'.format(name)))
def sendsmartmessage(self, target, message, **kwargs): message = self.perform_replacements(message, **kwargs) self.fire(sendmessage(target, message))
def eightball(self, user, channel, message): if message[-1] == '?': self.fire(sendmessage(channel, '{}: {}'.format(user.nick, random.choice(eightball_responses))))
def mangle(self, user, channel, args): try: self.fire(sendmessage(channel, '{}: {}'.format(user.nick, mangle(args)))) except Exception as err: self.fire(sendmessage(channel, '{}: Error mangling: {}'.format(user.nick, err))) raise
def help_cmd(self, user, chan, args): if args: msg = self.specific_help_message(user, chan, args) else: msg = self.general_help_message(user, chan) self.fire(sendmessage(chan, msg))
def stats_cmd(self, user, chan, args): func, labels = self.stat(args) if not func: self.fire(sendmessage(chan, '{}: No stats found for given labels.'.format(user.nick))) else: self.fire(sendmessage(chan, '{}: {}'.format('/'.join(labels), func())))
def define(self, user, channel, args): self.fire(sendmessage(channel, '{}: {}'.format(user.nick, define_command(args))))
def print_factoid_info(self, user, channel, factoid): self.fire(sendmessage(channel, '{}: Factoid #{} was set by {} with trigger {}.'.format( user.nick, factoid.id, factoid.creator.base.nick, factoid.trigger)))