aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/resources/easter/bunny_names.json29
-rw-r--r--bot/seasons/easter/bunny_name_generator.py106
2 files changed, 135 insertions, 0 deletions
diff --git a/bot/resources/easter/bunny_names.json b/bot/resources/easter/bunny_names.json
new file mode 100644
index 00000000..8c97169c
--- /dev/null
+++ b/bot/resources/easter/bunny_names.json
@@ -0,0 +1,29 @@
+{
+ "names": [
+ "Flopsy",
+ "Hopsalot",
+ "Thumper",
+ "Nibbles",
+ "Daisy",
+ "Fuzzy",
+ "Cottontail",
+ "Carrot Top",
+ "Marshmallow",
+ "Lucky",
+ "Clover",
+ "Daffodil",
+ "Buttercup",
+ "Goldie",
+ "Dizzy",
+ "Trixie",
+ "Snuffles",
+ "Hopscotch",
+ "Skipper",
+ "Thunderfoot",
+ "Bigwig",
+ "Dandelion",
+ "Pipkin",
+ "Buckthorn",
+ "Skipper"
+ ]
+}
diff --git a/bot/seasons/easter/bunny_name_generator.py b/bot/seasons/easter/bunny_name_generator.py
new file mode 100644
index 00000000..5dcbe62f
--- /dev/null
+++ b/bot/seasons/easter/bunny_name_generator.py
@@ -0,0 +1,106 @@
+import json
+import logging
+import random
+import re
+from pathlib import Path
+
+from discord.ext import commands
+
+log = logging.getLogger(__name__)
+
+with open(Path("bot", "resources", "easter", "bunny_names.json"), "r", encoding="utf8") as f:
+ BUNNY_NAMES = json.load(f)
+
+
+class BunnyNameGenerator(commands.Cog):
+ """Generate a random bunny name, or bunnify your Discord username!"""
+
+ def __init__(self, bot):
+ self.bot = bot
+
+ def find_separators(self, displayname):
+ """Check if Discord name contains spaces so we can bunnify an individual word in the name."""
+
+ new_name = re.split(r'[_.\s]', str(displayname))
+ if displayname not in new_name:
+ return new_name
+
+ def find_vowels(self, displayname):
+ """
+ Finds vowels in the user's display name.
+
+ If the Discord name contains a vowel and the letter y,
+ it will match one or more of these patterns.
+ Only the most recently matched pattern will apply the changes.
+ """
+
+ new_name = None
+
+ option1 = re.sub(r'a.+y', 'patchy', displayname)
+ option2 = re.sub(r'e.+y', 'ears', displayname)
+ option3 = re.sub(r'i.+y', 'ditsy', displayname)
+ option4 = re.sub(r'o.+y', 'oofy', displayname)
+ option5 = re.sub(r'u.+y', 'uffy', displayname)
+
+ if option1 != displayname:
+ new_name = option1
+ if option2 != displayname:
+ new_name = option2
+ if option3 != displayname:
+ new_name = option3
+ if option4 != displayname:
+ new_name = option4
+ if option5 != displayname:
+ new_name = option5
+
+ return new_name
+
+ def append_name(self, displayname):
+ """Adds a suffix to the end of the Discord name"""
+
+ extensions = ['foot', 'ear', 'nose', 'tail']
+ suffix = random.choice(extensions)
+ appended_name = displayname + suffix
+
+ return appended_name
+
+ @commands.command()
+ async def bunnyname(self, ctx):
+ """Picks a random bunny name from a JSON file"""
+
+ await ctx.send(random.choice(BUNNY_NAMES["names"]))
+
+ @commands.command()
+ async def bunnifyme(self, ctx):
+ """Gets your Discord username and bunnifies it"""
+
+ username = ctx.message.author.display_name
+
+ # If name contains spaces or other separators, get the individual words to randomly bunnify
+ spaces_in_name = self.find_separators(username)
+
+ # If name contains vowels, see if it matches any of the patterns in this function
+ # If there are matches, the bunnified name is returned.
+ vowels_in_name = self.find_vowels(username)
+
+ # Default if the checks above return None
+ unmatched_name = self.append_name(username)
+
+ if spaces_in_name is not None:
+ replacements = ['Cotton', 'Fluff', 'Floof' 'Bounce', 'Snuffle', 'Nibble', 'Cuddle', 'Velvetpaw', 'Carrot']
+ word_to_replace = random.choice(spaces_in_name)
+ substitute = random.choice(replacements)
+ bunnified_name = username.replace(word_to_replace, substitute)
+ elif vowels_in_name is not None:
+ bunnified_name = vowels_in_name
+ elif unmatched_name:
+ bunnified_name = unmatched_name
+
+ await ctx.send(bunnified_name)
+
+
+def setup(bot):
+ """Cog load."""
+
+ bot.add_cog(BunnyNameGenerator(bot))
+ log.info("BunnyNameGenerator cog loaded.")