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
|
2023-03-09 22:01:10 +00:00
|
|
|
|
|
|
|
import discord
|
2018-12-30 20:36:11 +00:00
|
|
|
from discord.ext import commands
|
2019-02-28 22:10:30 +00:00
|
|
|
from discord.ext.commands import Cog
|
2023-03-09 22:01:10 +00:00
|
|
|
|
|
|
|
from robocop_ng.helpers.robocronp import add_job, get_crontab
|
2018-12-30 20:36:11 +00:00
|
|
|
|
|
|
|
|
2019-02-28 22:10:30 +00:00
|
|
|
class Remind(Cog):
|
2018-12-30 20:36:11 +00:00
|
|
|
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."""
|
2023-04-05 10:10:18 +00:00
|
|
|
ctab = get_crontab(self.bot)
|
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]
|
2020-04-20 22:05:32 +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,
|
|
|
|
)
|
2018-12-30 20:36:11 +00:00
|
|
|
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."""
|
2024-04-14 13:34:12 +00:00
|
|
|
ref_message = None
|
|
|
|
if ctx.message.reference is not None:
|
|
|
|
ref_message = await ctx.channel.fetch_message(
|
|
|
|
ctx.message.reference.message_id
|
|
|
|
)
|
|
|
|
|
2019-01-01 23:15:53 +00:00
|
|
|
if ctx.guild:
|
|
|
|
await ctx.message.delete()
|
2024-04-14 13:34:12 +00:00
|
|
|
|
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:
|
2020-04-20 22:05:32 +00:00
|
|
|
msg = await ctx.send(
|
2020-05-17 20:44:15 +00:00
|
|
|
f"{ctx.author.mention}: Minimum remind interval is 5 seconds."
|
2020-04-20 22:05:32 +00:00
|
|
|
)
|
2018-12-30 22:53:55 +00:00
|
|
|
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)
|
2020-04-20 22:05:32 +00:00
|
|
|
duration_text = self.bot.get_relative_timestamp(
|
|
|
|
time_to=expiry_datetime, include_to=True, humanized=True
|
|
|
|
)
|
2018-12-30 20:36:11 +00:00
|
|
|
|
2019-01-07 08:49:19 +00:00
|
|
|
safe_text = await commands.clean_content().convert(ctx, str(text))
|
2024-04-14 13:34:12 +00:00
|
|
|
if ref_message is not None:
|
|
|
|
safe_text += f"\nMessage reference: {ref_message.jump_url}"
|
|
|
|
|
2018-12-30 20:36:11 +00:00
|
|
|
added_on = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S (UTC)")
|
|
|
|
|
2020-04-20 22:05:32 +00:00
|
|
|
add_job(
|
2023-04-05 10:10:18 +00:00
|
|
|
self.bot,
|
2020-04-20 22:05:32 +00:00
|
|
|
"remind",
|
|
|
|
ctx.author.id,
|
|
|
|
{"text": safe_text, "added": added_on},
|
|
|
|
expiry_timestamp,
|
|
|
|
)
|
2018-12-30 20:36:11 +00:00
|
|
|
|
2024-04-14 13:34:12 +00:00
|
|
|
await ctx.send(
|
2020-04-20 22:05:32 +00:00
|
|
|
f"{ctx.author.mention}: I'll remind you in "
|
|
|
|
f"DMs about `{safe_text}` in {duration_text}."
|
|
|
|
)
|
2018-12-30 20:36:11 +00:00
|
|
|
|
|
|
|
|
2022-05-24 18:35:42 +00:00
|
|
|
async def setup(bot):
|
|
|
|
await bot.add_cog(Remind(bot))
|