diff options
Diffstat (limited to 'bot')
34 files changed, 63 insertions, 98 deletions
| diff --git a/bot/exts/christmas/advent_of_code/_cog.py b/bot/exts/christmas/advent_of_code/_cog.py index 863d2a21..ce6a4cb6 100644 --- a/bot/exts/christmas/advent_of_code/_cog.py +++ b/bot/exts/christmas/advent_of_code/_cog.py @@ -279,8 +279,7 @@ class AdventOfCode(commands.Cog):      def _build_about_embed(self) -> discord.Embed:          """Build and return the informational "About AoC" embed from the resources file.""" -        with self.about_aoc_filepath.open("r", encoding="utf8") as f: -            embed_fields = json.load(f) +        embed_fields = json.loads(self.about_aoc_filepath.read_text("utf8"))          about_embed = discord.Embed(              title=self._base_url, diff --git a/bot/exts/easter/april_fools_vids.py b/bot/exts/easter/april_fools_vids.py index 3ce1f72a..5ef40704 100644 --- a/bot/exts/easter/april_fools_vids.py +++ b/bot/exts/easter/april_fools_vids.py @@ -1,6 +1,7 @@  import logging  import random -from json import load +from json import loads +from pathlib import Path  from discord.ext import commands @@ -8,8 +9,7 @@ from bot.bot import Bot  log = logging.getLogger(__name__) -with open("bot/resources/easter/april_fools_vids.json", encoding="utf-8") as f: -    ALL_VIDS = load(f) +ALL_VIDS = loads(Path("bot/resources/easter/april_fools_vids.json").read_text("utf-8"))  class AprilFoolVideos(commands.Cog): diff --git a/bot/exts/easter/bunny_name_generator.py b/bot/exts/easter/bunny_name_generator.py index 5e3b014d..adde8704 100644 --- a/bot/exts/easter/bunny_name_generator.py +++ b/bot/exts/easter/bunny_name_generator.py @@ -11,8 +11,7 @@ from bot.bot import Bot  log = logging.getLogger(__name__) -with Path("bot/resources/easter/bunny_names.json").open("r", encoding="utf8") as f: -    BUNNY_NAMES = json.load(f) +BUNNY_NAMES = json.loads(Path("bot/resources/easter/bunny_names.json").read_text("utf8"))  class BunnyNameGenerator(commands.Cog): diff --git a/bot/exts/easter/easter_riddle.py b/bot/exts/easter/easter_riddle.py index 9a253a6a..01b956f1 100644 --- a/bot/exts/easter/easter_riddle.py +++ b/bot/exts/easter/easter_riddle.py @@ -1,7 +1,7 @@  import asyncio  import logging  import random -from json import load +from json import loads  from pathlib import Path  import discord @@ -12,8 +12,7 @@ from bot.constants import Colours, NEGATIVE_REPLIES  log = logging.getLogger(__name__) -with Path("bot/resources/easter/easter_riddle.json").open("r", encoding="utf8") as f: -    RIDDLE_QUESTIONS = load(f) +RIDDLE_QUESTIONS = loads(Path("bot/resources/easter/easter_riddle.json").read_text("utf8"))  TIMELIMIT = 10 diff --git a/bot/exts/easter/egg_decorating.py b/bot/exts/easter/egg_decorating.py index 3744989d..7448f702 100644 --- a/bot/exts/easter/egg_decorating.py +++ b/bot/exts/easter/egg_decorating.py @@ -15,11 +15,9 @@ from bot.utils import helpers  log = logging.getLogger(__name__) -with open(Path("bot/resources/evergreen/html_colours.json"), encoding="utf8") as f: -    HTML_COLOURS = json.load(f) +HTML_COLOURS = json.loads(Path("bot/resources/evergreen/html_colours.json").read_text("utf8")) -with open(Path("bot/resources/evergreen/xkcd_colours.json"), encoding="utf8") as f: -    XKCD_COLOURS = json.load(f) +XKCD_COLOURS = json.loads(Path("bot/resources/evergreen/xkcd_colours.json").read_text("utf8"))  COLOURS = [      (255, 0, 0, 255), (255, 128, 0, 255), (255, 255, 0, 255), (0, 255, 0, 255), diff --git a/bot/exts/easter/egg_facts.py b/bot/exts/easter/egg_facts.py index 8c93ca7b..c1c43f80 100644 --- a/bot/exts/easter/egg_facts.py +++ b/bot/exts/easter/egg_facts.py @@ -1,6 +1,6 @@  import logging  import random -from json import load +from json import loads  from pathlib import Path  import discord @@ -30,8 +30,7 @@ class EasterFacts(commands.Cog):      def load_json() -> dict:          """Load a list of easter egg facts from the resource JSON file."""          p = Path("bot/resources/easter/easter_egg_facts.json") -        with p.open(encoding="utf8") as f: -            return load(f) +        return loads(p.read_text("utf8"))      @seasonal_task(Month.APRIL)      async def send_egg_fact_daily(self) -> None: diff --git a/bot/exts/easter/egghead_quiz.py b/bot/exts/easter/egghead_quiz.py index b6b1593d..4b67310f 100644 --- a/bot/exts/easter/egghead_quiz.py +++ b/bot/exts/easter/egghead_quiz.py @@ -1,7 +1,7 @@  import asyncio  import logging  import random -from json import load +from json import loads  from pathlib import Path  from typing import Union @@ -13,8 +13,7 @@ from bot.constants import Colours  log = logging.getLogger(__name__) -with open(Path("bot/resources/easter/egghead_questions.json"), "r", encoding="utf8") as f: -    EGGHEAD_QUESTIONS = load(f) +EGGHEAD_QUESTIONS = loads(Path("bot/resources/easter/egghead_questions.json").read_text("utf8"))  EMOJIS = [ diff --git a/bot/exts/easter/save_the_planet.py b/bot/exts/easter/save_the_planet.py index 444bb030..1bd515f2 100644 --- a/bot/exts/easter/save_the_planet.py +++ b/bot/exts/easter/save_the_planet.py @@ -7,9 +7,7 @@ from discord.ext import commands  from bot.bot import Bot  from bot.utils.randomization import RandomCycle - -with Path("bot/resources/easter/save_the_planet.json").open("r", encoding="utf8") as f: -    EMBED_DATA = RandomCycle(json.load(f)) +EMBED_DATA = RandomCycle(json.loads(Path("bot/resources/easter/save_the_planet.json").read_text("utf8")))  class SaveThePlanet(commands.Cog): diff --git a/bot/exts/easter/traditions.py b/bot/exts/easter/traditions.py index cb70f2d0..93404f3e 100644 --- a/bot/exts/easter/traditions.py +++ b/bot/exts/easter/traditions.py @@ -9,8 +9,7 @@ from bot.bot import Bot  log = logging.getLogger(__name__) -with open(Path("bot/resources/easter/traditions.json"), "r", encoding="utf8") as f: -    traditions = json.load(f) +traditions = json.loads(Path("bot/resources/easter/traditions.json").read_text("utf8"))  class Traditions(commands.Cog): diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index 5685b2c1..199b6dcb 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -6,6 +6,7 @@ import string  import typing as t  import unicodedata  from concurrent.futures import ThreadPoolExecutor +from pathlib import Path  import discord  from aiohttp import client_exceptions @@ -27,8 +28,7 @@ MAX_SQUARES = 10_000  T = t.TypeVar("T") -with open("bot/resources/pride/gender_options.json") as f: -    GENDER_OPTIONS = json.load(f) +GENDER_OPTIONS = json.loads(Path("bot/resources/pride/gender_options.json").read_text("utf8"))  async def in_executor(func: t.Callable[..., T], *args) -> T: diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index ed51358c..3b266e1b 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -56,8 +56,7 @@ class Fun(Cog):      def __init__(self, bot: Bot) -> None:          self.bot = bot -        with Path("bot/resources/evergreen/caesar_info.json").open("r", encoding="UTF-8") as f: -            self._caesar_cipher_embed = json.load(f) +        self._caesar_cipher_embed = json.loads(Path("bot/resources/evergreen/caesar_info.json").read_text("UTF-8"))      @staticmethod      def _get_random_die() -> str: diff --git a/bot/exts/evergreen/magic_8ball.py b/bot/exts/evergreen/magic_8ball.py index 7c9b929d..4b3ed2a4 100644 --- a/bot/exts/evergreen/magic_8ball.py +++ b/bot/exts/evergreen/magic_8ball.py @@ -14,8 +14,7 @@ class Magic8ball(commands.Cog):      """A Magic 8ball command to respond to a user's question."""      def __init__(self): -        with open(Path("bot/resources/evergreen/magic8ball.json"), "r", encoding="utf8") as file: -            self.answers = json.load(file) +        self.answers = json.loads(Path("bot/resources/evergreen/magic8ball.json").read_text("utf8"))      @commands.command(name="8ball")      async def output_answer(self, ctx: commands.Context, *, question: str) -> None: diff --git a/bot/exts/evergreen/recommend_game.py b/bot/exts/evergreen/recommend_game.py index 340a42d3..56596020 100644 --- a/bot/exts/evergreen/recommend_game.py +++ b/bot/exts/evergreen/recommend_game.py @@ -13,8 +13,7 @@ game_recs = []  # Populate the list `game_recs` with resource files  for rec_path in Path("bot/resources/evergreen/game_recs").glob("*.json"): -    with rec_path.open(encoding="utf8") as file: -        data = json.load(file) +    data = json.loads(rec_path.read_text("utf8"))      game_recs.append(data)  shuffle(game_recs) diff --git a/bot/exts/evergreen/snakes/_converter.py b/bot/exts/evergreen/snakes/_converter.py index 0ca10d6c..26bde611 100644 --- a/bot/exts/evergreen/snakes/_converter.py +++ b/bot/exts/evergreen/snakes/_converter.py @@ -63,13 +63,10 @@ class Snake(Converter):          """Build list of snakes from the static snake resources."""          # Get all the snakes          if cls.snakes is None: -            with (SNAKE_RESOURCES / "snake_names.json").open(encoding="utf8") as snakefile: -                cls.snakes = json.load(snakefile) - +            cls.snakes = json.loads((SNAKE_RESOURCES / "snake_names.json").read_text("utf8"))          # Get the special cases          if cls.special_cases is None: -            with (SNAKE_RESOURCES / "special_snakes.json").open(encoding="utf8") as snakefile: -                special_cases = json.load(snakefile) +            special_cases = json.loads((SNAKE_RESOURCES / "special_snakes.json").read_text("utf8"))              cls.special_cases = {snake["name"].lower(): snake for snake in special_cases}      @classmethod diff --git a/bot/exts/evergreen/snakes/_utils.py b/bot/exts/evergreen/snakes/_utils.py index 9b38ffa2..8b39f217 100644 --- a/bot/exts/evergreen/snakes/_utils.py +++ b/bot/exts/evergreen/snakes/_utils.py @@ -114,8 +114,7 @@ ANGLE_RANGE = math.pi * 2  def get_resource(file: str) -> List[dict]:      """Load Snake resources JSON.""" -    with (SNAKE_RESOURCES / f"{file}.json").open(encoding="utf-8") as snakefile: -        return json.load(snakefile) +    return json.loads((SNAKE_RESOURCES / f"{file}.json").read_text("utf-8"))  def smoothstep(t: float) -> float: @@ -560,7 +559,7 @@ class SnakeAndLaddersGame:          self.state = "roll"          for user in self.players:              self.round_has_rolled[user.id] = False -        board_img = Image.open(str(SNAKE_RESOURCES / "snakes_and_ladders" / "board.jpg")) +        board_img = Image.open(SNAKE_RESOURCES / "snakes_and_ladders" / "board.jpg")          player_row_size = math.ceil(MAX_PLAYERS / 2)          for i, player in enumerate(self.players): diff --git a/bot/exts/evergreen/speedrun.py b/bot/exts/evergreen/speedrun.py index d9820287..774eff81 100644 --- a/bot/exts/evergreen/speedrun.py +++ b/bot/exts/evergreen/speedrun.py @@ -8,8 +8,8 @@ from discord.ext import commands  from bot.bot import Bot  log = logging.getLogger(__name__) -with Path("bot/resources/evergreen/speedrun_links.json").open(encoding="utf8") as file: -    LINKS = json.load(file) + +LINKS = json.loads(Path("bot/resources/evergreen/speedrun_links.json").read_text("utf8"))  class Speedrun(commands.Cog): diff --git a/bot/exts/evergreen/trivia_quiz.py b/bot/exts/evergreen/trivia_quiz.py index 1953253b..9db201ef 100644 --- a/bot/exts/evergreen/trivia_quiz.py +++ b/bot/exts/evergreen/trivia_quiz.py @@ -41,9 +41,7 @@ class TriviaQuiz(commands.Cog):      def load_questions() -> dict:          """Load the questions from the JSON file."""          p = Path("bot", "resources", "evergreen", "trivia_quiz.json") -        with p.open(encoding="utf8") as json_data: -            questions = json.load(json_data) -            return questions +        return json.loads(p.read_text("utf8"))      @commands.group(name="quiz", aliases=["trivia"], invoke_without_command=True)      async def quiz_game(self, ctx: commands.Context, category: str = None) -> None: 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): diff --git a/bot/exts/pride/drag_queen_name.py b/bot/exts/pride/drag_queen_name.py index d9424001..6bf43913 100644 --- a/bot/exts/pride/drag_queen_name.py +++ b/bot/exts/pride/drag_queen_name.py @@ -19,8 +19,7 @@ class DragNames(commands.Cog):      @staticmethod      def load_names() -> list:          """Loads a list of drag queen names.""" -        with Path("bot/resources/pride/drag_queen_names.json").open(encoding="utf8") as f: -            return json.load(f) +        return json.loads(Path("bot/resources/pride/drag_queen_names.json").read_text("utf8"))      @commands.command(name="dragname", aliases=["dragqueenname", "queenme"])      async def dragname(self, ctx: commands.Context) -> None: diff --git a/bot/exts/pride/pride_anthem.py b/bot/exts/pride/pride_anthem.py index a7f8d7ef..21b7e468 100644 --- a/bot/exts/pride/pride_anthem.py +++ b/bot/exts/pride/pride_anthem.py @@ -36,9 +36,7 @@ class PrideAnthem(commands.Cog):      @staticmethod      def load_vids() -> list:          """Loads a list of videos from the resources folder as dictionaries.""" -        with open(Path("bot/resources/pride/anthems.json"), "r", encoding="utf8") as f: -            anthems = json.load(f) -        return anthems +        return json.loads(Path("bot/resources/pride/anthems.json").read_text("utf8"))      @commands.command(name="prideanthem", aliases=["anthem", "pridesong"])      async def prideanthem(self, ctx: commands.Context, genre: str = None) -> None: diff --git a/bot/exts/pride/pride_facts.py b/bot/exts/pride/pride_facts.py index 6d06cf64..47e69a03 100644 --- a/bot/exts/pride/pride_facts.py +++ b/bot/exts/pride/pride_facts.py @@ -28,8 +28,7 @@ class PrideFacts(commands.Cog):      @staticmethod      def load_facts() -> dict:          """Loads a dictionary of years mapping to lists of facts.""" -        with open(Path("bot/resources/pride/facts.json"), "r", encoding="utf8") as f: -            return json.load(f) +        return json.loads(Path("bot/resources/pride/facts.json").read_text("utf8"))      @seasonal_task(Month.JUNE)      async def send_pride_fact_daily(self) -> None: diff --git a/bot/exts/valentines/be_my_valentine.py b/bot/exts/valentines/be_my_valentine.py index d1eea388..8b522a72 100644 --- a/bot/exts/valentines/be_my_valentine.py +++ b/bot/exts/valentines/be_my_valentine.py @@ -1,6 +1,6 @@  import logging  import random -from json import load +from json import loads  from pathlib import Path  from typing import Tuple @@ -28,9 +28,7 @@ class BeMyValentine(commands.Cog):      def load_json() -> dict:          """Load Valentines messages from the static resources."""          p = Path("bot/resources/valentines/bemyvalentine_valentines.json") -        with p.open(encoding="utf8") as json_data: -            valentines = load(json_data) -            return valentines +        return loads(p.read_text("utf8"))      @in_month(Month.FEBRUARY)      @commands.group(name="lovefest") diff --git a/bot/exts/valentines/lovecalculator.py b/bot/exts/valentines/lovecalculator.py index 8a4c71eb..b10b7bca 100644 --- a/bot/exts/valentines/lovecalculator.py +++ b/bot/exts/valentines/lovecalculator.py @@ -15,9 +15,8 @@ from bot.bot import Bot  log = logging.getLogger(__name__) -with Path("bot/resources/valentines/love_matches.json").open(encoding="utf8") as file: -    LOVE_DATA = json.load(file) -    LOVE_DATA = sorted((int(key), value) for key, value in LOVE_DATA.items()) +LOVE_DATA = json.loads(Path("bot/resources/valentines/love_matches.json").read_text("utf8")) +LOVE_DATA = sorted((int(key), value) for key, value in LOVE_DATA.items())  class LoveCalculator(Cog): diff --git a/bot/exts/valentines/myvalenstate.py b/bot/exts/valentines/myvalenstate.py index 1c67984b..d2409dcc 100644 --- a/bot/exts/valentines/myvalenstate.py +++ b/bot/exts/valentines/myvalenstate.py @@ -12,8 +12,7 @@ from bot.constants import Colours  log = logging.getLogger(__name__) -with open(Path("bot/resources/valentines/valenstates.json"), "r", encoding="utf8") as file: -    STATES = json.load(file) +STATES = json.loads(Path("bot/resources/valentines/valenstates.json").read_text("utf8"))  class MyValenstate(commands.Cog): diff --git a/bot/exts/valentines/pickuplines.py b/bot/exts/valentines/pickuplines.py index 909169e6..00741a72 100644 --- a/bot/exts/valentines/pickuplines.py +++ b/bot/exts/valentines/pickuplines.py @@ -1,6 +1,6 @@  import logging  import random -from json import load +from json import loads  from pathlib import Path  import discord @@ -11,8 +11,7 @@ from bot.constants import Colours  log = logging.getLogger(__name__) -with open(Path("bot/resources/valentines/pickup_lines.json"), "r", encoding="utf8") as f: -    pickup_lines = load(f) +PICKUP_LINES = loads(Path("bot/resources/valentines/pickup_lines.json").read_text("utf8"))  class PickupLine(commands.Cog): @@ -25,14 +24,14 @@ class PickupLine(commands.Cog):          Note that most of them are very cheesy.          """ -        random_line = random.choice(pickup_lines["lines"]) +        random_line = random.choice(PICKUP_LINES["lines"])          embed = discord.Embed(              title=":cheese: Your pickup line :cheese:",              description=random_line["line"],              color=Colours.pink          )          embed.set_thumbnail( -            url=random_line.get("image", pickup_lines["placeholder"]) +            url=random_line.get("image", PICKUP_LINES["placeholder"])          )          await ctx.send(embed=embed) diff --git a/bot/exts/valentines/savethedate.py b/bot/exts/valentines/savethedate.py index cc16f5c9..ffe559d6 100644 --- a/bot/exts/valentines/savethedate.py +++ b/bot/exts/valentines/savethedate.py @@ -1,6 +1,6 @@  import logging  import random -from json import load +from json import loads  from pathlib import Path  import discord @@ -13,8 +13,7 @@ log = logging.getLogger(__name__)  HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_heart:", ":two_hearts:"] -with open(Path("bot/resources/valentines/date_ideas.json"), "r", encoding="utf8") as f: -    VALENTINES_DATES = load(f) +VALENTINES_DATES = loads(Path("bot/resources/valentines/date_ideas.json").read_text("utf8"))  class SaveTheDate(commands.Cog): diff --git a/bot/exts/valentines/valentine_zodiac.py b/bot/exts/valentines/valentine_zodiac.py index a444a355..45d1edd5 100644 --- a/bot/exts/valentines/valentine_zodiac.py +++ b/bot/exts/valentines/valentine_zodiac.py @@ -29,14 +29,14 @@ class ValentineZodiac(commands.Cog):          """Load zodiac compatibility from static JSON resource."""          explanation_file = Path("bot/resources/valentines/zodiac_explanation.json")          compatibility_file = Path("bot/resources/valentines/zodiac_compatibility.json") -        with explanation_file.open(encoding="utf8") as json_data: -            zodiac_fact = json.load(json_data) -            for zodiac_data in zodiac_fact.values(): -                zodiac_data["start_at"] = datetime.fromisoformat(zodiac_data["start_at"]) -                zodiac_data["end_at"] = datetime.fromisoformat(zodiac_data["end_at"]) - -        with compatibility_file.open(encoding="utf8") as json_data: -            zodiacs = json.load(json_data) + +        zodiac_fact = json.loads(explanation_file.read_text("utf8")) + +        for zodiac_data in zodiac_fact.values(): +            zodiac_data["start_at"] = datetime.fromisoformat(zodiac_data["start_at"]) +            zodiac_data["end_at"] = datetime.fromisoformat(zodiac_data["end_at"]) + +        zodiacs = json.loads(compatibility_file.read_text("utf8"))          return zodiacs, zodiac_fact diff --git a/bot/exts/valentines/whoisvalentine.py b/bot/exts/valentines/whoisvalentine.py index 3f23201f..211b1f27 100644 --- a/bot/exts/valentines/whoisvalentine.py +++ b/bot/exts/valentines/whoisvalentine.py @@ -11,8 +11,7 @@ from bot.constants import Colours  log = logging.getLogger(__name__) -with open(Path("bot/resources/valentines/valentine_facts.json"), "r", encoding="utf8") as file: -    FACTS = json.load(file) +FACTS = json.loads(Path("bot/resources/valentines/valentine_facts.json").read_text("utf8"))  class ValentineFacts(commands.Cog): | 
