Rename bot.py for namespace reasons. Added register command. Added highscores config file.
This commit is contained in:
@@ -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))
|
||||
@@ -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()
|
||||
Executable
+206
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user