bitbot-3.11-fork/modules/in.py

45 lines
1.7 KiB
Python
Raw Normal View History

2016-03-29 11:56:58 +00:00
import time
import Utils
2018-08-31 09:50:37 +00:00
SECONDS_MAX = Utils.SECONDS_WEEKS * 8
2016-03-29 11:56:58 +00:00
SECONDS_MAX_DESCRIPTION = "8 weeks"
2018-08-31 09:50:37 +00:00
2016-03-29 11:56:58 +00:00
class Module(object):
def __init__(self, bot):
self.bot = bot
bot.events.on("received").on("command").on("in").hook(
self.in_command, min_args=2,
help="Set a reminder", usage="<time> <message>")
bot.events.on("timer").on("in").hook(self.timer_due)
2016-03-29 11:56:58 +00:00
def in_command(self, event):
seconds = Utils.from_pretty_time(event["args_split"][0])
message = " ".join(event["args_split"][1:])
if seconds:
if seconds <= SECONDS_MAX:
2018-08-31 09:50:37 +00:00
due_time = int(time.time()) + seconds
2016-03-29 11:56:58 +00:00
self.bot.add_timer("in", seconds,
2018-08-31 09:50:37 +00:00
target=event["target"].name,
due_time=due_time,
server_id=event["server"].id,
nickname=event["user"].nickname,
message=message)
event["stdout"].write("Saved")
2016-03-29 11:56:58 +00:00
else:
event["stderr"].write(
"The given time is above the max (%s)" % (
2018-08-31 09:50:37 +00:00
SECONDS_MAX_DESCRIPTION))
2016-03-29 11:56:58 +00:00
else:
event["stderr"].write(
"Please provided a valid time above 0 seconds")
def timer_due(self, event):
2016-03-29 11:56:58 +00:00
for server in self.bot.servers.values():
if event["server_id"] == server.id:
server.send_message(event["target"],
2018-08-31 09:50:37 +00:00
"%s, this is your reminder: %s" % (
event["nickname"], event["message"]))
2016-03-29 11:56:58 +00:00
break