From 259e335e8c8e862883c8515d55a45dae3146f595 Mon Sep 17 00:00:00 2001 From: "S. Co1" Date: Thu, 24 Oct 2019 16:51:17 -0400 Subject: Readd cog init & rename *.py file --- bot/seasons/halloween/monster.py | 49 ---------------------------------- bot/seasons/halloween/monsterbio.py | 52 +++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 49 deletions(-) delete mode 100644 bot/seasons/halloween/monster.py create mode 100644 bot/seasons/halloween/monsterbio.py (limited to 'bot') diff --git a/bot/seasons/halloween/monster.py b/bot/seasons/halloween/monster.py deleted file mode 100644 index 5a735b69..00000000 --- a/bot/seasons/halloween/monster.py +++ /dev/null @@ -1,49 +0,0 @@ -import json -import logging -import random -from pathlib import Path - -import discord -from discord.ext import commands - -from bot.constants import Colours - -log = logging.getLogger(__name__) - -with open(Path("bot/resources/halloween/monster.json"), "r", encoding="utf8") as f: - TEXT_OPTIONS = json.load(f) # Data for a mad-lib style generation of text - - -class MonsterBio(commands.Cog): - """A cog that generates a spooky monster biography.""" - - def generate_name(self, length: int) -> str: - """Generates a name (for either monster species or monster name).""" - return "".join([random.choice(TEXT_OPTIONS["monster_type"][i]) for i in range(length)]) - - @commands.command(brief="Sends your monster bio!") - async def monsterbio(self, ctx: commands.Context) -> None: - """Sends a description of a monster.""" - random.seed(ctx.message.author.id) - name = self.generate_name(random.randint(2, len(TEXT_OPTIONS["monster_type"]))) - species = self.generate_name(random.randint(2, len(TEXT_OPTIONS["monster_type"]))) - biography_text = random.choice(TEXT_OPTIONS["biography_text"]) - words = {"monster_name": name, "monster_species": species} - for key, value in biography_text.items(): - if key == "text": - continue - if value > 1: - words[key] = random.sample(TEXT_OPTIONS[key], value) - else: - words[key] = random.choice(TEXT_OPTIONS[key]) - embed = discord.Embed( - title=f"{name}'s Biography", - color=random.choice([Colours.orange, Colours.purple]), description=biography_text["text"].format(**words) - ) - await ctx.send(embed=embed) - - -def setup(bot: commands.Bot) -> None: - """Monster bio Cog load.""" - bot.add_cog(MonsterBio(bot)) - log.info("MonsterBio cog loaded.") diff --git a/bot/seasons/halloween/monsterbio.py b/bot/seasons/halloween/monsterbio.py new file mode 100644 index 00000000..d84498a8 --- /dev/null +++ b/bot/seasons/halloween/monsterbio.py @@ -0,0 +1,52 @@ +import json +import logging +import random +from pathlib import Path + +import discord +from discord.ext import commands + +from bot.constants import Colours + +log = logging.getLogger(__name__) + +with open(Path("bot/resources/halloween/monster.json"), "r", encoding="utf8") as f: + TEXT_OPTIONS = json.load(f) # Data for a mad-lib style generation of text + + +class MonsterBio(commands.Cog): + """A cog that generates a spooky monster biography.""" + + def __init__(self, bot: commands.Bot): + self.bot = bot + + def generate_name(self, length: int) -> str: + """Generates a name (for either monster species or monster name).""" + return "".join([random.choice(TEXT_OPTIONS["monster_type"][i]) for i in range(length)]) + + @commands.command(brief="Sends your monster bio!") + async def monsterbio(self, ctx: commands.Context) -> None: + """Sends a description of a monster.""" + random.seed(ctx.message.author.id) + name = self.generate_name(random.randint(2, len(TEXT_OPTIONS["monster_type"]))) + species = self.generate_name(random.randint(2, len(TEXT_OPTIONS["monster_type"]))) + biography_text = random.choice(TEXT_OPTIONS["biography_text"]) + words = {"monster_name": name, "monster_species": species} + for key, value in biography_text.items(): + if key == "text": + continue + if value > 1: + words[key] = random.sample(TEXT_OPTIONS[key], value) + else: + words[key] = random.choice(TEXT_OPTIONS[key]) + embed = discord.Embed( + title=f"{name}'s Biography", + color=random.choice([Colours.orange, Colours.purple]), description=biography_text["text"].format(**words) + ) + await ctx.send(embed=embed) + + +def setup(bot: commands.Bot) -> None: + """Monster bio Cog load.""" + bot.add_cog(MonsterBio(bot)) + log.info("MonsterBio cog loaded.") -- cgit v1.2.3