Saving guild after modification.

This commit is contained in:
alwayscompiling
2022-08-03 22:21:49 -04:00
parent 4d9c70bf09
commit 66ace947c6
4 changed files with 15 additions and 7 deletions
+1
View File
@@ -32,6 +32,7 @@ class DeleteScores(commands.Cog, name="Delete Scores"):
for table in highscores_data.get_guild(ctx.guild.id).tables:
for category in table.categories:
category.clear()
highscores_data.save_guild_data(highscores_data.get_guild(ctx.guild.id))
# This function will be called when this extension is loaded.
+1
View File
@@ -18,6 +18,7 @@ class GuildListener(commands.Cog, name="Guild Listener"):
async def on_guild_join(self, guild: nextcord.Guild):
"""Listener for Guild Join. Creates skeleton for new guild joined and saves it."""
highscores_data.add_guild(guild.id)
highscores_data.save_guild_data(highscores_data.get_guild(guild.id))
welcome_message: str = "Hello, I keep track of Highscores for you!"
welcome_message += " Currently only supporting RuneScape boss highscores,"
+11 -6
View File
@@ -11,12 +11,12 @@ from highscores import highscores_data # pylint: disable=import-error
class RegisterVerificationChannel(commands.Cog, name="Register"):
"""Bot command for registering various channels to the bot."""
def __init__(self, bot: commands.Bot):
def __init__(self, bot: commands.Bot) -> None:
self.bot = bot
@commands.command(name="register")
@commands.has_permissions(administrator=True)
async def register_highscores(self, ctx: commands.Context, registration_type: str):
async def register_highscores(self, ctx: commands.Context, registration_type: str) -> None:
"""A command which registers current channel as for various uses.
Usage:
```
@@ -28,16 +28,17 @@ class RegisterVerificationChannel(commands.Cog, name="Register"):
"""
# respond to the message
channel_id = ctx.channel.id
guild = highscores_data.get_guild(ctx.guild.id)
if registration_type == "verify":
await ctx.send(f"Registered <#{channel_id}> as channel to post verifications in.")
highscores_data.get_guild(ctx.guild.id).verification_channel = channel_id
guild.verification_channel = channel_id
elif registration_type == "highscore":
await ctx.send(f"Registered <#{channel_id}> as channel to post highscores in.")
highscores_data.get_guild(ctx.guild.id).highscore_channel = channel_id
guild.highscore_channel = channel_id
elif registration_type == "submission":
await ctx.send(f"Registered <#{channel_id}> as channel to post submissions in.")
highscores_data.get_guild(ctx.guild.id).submission_channel = channel_id
guild.submission_channel = channel_id
else:
embed = Embed(
title="Register command help", description="How to use the register command."
@@ -55,10 +56,14 @@ class RegisterVerificationChannel(commands.Cog, name="Register"):
)
embed.add_field(name="?register help", value="Use to show this message.")
await ctx.reply(embed=embed)
# return, don't need to save data
return
highscores_data.save_guild_data(guild)
# 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):
def setup(bot: commands.Bot) -> None:
"""Adds function to bot"""
bot.add_cog(RegisterVerificationChannel(bot))
+2 -1
View File
@@ -3,7 +3,7 @@ Contains various utlity functions for highscores bot
"""
import nextcord
from highscores import highscores_message_map # pylint: disable=import-error
from highscores import highscores_data, highscores_message_map # pylint: disable=import-error
from data.score import Score # pylint: disable=import-error
from data.guild import Guild # pylint: disable=import-error
from data.category import Category # pylint: disable=import-error
@@ -112,6 +112,7 @@ async def submit_score(
"""
category.add_score(score)
highscores_data.save_guild_data(guild)
# edit message
print(f"Editting message {guild.highscore_channel}")