2019-05-25 20:40:06 +00:00
|
|
|
#--depends-on commands
|
2016-03-29 11:56:58 +00:00
|
|
|
import time
|
2018-10-03 12:22:37 +00:00
|
|
|
from src import ModuleManager, utils
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2019-11-15 13:59:09 +00:00
|
|
|
SECONDS_MAX = utils.datetime.SECONDS_WEEKS*8
|
2016-03-29 11:56:58 +00:00
|
|
|
SECONDS_MAX_DESCRIPTION = "8 weeks"
|
|
|
|
|
2018-09-27 10:46:10 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2019-08-14 09:56:18 +00:00
|
|
|
@utils.hook("received.command.remindme", alias_of="in")
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.in", min_args=2)
|
2019-08-14 09:56:18 +00:00
|
|
|
@utils.kwarg("help", "Set a reminder")
|
|
|
|
@utils.kwarg("usage", "<time> <message>")
|
2016-03-29 11:56:58 +00:00
|
|
|
def in_command(self, event):
|
2018-10-03 12:22:37 +00:00
|
|
|
seconds = utils.from_pretty_time(event["args_split"][0])
|
2016-03-29 11:56:58 +00:00
|
|
|
message = " ".join(event["args_split"][1:])
|
|
|
|
if seconds:
|
|
|
|
if seconds <= SECONDS_MAX:
|
|
|
|
due_time = int(time.time())+seconds
|
|
|
|
|
2018-10-12 17:07:23 +00:00
|
|
|
self.timers.add_persistent("in", seconds, due_time=due_time,
|
2018-09-28 15:51:36 +00:00
|
|
|
target=event["target"].name, server_id=event["server"].id,
|
|
|
|
nickname=event["user"].nickname, message=message)
|
2016-04-10 16:32:51 +00:00
|
|
|
event["stdout"].write("Saved")
|
2016-03-29 11:56:58 +00:00
|
|
|
else:
|
|
|
|
event["stderr"].write(
|
|
|
|
"The given time is above the max (%s)" % (
|
|
|
|
SECONDS_MAX_DESCRIPTION))
|
|
|
|
else:
|
|
|
|
event["stderr"].write(
|
|
|
|
"Please provided a valid time above 0 seconds")
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("timer.in")
|
2016-04-19 11:21:27 +00:00
|
|
|
def timer_due(self, event):
|
2019-04-24 11:07:30 +00:00
|
|
|
server = self.bot.get_server_by_id(event["server_id"])
|
2018-10-12 13:04:14 +00:00
|
|
|
if server:
|
2018-11-21 20:05:08 +00:00
|
|
|
message = "%s: this is your reminder: %s" % (
|
|
|
|
event["nickname"], event["message"])
|
|
|
|
target = server.get_target(event["target"])
|
|
|
|
self.events.on("send.stdout").call(target=target, module_name="In",
|
|
|
|
server=server, message=message)
|
2019-02-10 13:18:25 +00:00
|
|
|
|
|
|
|
@utils.hook("received.command.inlist")
|
|
|
|
def in_list(self, event):
|
|
|
|
"""
|
|
|
|
:help: List reminders
|
|
|
|
:usage: [index]
|
|
|
|
"""
|
|
|
|
timers = self.timers.find_all("in")
|
|
|
|
found = []
|
|
|
|
for timer in timers:
|
|
|
|
nickname_match = (event["server"].irc_lower(
|
|
|
|
timer.kwargs["nickname"]) == event["user"].nickname_lower)
|
|
|
|
target_match = timer.kwargs["target"] == event["target"].name
|
|
|
|
|
|
|
|
if nickname_match and target_match:
|
|
|
|
found.append(timer)
|
|
|
|
|
|
|
|
if len(event["args_split"]) > 0:
|
|
|
|
index = event["args_split"][0]
|
|
|
|
if not index.isdigit() or index == "0":
|
|
|
|
raise utils.EventError("Please provide a valid reminder index")
|
|
|
|
|
|
|
|
index = int(index)
|
|
|
|
actual_index = index-1
|
|
|
|
if actual_index > len(found):
|
|
|
|
raise utils.EventError("You do not have that many reminders")
|
|
|
|
|
|
|
|
timer = found[actual_index]
|
2019-02-10 13:27:49 +00:00
|
|
|
event["stdout"].write("Reminder %d: %s" % (index,
|
|
|
|
timer.kwargs["message"]))
|
2019-02-10 13:18:25 +00:00
|
|
|
else:
|
|
|
|
event["stdout"].write("%s: you have %d reminders" % (
|
|
|
|
event["user"].nickname, len(found)))
|