From 3382ca2862636ae997cb6badfd4ebd8f3ee5d8b0 Mon Sep 17 00:00:00 2001 From: Ske Date: Sat, 15 Dec 2018 19:56:59 +0100 Subject: [PATCH] Fix Discord throwing errors on members named "Clyde" This adds a hair-space (\u200A) between the C and the l, which won't trigger their check for the name. Discord throws this error because their built-in "status bot" used in the client is named Clyde. --- src/pluralkit/bot/proxy.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pluralkit/bot/proxy.py b/src/pluralkit/bot/proxy.py index f3a3e66a..5fd1dab5 100644 --- a/src/pluralkit/bot/proxy.py +++ b/src/pluralkit/bot/proxy.py @@ -1,3 +1,5 @@ +import re + import discord from io import BytesIO from typing import Optional @@ -66,6 +68,13 @@ async def make_attachment_file(message: discord.Message): return discord.File(bio, first_attachment.filename) +def fix_clyde(name: str) -> str: + # Discord doesn't allow any webhook username to contain the word "Clyde" + # So replace "Clyde" with "C lyde" (except with a hair space, hence \u200A) + # Zero-width spacers are ignored by Discord and will still trigger the error + return re.sub("(c)(lyde)", "\\1\u200A\\2", name, flags=re.IGNORECASE) + + async def send_proxy_message(conn, original_message: discord.Message, system: System, member: Member, inner_text: str, logger: ChannelLogger, bot_user: discord.User): # Send the message through the webhook @@ -73,6 +82,7 @@ async def send_proxy_message(conn, original_message: discord.Message, system: Sy # Bounds check the combined name to avoid silent erroring full_username = "{} {}".format(member.name, system.tag or "").strip() + full_username = fix_clyde(full_username) if len(full_username) < 2: raise ProxyError( "The webhook's name, `{}`, is shorter than two characters, and thus cannot be proxied. Please change the member name or use a longer system tag.".format( @@ -153,7 +163,8 @@ async def try_proxy_message(conn, message: discord.Message, logger: ChannelLogge member, inner_message = proxy_match - # Make sure no @everyones slip through, etc + # Make sure no @everyones slip through + # Webhooks implicitly have permission to mention @everyone so we have to enforce that manually inner_message = utils.sanitize(inner_message) # If we don't have an inner text OR an attachment, we cancel because the hook can't send that