diff --git a/evennia/accounts/accounts.py b/evennia/accounts/accounts.py index 3f92d840d3..328ee6b90d 100644 --- a/evennia/accounts/accounts.py +++ b/evennia/accounts/accounts.py @@ -965,9 +965,9 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): def at_pre_channel_msg(self, message, channel, senders=None, **kwargs): """ - Called by `self.channel_msg` before sending a channel message to the - user. This allows for customizing messages per-user and also to abort - the receive on the receiver-level. + Called by the Channel just before passing a message into `channel_msg`. + This allows for tweak messages per-user and also to abort the + receive on the receiver-level. Args: message (str): The message sent to the channel. @@ -1020,22 +1020,13 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): `Channel.msg`. Notes: - Before this, `Channel.at_before_msg` will fire, which offers a way + Before this, `Channel.at_pre_channel_msg` will fire, which offers a way to customize the message for the receiver on the channel-level. """ - # channel pre-msg hook - message = self.at_pre_channel_msg(message, channel, senders=senders, **kwargs) - if message in (None, False): - return - - # the actual sending self.msg(text=(message, {"from_channel": channel.id}), from_obj=senders, options={"from_channel": channel.id}) - # channel post-msg hook - self.at_post_channel_msg(message, channel, senders=senders, **kwargs) - def at_post_channel_msg(self, message, channel, senders=None, **kwargs): """ Called by `self.channel_msg` after message was received. diff --git a/evennia/comms/comms.py b/evennia/comms/comms.py index eb01072f7e..2cf9e1697f 100644 --- a/evennia/comms/comms.py +++ b/evennia/comms/comms.py @@ -444,11 +444,21 @@ class DefaultChannel(ChannelDB, metaclass=TypeclassBase): for receiver in receivers: # send to each individual subscriber + + try: - # this will in turn call receiver.at_pre/post_channel_msg + message = receiver.at_pre_channel_msg(message, self, **send_kwargs) + if message in (None, False): + return + receiver.channel_msg(message, self, **send_kwargs) + + receiver.at_post_channel_msg(message, self, **send_kwargs) + except Exception: - logger.log_trace(f"Cannot send channel message to {receiver}.") + logger.log_trace(f"Error sending channel message to {receiver}.") + + # post-send hook self.at_post_msg(message, **send_kwargs)