aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-06-15 18:10:52 -0700
committerGravatar MarkKoz <[email protected]>2020-06-15 19:13:51 -0700
commitbcf6993de7de726683e6ca9b0f102b6ad1a732fa (patch)
treec9f06fd35592d63d68cb96184406e70239aa363a
parentLog exception info for failed attachment uploads (diff)
Fix 400 when "clyde" is in webhook username
Discord just disallows this name.
-rw-r--r--bot/cogs/duck_pond.py4
-rw-r--r--bot/cogs/python_news.py3
-rw-r--r--bot/cogs/reddit.py8
-rw-r--r--bot/cogs/watchchannels/watchchannel.py1
-rw-r--r--bot/utils/messages.py16
5 files changed, 24 insertions, 8 deletions
diff --git a/bot/cogs/duck_pond.py b/bot/cogs/duck_pond.py
index 37d1786a2..5b6a7fd62 100644
--- a/bot/cogs/duck_pond.py
+++ b/bot/cogs/duck_pond.py
@@ -7,7 +7,7 @@ from discord.ext.commands import Cog
from bot import constants
from bot.bot import Bot
-from bot.utils.messages import send_attachments
+from bot.utils.messages import send_attachments, sub_clyde
log = logging.getLogger(__name__)
@@ -58,7 +58,7 @@ class DuckPond(Cog):
try:
await self.webhook.send(
content=content,
- username=username,
+ username=sub_clyde(username),
avatar_url=avatar_url,
embed=embed
)
diff --git a/bot/cogs/python_news.py b/bot/cogs/python_news.py
index d15d0371e..adefd5c7c 100644
--- a/bot/cogs/python_news.py
+++ b/bot/cogs/python_news.py
@@ -10,6 +10,7 @@ from discord.ext.tasks import loop
from bot import constants
from bot.bot import Bot
+from bot.utils.messages import sub_clyde
PEPS_RSS_URL = "https://www.python.org/dev/peps/peps.rss/"
@@ -208,7 +209,7 @@ class PythonNews(Cog):
return await self.webhook.send(
embed=embed,
- username=webhook_profile_name,
+ username=sub_clyde(webhook_profile_name),
avatar_url=AVATAR_URL,
wait=True
)
diff --git a/bot/cogs/reddit.py b/bot/cogs/reddit.py
index 3b77538a0..d853ab2ea 100644
--- a/bot/cogs/reddit.py
+++ b/bot/cogs/reddit.py
@@ -16,6 +16,7 @@ from bot.constants import Channels, ERROR_REPLIES, Emojis, Reddit as RedditConfi
from bot.converters import Subreddit
from bot.decorators import with_role
from bot.pagination import LinePaginator
+from bot.utils.messages import sub_clyde
log = logging.getLogger(__name__)
@@ -218,7 +219,8 @@ class Reddit(Cog):
for subreddit in RedditConfig.subreddits:
top_posts = await self.get_top_posts(subreddit=subreddit, time="day")
- message = await self.webhook.send(username=f"{subreddit} Top Daily Posts", embed=top_posts, wait=True)
+ username = sub_clyde(f"{subreddit} Top Daily Posts")
+ message = await self.webhook.send(username=username, embed=top_posts, wait=True)
if message.channel.is_news():
await message.publish()
@@ -228,8 +230,8 @@ class Reddit(Cog):
for subreddit in RedditConfig.subreddits:
# Send and pin the new weekly posts.
top_posts = await self.get_top_posts(subreddit=subreddit, time="week")
-
- message = await self.webhook.send(wait=True, username=f"{subreddit} Top Weekly Posts", embed=top_posts)
+ username = sub_clyde(f"{subreddit} Top Weekly Posts")
+ message = await self.webhook.send(wait=True, username=username, embed=top_posts)
if subreddit.lower() == "r/python":
if not self.channel:
diff --git a/bot/cogs/watchchannels/watchchannel.py b/bot/cogs/watchchannels/watchchannel.py
index 436778c46..7c58a0fb5 100644
--- a/bot/cogs/watchchannels/watchchannel.py
+++ b/bot/cogs/watchchannels/watchchannel.py
@@ -204,6 +204,7 @@ class WatchChannel(metaclass=CogABCMeta):
embed: Optional[Embed] = None,
) -> None:
"""Sends a message to the webhook with the specified kwargs."""
+ username = messages.sub_clyde(username)
try:
await self.webhook.send(content=content, username=username, avatar_url=avatar_url, embed=embed)
except discord.HTTPException as exc:
diff --git a/bot/utils/messages.py b/bot/utils/messages.py
index 23519a514..6ad9351cc 100644
--- a/bot/utils/messages.py
+++ b/bot/utils/messages.py
@@ -1,6 +1,7 @@
import asyncio
import contextlib
import logging
+import re
from io import BytesIO
from typing import List, Optional, Sequence, Union
@@ -86,7 +87,7 @@ async def send_attachments(
else:
await destination.send(
file=attachment_file,
- username=message.author.display_name,
+ username=sub_clyde(message.author.display_name),
avatar_url=message.author.avatar_url
)
elif link_large:
@@ -109,8 +110,19 @@ async def send_attachments(
else:
await destination.send(
embed=embed,
- username=message.author.display_name,
+ username=sub_clyde(message.author.display_name),
avatar_url=message.author.avatar_url
)
return urls
+
+
+def sub_clyde(username: Optional[str]) -> Optional[str]:
+ """
+ Replace "e" in any "clyde" in `username` with a similar Unicode char and return the new string.
+
+ Discord disallows "clyde" anywhere in the username for webhooks. It will return a 400.
+ Return None only if `username` is None.
+ """
+ if username:
+ return re.sub(r"(clyd)e", r"\1𝖾", username, flags=re.I)