Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f84e2eef29 | ||
|
|
b4eb5ab6d1 | ||
|
|
1ae6a4a223 | ||
|
|
e1a429c42a | ||
|
|
790e8ca50f | ||
|
|
7ba43ea4f4 | ||
|
|
39c858af64 |
@@ -0,0 +1,49 @@
|
||||
"""
|
||||
Bot command for deleting the guild's scores.
|
||||
"""
|
||||
|
||||
from nextcord import Embed
|
||||
from nextcord.ext import commands
|
||||
|
||||
from highscores import highscores_data # pylint: disable=import-error
|
||||
from utilities.data_storage import save_highscores_data # pylint: disable=import-error
|
||||
from utilities.data_storage import create_highscore_skeleton # pylint: disable=import-error
|
||||
|
||||
|
||||
class DeleteScores(commands.Cog, name="Delete Scores"):
|
||||
"""
|
||||
Warning: This command only works for developers.
|
||||
Deletes this guild's scores.
|
||||
"""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.command(name="delete-scores")
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def delete_scores(self, ctx: commands.Context):
|
||||
"""A command which registers current channel as for various uses.
|
||||
Usage:
|
||||
```
|
||||
?delete_scores
|
||||
```
|
||||
"""
|
||||
# only allow AlwaysCompiling to use.
|
||||
# If you are a developer and want to use command, can add name to list
|
||||
if ctx.author.id == 206602713511886849:
|
||||
guild_data: dict = highscores_data[str(ctx.guild.id)]
|
||||
|
||||
for boss, boss_data in guild_data["tables"].items():
|
||||
for category, category_data in boss_data["categories"].items():
|
||||
category_data = []
|
||||
boss_data["categories"][category] = category_data
|
||||
guild_data["tables"][boss] = boss_data
|
||||
|
||||
save_highscores_data(highscores_data)
|
||||
|
||||
|
||||
# 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):
|
||||
"""Adds function to bot"""
|
||||
bot.add_cog(DeleteScores(bot))
|
||||
@@ -44,10 +44,10 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
|
||||
]["is_time_record"]
|
||||
|
||||
time_regex = re.search(
|
||||
"([0-9]{2}:)?[0-9]{2}(\.[0-9])?", # pylint: disable=anomalous-backslash-in-string
|
||||
"^([0-9]{1,2}:)?[0-9]{2}(\.[0-9])?$", # pylint: disable=anomalous-backslash-in-string
|
||||
message.content,
|
||||
)
|
||||
int_regex = re.search("[0-9]+", message.content)
|
||||
int_regex = re.search("^[0-9]+$", message.content)
|
||||
if time_regex is None and is_time_record:
|
||||
embed = submission_message.embeds[0]
|
||||
embed.add_field(
|
||||
@@ -61,12 +61,11 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
|
||||
score = message.content
|
||||
if is_time_record:
|
||||
# standardize time score format.
|
||||
# add colon if its not there
|
||||
# strip leading 0s and colon
|
||||
# then add colon if its not there
|
||||
score = score.lstrip("0:")
|
||||
if score.find(":") == -1:
|
||||
score = "00:" + score
|
||||
# add a 0 if there isn't 2 digits before a colon
|
||||
elif len(score.split(":", maxsplit=1)[0]) < 2:
|
||||
score = "0" + score
|
||||
score = "0:" + score
|
||||
submission_objects[message.author.id]["score"] = score
|
||||
embed = get_submission_embed(message.author.id)
|
||||
|
||||
|
||||
@@ -189,6 +189,11 @@ class SubmissionCreateButton(nextcord.ui.View):
|
||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||
): # pylint: disable=unused-argument
|
||||
"""Button for score submission."""
|
||||
# Don't allow a user to start a new submission if one already exists
|
||||
if interaction.user.id in submission_objects:
|
||||
await interaction.send("Please finish in progress submission first.", ephemeral=True)
|
||||
return
|
||||
|
||||
guild_id_str = str(interaction.guild.id)
|
||||
guild_data = highscores_data[guild_id_str]
|
||||
|
||||
|
||||
+11
-10
@@ -36,13 +36,16 @@ def format_highscore_message(boss_name: str, guild_data: dict):
|
||||
username: str = score_pair[0].ljust(guild_data["username_length"], " ")
|
||||
score: str = str(score_pair[1])
|
||||
|
||||
# pad score to correct length
|
||||
# MM:SS.ms is 7 characters long
|
||||
if highscores_config["categories"][key]["is_time_record"]:
|
||||
# pad score to correct length
|
||||
# MM:SS.ms is 7 characters long
|
||||
score = score.ljust(7, " ")
|
||||
# if there are single digit minutes, add a space for formatting.
|
||||
if score.find(":") and len(score.split(":", maxsplit=1)[0]) < 2:
|
||||
score = " " + score
|
||||
else:
|
||||
score = score.rjust(7, " ")
|
||||
|
||||
line_str = f"{i+1}: {username} - "
|
||||
ret_string += line_str + score.rjust(26 - len(line_str) - 1) + " "
|
||||
ret_string += f"{i+1}: {username} - {score}".ljust(26, " ")
|
||||
else:
|
||||
ret_string += f"{i+1}: submit your score".ljust(26, " ")
|
||||
ret_string += "\n"
|
||||
@@ -75,6 +78,9 @@ async def send_highscore_message(
|
||||
# save message -> boss_name in message_map
|
||||
# get guild id from channel
|
||||
# channel should come from the guild that is requesting this highscores message anyways.
|
||||
# check if guild is in message map already
|
||||
if not str(channel.guild.id) in highscores_message_map:
|
||||
highscores_message_map[str(channel.guild.id)] = {}
|
||||
highscores_message_map[str(channel.guild.id)][message_id] = boss_name
|
||||
|
||||
return message
|
||||
@@ -141,11 +147,6 @@ async def submit_score(
|
||||
reverse=not boss_category_config["ascending"],
|
||||
)
|
||||
|
||||
# enforce highscore size
|
||||
while len(scores) > highscores_config["highscore_size"]:
|
||||
scores.pop()
|
||||
guild_data["tables"][boss_name]["categories"][category] = scores
|
||||
|
||||
# edit message
|
||||
highscore_channel_id = guild_data["highscore_channel_id"]
|
||||
print(f"Editting message {highscore_channel_id}")
|
||||
|
||||
Reference in New Issue
Block a user