2016-03-29 11:56:58 +00:00
|
|
|
import time
|
2018-09-27 10:46:10 +00:00
|
|
|
from src import ModuleManager, Utils
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
SECONDS_MAX = Utils.SECONDS_WEEKS*8
|
|
|
|
SECONDS_MAX_DESCRIPTION = "8 weeks"
|
|
|
|
|
2018-09-27 10:46:10 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.command.in", min_args=2, usage="<time> <message>")
|
2016-03-29 11:56:58 +00:00
|
|
|
def in_command(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
Set a reminder
|
|
|
|
"""
|
2016-03-29 11:56:58 +00:00
|
|
|
seconds = Utils.from_pretty_time(event["args_split"][0])
|
|
|
|
message = " ".join(event["args_split"][1:])
|
|
|
|
if seconds:
|
|
|
|
if seconds <= SECONDS_MAX:
|
|
|
|
due_time = int(time.time())+seconds
|
|
|
|
|
2018-09-28 15:51:36 +00:00
|
|
|
self.bot.timers.add_persistent("in", seconds, due_time=due_time,
|
|
|
|
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-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("timer.in")
|
2016-04-19 11:21:27 +00:00
|
|
|
def timer_due(self, event):
|
2016-03-29 11:56:58 +00:00
|
|
|
for server in self.bot.servers.values():
|
2016-04-19 11:21:27 +00:00
|
|
|
if event["server_id"] == server.id:
|
|
|
|
server.send_message(event["target"],
|
2016-03-29 11:56:58 +00:00
|
|
|
"%s, this is your reminder: %s" % (
|
2016-04-19 11:21:27 +00:00
|
|
|
event["nickname"], event["message"]))
|
2016-03-29 11:56:58 +00:00
|
|
|
break
|