bitbot-3.11-fork/modules/to.py

42 lines
1.7 KiB
Python
Raw Normal View History

#--depends-on commands
from src import EventManager, ModuleManager, utils
2016-03-29 11:56:58 +00:00
class Module(ModuleManager.BaseModule):
@utils.hook("received.message.channel", priority=EventManager.PRIORITY_HIGH)
2016-03-29 11:56:58 +00:00
def channel_message(self, event):
messages = event["channel"].get_user_setting(event["user"].get_id(),
"to", [])
2019-04-24 13:32:56 +00:00
for nickname, message, timestamp in messages:
timestamp_parsed = utils.datetime.iso8601_parse(timestamp)
timestamp_human = utils.datetime.datetime_human(timestamp_parsed)
2019-04-24 13:32:56 +00:00
event["channel"].send_message("%s: <%s> %s (at %s UTC)" % (
event["user"].nickname, nickname, message, timestamp_human))
if messages:
event["channel"].del_user_setting(event["user"].get_id(), "to")
2016-03-29 11:56:58 +00:00
@utils.hook("received.command.to", min_args=2, channel_only=True)
2016-03-29 11:56:58 +00:00
def to(self, event):
"""
:help: Relay a message to a user the next time they talk in this
channel
:usage: <nickname> <message>
"""
target_name = event["args_split"][0]
if not event["server"].has_user_id(target_name):
raise utils.EventError("I've never seen %s before" % target_name)
target_user = event["server"].get_user(event["args_split"][0])
messages = event["target"].get_user_setting(target_user.get_id(),
"to", [])
2019-04-30 10:57:31 +00:00
if len(messages) == 5:
raise utils.EventError("Users can only have 5 messages stored")
2016-03-29 11:56:58 +00:00
messages.append([event["user"].nickname,
2019-04-24 13:32:56 +00:00
" ".join(event["args_split"][1:]),
utils.datetime.iso8601_format_now()])
event["target"].set_user_setting(target_user.get_id(),
"to", messages)
2016-03-29 11:56:58 +00:00
event["stdout"].write("Message saved")