aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/halloween
diff options
context:
space:
mode:
authorGravatar ToxicKidz <[email protected]>2021-05-13 13:34:06 -0400
committerGravatar ToxicKidz <[email protected]>2021-05-13 13:34:06 -0400
commit2aa1916d5c8e4832f26f6da4094238e9a0021d1c (patch)
tree2ce3195a019ef84fd0b2d6509f5deec7b25e19bc /bot/exts/halloween
parentfix: Resolve Merge Conflicts (diff)
chore: Use pathlib.Path.read_text & write_text over open
Diffstat (limited to 'bot/exts/halloween')
-rw-r--r--bot/exts/halloween/8ball.py3
-rw-r--r--bot/exts/halloween/halloween_facts.py3
-rw-r--r--bot/exts/halloween/halloweenify.py5
-rw-r--r--bot/exts/halloween/monsterbio.py5
-rw-r--r--bot/exts/halloween/monstersurvey.py6
-rw-r--r--bot/exts/halloween/spookynamerate.py3
-rw-r--r--bot/exts/halloween/spookyrating.py6
7 files changed, 13 insertions, 18 deletions
diff --git a/bot/exts/halloween/8ball.py b/bot/exts/halloween/8ball.py
index d6c5a299..a2431190 100644
--- a/bot/exts/halloween/8ball.py
+++ b/bot/exts/halloween/8ball.py
@@ -10,8 +10,7 @@ from bot.bot import Bot
log = logging.getLogger(__name__)
-with Path("bot/resources/halloween/responses.json").open("r", encoding="utf8") as f:
- RESPONSES = json.load(f)
+RESPONSES = json.loads(Path("bot/resources/halloween/responses.json").read_text("utf8"))
class SpookyEightBall(commands.Cog):
diff --git a/bot/exts/halloween/halloween_facts.py b/bot/exts/halloween/halloween_facts.py
index 3a89b5aa..98cc2db0 100644
--- a/bot/exts/halloween/halloween_facts.py
+++ b/bot/exts/halloween/halloween_facts.py
@@ -30,8 +30,7 @@ class HalloweenFacts(commands.Cog):
"""A Cog for displaying interesting facts about Halloween."""
def __init__(self):
- with Path("bot/resources/halloween/halloween_facts.json").open("r", encoding="utf8") as file:
- self.halloween_facts = json.load(file)
+ 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]:
diff --git a/bot/exts/halloween/halloweenify.py b/bot/exts/halloween/halloweenify.py
index df55b55d..e839950a 100644
--- a/bot/exts/halloween/halloweenify.py
+++ b/bot/exts/halloween/halloweenify.py
@@ -1,5 +1,5 @@
import logging
-from json import load
+from json import loads
from pathlib import Path
from random import choice
@@ -21,8 +21,7 @@ class Halloweenify(commands.Cog):
async def halloweenify(self, ctx: commands.Context) -> None:
"""Change your nickname into a much spookier one!"""
async with ctx.typing():
- with open(Path("bot/resources/halloween/halloweenify.json"), "r", encoding="utf8") as f:
- data = load(f)
+ 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"])
diff --git a/bot/exts/halloween/monsterbio.py b/bot/exts/halloween/monsterbio.py
index 1aaba7bb..69e898cb 100644
--- a/bot/exts/halloween/monsterbio.py
+++ b/bot/exts/halloween/monsterbio.py
@@ -11,8 +11,9 @@ 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
+TEXT_OPTIONS = json.loads(
+ Path("bot/resources/halloween/monster.json").read_text("utf8")
+) # Data for a mad-lib style generation of text
class MonsterBio(commands.Cog):
diff --git a/bot/exts/halloween/monstersurvey.py b/bot/exts/halloween/monstersurvey.py
index 231454ea..240a97db 100644
--- a/bot/exts/halloween/monstersurvey.py
+++ b/bot/exts/halloween/monstersurvey.py
@@ -26,14 +26,12 @@ class MonsterSurvey(Cog):
def __init__(self):
"""Initializes values for the bot to use within the voting commands."""
self.registry_path = pathlib.Path("bot", "resources", "halloween", "monstersurvey.json")
- with self.registry_path.open(encoding="utf8") as data:
- self.voter_registry = json.load(data)
+ self.voter_registry = json.loads(self.registry_path.read_text("utf8"))
def json_write(self) -> None:
"""Write voting results to a local JSON file."""
log.info("Saved Monster Survey Results")
- with self.registry_path.open("w", encoding="utf8") as data:
- json.dump(self.voter_registry, data, indent=2)
+ self.registry_path.write_text(json.dumps(self.voter_registry, indent=2))
def cast_vote(self, id: int, monster: str) -> None:
"""
diff --git a/bot/exts/halloween/spookynamerate.py b/bot/exts/halloween/spookynamerate.py
index 87172922..63040289 100644
--- a/bot/exts/halloween/spookynamerate.py
+++ b/bot/exts/halloween/spookynamerate.py
@@ -371,8 +371,7 @@ class SpookyNameRate(Cog):
@staticmethod
def load_json(file: Path) -> Dict[str, str]:
"""Loads a JSON file and returns its contents."""
- with file.open("r", encoding="utf-8") as f:
- return json.load(f)
+ return json.loads(file.read_text("utf8"))
@staticmethod
def in_allowed_month() -> bool:
diff --git a/bot/exts/halloween/spookyrating.py b/bot/exts/halloween/spookyrating.py
index 6c79fbed..105d2164 100644
--- a/bot/exts/halloween/spookyrating.py
+++ b/bot/exts/halloween/spookyrating.py
@@ -3,6 +3,7 @@ import json
import logging
import random
from pathlib import Path
+from typing import Dict
import discord
from discord.ext import commands
@@ -12,9 +13,8 @@ from bot.constants import Colours
log = logging.getLogger(__name__)
-with Path("bot/resources/halloween/spooky_rating.json").open(encoding="utf8") as file:
- data = json.load(file)
- SPOOKY_DATA = sorted((int(key), value) for key, value in data.items())
+data: Dict[str, Dict[str, str]] = json.loads(Path("bot/resources/halloween/spooky_rating.json").read_text("utf8"))
+SPOOKY_DATA = sorted((int(key), value) for key, value in data.items())
class SpookyRating(commands.Cog):