Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b134a8107d | ||
|
|
71611502cf | ||
|
|
d30382dd91 | ||
|
|
68c15c48a5 | ||
|
|
46dcb81a9a | ||
|
|
96c6bd7935 |
@@ -5,7 +5,7 @@ Bot command to post the highscores
|
|||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
import highscores # pylint: disable=import-error
|
import highscores # pylint: disable=import-error
|
||||||
from utils import data_storage # pylint: disable=import-error
|
from utils import data_storage # pylint: disable=import-error
|
||||||
from utils import message_formatter # pylint: disable=import-error
|
from utils import highscore_message # pylint: disable=import-error
|
||||||
|
|
||||||
|
|
||||||
class PostHighscores(commands.Cog, name="Post Highscores"):
|
class PostHighscores(commands.Cog, name="Post Highscores"):
|
||||||
@@ -16,7 +16,8 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
|
|||||||
|
|
||||||
@commands.command(name="post-scores")
|
@commands.command(name="post-scores")
|
||||||
async def post_highscores(self, ctx: commands.Context):
|
async def post_highscores(self, ctx: commands.Context):
|
||||||
"""A command which posts the highscore in the designated channel. Sends warning if no channel has been registered.
|
"""
|
||||||
|
A command which posts the highscore in the designated channel. Sends warning if no channel has been registered.
|
||||||
Usage:
|
Usage:
|
||||||
```
|
```
|
||||||
?post-scores
|
?post-scores
|
||||||
@@ -24,25 +25,14 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
|
|||||||
"""
|
"""
|
||||||
# temporarily sending config data...
|
# temporarily sending config data...
|
||||||
channel_id = highscores.highscores_data["channel_id"]
|
channel_id = highscores.highscores_data["channel_id"]
|
||||||
if (channel_id != -1):
|
print(f"Printing out highscores information in channel {channel_id}")
|
||||||
print(
|
|
||||||
f"Printing out highscores information in channel {channel_id}")
|
|
||||||
channel = self.bot.get_channel(channel_id)
|
channel = self.bot.get_channel(channel_id)
|
||||||
for boss in highscores.highscores_config["bosses"]:
|
if channel is None:
|
||||||
highscore_string = message_formatter.format_boss_highscore(
|
response = 'Registered Highscores channel does not exist or was never registered. Register with "?register" command.'
|
||||||
boss)
|
|
||||||
message = await channel.send(highscore_string)
|
|
||||||
message_id = message.id
|
|
||||||
|
|
||||||
# check if there is a dict for the boss in the highscores data
|
|
||||||
if not boss["boss"] in highscores.highscores_data:
|
|
||||||
highscores.highscores_data[boss["boss"]] = {}
|
|
||||||
|
|
||||||
highscores.highscores_data[boss["boss"]
|
|
||||||
]["message_id"] = message_id
|
|
||||||
else:
|
|
||||||
response = "Highscores channel is not registered. Register with \"?register\" command."
|
|
||||||
await ctx.send(response)
|
await ctx.send(response)
|
||||||
|
return
|
||||||
|
for boss in highscores.highscores_config["bosses"]:
|
||||||
|
await highscore_message.send_highscore_message(channel, boss)
|
||||||
|
|
||||||
data_storage.save_highscores_data(highscores.highscores_data)
|
data_storage.save_highscores_data(highscores.highscores_data)
|
||||||
|
|
||||||
|
|||||||
+3
-6
@@ -2,7 +2,6 @@
|
|||||||
main file for pvm-highscores bot
|
main file for pvm-highscores bot
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -12,12 +11,10 @@ from nextcord.ext import commands
|
|||||||
import config
|
import config
|
||||||
from utils import data_storage
|
from utils import data_storage
|
||||||
|
|
||||||
logger = logging.getLogger('nextcord')
|
logger = logging.getLogger("nextcord")
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
handler = logging.FileHandler(
|
handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w")
|
||||||
filename='nextcord.log', encoding='utf-8', mode='w')
|
handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
|
||||||
handler.setFormatter(logging.Formatter(
|
|
||||||
'%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
|
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+45
-45
@@ -2,183 +2,183 @@
|
|||||||
"bosses": [
|
"bosses": [
|
||||||
{
|
{
|
||||||
"boss": "The Ambassador",
|
"boss": "The Ambassador",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Araxxi",
|
"boss": "Araxxi",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Arch-Glacor",
|
"boss": "Arch-Glacor",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Astellarn",
|
"boss": "Astellarn",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "The Barrows Brothers",
|
"boss": "The Barrows Brothers",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "The Barrows: Rise of the Six",
|
"boss": "The Barrows: Rise of the Six",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Beastmaster Durzag",
|
"boss": "Beastmaster Durzag",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Black Stone Dragon",
|
"boss": "Black Stone Dragon",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Chaos Elemental",
|
"boss": "Chaos Elemental",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Commander Zilyana",
|
"boss": "Commander Zilyana",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Corporeal Beast",
|
"boss": "Corporeal Beast",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Crassian Leviathan",
|
"boss": "Crassian Leviathan",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Croesus",
|
"boss": "Croesus",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Dagannoth Kings",
|
"boss": "Dagannoth Kings",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "General Graardor",
|
"boss": "General Graardor",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Giant Mole",
|
"boss": "Giant Mole",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Gregorovic",
|
"boss": "Gregorovic",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Har-Aken",
|
"boss": "Har-Aken",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Helwyr",
|
"boss": "Helwyr",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Kalphite King",
|
"boss": "Kalphite King",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Kalphite Queen",
|
"boss": "Kalphite Queen",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Kerapac",
|
"boss": "Kerapac",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "King Black Dragon",
|
"boss": "King Black Dragon",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Kree'arra",
|
"boss": "Kree'arra",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "K'ril Tsutsaroth",
|
"boss": "K'ril Tsutsaroth",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Legiones",
|
"boss": "Legiones",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "The Magister",
|
"boss": "The Magister",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Masuta the Ascended",
|
"boss": "Masuta the Ascended",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Nex",
|
"boss": "Nex",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Nex - Angel of Death",
|
"boss": "Nex - Angel of Death",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Queen Black Dragon",
|
"boss": "Queen Black Dragon",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Raksha",
|
"boss": "Raksha",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Rex Matriarchs",
|
"boss": "Rex Matriarchs",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "The Sanctum Guardian",
|
"boss": "The Sanctum Guardian",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Seiryu the Azure Serpent",
|
"boss": "Seiryu the Azure Serpent",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Solak",
|
"boss": "Solak",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Taraket the Necromancer",
|
"boss": "Taraket the Necromancer",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Telos",
|
"boss": "Telos",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "The Twin Furies",
|
"boss": "The Twin Furies",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "TzKal-Zuk",
|
"boss": "TzKal-Zuk",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "TzTok-Jad",
|
"boss": "TzTok-Jad",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Verak Lith",
|
"boss": "Verak Lith",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Vindicta & Gorvek",
|
"boss": "Vindicta & Gorvek",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Vorago",
|
"boss": "Vorago",
|
||||||
"hardmode": "true"
|
"hardmode": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"boss": "Yakamaru",
|
"boss": "Yakamaru",
|
||||||
"hardmode": "false"
|
"hardmode": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"categories": [
|
"categories": [
|
||||||
|
|||||||
+22
-7
@@ -14,13 +14,28 @@ def open_highscores_data():
|
|||||||
Opens a highscores_data.json file if one exists, otherwise creates a skeleton of the data.
|
Opens a highscores_data.json file if one exists, otherwise creates a skeleton of the data.
|
||||||
@return: dict of highscores data.
|
@return: dict of highscores data.
|
||||||
"""
|
"""
|
||||||
if (os.path.exists(HIGHSCORES_DATA_FILE)):
|
if os.path.exists(HIGHSCORES_DATA_FILE):
|
||||||
with open(HIGHSCORES_DATA_FILE, encoding='utf-8', mode="r") as file:
|
with open(HIGHSCORES_DATA_FILE, encoding="utf-8", mode="r") as file:
|
||||||
data = json.load(file)
|
data = json.load(file)
|
||||||
else:
|
else:
|
||||||
# create the json object
|
# create the json object
|
||||||
data = {}
|
data = {"channel_id": -1}
|
||||||
|
config = open_highscores_config()
|
||||||
|
size = config["highscore_size"]
|
||||||
|
for boss in config["bosses"]:
|
||||||
|
data[boss["boss"]] = {"message_id": -1}
|
||||||
|
for category in config["categories"]:
|
||||||
|
rank_list = []
|
||||||
|
for i in range(size): # pylint: disable=unused-variable
|
||||||
|
rank = {"player": "", "score": -1}
|
||||||
|
rank_list.append(rank)
|
||||||
|
data[boss["boss"]][category["category"]] = rank_list
|
||||||
|
if boss["hardmode"] and category["hardmode"]:
|
||||||
|
rank_list = []
|
||||||
|
for i in range(size): # pylint: disable=unused-variable
|
||||||
|
rank = {"player": "", "score": -1}
|
||||||
|
rank_list.append(rank)
|
||||||
|
data[boss["boss"]][category["category"] + "_hardmode"] = rank_list
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
@@ -30,14 +45,14 @@ def open_highscores_config():
|
|||||||
@return: dict of highscores config.
|
@return: dict of highscores config.
|
||||||
"""
|
"""
|
||||||
# Load bot config
|
# Load bot config
|
||||||
with open(HIGHSCORES_CONFIG_FILE, encoding='utf-8', mode='r') as file:
|
with open(HIGHSCORES_CONFIG_FILE, encoding="utf-8", mode="r") as file:
|
||||||
return json.load(file)
|
return json.load(file)
|
||||||
|
|
||||||
|
|
||||||
def save_highscores_data(data):
|
def save_highscores_data(data):
|
||||||
"""
|
"""
|
||||||
Saves the highscores data dict into a json file.
|
Saves the highscores data dict into a json file.
|
||||||
@param: dict of highscores data.
|
@param data: dict of highscores data.
|
||||||
"""
|
"""
|
||||||
with open(HIGHSCORES_DATA_FILE, encoding='utf-8', mode='w') as file:
|
with open(HIGHSCORES_DATA_FILE, encoding="utf-8", mode="w") as file:
|
||||||
file.write(json.dumps(data, indent=4))
|
file.write(json.dumps(data, indent=4))
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
"""
|
||||||
|
Contains various functions for sending/editing the highscore messages.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import nextcord
|
||||||
|
import highscores # pylint: disable=import-error
|
||||||
|
|
||||||
|
|
||||||
|
def format_highscore_message(boss):
|
||||||
|
"""
|
||||||
|
returns a formattedd string for a boss's highscore
|
||||||
|
@param boss: the dictionary object for the boss
|
||||||
|
@return the formatted string
|
||||||
|
"""
|
||||||
|
boss_name = boss["boss"]
|
||||||
|
ret_string = f"**{boss_name}**\n"
|
||||||
|
|
||||||
|
# Gather all categories and add to string
|
||||||
|
for category in highscores.highscores_config["categories"]:
|
||||||
|
category_name = category["category"]
|
||||||
|
ret_string += f"{category_name}".ljust(30, " ")
|
||||||
|
ret_string += "\n"
|
||||||
|
|
||||||
|
highscore_size = highscores.highscores_config["highscore_size"]
|
||||||
|
|
||||||
|
# list rankings
|
||||||
|
for i in range(highscore_size):
|
||||||
|
for category in highscores.highscores_config["categories"]:
|
||||||
|
ret_string += f"{i+1}: submit your score".ljust(30, " ")
|
||||||
|
ret_string += "\n"
|
||||||
|
|
||||||
|
# if boss is hardmode, repeat above for hardmode applicable categories
|
||||||
|
if boss["hardmode"]:
|
||||||
|
for category in highscores.highscores_config["categories"]:
|
||||||
|
if category["hardmode"]:
|
||||||
|
category_name = category["category"]
|
||||||
|
ret_string += f"{category_name}".ljust(30, " ")
|
||||||
|
|
||||||
|
ret_string += "\n"
|
||||||
|
|
||||||
|
for i in range(highscore_size):
|
||||||
|
for category in highscores.highscores_config["categories"]:
|
||||||
|
if category["hardmode"]:
|
||||||
|
ret_string += f"{i+1}: (name here)".ljust(30, " ")
|
||||||
|
ret_string += "\n"
|
||||||
|
return ret_string
|
||||||
|
|
||||||
|
|
||||||
|
async def send_highscore_message(channel, boss):
|
||||||
|
"""
|
||||||
|
Function takes care of checking if a message exists for a boss, then creating and sending/editing the message
|
||||||
|
@param channel: the channel to send the message in/search for message id
|
||||||
|
@param boss: the boss to send the message about
|
||||||
|
"""
|
||||||
|
highscore_string = format_highscore_message(boss)
|
||||||
|
|
||||||
|
message_id = highscores.highscores_data[boss["boss"]]["message_id"]
|
||||||
|
try:
|
||||||
|
message = await channel.fetch_message(message_id)
|
||||||
|
await message.edit(content=highscore_string)
|
||||||
|
except nextcord.NotFound:
|
||||||
|
# message doesn't exist.
|
||||||
|
message = await channel.send(highscore_string)
|
||||||
|
message_id = message.id
|
||||||
|
highscores.highscores_data[boss["boss"]]["message_id"] = message_id
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
"""
|
|
||||||
Contains various function to format the highscore messages
|
|
||||||
"""
|
|
||||||
|
|
||||||
import highscores # pylint: disable=import-error
|
|
||||||
|
|
||||||
|
|
||||||
def format_boss_highscore(boss):
|
|
||||||
"""
|
|
||||||
returns a formattedd string for a boss's highscore
|
|
||||||
@param the dictionary object for the boss
|
|
||||||
@return the formatted string
|
|
||||||
"""
|
|
||||||
boss_name = boss["boss"]
|
|
||||||
ret_string = f"**{boss_name}**\n"
|
|
||||||
|
|
||||||
# Gather all categories and add to string
|
|
||||||
for category in highscores.highscores_config["categories"]:
|
|
||||||
category_name = category["category"]
|
|
||||||
ret_string += f"{category_name}\t\t"
|
|
||||||
ret_string += "\n"
|
|
||||||
|
|
||||||
highscore_size = highscores.highscores_config["highscore_size"]
|
|
||||||
|
|
||||||
# list rankings
|
|
||||||
for i in range(highscore_size):
|
|
||||||
for category in highscores.highscores_config["categories"]:
|
|
||||||
ret_string += f"{i+1}: (name here)\t\t"
|
|
||||||
ret_string += "\n"
|
|
||||||
|
|
||||||
# if boss is hardmode, repeat above for hardmode applicable categories
|
|
||||||
if boss["hardmode"]:
|
|
||||||
for category in highscores.highscores_config["categories"]:
|
|
||||||
if category["hardmode"]:
|
|
||||||
category_name = category["category"]
|
|
||||||
ret_string += f"{category_name}\t\t"
|
|
||||||
|
|
||||||
ret_string += "\n"
|
|
||||||
|
|
||||||
for i in range(highscore_size):
|
|
||||||
for category in highscores.highscores_config["categories"]:
|
|
||||||
if category["hardmode"]:
|
|
||||||
ret_string += f"{i+1}: (name here)\t\t"
|
|
||||||
ret_string += "\n"
|
|
||||||
return ret_string
|
|
||||||
Reference in New Issue
Block a user