aboutsummaryrefslogtreecommitdiffstats
path: root/bot/utils/messages.py
diff options
context:
space:
mode:
authorGravatar Shivansh-007 <[email protected]>2021-05-20 18:30:07 +0530
committerGravatar GitHub <[email protected]>2021-05-20 18:30:07 +0530
commitd032dd1a0e0fb0f866b1b492f917990d66dae55a (patch)
tree0adfc37d1350c7eb0b33ea44d4170a44a017e119 /bot/utils/messages.py
parentMerge remote-tracking branch 'origin/feature/command-suggestions' into featur... (diff)
parentMerge pull request #733 from Icebluewolf/http_status_command_randomness (diff)
Merge branch 'main' into feature/command-suggestions
Diffstat (limited to 'bot/utils/messages.py')
-rw-r--r--bot/utils/messages.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/bot/utils/messages.py b/bot/utils/messages.py
new file mode 100644
index 00000000..a6c035f9
--- /dev/null
+++ b/bot/utils/messages.py
@@ -0,0 +1,19 @@
+import re
+from typing import Optional
+
+
+def sub_clyde(username: Optional[str]) -> Optional[str]:
+ """
+ Replace "e"/"E" in any "clyde" in `username` with a Cyrillic "е"/"E" 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.
+ """
+ def replace_e(match: re.Match) -> str:
+ char = "е" if match[2] == "e" else "Е"
+ return match[1] + char
+
+ if username:
+ return re.sub(r"(clyd)(e)", replace_e, username, flags=re.I)
+ else:
+ return username # Empty string or None