aboutsummaryrefslogtreecommitdiffstats
path: root/bot/seasons/halloween/monster.py
diff options
context:
space:
mode:
authorGravatar quizzicaltrains <[email protected]>2019-10-18 18:39:46 -0700
committerGravatar quizzicaltrains <[email protected]>2019-10-18 18:39:46 -0700
commitda4c08b60a8e9f25fb24ed4c094010dbdcddcc41 (patch)
tree1a0ef8d6a134f1c9aa4b66715bd825c668f6c491 /bot/seasons/halloween/monster.py
parentAdds the monsterbio command! (diff)
Changed several things.
Diffstat (limited to 'bot/seasons/halloween/monster.py')
-rw-r--r--bot/seasons/halloween/monster.py31
1 files changed, 11 insertions, 20 deletions
diff --git a/bot/seasons/halloween/monster.py b/bot/seasons/halloween/monster.py
index a068d02c..a54c7088 100644
--- a/bot/seasons/halloween/monster.py
+++ b/bot/seasons/halloween/monster.py
@@ -5,46 +5,37 @@ from pathlib import Path
import discord
from discord.ext import commands
+from constants import Colour
log = logging.getLogger(__name__)
with open(Path("bot/resources/halloween/monster.json"), "r", encoding="utf8") as f:
- data = json.load(f)
-
-PUMPKIN_ORANGE = discord.Color(0xFF7518)
-OTHER_PURPLE = discord.Color(0xB734EB)
-
+ 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
- self.channel = None
+ def generate_name(length):
+ 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_length = random.randint(2, len(data["monster_type"]))
- species_length = random.randint(2, len(data["monster_type"]))
- name = species = ""
- for i in range(name_length):
- name += random.choice(data["monster_type"][i])
- for i in range(species_length):
- species += random.choice(data["monster_type"][i])
- format = random.choice(data["format"])
+ name = self.generate_name(random.randint(2, len(TEXT_OPTIONS["monster_type"])))
+ species = selfgenerate_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 format.items():
+ for key, value in biography_text.items():
if key == "text":
continue
if value > 1:
- words[key] = random.sample(data[key], value)
+ words[key] = random.sample(TEXT_OPTIONS[key], value)
else:
- words[key] = random.choice(data[key])
+ words[key] = random.choice(TEXT_OPTIONS[key])
embed = discord.Embed(
title=f"{name}'s Biography",
- color=random.choice([PUMPKIN_ORANGE, OTHER_PURPLE]), description=format["text"].format(**words)
+ color=random.choice([Colours.orange, Colours.purple]), description=biography_text["text"].format(**words)
)
await ctx.send(embed=embed)