aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/fun/wonder_twins.py
diff options
context:
space:
mode:
authorGravatar Janine vN <[email protected]>2021-09-05 00:31:20 -0400
committerGravatar Janine vN <[email protected]>2021-09-05 00:31:20 -0400
commit02512e43f3d68ffd89654c5f2e9e3e9a27c0c018 (patch)
tree4b62a6dbb39601f02aa435c7eb8a10433585c3bb /bot/exts/fun/wonder_twins.py
parentMove snakes commands into fun folder (diff)
Move game and fun commands to Fun folder, fix ddg
This moves all the fun commands and games into the fun folder. This commit also makes changes to the duck_game. It was setting a footer during an embed init, which is no longer possible with the version of d.py we use. Additionally, an issue with editing an embed that had a local image loaded. The workaround for the time being is to update the message, not the embed.
Diffstat (limited to 'bot/exts/fun/wonder_twins.py')
-rw-r--r--bot/exts/fun/wonder_twins.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/bot/exts/fun/wonder_twins.py b/bot/exts/fun/wonder_twins.py
new file mode 100644
index 00000000..79d6b6d9
--- /dev/null
+++ b/bot/exts/fun/wonder_twins.py
@@ -0,0 +1,49 @@
+import random
+from pathlib import Path
+
+import yaml
+from discord.ext.commands import Cog, Context, command
+
+from bot.bot import Bot
+
+
+class WonderTwins(Cog):
+ """Cog for a Wonder Twins inspired command."""
+
+ def __init__(self):
+ with open(Path.cwd() / "bot" / "resources" / "fun" / "wonder_twins.yaml", "r", encoding="utf-8") as f:
+ info = yaml.load(f, Loader=yaml.FullLoader)
+ self.water_types = info["water_types"]
+ self.objects = info["objects"]
+ self.adjectives = info["adjectives"]
+
+ @staticmethod
+ def append_onto(phrase: str, insert_word: str) -> str:
+ """Appends one word onto the end of another phrase in order to format with the proper determiner."""
+ if insert_word.endswith("s"):
+ phrase = phrase.split()
+ del phrase[0]
+ phrase = " ".join(phrase)
+
+ insert_word = insert_word.split()[-1]
+ return " ".join([phrase, insert_word])
+
+ def format_phrase(self) -> str:
+ """Creates a transformation phrase from available words."""
+ adjective = random.choice((None, random.choice(self.adjectives)))
+ object_name = random.choice(self.objects)
+ water_type = random.choice(self.water_types)
+
+ if adjective:
+ object_name = self.append_onto(adjective, object_name)
+ return f"{object_name} of {water_type}"
+
+ @command(name="formof", aliases=("wondertwins", "wondertwin", "fo"))
+ async def form_of(self, ctx: Context) -> None:
+ """Command to send a Wonder Twins inspired phrase to the user invoking the command."""
+ await ctx.send(f"Form of {self.format_phrase()}!")
+
+
+def setup(bot: Bot) -> None:
+ """Load the WonderTwins cog."""
+ bot.add_cog(WonderTwins())