From 04faff3bdbd2bbab4565f9520786d5c8f8abd3db Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Sun, 3 Jul 2022 11:20:08 -0400 Subject: [PATCH] Adding verification channel register command. --- cogs/post_highscores/__init__.py | 6 ++-- cogs/register_highscore_channel/__init__.py | 6 ++-- .../register_verification_channel/__init__.py | 35 +++++++++++++++++++ utils/data_storage.py | 2 +- utils/highscore_manage.py | 6 ++-- 5 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 cogs/register_verification_channel/__init__.py diff --git a/cogs/post_highscores/__init__.py b/cogs/post_highscores/__init__.py index f67af39..300b5a4 100644 --- a/cogs/post_highscores/__init__.py +++ b/cogs/post_highscores/__init__.py @@ -25,9 +25,9 @@ class PostHighscores(commands.Cog, name="Post Highscores"): ?post-scores ``` """ - channel_id = highscores_data["channel_id"] - print(f"Printing out highscores information in channel {channel_id}") - channel = self.bot.get_channel(channel_id) + highscore_channel_id = highscores_data["highscore_channel_id"] + print(f"Printing out highscores information in channel {highscore_channel_id}") + channel = self.bot.get_channel(highscore_channel_id) if channel is None: response = 'Registered Highscores channel does not exist or was never registered. \ Register with "?register" command.' diff --git a/cogs/register_highscore_channel/__init__.py b/cogs/register_highscore_channel/__init__.py index a698bae..e6630d3 100644 --- a/cogs/register_highscore_channel/__init__.py +++ b/cogs/register_highscore_channel/__init__.py @@ -13,18 +13,18 @@ class RegisterHighscoreChannel(commands.Cog, name="Register HighScore Channel"): def __init__(self, bot: commands.Bot): self.bot = bot - @commands.command(name="register") + @commands.command(name="register-highscore") async def register_highscores(self, ctx: commands.Context): """A command which registers current channel as channel to post highscores in. Usage: ``` - ?register (in channel to post highscores in) + ?register-highscore (in channel to post highscores in) ``` """ print(f"Registering {ctx.channel.id}.") # respond to the message await ctx.send(f"Registered <#{ctx.channel.id}> as channel to post highscores in.") - highscores_data["channel_id"] = ctx.channel.id + highscores_data["highscore_channel_id"] = ctx.channel.id data_storage.save_highscores_data(highscores_data) diff --git a/cogs/register_verification_channel/__init__.py b/cogs/register_verification_channel/__init__.py new file mode 100644 index 0000000..d702308 --- /dev/null +++ b/cogs/register_verification_channel/__init__.py @@ -0,0 +1,35 @@ +""" +Bot command to register the verification channel +""" + +from nextcord.ext import commands +from highscores import highscores_data # pylint: disable=import-error +from utils import data_storage # pylint: disable=import-error + + +class RegisterVerificationChannel(commands.Cog, name="Register HighScore Channel"): + """Registers Verification channel""" + + def __init__(self, bot: commands.Bot): + self.bot = bot + + @commands.command(name="register-verify") + async def register_highscores(self, ctx: commands.Context): + """A command which registers current channel as channel to post verifications in. + Usage: + ``` + ?register-verify (in channel to post highscores in) + ``` + """ + print(f"Registering {ctx.channel.id} for verification.") + # respond to the message + await ctx.send(f"Registered <#{ctx.channel.id}> as channel to post verifications in.") + highscores_data["verification_channel_id"] = ctx.channel.id + data_storage.save_highscores_data(highscores_data) + + +# This function will be called when this extension is loaded. +# It is necessary to add these functions to the bot. +def setup(bot: commands.Bot): + """Adds functon to bot""" + bot.add_cog(RegisterVerificationChannel(bot)) diff --git a/utils/data_storage.py b/utils/data_storage.py index bfb3e54..e2fb5a9 100644 --- a/utils/data_storage.py +++ b/utils/data_storage.py @@ -19,7 +19,7 @@ def open_highscores_data(): data = json.load(file) else: # create the json object - data = {"channel_id": -1} + data = {"highscore_channel_id": -1, "verification_channel_id": -1} config = open_highscores_config() for boss in config["bosses"]: data[boss["boss"]] = {"message_id": 0} diff --git a/utils/highscore_manage.py b/utils/highscore_manage.py index a1f010d..20678f7 100644 --- a/utils/highscore_manage.py +++ b/utils/highscore_manage.py @@ -46,9 +46,9 @@ async def submit_score(self, ctx: commands.Context, boss_name: str, category: st highscores_data[boss_name]["categories"][category] = scores # edit message - channel_id = highscores_data["channel_id"] - print(f"Editting message {channel_id}") - channel = self.bot.get_channel(channel_id) + highscore_channel_id = highscores_data["highscore_channel_id"] + print(f"Editting message {highscore_channel_id}") + channel = self.bot.get_channel(highscore_channel_id) if channel is None: response = 'Registered Highscores channel does not exist or was never registered. \ Register with "?register" command.'