2018-12-30 20:36:11 +00:00
|
|
|
import discord
|
2018-12-30 22:53:55 +00:00
|
|
|
import asyncio
|
2018-12-30 22:51:21 +00:00
|
|
|
import time
|
2018-12-30 20:36:11 +00:00
|
|
|
from datetime import datetime
|
|
|
|
from discord.ext import commands
|
|
|
|
from helpers.robocronp import add_job, get_crontab
|
|
|
|
|
|
|
|
|
|
|
|
class Remind:
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
|
2018-12-30 23:05:40 +00:00
|
|
|
@commands.cooldown(1, 60, type=commands.BucketType.user)
|
2018-12-30 20:36:11 +00:00
|
|
|
@commands.command()
|
|
|
|
async def remindlist(self, ctx):
|
|
|
|
"""Lists your reminders."""
|
|
|
|
ctab = get_crontab()
|
2018-12-30 23:13:04 +00:00
|
|
|
uid = str(ctx.author.id)
|
2018-12-30 20:36:11 +00:00
|
|
|
embed = discord.Embed(title=f"Active robocronp jobs")
|
|
|
|
for jobtimestamp in ctab["remind"]:
|
2018-12-30 23:13:04 +00:00
|
|
|
if uid not in ctab["remind"][jobtimestamp]:
|
|
|
|
continue
|
|
|
|
job_details = ctab["remind"][jobtimestamp][uid]
|
2018-12-30 20:36:11 +00:00
|
|
|
expiry_timestr = datetime.utcfromtimestamp(int(jobtimestamp))\
|
|
|
|
.strftime('%Y-%m-%d %H:%M:%S (UTC)')
|
|
|
|
embed.add_field(name=f"Reminder for {expiry_timestr}",
|
|
|
|
value=f"Added on: {job_details['added']}, "
|
|
|
|
f"Text: {job_details['text']}",
|
|
|
|
inline=False)
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
2018-12-30 23:05:40 +00:00
|
|
|
@commands.cooldown(1, 60, type=commands.BucketType.user)
|
2018-12-30 23:08:38 +00:00
|
|
|
@commands.command(aliases=["remindme"])
|
2018-12-30 20:36:11 +00:00
|
|
|
async def remind(self, ctx, when: str, *, text: str = "something"):
|
|
|
|
"""Reminds you about something."""
|
2019-01-01 23:15:53 +00:00
|
|
|
if ctx.guild:
|
|
|
|
await ctx.message.delete()
|
2018-12-30 22:51:21 +00:00
|
|
|
current_timestamp = time.time()
|
2018-12-30 20:36:11 +00:00
|
|
|
expiry_timestamp = self.bot.parse_time(when)
|
2018-12-30 22:51:21 +00:00
|
|
|
|
|
|
|
if current_timestamp + 5 > expiry_timestamp:
|
2018-12-30 22:53:55 +00:00
|
|
|
msg = await ctx.send(f"{ctx.author.mention}: Minimum "
|
|
|
|
"remind interval is 5 seconds.")
|
|
|
|
await asyncio.sleep(5)
|
|
|
|
await msg.delete()
|
2018-12-30 23:05:40 +00:00
|
|
|
return
|
2018-12-30 22:51:21 +00:00
|
|
|
|
2018-12-30 20:36:11 +00:00
|
|
|
expiry_datetime = datetime.utcfromtimestamp(expiry_timestamp)
|
|
|
|
duration_text = self.bot.get_relative_timestamp(time_to=expiry_datetime,
|
|
|
|
include_to=True,
|
|
|
|
humanized=True)
|
|
|
|
|
2019-01-07 08:49:19 +00:00
|
|
|
safe_text = await commands.clean_content().convert(ctx, str(text))
|
2018-12-30 20:36:11 +00:00
|
|
|
added_on = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S (UTC)")
|
|
|
|
|
|
|
|
add_job("remind",
|
|
|
|
ctx.author.id,
|
|
|
|
{"text": safe_text, "added": added_on},
|
|
|
|
expiry_timestamp)
|
|
|
|
|
2018-12-30 22:53:55 +00:00
|
|
|
msg = await ctx.send(f"{ctx.author.mention}: I'll remind you in "
|
|
|
|
f"DMs about `{safe_text}` in {duration_text}.")
|
|
|
|
await asyncio.sleep(5)
|
|
|
|
await msg.delete()
|
2018-12-30 20:36:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setup(bot):
|
|
|
|
bot.add_cog(Remind(bot))
|