aboutsummaryrefslogtreecommitdiffstats
path: root/bot
diff options
context:
space:
mode:
authorGravatar Janine vN <[email protected]>2021-04-21 00:04:33 -0400
committerGravatar GitHub <[email protected]>2021-04-21 00:04:33 -0400
commit38c5d61430b3ac7946321dd86a42af52cae90da0 (patch)
tree1acfc86af4c85322ca08123c63a34ec32c832b23 /bot
parentAdd Catify command (#694) (diff)
parentchore: use 'nickname' and 'display name' in the right places and use allowed_... (diff)
Merge pull request #697 from ToxicKidz/fix_catify
Fixed the .catify command producing UnboundLocal and Forbidden Errors
Diffstat (limited to 'bot')
-rw-r--r--bot/exts/evergreen/catify.py46
1 files changed, 27 insertions, 19 deletions
diff --git a/bot/exts/evergreen/catify.py b/bot/exts/evergreen/catify.py
index a0121403..ae8d54b6 100644
--- a/bot/exts/evergreen/catify.py
+++ b/bot/exts/evergreen/catify.py
@@ -1,7 +1,8 @@
import random
+from contextlib import suppress
from typing import Optional
-from discord import AllowedMentions, Embed
+from discord import AllowedMentions, Embed, Forbidden
from discord.ext import commands
from bot.constants import Cats, Colours, NEGATIVE_REPLIES
@@ -26,7 +27,10 @@ class Catify(commands.Cog):
if len(display_name) > 26:
embed = Embed(
title=random.choice(NEGATIVE_REPLIES),
- description="Your nickname is too long to be catified! Please change it to be under 26 characters.",
+ description=(
+ "Your display name is too long to be catified! "
+ "Please change it to be under 26 characters."
+ ),
color=Colours.soft_red
)
await ctx.send(embed=embed)
@@ -34,8 +38,11 @@ class Catify(commands.Cog):
else:
display_name += f" | {random.choice(Cats.cats)}"
- await ctx.send(f"Your catified username is: `{display_name}`")
- await ctx.author.edit(nick=display_name)
+
+ await ctx.send(f"Your catified nickname is: `{display_name}`", allowed_mentions=AllowedMentions.none())
+
+ with suppress(Forbidden):
+ await ctx.author.edit(nick=display_name)
else:
if len(text) >= 1500:
embed = Embed(
@@ -48,29 +55,30 @@ class Catify(commands.Cog):
string_list = text.split()
for index, name in enumerate(string_list):
+ name = name.lower()
if "cat" in name:
if random.randint(0, 5) == 5:
- string_list[index] = string_list[index].replace("cat", f"**{random.choice(Cats.cats)}**")
+ string_list[index] = name.replace("cat", f"**{random.choice(Cats.cats)}**")
else:
- string_list[index] = string_list[index].replace("cat", random.choice(Cats.cats))
+ string_list[index] = name.replace("cat", random.choice(Cats.cats))
for element in Cats.cats:
if element in name:
- string_list[index] = string_list[index].replace(element, "cat")
+ string_list[index] = name.replace(element, "cat")
- string_len = len(string_list) // 3 or len(string_list)
+ string_len = len(string_list) // 3 or len(string_list)
- for _ in range(random.randint(1, string_len)):
- # insert cat at random index
- if random.randint(0, 5) == 5:
- string_list.insert(random.randint(0, len(string_list)), f"**{random.choice(Cats.cats)}**")
- else:
- string_list.insert(random.randint(0, len(string_list)), random.choice(Cats.cats))
+ for _ in range(random.randint(1, string_len)):
+ # insert cat at random index
+ if random.randint(0, 5) == 5:
+ string_list.insert(random.randint(0, len(string_list)), f"**{random.choice(Cats.cats)}**")
+ else:
+ string_list.insert(random.randint(0, len(string_list)), random.choice(Cats.cats))
- text = " ".join(string_list)
- await ctx.send(
- f">>> {text}",
- allowed_mentions=AllowedMentions.none()
- )
+ text = " ".join(string_list)
+ await ctx.send(
+ f">>> {text}",
+ allowed_mentions=AllowedMentions.none()
+ )
def setup(bot: commands.Bot) -> None: