aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar kosayoda <[email protected]>2020-07-19 13:31:00 +0800
committerGravatar kosayoda <[email protected]>2020-07-19 13:31:00 +0800
commitced9117e848a9eb1e003576d4f355ba7aa220cd8 (patch)
tree73f3bc501fbefb1183deb277aab0777783c39f2b
parentNamespace Member and Role to avoid extra imports (diff)
Extract `send_denial` to a utility function
-rw-r--r--bot/cogs/reminders.py21
-rw-r--r--bot/utils/messages.py16
2 files changed, 20 insertions, 17 deletions
diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py
index ae387f09a..f36b67f5a 100644
--- a/bot/cogs/reminders.py
+++ b/bot/cogs/reminders.py
@@ -12,10 +12,11 @@ from dateutil.relativedelta import relativedelta
from discord.ext.commands import Cog, Context, Greedy, group
from bot.bot import Bot
-from bot.constants import Guild, Icons, MODERATION_ROLES, NEGATIVE_REPLIES, POSITIVE_REPLIES, STAFF_ROLES
+from bot.constants import Guild, Icons, MODERATION_ROLES, POSITIVE_REPLIES, STAFF_ROLES
from bot.converters import Duration
from bot.pagination import LinePaginator
from bot.utils.checks import without_role_check
+from bot.utils.messages import send_denial
from bot.utils.scheduling import Scheduler
from bot.utils.time import humanize_delta
@@ -103,16 +104,6 @@ class Reminders(Cog):
await ctx.send(embed=embed)
@staticmethod
- async def _send_denial(ctx: Context, reason: str) -> None:
- """Send an embed denying the user from creating a reminder."""
- embed = discord.Embed()
- embed.colour = discord.Colour.red()
- embed.title = random.choice(NEGATIVE_REPLIES)
- embed.description = reason
-
- await ctx.send(embed=embed)
-
- @staticmethod
async def allow_mentions(ctx: Context, mentions: t.List[Mentionable]) -> t.Tuple[bool, str]:
"""
Returns whether or not the list of mentions is allowed.
@@ -220,7 +211,7 @@ class Reminders(Cog):
# If they don't have permission to set a reminder in this channel
if ctx.channel.id not in WHITELISTED_CHANNELS:
- return await self._send_denial(ctx, "Sorry, you can't do that here!")
+ return await send_denial(ctx, "Sorry, you can't do that here!")
# Get their current active reminders
active_reminders = await self.bot.api_client.get(
@@ -233,13 +224,13 @@ class Reminders(Cog):
# Let's limit this, so we don't get 10 000
# reminders from kip or something like that :P
if len(active_reminders) > MAXIMUM_REMINDERS:
- return await self._send_denial(ctx, "You have too many active reminders!")
+ return await send_denial(ctx, "You have too many active reminders!")
# Filter mentions to see if the user can mention members/roles
if mentions:
mentions_allowed, disallowed_mentions = await self.allow_mentions(ctx, mentions)
if not mentions_allowed:
- return await self._send_denial(
+ return await send_denial(
ctx, f"You can't mention other {disallowed_mentions} in your reminder!"
)
@@ -389,7 +380,7 @@ class Reminders(Cog):
# Filter mentions to see if the user can mention members/roles
mentions_allowed, disallowed_mentions = await self.allow_mentions(ctx, mentions)
if not mentions_allowed:
- return await self._send_denial(
+ return await send_denial(
ctx, f"You can't mention other {disallowed_mentions} in your reminder!"
)
diff --git a/bot/utils/messages.py b/bot/utils/messages.py
index a40a12e98..670289941 100644
--- a/bot/utils/messages.py
+++ b/bot/utils/messages.py
@@ -1,15 +1,17 @@
import asyncio
import contextlib
import logging
+import random
import re
from io import BytesIO
from typing import List, Optional, Sequence, Union
-from discord import Client, Embed, File, Member, Message, Reaction, TextChannel, Webhook
+from discord import Client, Colour, Embed, File, Member, Message, Reaction, TextChannel, Webhook
from discord.abc import Snowflake
from discord.errors import HTTPException
+from discord.ext.commands import Context
-from bot.constants import Emojis
+from bot.constants import Emojis, NEGATIVE_REPLIES
log = logging.getLogger(__name__)
@@ -132,3 +134,13 @@ def sub_clyde(username: Optional[str]) -> Optional[str]:
return re.sub(r"(clyd)(e)", replace_e, username, flags=re.I)
else:
return username # Empty string or None
+
+
+async def send_denial(ctx: Context, reason: str) -> None:
+ """Send an embed denying the user with the given reason."""
+ embed = Embed()
+ embed.colour = Colour.red()
+ embed.title = random.choice(NEGATIVE_REPLIES)
+ embed.description = reason
+
+ await ctx.send(embed=embed)