aboutsummaryrefslogtreecommitdiff
path: root/modules/tell.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-11-25 12:15:43 +0000
committerGravatar jesopo2019-11-25 12:18:07 +0000
commit985e4704a0465b2ab5d5c6b0805029c2844c2fa7 (patch)
treebcb19ea6562b39c2825efc80dec9abb1fb45164a /modules/tell.py
parentupdate CHANGELOG.md (diff)
signature
switch !to to !tell, add !to as an alias of !tell
Diffstat (limited to 'modules/tell.py')
-rw-r--r--modules/tell.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/modules/tell.py b/modules/tell.py
new file mode 100644
index 00000000..93aaba0c
--- /dev/null
+++ b/modules/tell.py
@@ -0,0 +1,42 @@
+#--depends-on commands
+
+from src import EventManager, ModuleManager, utils
+
+class Module(ModuleManager.BaseModule):
+ @utils.hook("received.message.channel", priority=EventManager.PRIORITY_HIGH)
+ def channel_message(self, event):
+ messages = event["channel"].get_user_setting(event["user"].get_id(),
+ "to", [])
+ for nickname, message, timestamp in messages:
+ timestamp_parsed = utils.datetime.iso8601_parse(timestamp)
+ timestamp_human = utils.datetime.datetime_human(timestamp_parsed)
+ 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")
+
+ @utils.hook("received.command.to", alias_of="tell")
+ @utils.hook("received.command.tell")
+ @utils.kwarg("min_args", 2)
+ @utils.kwarg("channel_only", True)
+ @utils.kwarg("help",
+ "Relay a message to a user the next time they talk in this channel")
+ @utils.kwarg("usage", "<nickname> <message>")
+ def tell(self, event):
+ 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", [])
+
+ if len(messages) == 5:
+ raise utils.EventError("Users can only have 5 messages stored")
+
+ messages.append([event["user"].nickname,
+ " ".join(event["args_split"][1:]),
+ utils.datetime.iso8601_format_now()])
+ event["target"].set_user_setting(target_user.get_id(),
+ "to", messages)
+ event["stdout"].write("Message saved")