diff --git a/evennia/accounts/accounts.py b/evennia/accounts/accounts.py index 028b517d98..b06a0661ac 100644 --- a/evennia/accounts/accounts.py +++ b/evennia/accounts/accounts.py @@ -392,8 +392,8 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)): Args: text (str, optional): text data to send - from_obj (Object or Account, optional): Object sending. If given, - its at_msg_send() hook will be called. + from_obj (Object or Account or list, optional): Object sending. If given, its + at_msg_send() hook will be called. If iterable, call on all entities. session (Session or list, optional): Session object or a list of Sessions to receive this send. If given, overrules the default send behavior for the current @@ -405,11 +405,12 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)): """ if from_obj: # call hook - try: - from_obj.at_msg_send(text=text, to_obj=self, **kwargs) - except Exception: - # this may not be assigned. - pass + for obj in make_iter(from_obj): + try: + obj.at_msg_send(text=text, to_obj=self, **kwargs) + except Exception: + # this may not be assigned. + logger.log_trace() try: if not self.at_msg_receive(text=text, **kwargs): # abort message to this account diff --git a/evennia/accounts/bots.py b/evennia/accounts/bots.py index 817b6e2f17..b0a765fbba 100644 --- a/evennia/accounts/bots.py +++ b/evennia/accounts/bots.py @@ -205,6 +205,10 @@ class IRCBot(Bot): "ssl": self.db.irc_ssl} _SESSIONS.start_bot_session("evennia.server.portal.irc.IRCBotFactory", configdict) + def at_msg_send(self, **kwargs): + "Shortcut here or we can end up in infinite loop" + pass + def get_nicklist(self, caller): """ Retrive the nick list from the connected channel. @@ -256,7 +260,7 @@ class IRCBot(Bot): Kwargs: options (dict): Options dict with the following allowed keys: - from_channel (str): dbid of a channel this text originated from. - - from_obj (list): list of objects this text. + - from_obj (list): list of objects sending this text. """ from_obj = kwargs.get("from_obj", None) @@ -265,7 +269,7 @@ class IRCBot(Bot): # cache channel lookup self.ndb.ev_channel = self.db.ev_channel if "from_channel" in options and text and self.ndb.ev_channel.dbid == options["from_channel"]: - if not from_obj or from_obj != [self.id]: + if not from_obj or from_obj != [self]: super(IRCBot, self).msg(channel=text) def execute_cmd(self, session=None, txt=None, **kwargs): @@ -346,7 +350,7 @@ class IRCBot(Bot): # cache channel lookup self.ndb.ev_channel = self.db.ev_channel if self.ndb.ev_channel: - self.ndb.ev_channel.msg(text, senders=self.id) + self.ndb.ev_channel.msg(text, senders=self) # # RSS diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index 94f1372056..9bbdac586a 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -487,9 +487,10 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)): is treated internally like any send-command, so its value can be a tuple if sending multiple arguments to the `text` oob command. - from_obj (obj, optional): object that is sending. If + from_obj (obj or list, optional): object that is sending. If given, at_msg_send will be called. This value will be - passed on to the protocol. + passed on to the protocol. If iterable, will execute hook + on all entities in it. session (Session or list, optional): Session or list of Sessions to relay data to, if any. If set, will force send to these sessions. If unset, who receives the message @@ -508,10 +509,11 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)): """ # try send hooks if from_obj: - try: - from_obj.at_msg_send(text=text, to_obj=self, **kwargs) - except Exception: - logger.log_trace() + for obj in make_iter(from_obj): + try: + obj.at_msg_send(text=text, to_obj=self, **kwargs) + except Exception: + logger.log_trace() try: if not self.at_msg_receive(text=text, **kwargs): # if at_msg_receive returns false, we abort message to this object