Saving deleted data from left servers.
This commit is contained in:
+2
-1
@@ -133,4 +133,5 @@ nextcord.log
|
||||
# data file for bot
|
||||
highscores_data.json
|
||||
highscores_message_map.json
|
||||
highscores_config.json
|
||||
highscores_config.json
|
||||
deleted_backups/
|
||||
@@ -2,6 +2,9 @@
|
||||
Defines cog for guild listeners. Contains functions for various guild events.
|
||||
"""
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
from nextcord.ext import commands
|
||||
import nextcord
|
||||
|
||||
@@ -24,7 +27,8 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
||||
save_highscores_data(highscores_data)
|
||||
|
||||
welcome_message: str = "Hello, I keep track of Highscores for you!"
|
||||
welcome_message += " Currently only supporting RuneScape boss highscores, but will be more dynamic support in future."
|
||||
welcome_message += " Currently only supporting RuneScape boss highscores,"
|
||||
welcome_message += " but will be more dynamic support in future."
|
||||
welcome_message += ' For assistance on getting started, use "?register help".'
|
||||
|
||||
await guild.system_channel.send(content=welcome_message)
|
||||
@@ -33,9 +37,15 @@ class GuildListener(commands.Cog, name="Guild 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.pop(str(guild.id))
|
||||
old_data = highscores_data.pop(str(guild.id))
|
||||
save_highscores_data(highscores_data)
|
||||
|
||||
if not os.path.exists("deleted_backups"):
|
||||
os.mkdir("deleted_backups")
|
||||
|
||||
with open(f"deleted_backups/{guild.name}_backup.json", encoding="utf-8", mode="w") as file:
|
||||
file.write(json.dumps(old_data, indent=4))
|
||||
|
||||
|
||||
# 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