Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f33dc8ce37 | ||
|
|
306f983c8e | ||
|
|
9e9d616814 | ||
|
|
5a09beea31 | ||
|
|
e2b0c0ea89 |
@@ -4,6 +4,7 @@ main file for pvm-highscores bot
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
@@ -32,6 +33,11 @@ submission_objects: dict = {}
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main function for bot."""
|
"""Main function for bot."""
|
||||||
|
min_python_version = (3, 7)
|
||||||
|
if sys.version_info < min_python_version:
|
||||||
|
print("ERROR: Python version must be >= 3.7")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
# Allows privledged intents for monitoring members joining, roles editing, and role assignments
|
# Allows privledged intents for monitoring members joining, roles editing, and role assignments
|
||||||
# These need to be enabled in the developer portal as well
|
# These need to be enabled in the developer portal as well
|
||||||
intents = nextcord.Intents.default()
|
intents = nextcord.Intents.default()
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ class HighscoresData:
|
|||||||
skeleton["tables"][boss] = {"message_id": 0}
|
skeleton["tables"][boss] = {"message_id": 0}
|
||||||
boss_categories = {}
|
boss_categories = {}
|
||||||
for category in categories:
|
for category in categories:
|
||||||
rank_list = []
|
scores_list = {}
|
||||||
boss_categories[category] = rank_list
|
boss_categories[category] = scores_list
|
||||||
skeleton["tables"][boss]["categories"] = boss_categories
|
skeleton["tables"][boss]["categories"] = boss_categories
|
||||||
|
|
||||||
self._data[str(guild_id)] = skeleton
|
self._data[str(guild_id)] = skeleton
|
||||||
@@ -66,40 +66,17 @@ class HighscoresData:
|
|||||||
minutes = score.split(":")[0]
|
minutes = score.split(":")[0]
|
||||||
seconds = score.split(":")[1]
|
seconds = score.split(":")[1]
|
||||||
score_seconds = int(minutes) * 60 + float(seconds)
|
score_seconds = int(minutes) * 60 + float(seconds)
|
||||||
score_tuple = (user, score, score_seconds)
|
score_list = [score, score_seconds]
|
||||||
sort_index = 2
|
|
||||||
else:
|
|
||||||
score_tuple = (user, int(score))
|
|
||||||
sort_index = 1
|
sort_index = 1
|
||||||
|
else:
|
||||||
|
score_list = [int(score)]
|
||||||
|
sort_index = 0
|
||||||
|
|
||||||
# if user is in an existing tuple, delete it.
|
# Will not ensure new score is better than old one. Allows for correcting mistakes.
|
||||||
users_scores: "list[tuple]" = [score_tuple]
|
|
||||||
for tup in scores:
|
|
||||||
if user == tup[0]:
|
|
||||||
# Add tup to users_scores, remove from scores
|
|
||||||
users_scores.append(tup)
|
|
||||||
|
|
||||||
# sort users_scores
|
scores[user] = score_list
|
||||||
users_scores.sort(
|
|
||||||
key=lambda x: x[sort_index],
|
|
||||||
reverse=not ascending,
|
|
||||||
)
|
|
||||||
|
|
||||||
for index, tup in enumerate(users_scores):
|
scores = dict(sorted(scores.items(), key=lambda x: x[1][sort_index], reverse=not ascending))
|
||||||
if index == 0:
|
|
||||||
# first score is the best score.
|
|
||||||
if tup not in scores:
|
|
||||||
scores.append(tup)
|
|
||||||
else:
|
|
||||||
# discard all other scores from scores list.
|
|
||||||
if tup in scores:
|
|
||||||
scores.remove(tup)
|
|
||||||
|
|
||||||
# sort scores.
|
|
||||||
scores.sort(
|
|
||||||
key=lambda x: x[sort_index],
|
|
||||||
reverse=not ascending,
|
|
||||||
)
|
|
||||||
|
|
||||||
self._data[str(guild_id)]["tables"][boss_name]["categories"][category] = scores
|
self._data[str(guild_id)]["tables"][boss_name]["categories"][category] = scores
|
||||||
save_highscores_data(self._data)
|
save_highscores_data(self._data)
|
||||||
|
|||||||
+10
-9
@@ -17,27 +17,28 @@ def format_highscore_message(boss_name: str, guild_id: int):
|
|||||||
ret_string = f"**{boss_name}**\n```"
|
ret_string = f"**{boss_name}**\n```"
|
||||||
|
|
||||||
# Gather all categories and add to string
|
# Gather all categories and add to string
|
||||||
for key, value in highscores_data.get_categories_data(guild_id, boss_name):
|
for category_name in highscores_data.get_table_categories(guild_id, boss_name):
|
||||||
ret_string += f"{key}".ljust(26, " ")
|
ret_string += f"{category_name}".ljust(26, " ")
|
||||||
ret_string += "\n"
|
ret_string += "\n"
|
||||||
|
|
||||||
highscore_size = highscores_data.get_config_highscore_size()
|
highscore_size = highscores_data.get_config_highscore_size()
|
||||||
|
|
||||||
# list rankings in a single line. Start with first place for each category and then continue
|
# list rankings in a single line. Start with first place for each category and then continue
|
||||||
for i in range(highscore_size):
|
for i in range(highscore_size):
|
||||||
for key, value in highscores_data.get_categories_data(guild_id, boss_name):
|
for category_name, category_data in highscores_data.get_categories_data(
|
||||||
if len(value) > i:
|
guild_id, boss_name
|
||||||
score_pair = value[i]
|
):
|
||||||
|
if len(category_data) > i:
|
||||||
# pad username to max length.
|
# pad username to max length.
|
||||||
username: str = score_pair[0].ljust(
|
username: str = list(category_data.keys())[i].ljust(
|
||||||
highscores_data.get_guild_username_length(guild_id), " "
|
highscores_data.get_guild_username_length(guild_id), " "
|
||||||
)
|
)
|
||||||
score: str = str(score_pair[1])
|
# turns category data value into a string. Very janky.
|
||||||
|
score: str = str(list(category_data.values())[i][0])
|
||||||
|
|
||||||
# pad score to correct length
|
# pad score to correct length
|
||||||
# MM:SS.ms is 7 characters long
|
# MM:SS.ms is 7 characters long
|
||||||
if highscores_data.get_config_time_record(key):
|
if highscores_data.get_config_time_record(category_name):
|
||||||
# if there are single digit minutes, add a space for formatting.
|
# if there are single digit minutes, add a space for formatting.
|
||||||
if score.find(":") and len(score.split(":", maxsplit=1)[0]) < 2:
|
if score.find(":") and len(score.split(":", maxsplit=1)[0]) < 2:
|
||||||
score = " " + score
|
score = " " + score
|
||||||
|
|||||||
Reference in New Issue
Block a user