aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2020-02-23 20:17:37 +0100
committerGravatar GitHub <[email protected]>2020-02-23 20:17:37 +0100
commit08a3e03b19eb1621a23930294fa5662c12eb0290 (patch)
tree2b12c43088bec679fba8d349cbd27b9721ab6756
parentAdd Sentdex server to whitelist (diff)
parentMerge branch 'master' into reminder-enhancements (diff)
Merge pull request #749 from python-discord/reminder-enhancements
Reminder Embed Enhancements & Whitelist Expansion
-rw-r--r--bot/cogs/moderation/superstarify.py3
-rw-r--r--bot/cogs/reminders.py52
-rw-r--r--bot/constants.py3
-rw-r--r--config-default.yml4
4 files changed, 47 insertions, 15 deletions
diff --git a/bot/cogs/moderation/superstarify.py b/bot/cogs/moderation/superstarify.py
index 050c847ac..c41874a95 100644
--- a/bot/cogs/moderation/superstarify.py
+++ b/bot/cogs/moderation/superstarify.py
@@ -109,7 +109,8 @@ class Superstarify(InfractionScheduler, Cog):
ctx: Context,
member: Member,
duration: Expiry,
- reason: str = None
+ *,
+ reason: str = None,
) -> None:
"""
Temporarily force a random superstar name (like Taylor Swift) to be the user's nickname.
diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py
index ef46f4f3e..42229123b 100644
--- a/bot/cogs/reminders.py
+++ b/bot/cogs/reminders.py
@@ -7,11 +7,12 @@ from datetime import datetime, timedelta
from operator import itemgetter
import discord
+from dateutil.parser import isoparse
from dateutil.relativedelta import relativedelta
from discord.ext.commands import Cog, Context, group
from bot.bot import Bot
-from bot.constants import Channels, Icons, NEGATIVE_REPLIES, POSITIVE_REPLIES, STAFF_ROLES
+from bot.constants import Guild, Icons, NEGATIVE_REPLIES, POSITIVE_REPLIES, STAFF_ROLES
from bot.converters import Duration
from bot.pagination import LinePaginator
from bot.utils.checks import without_role_check
@@ -20,7 +21,7 @@ from bot.utils.time import humanize_delta, wait_until
log = logging.getLogger(__name__)
-WHITELISTED_CHANNELS = (Channels.bot,)
+WHITELISTED_CHANNELS = Guild.reminder_whitelist
MAXIMUM_REMINDERS = 5
@@ -49,13 +50,12 @@ class Reminders(Scheduler, Cog):
if not is_valid:
continue
- remind_at = datetime.fromisoformat(reminder['expiration'][:-1])
+ remind_at = isoparse(reminder['expiration']).replace(tzinfo=None)
# If the reminder is already overdue ...
if remind_at < now:
late = relativedelta(now, remind_at)
await self.send_reminder(reminder, late)
-
else:
self.schedule_task(loop, reminder["id"], reminder)
@@ -75,18 +75,31 @@ class Reminders(Scheduler, Cog):
return is_valid, user, channel
@staticmethod
- async def _send_confirmation(ctx: Context, on_success: str) -> None:
+ async def _send_confirmation(
+ ctx: Context,
+ on_success: str,
+ reminder_id: str,
+ delivery_dt: t.Optional[datetime],
+ ) -> None:
"""Send an embed confirming the reminder change was made successfully."""
embed = discord.Embed()
embed.colour = discord.Colour.green()
embed.title = random.choice(POSITIVE_REPLIES)
embed.description = on_success
+
+ footer_str = f"ID: {reminder_id}"
+ if delivery_dt:
+ # Reminder deletion will have a `None` `delivery_dt`
+ footer_str = f"{footer_str}, Due: {delivery_dt.strftime('%Y-%m-%dT%H:%M:%S')}"
+
+ embed.set_footer(text=footer_str)
+
await ctx.send(embed=embed)
async def _scheduled_task(self, reminder: dict) -> None:
"""A coroutine which sends the reminder once the time is reached, and cancels the running task."""
reminder_id = reminder["id"]
- reminder_datetime = datetime.fromisoformat(reminder['expiration'][:-1])
+ reminder_datetime = isoparse(reminder['expiration']).replace(tzinfo=None)
# Send the reminder message once the desired duration has passed
await wait_until(reminder_datetime)
@@ -198,11 +211,14 @@ class Reminders(Scheduler, Cog):
)
now = datetime.utcnow() - timedelta(seconds=1)
+ humanized_delta = humanize_delta(relativedelta(expiration, now))
# Confirm to the user that it worked.
await self._send_confirmation(
ctx,
- on_success=f"Your reminder will arrive in {humanize_delta(relativedelta(expiration, now))}!"
+ on_success=f"Your reminder will arrive in {humanized_delta}!",
+ reminder_id=reminder["id"],
+ delivery_dt=expiration,
)
loop = asyncio.get_event_loop()
@@ -232,7 +248,7 @@ class Reminders(Scheduler, Cog):
for content, remind_at, id_ in reminders:
# Parse and humanize the time, make it pretty :D
- remind_datetime = datetime.fromisoformat(remind_at[:-1])
+ remind_datetime = isoparse(remind_at).replace(tzinfo=None)
time = humanize_delta(relativedelta(remind_datetime, now))
text = textwrap.dedent(f"""
@@ -281,7 +297,10 @@ class Reminders(Scheduler, Cog):
# Send a confirmation message to the channel
await self._send_confirmation(
- ctx, on_success="That reminder has been edited successfully!"
+ ctx,
+ on_success="That reminder has been edited successfully!",
+ reminder_id=id_,
+ delivery_dt=expiration,
)
await self._reschedule_reminder(reminder)
@@ -295,18 +314,27 @@ class Reminders(Scheduler, Cog):
json={'content': content}
)
+ # Parse the reminder expiration back into a datetime for the confirmation message
+ expiration = isoparse(reminder['expiration']).replace(tzinfo=None)
+
# Send a confirmation message to the channel
await self._send_confirmation(
- ctx, on_success="That reminder has been edited successfully!"
+ ctx,
+ on_success="That reminder has been edited successfully!",
+ reminder_id=id_,
+ delivery_dt=expiration,
)
await self._reschedule_reminder(reminder)
- @remind_group.command("delete", aliases=("remove",))
+ @remind_group.command("delete", aliases=("remove", "cancel"))
async def delete_reminder(self, ctx: Context, id_: int) -> None:
"""Delete one of your active reminders."""
await self._delete_reminder(id_)
await self._send_confirmation(
- ctx, on_success="That reminder has been deleted successfully!"
+ ctx,
+ on_success="That reminder has been deleted successfully!",
+ reminder_id=id_,
+ delivery_dt=None,
)
diff --git a/bot/constants.py b/bot/constants.py
index a4c65a1f8..681d8da49 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -365,6 +365,7 @@ class Channels(metaclass=YAMLGetter):
bot: int
checkpoint_test: int
defcon: int
+ devcontrib: int
devlog: int
devtest: int
esoteric: int
@@ -432,7 +433,7 @@ class Guild(metaclass=YAMLGetter):
id: int
ignored: List[int]
staff_channels: List[int]
-
+ reminder_whitelist: List[int]
class Keys(metaclass=YAMLGetter):
section = "keys"
diff --git a/config-default.yml b/config-default.yml
index ba6ea2742..379475907 100644
--- a/config-default.yml
+++ b/config-default.yml
@@ -119,9 +119,10 @@ guild:
announcements: 354619224620138496
attachment_log: &ATTCH_LOG 649243850006855680
big_brother_logs: &BBLOGS 468507907357409333
- bot: 267659945086812160
+ bot: &BOT_CMD 267659945086812160
checkpoint_test: 422077681434099723
defcon: &DEFCON 464469101889454091
+ devcontrib: &DEV_CONTRIB 635950537262759947
devlog: &DEVLOG 622895325144940554
devtest: &DEVTEST 414574275865870337
esoteric: 470884583684964352
@@ -156,6 +157,7 @@ guild:
staff_channels: [*ADMINS, *ADMIN_SPAM, *MOD_SPAM, *MODS, *HELPERS, *ORGANISATION, *DEFCON]
ignored: [*ADMINS, *MESSAGE_LOG, *MODLOG, *ADMINS_VOICE, *STAFF_VOICE, *ATTCH_LOG]
+ reminder_whitelist: [*BOT_CMD, *DEV_CONTRIB]
roles:
admin: &ADMIN_ROLE 267628507062992896