def on_join(self, c, e): nick = e.source.nick # ignore the commings and goings of the GitHub bots if 'github' in nick.lower(): return if not nick == c.get_nickname(): c.privmsg(e.target, _("Welcome %s") % nick) elif self._last_kicker: c.privmsg(e.target, _("Why did you kick me, %s?") % self._last_kicker) self._last_kicker = ''
def main(): args = get_args() setup_logging() bot = FidiBot(args.channel, args.nickname, args.server, args.port, realname= args.realname, password=args.password, callsign=args.callsign) setup_client_logging(bot) try: bot.start() except KeyboardInterrupt: bot.disconnect(_("Someone closed me!")) except Exception as e: log.exception(e) bot.disconnect(_("I crashed damn it!")) raise SystemExit(4)
def on_privmsg(self, c, e): # first try to defer the message to the active modules for m in self.modules: if m.on_privmsg(c, e): return # default behaviour if no module processes the message. command = lower(e.arguments[0].split(" ", 1)[0]) if "fidi" in command: # maybe someone is calling us by name? c.privmsg(e.source.nick, _("You don't have to call me by name in private")) return log.debug("Failed to understand private message '%s' from user %s", e.arguments[0], e.source.nick) c.privmsg(e.source.nick, _("I don't understand %s") % command)
def on_privmsg(self, c, e): # first try to defer the message to the active modules for m in self.modules: if m.on_privmsg(c, e): return # default behaviour if no module processes the message. command = lower(e.arguments[0].split(" ", 1)[0]) if self.callsign in command: # maybe someone is calling us by name? c.privmsg(e.source.nick, _("You don't have to call me by name in private")) return log.debug("Failed to understand private message '%s' from user %s", e.arguments[0], e.source.nick) c.privmsg(e.source.nick, _("I don't understand %s") % command)
def cmd_say_private(self, argument): """Say the argument to the list of channels the bot is in""" if argument: for channel in self.bot.channels: self.send(channel, "%s", argument) else: self.send(self.nick, _("There's nothing to say"))
def cmd_enable_private(self, argument): """Enable self to use admin commands""" if self.bot.admins.authenticate(argument): self.bot.admins.add(self.nick) self.send(self.nick, _("User %s added to admins"), self.nick) self.logger.info("User %s added to admins" % self.nick) else: self.bot.admins.remove(self.nick) self.logger.warning("User %s tried to elevate privileges with wrong password '%s'" % (self.nick, argument))
def cmd_remadmin_private(self, argument): """Remove user(s) from admin list""" if self.is_admin: users = argument.split() for user in users: self.bot.admins.remove(user) self.send(self.nick, _("User %s removed from admins"), user) self.logger.info("User %s removed %s from admins" % (self.nick, user)) else: self.logger.warning("User %s tried to use '%s' without being admin" % (self.nick, "remadmin"))
def cmd_echo(self, argument): """ Echo back the argument, either to the channel or the user that sent us the command. """ # determine if the source was a channel or a user if argument: self.send(self.target, "%s", argument) else: self.send(self.target, _("There's nothing to echo"))
def on_pubmsg(self, c, e): # first try to defer the message to the active modules for m in self.modules: if m.on_pubmsg(c, e): return # default behaviour if no module processes the message. if "fidi" in lower(e.arguments[0]): log.debug("Failed to understand public message '%s' from user %s", e.arguments[0], e.source.nick) c.privmsg(e.target, _("Someone talking about me? Duh!"))
def cmd_echo(self, argument): """ Echo back the argument, either to the channel or the user that sent us the command. """ # determine if the source was a channel or a user target = self.channel if self.channel.startswith("#") else self.nick if argument: self.send(target, "%s", argument) else: self.send(target, _("There's nothing to echo"))
def cmd_keros(self, argument): """Gives The Temperature and Weather of Nafpaktos """ # Get the weather for Nafpaktos nafpaktos = pywapi.get_weather_from_weather_com('GRXX1283:1') # Check for errors error = nafpaktos.get('error') if error: self.logger.error(error) self.send(self.target, _("Error retrieving data: %s"), error) return # Get the Current Weather curcond = nafpaktos.get('current_conditions', {}) temp = curcond.get('temperature') text = curcond.get('text') time = curcond.get('last_updated') fmt_str = _("The Temperature is %s\nThe Weather is %s\nNafpaktos %s") self.send(self.target, fmt_str, temp, _(text), time)
def cmd_keros(self, argument): """Gives The Temperature and Weather of Nafpaktos """ target = self.channel if self.channel.startswith("#") else self.nick # Get the weather for Nafpaktos nafpaktos = pywapi.get_weather_from_weather_com('GRXX1283:1') # Check for errors error = nafpaktos.get('error') if error: self.logger.error(error) self.send(target, _("Error retrieving data: %s"), error) return # Get the Current Weather curcond = nafpaktos.get('current_conditions', {}) temp = curcond.get('temperature') text = curcond.get('text') time = curcond.get('last_updated') fmt_str = _("The Temperature is %s\nThe Weather is %s\nNafpaktos %s") self.send(target, fmt_str, temp, _(text), time)
def cmd_example(self, argument): """ An example command. Just name it cmd_<command name>. Add a docstring like this one for help to use it You can instead end your command in _public or _private so it only works for channel or private messages """ # Send something back # You should always use a formatted string so the bot can log easily # and you can use alternatives by wrapping your format string in _() self.send(self.target, _("%s"), argument)
def on_pubmsg(self, c, e): # first try to defer the message to the active modules for m in self.modules: if m.on_pubmsg(c, e): return # don't do default behaviour for the GitHub bots if 'github' in e.source.nick.lower(): return # default behaviour if no module processes the message. if self.callsign in lower(e.arguments[0]): log.debug("Failed to understand public message '%s' from user %s", e.arguments[0], e.source.nick) c.privmsg(e.target, _("Someone talking about me? Duh!"))
def cmd_help(self, argument): """Get help on a command or module""" arg = argument.lower() index = self.bot.help_index target = self.target args = arg.split() if not args: s = "usage: help <command> [public|private] / help module <module>" self.send(target, s) elif args[0] == 'module': args.pop(0) if not args: self.send(target, "usage: help module <module>") else: help_item = index['modules'].get(args[0]) if help_item: self.send(target, help_item['summary']) else: self.send(target, _("No help for %s"), args[0]) else: args.append("") cmd = args.pop(0) cmd_type = args.pop(0) if 'pu' in cmd_type or self.target.startswith('#'): cmd_type = 'public' elif 'pr' in cmd_type or not self.target.startswith('#'): cmd_type = 'private' else: # we shouldn't be here self.logger.error("cmd_list") return help_item = index[cmd_type].get(cmd) if help_item: self.send(target, index[cmd_type][cmd]['summary']) else: self.send(target, _("No help for %s"), cmd)
def cmd_example(self, argument): """ An example command. Just name it cmd_<command name>. Add a docstring like this one for help to use it You can instead end your command in _public or _private so it only works for channel or private messages """ # This is a nice recipe to get either the channel or the user, # if your command works both in channel and private target = self.channel if self.channel.startswith("#") else self.nick # Send something back # You should always use a formatted string so the bot can log easily # and you can use alternatives by wrapping your format string in _() self.send(target, _("%s"), argument)
def cmd_disconnect_private(self, argument): """Disconnect from server. Bot will try to reconnect""" self.bot.disconnect(_("I'll be back!"))
def cmd_fail(self, argument): """Give a random FAIL quote :-)""" self.send(self.target, _("FAIL mofa"))
def cmd_die_private(self, argument): """Disconnect and exit""" self.bot.die(_("Goodbye cruel world!"))
def cmd_example(self, argument): """ """ self.send(self.target, _("%s"), argument)
def cmd_fail_public(self, argument): """Give a random FAIL quote :-)""" target = self.channel self.send(target, _("FAIL mofa"))
def cmd_roll(self, argument): """ Rolling D&D style Usage: roll attack|save modifiers difficulty """ # Analyze Arguments argument = argument.split() try: roll_type = argument[0].lower() modifier = int(argument[1]) difficulty = int(argument[2]) except (IndexError, ValueError): error = _("DM: Read The Freaking PHB") self.send(self.target, error) return #Choose Between Attack or Save if "att" in roll_type: success = _("You Hit") fail = _("You Miss") crit_success = _("Critical Hit!") crit_fail = _("Critical Miss!") elif "sav" in roll_type: success = _("You Save") fail = _("You Fail") crit_success = _("Critical Save!") crit_fail = _("Critical Fail!") else: invalid = _("DM: You cannot %s") self.send(self.target, invalid, roll_type) return # ROLL roll = random.randint(1, 20) # Determine Critical if roll == 20: result = crit_success elif roll == 1: result = crit_fail # Determine Success elif (roll + modifier) >= difficulty: result = success else: result = fail # Send the result self.send(self.target, _("You roll %s. %s"), roll, result)
def cmd_die_private(self, argument): """Disconnect and exit""" if self.is_admin: self.bot.die(_("Goodbye cruel world!")) else: self.logger.warning("User %s tried to use '%s' without being admin" % (self.nick, "die"))
def cmd_say_public(self, argument): """Say the argument back to the channel the command was called""" if argument: self.send(self.channel, "%s", argument) else: self.send(self.channel, _("There's nothing to say"))
def cmd_disconnect_private(self, argument): """Disconnect from server. Bot will try to reconnect""" if self.is_admin: self.bot.disconnect(_("I'll be back!")) else: self.logger.warning("User %s tried to use '%s' without being admin" % (self.nick, "disconnect"))
def cmd_disable_private(self, argument): """Disable self from using admin commands""" if self.is_admin: self.bot.admins.remove(self.nick) self.send(self.nick, _("User %s removed from admins"), self.nick) self.logger.info("User %s removed from admins" % self.nick)
def on_join(self, c, e): nick = e.source.nick if not nick == c.get_nickname(): c.privmsg(e.target, _("Welcome %s") % nick)
def cmd_update_private(self, argument): """Exit, pending an update""" self.bot.disconnect(_("Going for an update")) raise SystemExit(42)