mirror of
https://github.com/evennia/evennia.git
synced 2026-03-28 18:47:16 +01:00
Move calling of channel-msg hooks to channel side
This commit is contained in:
parent
bfb8faaf7d
commit
c9d8208c47
2 changed files with 16 additions and 15 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue