diff options
| author | 2021-05-15 13:31:34 -0400 | |
|---|---|---|
| committer | 2021-05-15 13:31:34 -0400 | |
| commit | f8a179df350eb3abb7f3595aaff3dbca312f540c (patch) | |
| tree | 6868ae98b81b614f8d8d68f1a9bbc06c7cb94490 /bot/exts/halloween | |
| parent | chore: Make all aliases in commands tuples (diff) | |
chore: Make things that are only used once constants
Diffstat (limited to 'bot/exts/halloween')
| -rw-r--r-- | bot/exts/halloween/halloween_facts.py | 9 | ||||
| -rw-r--r-- | bot/exts/halloween/halloweenify.py | 10 | ||||
| -rw-r--r-- | bot/exts/halloween/spookygif.py | 7 | 
3 files changed, 13 insertions, 13 deletions
| diff --git a/bot/exts/halloween/halloween_facts.py b/bot/exts/halloween/halloween_facts.py index 98cc2db0..5ad8cc57 100644 --- a/bot/exts/halloween/halloween_facts.py +++ b/bot/exts/halloween/halloween_facts.py @@ -25,17 +25,16 @@ SPOOKY_EMOJIS = [  PUMPKIN_ORANGE = 0xFF7518  INTERVAL = timedelta(hours=6).total_seconds() +FACTS = json.loads(Path("bot/resources/halloween/halloween_facts.json").read_text("utf8")) +FACTS = list(enumerate(FACTS)) +  class HalloweenFacts(commands.Cog):      """A Cog for displaying interesting facts about Halloween.""" -    def __init__(self): -        self.halloween_facts = json.loads(Path("bot/resources/halloween/halloween_facts.json").read_text("utf8")) -        self.facts = list(enumerate(self.halloween_facts)) -      def random_fact(self) -> Tuple[int, str]:          """Return a random fact from the loaded facts.""" -        return random.choice(self.facts) +        return random.choice(FACTS)      @commands.command(name="spookyfact", aliases=("halloweenfact",), brief="Get the most recent Halloween fact")      async def get_random_fact(self, ctx: commands.Context) -> None: diff --git a/bot/exts/halloween/halloweenify.py b/bot/exts/halloween/halloweenify.py index e839950a..83cfbaa7 100644 --- a/bot/exts/halloween/halloweenify.py +++ b/bot/exts/halloween/halloweenify.py @@ -12,6 +12,8 @@ from bot.bot import Bot  log = logging.getLogger(__name__) +HALLOWEENIFY_DATA = loads(Path("bot/resources/halloween/halloweenify.json").read_text("utf8")) +  class Halloweenify(commands.Cog):      """A cog to change a invokers nickname to a spooky one!""" @@ -21,12 +23,10 @@ class Halloweenify(commands.Cog):      async def halloweenify(self, ctx: commands.Context) -> None:          """Change your nickname into a much spookier one!"""          async with ctx.typing(): -            data = loads(Path("bot/resources/halloween/halloweenify.json").read_text("utf8")) -              # Choose a random character from our list we loaded above and set apart the nickname and image url. -            character = choice(data["characters"]) -            nickname = "".join([nickname for nickname in character]) -            image = "".join([character[nickname] for nickname in character]) +            character = choice(HALLOWEENIFY_DATA["characters"]) +            nickname = "".join(nickname for nickname in character) +            image = "".join(character[nickname] for nickname in character)              # Build up a Embed              embed = discord.Embed() diff --git a/bot/exts/halloween/spookygif.py b/bot/exts/halloween/spookygif.py index ffb91b1b..a2146a84 100644 --- a/bot/exts/halloween/spookygif.py +++ b/bot/exts/halloween/spookygif.py @@ -8,6 +8,8 @@ from bot.constants import Tokens  log = logging.getLogger(__name__) +API_URL = "http://api.giphy.com/v1/gifs/random" +  class SpookyGif(commands.Cog):      """A cog to fetch a random spooky gif from the web!""" @@ -21,12 +23,11 @@ class SpookyGif(commands.Cog):          async with ctx.typing():              params = {"api_key": Tokens.giphy, "tag": "halloween", "rating": "g"}              # Make a GET request to the Giphy API to get a random halloween gif. -            async with self.bot.http_session.get("http://api.giphy.com/v1/gifs/random", params=params) as resp: +            async with self.bot.http_session.get(API_URL, params=params) as resp:                  data = await resp.json()              url = data["data"]["image_url"] -            embed = discord.Embed(colour=0x9b59b6) -            embed.title = "A spooooky gif!" +            embed = discord.Embed(title="A spooooky gif!", colour=0x9b59b6)              embed.set_image(url=url)          await ctx.send(embed=embed) | 
