From 20ec3f7ac92514659ec7e204dc864310fe5c04b3 Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Sat, 25 Jun 2022 23:41:14 -0400 Subject: [PATCH] Rename bot.py for namespace reasons. Added register command. Added highscores config file. --- cogs/register_highscore_channel/__init__.py | 27 +++ bot.py => highscores.py | 34 ++++ highscores_config.json | 206 ++++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 cogs/register_highscore_channel/__init__.py rename bot.py => highscores.py (60%) create mode 100755 highscores_config.json diff --git a/cogs/register_highscore_channel/__init__.py b/cogs/register_highscore_channel/__init__.py new file mode 100644 index 0000000..665bb9e --- /dev/null +++ b/cogs/register_highscore_channel/__init__.py @@ -0,0 +1,27 @@ +from nextcord.ext import commands +import highscores # pylint: disable=import-error + + +class RegisterHighscoreChannel(commands.Cog, name="Register HighScore Channel"): + def __init__(self, bot: commands.Bot): + self.bot = bot + + @commands.command(name="register") + async def ping(self, ctx: commands.Context): + """A command which registers the channel command is sent in as channel to post highscores in + Usage: + ``` + ?register (in channel to post highscores in) + ``` + """ + # log in console that a ping was received + print(f"Registering {ctx.channel.id}.") + print(bot.open_highscores_data()) + # respond to the message + await ctx.send(f"Registered <#{ctx.channel.id}> as channel to post highscores in.") + + +# 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): + bot.add_cog(RegisterHighscoreChannel(bot)) diff --git a/bot.py b/highscores.py similarity index 60% rename from bot.py rename to highscores.py index 1dfc4d7..d5f6f2b 100644 --- a/bot.py +++ b/highscores.py @@ -4,6 +4,7 @@ main file for pvm-highscores bot import os import logging +import json import nextcord from nextcord.ext import commands @@ -18,8 +19,12 @@ handler.setFormatter(logging.Formatter( '%(asctime)s:%(levelname)s:%(name)s: %(message)s')) logger.addHandler(handler) +highscores_config_file = "highscores_config.json" +highscores_data_file = "highscores_data.json" + def main(): + """Main function for bot.""" # Allows privledged intents for monitoring members joining, roles editing, and role assignments # These need to be enabled in the developer portal as well intents = nextcord.Intents.default() @@ -58,5 +63,34 @@ def main(): bot.run(config.DISCORD_TOKEN) +def open_highscores_data(): + """Opens a highscores_data.json file if one exists, otherwise creates a skeleton of the data.""" + if (os.path.exists(highscores_data_file)): + with open(highscores_data_file, encoding='utf-8', mode="r") as file: + data = json.load(file) + else: + # create the json object + x = { + "channel_id": 0 + } + data = json.dumps(x) + + return data + + +def open_highscores_config(): + """Opens the highscores config file as a json object and returns.""" + # Load bot config + with open(highscores_config_file, encoding='utf-8', mode='r') as file: + highscores_config = json.load(file) + return highscores_config + + +def save_highscores_data(data): + """Saves the highscores data into a json file.""" + with open(highscores_data_file, encoding='utf-8', mode='w') as file: + file.write(json.dumps(data, indent=4)) + + if __name__ == "__main__": main() diff --git a/highscores_config.json b/highscores_config.json new file mode 100755 index 0000000..e89f7f6 --- /dev/null +++ b/highscores_config.json @@ -0,0 +1,206 @@ +{ + "bosses": [ + { + "boss": "The Ambassador", + "hardmode": "true" + }, + { + "boss": "Araxxi", + "hardmode": "false" + }, + { + "boss": "Arch-Glacor", + "hardmode": "true" + }, + { + "boss": "Astellarn", + "hardmode": "true" + }, + { + "boss": "The Barrows Brothers", + "hardmode": "false" + }, + { + "boss": "The Barrows: Rise of the Six", + "hardmode": "false" + }, + { + "boss": "Beastmaster Durzag", + "hardmode": "false" + }, + { + "boss": "Black Stone Dragon", + "hardmode": "true" + }, + { + "boss": "Chaos Elemental", + "hardmode": "false" + }, + { + "boss": "Commander Zilyana", + "hardmode": "true" + }, + { + "boss": "Corporeal Beast", + "hardmode": "false" + }, + { + "boss": "Crassian Leviathan", + "hardmode": "true" + }, + { + "boss": "Croesus", + "hardmode": "false" + }, + { + "boss": "Dagannoth Kings", + "hardmode": "false" + }, + { + "boss": "General Graardor", + "hardmode": "true" + }, + { + "boss": "Giant Mole", + "hardmode": "true" + }, + { + "boss": "Gregorovic", + "hardmode": "true" + }, + { + "boss": "Har-Aken", + "hardmode": "false" + }, + { + "boss": "Helwyr", + "hardmode": "true" + }, + { + "boss": "IM Compiling", + "hardmode": "true" + }, + { + "boss": "Kalphite King", + "hardmode": "false" + }, + { + "boss": "Kalphite Queen", + "hardmode": "false" + }, + { + "boss": "Kerapac", + "hardmode": "true" + }, + { + "boss": "King Black Dragon", + "hardmode": "false" + }, + { + "boss": "Kree'arra", + "hardmode": "true" + }, + { + "boss": "K'ril Tsutsaroth", + "hardmode": "true" + }, + { + "boss": "Legiones", + "hardmode": "false" + }, + { + "boss": "The Magister", + "hardmode": "false" + }, + { + "boss": "Masuta the Ascended", + "hardmode": "true" + }, + { + "boss": "Nex", + "hardmode": "false" + }, + { + "boss": "Nex - Angel of Death", + "hardmode": "false" + }, + { + "boss": "Queen Black Dragon", + "hardmode": "false" + }, + { + "boss": "Raksha", + "hardmode": "true" + }, + { + "boss": "Rex Matriarchs", + "hardmode": "false" + }, + { + "boss": "The Sanctum Guardian", + "hardmode": "true" + }, + { + "boss": "Seiryu the Azure Serpent", + "hardmode": "true" + }, + { + "boss": "Solak", + "hardmode": "false" + }, + { + "boss": "Taraket the Necromancer", + "hardmode": "true" + }, + { + "boss": "Telos", + "hardmode": "false" + }, + { + "boss": "The Twin Furies", + "hardmode": "true" + }, + { + "boss": "TzKal-Zuk", + "hardmode": "true" + }, + { + "boss": "TzTok-Jad", + "hardmode": "false" + }, + { + "boss": "Verak Lith", + "hardmode": "true" + }, + { + "boss": "Vindicta & Gorvek", + "hardmode": "true" + }, + { + "boss": "Vorago", + "hardmode": "true" + }, + { + "boss": "Yakamaru", + "hardmode": "false" + } + ], + "categories": [ + { + "category": "Kill Count", + "hardmode": true, + "ascending": false + }, + { + "category": "Kill Time", + "hardmore": true, + "ascending": true + }, + { + "category": "Spooned Log", + "hardmode": false, + "ascending": true + } + ], + "highscore_size": 3 +} \ No newline at end of file