bitbot-3.11-fork/modules/to.py

30 lines
1.2 KiB
Python
Raw Normal View History

import EventManager
2016-03-29 11:56:58 +00:00
class Module(object):
def __init__(self, bot, events, exports):
events.on("received.message.channel").hook(self.channel_message,
priority=EventManager.PRIORITY_HIGH)
events.on("received.command.to").hook(self.to, min_args=2,
help=("Relay a message to a user the next time they talk "
"in this channel"), channel_only=True,
usage="<username> <message>")
2016-03-29 11:56:58 +00:00
def channel_message(self, event):
messages = event["channel"].get_user_setting(event["user"].get_id(),
"to", [])
2016-03-29 11:56:58 +00:00
for nickname, message in messages:
event["channel"].send_message("%s: <%s> %s" % (
event["user"].nickname, nickname, message))
if messages:
event["channel"].del_user_setting(event["user"].get_id(), "to")
2016-03-29 11:56:58 +00:00
def to(self, event):
target_user = event["server"].get_user(event["args_split"][0])
messages = event["target"].get_user_setting(target_user.get_id(),
"to", [])
2016-03-29 11:56:58 +00:00
messages.append([event["user"].nickname,
" ".join(event["args_split"][1:])])
event["target"].set_user_setting(target_user.get_id(),
"to", messages)
2016-03-29 11:56:58 +00:00
event["stdout"].write("Message saved")