diff --git a/yaboli/bot.py b/yaboli/bot.py index 0b00f02..beb0f15 100644 --- a/yaboli/bot.py +++ b/yaboli/bot.py @@ -110,7 +110,7 @@ class Bot(): or no helptext at all. If the command is not bot specific, no id has to be specified if there are multiple bots - with the same name in a room. + with the same nick in a room. """ command = command.lower() @@ -138,22 +138,22 @@ class Bot(): call_command(message) -> None Calls all functions subscribed to the command with the arguments supplied in the message. - Deals with the situation that multiple bots of the same type and name are in the same room. + Deals with the situation that multiple bots of the same type and nick are in the same room. """ try: - command, bot_id, name, arguments, flags, options = self.parse(message.content) + command, bot_id, nick, arguments, flags, options = self.parse(message.content) except exceptions.ParseMessageException: return + else: + nick = self.room.mentionable(nick).lower() if not self.commands.exists(command): return - if not name == self.mentionable().lower(): + if not nick == self.mentionable().lower(): return - name = self.room.mentionable(name).lower() - if bot_id is not None: # id specified if self.manager.get(bot_id) == self: self.commands.call(command, message, arguments, flags, options) @@ -161,16 +161,16 @@ class Bot(): return else: # no id specified - bots = self.manager.get_similar(self.roomname(), name) + bots = self.manager.get_similar(self.roomname(), nick) if self.manager.get_id(self) == min(bots): # only one bot should act # either the bot is unique or the command is not bot-specific if not command in self.bot_specific_commands or len(bots) == 1: self.commands.call(command, message, arguments, flags, options) else: # user has to select a bot - msg = ("There are multiple bots with that name in this room. To select one,\n" + msg = ("There are multiple bots with that nick in this room. To select one,\n" "please specify its id (from the list below) as follows:\n" - "!{} @{} [your arguments...]\n").format(command, name) + "!{} @{} [your arguments...]\n").format(command, nick) for bot_id in sorted(bots): bot = bots[bot_id] @@ -272,7 +272,7 @@ class Bot(): def parse_command(self, message): """ - parse_command(message_content) -> command, bot_id, name, argpart + parse_command(message_content) -> command, bot_id, nick, argpart Parse the "!command[ bot_id] @botname[ argpart]" part of a command. """ @@ -283,7 +283,7 @@ class Bot(): if split[0][:1] != "!": raise exceptions.ParseMessageException("Not a command") elif not len(split) > 1: - raise exceptions.ParseMessageException("No bot name") + raise exceptions.ParseMessageException("No bot nick") command = split[0][1:].lower() message = split[1] @@ -296,16 +296,16 @@ class Bot(): bot_id = None else: if not len(split) > 1: - raise exceptions.ParseMessageException("No bot name") + raise exceptions.ParseMessageException("No bot nick") message = split[1] split = message.split(maxsplit=1) - # bot name (@mention) + # bot nick (@mention) if split[0][:1] != "@": - raise exceptions.ParseMessageException("No bot name") + raise exceptions.ParseMessageException("No bot nick") - name = split[0][1:].lower() + nick = split[0][1:].lower() # arguments to the command if len(split) > 1: @@ -313,7 +313,7 @@ class Bot(): else: argpart = None - return command, bot_id, name, argpart + return command, bot_id, nick, argpart def parse_arguments(self, argstr): """ @@ -399,7 +399,7 @@ class Bot(): Parse a message. """ - command, bot_id, name, argpart = self.parse_command(message) + command, bot_id, nick, argpart = self.parse_command(message) if argpart: arguments, flags, options = self.parse_arguments(argpart) @@ -408,7 +408,7 @@ class Bot(): flags = "" options = {} - return command, bot_id, name, arguments, flags, options + return command, bot_id, nick, arguments, flags, options # ----- HANDLING OF EVENTS ----- diff --git a/yaboli/room.py b/yaboli/room.py index 4054a08..9c2b24c 100644 --- a/yaboli/room.py +++ b/yaboli/room.py @@ -125,7 +125,7 @@ class Room(): """ add_callback(ptype, callback, *args, **kwargs) -> None - Add a function to be called when a packet of type ptype is received. + Add a function to be called when a certain event happens. """ self._callbacks.add(event, callback, *args, **kwargs) @@ -259,18 +259,18 @@ class Room(): self._con.add_next_callback(self._handle_nick_reply) self._con.send_packet("nick", name=nick) - def mentionable(self, name=None): + def mentionable(self, nick=None): """ mentionable() - A mentionable version of the name. - The name defaults to the bot's name. + A mentionable version of the nick. + The nick defaults to the bot's nick. """ - if name is None: - name = self.nick + if nick is None: + nick = self.nick - return "".join(c for c in name if not c in ".!?;&<'\"" and not c.isspace()) + return "".join(c for c in nick if not c in ".!?;&<'\"" and not c.isspace()) def send_message(self, content, parent=None): """ @@ -588,8 +588,6 @@ class Room(): if data["to"] != self.nick: self.set_nick(self.nick) - else: - self.nick = data["to"] def _handle_send_reply(self, data, error): """