2019-05-25 20:40:06 +00:00
|
|
|
#--depends-on commands
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
from src import EventManager, ModuleManager, utils
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.message.channel", priority=EventManager.PRIORITY_HIGH)
|
2016-03-29 11:56:58 +00:00
|
|
|
def channel_message(self, event):
|
2018-09-05 11:58:12 +00:00
|
|
|
messages = event["channel"].get_user_setting(event["user"].get_id(),
|
2018-08-18 23:19:53 +00:00
|
|
|
"to", [])
|
2019-04-24 13:32:56 +00:00
|
|
|
for nickname, message, timestamp in messages:
|
2019-11-15 13:59:09 +00:00
|
|
|
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))
|
2018-08-05 10:42:40 +00:00
|
|
|
if messages:
|
2018-09-05 11:58:12 +00:00
|
|
|
event["channel"].del_user_setting(event["user"].get_id(), "to")
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2019-11-25 12:15:43 +00:00
|
|
|
@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):
|
2019-10-04 14:20:38 +00:00
|
|
|
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)
|
|
|
|
|
2018-08-18 23:19:53 +00:00
|
|
|
target_user = event["server"].get_user(event["args_split"][0])
|
2018-09-05 11:58:12 +00:00
|
|
|
messages = event["target"].get_user_setting(target_user.get_id(),
|
2018-08-18 23:19:53 +00:00
|
|
|
"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:]),
|
2019-11-15 13:59:09 +00:00
|
|
|
utils.datetime.iso8601_format_now()])
|
2018-09-05 11:58:12 +00:00
|
|
|
event["target"].set_user_setting(target_user.get_id(),
|
2018-08-18 23:19:53 +00:00
|
|
|
"to", messages)
|
2016-03-29 11:56:58 +00:00
|
|
|
event["stdout"].write("Message saved")
|