2018-08-05 11:53:02 +00:00
|
|
|
import EventManager
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
class Module(object):
|
|
|
|
def __init__(self, bot):
|
|
|
|
bot.events.on("received").on("message").on("channel"
|
2018-08-05 11:53:02 +00:00
|
|
|
).hook(self.channel_message,
|
|
|
|
priority=EventManager.PRIORITY_MEDIUM)
|
2016-03-29 11:56:58 +00:00
|
|
|
bot.events.on("received").on("command").on("to").hook(
|
|
|
|
self.to, min_args=2, help=("Relay a message to a "
|
|
|
|
"user the next time they talk in a channel"),
|
2016-04-06 11:02:44 +00:00
|
|
|
channel_only=True, usage="<username> <message>")
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
def channel_message(self, event):
|
2018-08-05 11:53:02 +00:00
|
|
|
messages = event["channel"].get_user_setting(
|
|
|
|
event["user"].nickname, "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))
|
2018-08-05 10:42:40 +00:00
|
|
|
if messages:
|
2018-08-05 11:53:02 +00:00
|
|
|
event["channel"].del_user_setting(
|
|
|
|
event["user"].nickname, "to")
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
def to(self, event):
|
2018-08-05 11:53:02 +00:00
|
|
|
messages = event["target"].get_user_setting(
|
2018-08-13 17:19:17 +00:00
|
|
|
event["args_split"][0], "to", [])
|
2016-03-29 11:56:58 +00:00
|
|
|
messages.append([event["user"].nickname,
|
|
|
|
" ".join(event["args_split"][1:])])
|
2018-08-05 11:53:02 +00:00
|
|
|
event["target"].set_user_setting(
|
2018-08-13 17:19:17 +00:00
|
|
|
event["args_split"][0], "to", messages)
|
2016-03-29 11:56:58 +00:00
|
|
|
event["stdout"].write("Message saved")
|