Update guild listener to use new database. Add default config function to utils.
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
Defines cog for guild listeners. Contains functions for various guild events.
|
||||
"""
|
||||
|
||||
from nextcord.ext import commands
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
|
||||
from highscores import highscores_data # pylint: disable=import-error
|
||||
# pylint: disable=import-error
|
||||
from highscores import Guild, session
|
||||
from utilities.utils import add_preset_configuration
|
||||
|
||||
|
||||
class GuildListener(commands.Cog, name="Guild Listener"):
|
||||
@@ -17,10 +19,11 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
||||
@commands.Cog.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)
|
||||
new_guild = Guild(GuildId=guild.id)
|
||||
session.add(new_guild)
|
||||
session.commit()
|
||||
# This add config will be removed eventually. Config adding will have to be controlled by commands.
|
||||
highscores_data.add_configuration(guild.id, "runescape")
|
||||
highscores_data.save_guild_data(highscores_data.get_guild(guild.id))
|
||||
add_preset_configuration(guild.id, "runescape")
|
||||
|
||||
welcome_message: str = "Hello, I keep track of Highscores for you!"
|
||||
welcome_message += " Currently only supporting RuneScape boss highscores,"
|
||||
@@ -29,12 +32,6 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
||||
|
||||
await guild.system_channel.send(content=welcome_message)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_remove(self, guild: nextcord.Guild):
|
||||
"""Listener for Guild Remove. Removes data from highscores_data."""
|
||||
print(f"Removing data for guild {guild.name} (id {guild.id}).")
|
||||
highscores_data.remove_guild(guild.id)
|
||||
|
||||
|
||||
# This function will be called when this extension is loaded.
|
||||
# It is necessary to add these functions to the bot.
|
||||
|
||||
Reference in New Issue
Block a user