From 0e81951f75271592c8ccd7c6644d5bfff540139c Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Fri, 16 Aug 2024 10:08:00 +0100 Subject: [PATCH 1/3] Ensure the path directory is created before saving a json file --- matchy/files/ops.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/matchy/files/ops.py b/matchy/files/ops.py index a076286..1c159b8 100644 --- a/matchy/files/ops.py +++ b/matchy/files/ops.py @@ -1,6 +1,8 @@ """File operation helpers""" import json import shutil +import pathlib +import os def load(file: str) -> dict: @@ -12,8 +14,12 @@ def load(file: str) -> dict: def save(file: str, content: dict): """ Save out a content dictionary to a file - Stores it in an intermediary file first incase the dump fails """ + # Ensure the save directory exists first + dir = pathlib.Path(os.path.dirname(file)) + dir.mkdir(parents=True, exist_ok=True) + + # Store in an intermediary directory first intermediate = file + ".nxt" with open(intermediate, "w") as f: json.dump(content, f, indent=4) From 01e9c98d3f3cfb5adca7f25a982339fd06ccc62d Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Fri, 16 Aug 2024 10:21:43 +0100 Subject: [PATCH 2/3] Fix the matchy install link (use the OAuth one not the "install" one) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cb5e8ef..5887903 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Matchy matches matchees. -Matchy is a Discord bot that groups up users for fun and vibes. Matchy can be installed on your server by clicking [here](https://discord.com/oauth2/authorize?client_id=1270849346987884696). Matchy only allows authorised users to trigger posts in channels. +Matchy is a Discord bot that groups up users for fun and vibes. Matchy can be installed on your server by clicking [here](https://discord.com/oauth2/authorize?client_id=1270849346987884696&permissions=0&integration_type=0&scope=bot). Matchy only allows authorised users to trigger posts in channels. ![Tests](https://github.com/mdiluz/matchy/actions/workflows/test.yml/badge.svg) From a5d66aca4e342f0d365fc07cf7b07bd7fc6612ab Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Fri, 16 Aug 2024 10:22:35 +0100 Subject: [PATCH 3/3] Fix a bunch of failed imports and types from previous changes --- matchy.py | 4 ++-- matchy/cogs/matchy.py | 6 +++--- matchy/cogs/owner.py | 2 +- matchy/views/match.py | 2 +- tests/owner_cog_test.py | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/matchy.py b/matchy.py index ce3410e..9eb70b7 100644 --- a/matchy.py +++ b/matchy.py @@ -24,8 +24,8 @@ @bot.event async def setup_hook(): - await bot.add_cog(matchy.cogs.matchy.Cog(bot, state)) - await bot.add_cog(matchy.cogs.owner.Cog(bot, state)) + await bot.add_cog(matchy.cogs.matchy.MatchyCog(bot, state)) + await bot.add_cog(matchy.cogs.owner.OwnerCog(bot, state)) @bot.event diff --git a/matchy/cogs/matchy.py b/matchy/cogs/matchy.py index c247e28..d63fe23 100644 --- a/matchy/cogs/matchy.py +++ b/matchy/cogs/matchy.py @@ -8,15 +8,15 @@ from datetime import datetime, timedelta, time import matchy.views.match as match -import matching +import matchy.matching as matching from matchy.files.state import State, AuthScope -import util +import matchy.util as util logger = logging.getLogger("cog") logger.setLevel(logging.INFO) -class Cog(commands.Cog): +class MatchyCog(commands.Cog): def __init__(self, bot: commands.Bot, state: State): self.bot = bot self.state = state diff --git a/matchy/cogs/owner.py b/matchy/cogs/owner.py index 84b2275..bbd9336 100644 --- a/matchy/cogs/owner.py +++ b/matchy/cogs/owner.py @@ -9,7 +9,7 @@ logger.setLevel(logging.INFO) -class Cog(commands.Cog): +class OwnerCog(commands.Cog): def __init__(self, bot: commands.Bot, state: State): self._bot = bot self._state = state diff --git a/matchy/views/match.py b/matchy/views/match.py index 932d3be..7fc759e 100644 --- a/matchy/views/match.py +++ b/matchy/views/match.py @@ -6,7 +6,7 @@ import re import matchy.files.state as state -import matching +import matchy.matching as matching logger = logging.getLogger("match_button") logger.setLevel(logging.INFO) diff --git a/tests/owner_cog_test.py b/tests/owner_cog_test.py index 2c22ea9..f10100d 100644 --- a/tests/owner_cog_test.py +++ b/tests/owner_cog_test.py @@ -5,7 +5,7 @@ import matchy.files.state as state import discord.ext.test as dpytest -from matchy.cogs.owner import Cog +from matchy.cogs.owner import OwnerCog # Primarily borrowing from https://dpytest.readthedocs.io/en/latest/tutorials/using_pytest.html # TODO: Test more somehow, though it seems like dpytest is pretty incomplete @@ -20,7 +20,7 @@ async def bot(): b = commands.Bot(command_prefix="$", intents=intents) await b._async_setup_hook() - await b.add_cog(Cog(b, state.State(state._EMPTY_DICT))) + await b.add_cog(OwnerCog(b, state.State(state._EMPTY_DICT))) dpytest.configure(b) yield b await dpytest.empty_queue()