Compare commits
133
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
448bed17ec | ||
|
|
b4d0f8a15e | ||
|
|
72a97f6cb7 | ||
|
|
8aadf07968 | ||
|
|
a6f98d11ab | ||
|
|
4ee0593619 | ||
|
|
d4db9b51f0 | ||
|
|
f67eb75c7b | ||
|
|
6f4322bf6a | ||
|
|
66ace947c6 | ||
|
|
4d9c70bf09 | ||
|
|
4c944c8323 | ||
|
|
b65254c2cc | ||
|
|
5b3c9ef247 | ||
|
|
027da38574 | ||
|
|
80e4602621 | ||
|
|
07310c804a | ||
|
|
4641ce4048 | ||
|
|
142842a36b | ||
|
|
6371fc4e8c | ||
|
|
3fac5f7a06 | ||
|
|
80f3966d39 | ||
|
|
69a439d13a | ||
|
|
251ac2cf47 | ||
|
|
2dc0350213 | ||
|
|
7e40937cdd | ||
|
|
761a7df29f | ||
|
|
b3a84fc3a8 | ||
|
|
262bcd07b9 | ||
|
|
8ca77d93b3 | ||
|
|
1b4f0362b5 | ||
|
|
ce60288892 | ||
|
|
2515b90497 | ||
|
|
3ce9f8090f | ||
|
|
68da97e138 | ||
|
|
ef28b97a1b | ||
|
|
e43a0a8977 | ||
|
|
2ee2d3405e | ||
|
|
af204a3156 | ||
|
|
109b22be62 | ||
|
|
aa4b06c125 | ||
|
|
96fce1d661 | ||
|
|
3d471198f5 | ||
|
|
05d0653a5b | ||
|
|
6758f4e90d | ||
|
|
6e6b57c49c | ||
|
|
b4f72b9528 | ||
|
|
cd81ee3140 | ||
|
|
6ddba14908 | ||
|
|
0fc0fc33da | ||
|
|
529761b45f | ||
|
|
bac64110c1 | ||
|
|
d04de253e7 | ||
|
|
8c7a801800 | ||
|
|
01df80d358 | ||
|
|
06248cfe6c | ||
|
|
a3af93d4bc | ||
|
|
646ee0274b | ||
|
|
fe0a74cfc4 | ||
|
|
5bed587da9 | ||
|
|
f7a40f83a9 | ||
|
|
a66bc4982f | ||
|
|
04051eeacc | ||
|
|
f33dc8ce37 | ||
|
|
306f983c8e | ||
|
|
9e9d616814 | ||
|
|
5a09beea31 | ||
|
|
8c2b3fa487 | ||
|
|
62e89960f7 | ||
|
|
e2b0c0ea89 | ||
|
|
3eed30567d | ||
|
|
565babd1d3 | ||
|
|
455b51a998 | ||
|
|
f136181216 | ||
|
|
463ef48052 | ||
|
|
64004329da | ||
|
|
f497928054 | ||
|
|
0911ebfa45 | ||
|
|
beedf946c9 | ||
|
|
5b31314f02 | ||
|
|
4b15fef30c | ||
|
|
e11a86af7b | ||
|
|
f4f8f426d0 | ||
|
|
b8eb84165e | ||
|
|
273ff757af | ||
|
|
f84e2eef29 | ||
|
|
b4eb5ab6d1 | ||
|
|
1ae6a4a223 | ||
|
|
e1a429c42a | ||
|
|
790e8ca50f | ||
|
|
7ba43ea4f4 | ||
|
|
39c858af64 | ||
|
|
093861b2e6 | ||
|
|
4ef487a8c4 | ||
|
|
849ebb966a | ||
|
|
f1b0e34194 | ||
|
|
7cdc7d2cef | ||
|
|
db4672dcda | ||
|
|
fc2b601687 | ||
|
|
493d44fa19 | ||
|
|
5d3a1568a2 | ||
|
|
be29194a57 | ||
|
|
d067da2300 | ||
|
|
6d0c10e1cc | ||
|
|
609bfa1277 | ||
|
|
158e53e799 | ||
|
|
3cc67a4e9e | ||
|
|
df80eb2952 | ||
|
|
b78eb7b9bf | ||
|
|
65ce143cfc | ||
|
|
8dbb2a6895 | ||
|
|
a24fe52182 | ||
|
|
d0131b1044 | ||
|
|
307ef86493 | ||
|
|
a1a9fae9fa | ||
|
|
56984b3df0 | ||
|
|
7a261d56fc | ||
|
|
4ee2280565 | ||
|
|
a24900a957 | ||
|
|
ef17d3dc3e | ||
|
|
d711763c80 | ||
|
|
8318bf741a | ||
|
|
17c1915810 | ||
|
|
674ea94588 | ||
|
|
090184c1e9 | ||
|
|
31fa0b50a3 | ||
|
|
374632bbc6 | ||
|
|
8a36c9dac9 | ||
|
|
1900e21f72 | ||
|
|
2c85483db5 | ||
|
|
63db9fb7d4 | ||
|
|
5155744ec5 | ||
|
|
fedc8be778 |
+3
-2
@@ -132,5 +132,6 @@ nextcord.log
|
||||
|
||||
# data file for bot
|
||||
highscores_data.json
|
||||
highscores_message_map.json
|
||||
highscores_config.json
|
||||
highscores_config.json
|
||||
deleted_backups/
|
||||
highscores_data/
|
||||
@@ -0,0 +1,42 @@
|
||||
"""
|
||||
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
|
||||
|
||||
|
||||
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 deletes all scores for this guild.
|
||||
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:
|
||||
for table in highscores_data.get_guild(ctx.guild.id).tables:
|
||||
for category in table.categories:
|
||||
category.clear()
|
||||
highscores_data.save_guild_data(highscores_data.get_guild(ctx.guild.id))
|
||||
|
||||
|
||||
# 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))
|
||||
@@ -0,0 +1,43 @@
|
||||
"""
|
||||
Defines cog for guild listeners. Contains functions for various guild events.
|
||||
"""
|
||||
|
||||
from nextcord.ext import commands
|
||||
import nextcord
|
||||
|
||||
from highscores import highscores_data # pylint: disable=import-error
|
||||
|
||||
|
||||
class GuildListener(commands.Cog, name="Guild Listener"):
|
||||
"""Sets up message listener."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_join(self, guild: nextcord.Guild):
|
||||
"""Listener for Guild Join. Creates skeleton for new guild joined and saves it."""
|
||||
highscores_data.add_guild(guild.id)
|
||||
# This add config will be removed eventually. Config adding will have to be controlled by commands.
|
||||
highscores_data.add_configuration(guild.id, "runescape")
|
||||
highscores_data.save_guild_data(highscores_data.get_guild(guild.id))
|
||||
|
||||
welcome_message: str = "Hello, I keep track of Highscores for you!"
|
||||
welcome_message += " Currently only supporting RuneScape boss highscores,"
|
||||
welcome_message += " but will be more dynamic support in future."
|
||||
welcome_message += ' For assistance on getting started, use "?register help".'
|
||||
|
||||
await guild.system_channel.send(content=welcome_message)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_remove(self, guild: nextcord.Guild):
|
||||
"""Listener for Guild Remove. Removes data from highscores_data."""
|
||||
print(f"Removing data for guild {guild.name} (id {guild.id}).")
|
||||
highscores_data.remove_guild(guild.id)
|
||||
|
||||
|
||||
# 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(GuildListener(bot))
|
||||
@@ -2,11 +2,18 @@
|
||||
Defines cog for on message listener.
|
||||
"""
|
||||
|
||||
from datetime import date
|
||||
import random
|
||||
import re
|
||||
|
||||
from nextcord.ext import commands
|
||||
import nextcord
|
||||
|
||||
from highscores import submission_messages # pylint: disable=import-error
|
||||
from highscores import highscores_data # pylint: disable=import-error
|
||||
from cogs.submission.submission_views import ( # pylint: disable=import-error
|
||||
SubmissionState,
|
||||
get_submission_embed,
|
||||
)
|
||||
from highscores import highscores_data, submission_objects # pylint: disable=import-error
|
||||
|
||||
|
||||
class SubmissionListener(commands.Cog, name="Message Listener"):
|
||||
@@ -16,29 +23,92 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self, proof_message: nextcord.Message):
|
||||
async def on_message(self, message: nextcord.Message):
|
||||
"""Listener for message creation. Adds score and attachments to submission."""
|
||||
if proof_message.author.id in submission_messages:
|
||||
message_id = submission_messages[proof_message.author.id]
|
||||
submission_message: nextcord.Message = await self.bot.get_channel(
|
||||
highscores_data["submission_channel_id"]
|
||||
).fetch_message(message_id)
|
||||
# don't want to process any messages from bot.
|
||||
if message.author.id == self.bot.user.id:
|
||||
return
|
||||
|
||||
guild_id = message.guild.id
|
||||
|
||||
# troll addition for friends birthday
|
||||
if guild_id == 239758371358638080 and date.today() == date(2022, 7, 31):
|
||||
# 5% chance to send the message
|
||||
chance = random.randint(1, 20)
|
||||
if chance == 1:
|
||||
await message.channel.send("Happy Birthday Chris <@642330132958281750>")
|
||||
|
||||
if message.author.id in submission_objects:
|
||||
message_id = submission_objects[message.author.id]["message_id"]
|
||||
submission_channel_id = highscores_data.get_guild(guild_id).submission_channel
|
||||
submission_message: nextcord.Message = (
|
||||
await self.bot.get_guild(guild_id)
|
||||
.get_channel(submission_channel_id)
|
||||
.fetch_message(message_id)
|
||||
)
|
||||
|
||||
# need check if correct user and correct channel
|
||||
if proof_message.channel.id == highscores_data["submission_channel_id"]:
|
||||
if message.channel.id == submission_channel_id:
|
||||
state = submission_objects[message.author.id]["submission_state"]
|
||||
if state == SubmissionState.SCORE and message.content:
|
||||
|
||||
# check with regex if score matches correctly
|
||||
is_time_record = (
|
||||
highscores_data.get_guild(guild_id)
|
||||
.get_table(submission_objects[message.author.id]["boss_name"])
|
||||
.get_category(submission_objects[message.author.id]["category"])
|
||||
.time_record
|
||||
)
|
||||
|
||||
time_regex = re.search(
|
||||
"^([0-9]{1,2}:[0-9]|[0-9])?[0-9](\\.[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(
|
||||
name="Error",
|
||||
value="Time record must follow format MM:SS.ms, SS.ms, or SS.",
|
||||
)
|
||||
elif int_regex is None and not is_time_record:
|
||||
embed = submission_message.embeds[0]
|
||||
embed.add_field(name="Error", value="Number record must only be number.")
|
||||
else:
|
||||
score = message.content
|
||||
if is_time_record:
|
||||
# standardize time score format.
|
||||
if re.search("^[1-9]?[0-9]:[0-9]{2}(\\.[0-9])?$", score):
|
||||
# score is already fine.
|
||||
pass
|
||||
elif re.search("^[0-9]{2}(\\.[0-9])?$", score):
|
||||
# need to add leading colon and 0
|
||||
score = "0:" + score
|
||||
elif re.search("^[0-9](\\.[0-9])?$", score):
|
||||
# need to add 0 in seconds and leading colon and 0
|
||||
score = "0:0" + score
|
||||
elif re.search("^[0]?[0-9]:[0-9]{2}(\\.[0-9])?$", score):
|
||||
# if there is a minute 10ths place 0, remove
|
||||
score = score.lstrip("0")
|
||||
submission_objects[message.author.id]["score"] = score
|
||||
embed = get_submission_embed(message.author.id)
|
||||
|
||||
embed = submission_message.embeds[0]
|
||||
if proof_message.content:
|
||||
embed.add_field(name="Score", value=proof_message.content, inline=False)
|
||||
await submission_message.edit(
|
||||
embed=embed,
|
||||
)
|
||||
if len(proof_message.attachments) > 0:
|
||||
elif state == SubmissionState.PROOF and len(message.attachments) > 0:
|
||||
await submission_message.edit(
|
||||
files=[await attch.to_file() for attch in proof_message.attachments],
|
||||
files=[await attch.to_file() for attch in message.attachments],
|
||||
)
|
||||
elif state == SubmissionState.NAME and message.content:
|
||||
submission_objects[message.author.id]["username"] = message.content[
|
||||
: highscores_data.get_guild(guild_id).username_length
|
||||
]
|
||||
embed = get_submission_embed(message.author.id)
|
||||
await submission_message.edit(
|
||||
embed=embed,
|
||||
)
|
||||
|
||||
await proof_message.delete()
|
||||
await message.delete()
|
||||
|
||||
|
||||
# This function will be called when this extension is loaded.
|
||||
|
||||
@@ -5,10 +5,8 @@ Bot command to post the highscores
|
||||
from nextcord.ext import commands
|
||||
import nextcord
|
||||
|
||||
from cogs.submission.submission_views import SubmissionButton # pylint: disable=import-error
|
||||
from highscores import highscores_config # pylint: disable=import-error
|
||||
from cogs.submission.submission_views import SubmissionCreateButton # pylint: disable=import-error
|
||||
from highscores import highscores_data # pylint: disable=import-error
|
||||
from utilities.data_storage import save_highscores_data # pylint: disable=import-error
|
||||
from utilities.utils import send_highscore_message # pylint: disable=import-error
|
||||
|
||||
|
||||
@@ -29,21 +27,27 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
|
||||
?post-scores
|
||||
```
|
||||
"""
|
||||
highscore_channel_id = highscores_data["highscore_channel_id"]
|
||||
print(f"Printing out highscores information in channel {highscore_channel_id}")
|
||||
channel = self.bot.get_channel(highscore_channel_id)
|
||||
guild = highscores_data.get_guild(ctx.guild.id)
|
||||
print(f"Printing out highscores information in channel {guild.highscore_channel}")
|
||||
channel = ctx.guild.get_channel(guild.highscore_channel)
|
||||
|
||||
error_response = 'Registered Highscores channel does not exist or was never registered. \n\
|
||||
Register with "?register" command.'
|
||||
error_response = "Registered Highscores channel does not exist or was never registered. "
|
||||
error_response += 'Register with "?register" command.'
|
||||
assert channel is not None, await ctx.send(error_response)
|
||||
|
||||
for boss, categories in highscores_config[ # pylint: disable=unused-variable
|
||||
"highscore_table"
|
||||
].items():
|
||||
message: nextcord.Message = await send_highscore_message(channel, boss)
|
||||
await message.edit(view=SubmissionButton(self.bot))
|
||||
if len(highscores_data.get_guild(ctx.guild.id).tables) < 1:
|
||||
await channel.send(
|
||||
"No tables have been created for this guild. Please create some tables."
|
||||
)
|
||||
return
|
||||
|
||||
save_highscores_data(highscores_data)
|
||||
for table in highscores_data.get_guild(ctx.guild.id).tables:
|
||||
message: nextcord.Message = await send_highscore_message(channel, guild, table)
|
||||
await message.edit(view=SubmissionCreateButton(self.bot))
|
||||
|
||||
# have to save data here in case message id was changed. rather save here after all
|
||||
# messages have been sent.
|
||||
highscores_data.save_guild_data(guild)
|
||||
|
||||
|
||||
# This function will be called when this extension is loaded.
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
"""
|
||||
Functions for controlling the bot's presence.
|
||||
"""
|
||||
|
||||
import random
|
||||
|
||||
from nextcord.ext import commands
|
||||
from nextcord.ext import tasks
|
||||
import nextcord
|
||||
|
||||
|
||||
class BotPresence(commands.Cog, name="Bot Presence"):
|
||||
"""Class for bot presence functions."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_join(self, guild: nextcord.Guild): # pylint: disable=unused-argument
|
||||
"""Listener for Guild Join. Updated presence on guild join."""
|
||||
await self.change_presence()
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
"""Starts the loop when bot is ready."""
|
||||
await self.bot.wait_until_ready()
|
||||
# pylint doesn't recognize that periodic_change_presense is subclassed from tasks.loop.
|
||||
self.periodic_change_presence.start() # pylint: disable=no-member
|
||||
|
||||
@tasks.loop(minutes=2)
|
||||
async def periodic_change_presence(self):
|
||||
"""Loops every 2 minutes and changes presence."""
|
||||
await self.change_presence()
|
||||
|
||||
async def change_presence(self):
|
||||
"""Randomly chooses a presence and updates bot's presence."""
|
||||
statuses = [
|
||||
f"?help | {len(self.bot.guilds)} servers",
|
||||
f"Vuln Pls. | {len(self.bot.guilds)} servers",
|
||||
f"All your base are belong to us. | {len(self.bot.guilds)} servers",
|
||||
f"Double plus good. | {len(self.bot.guilds)} servers",
|
||||
]
|
||||
|
||||
status = random.choice(statuses)
|
||||
|
||||
await self.bot.change_presence(activity=nextcord.Game(status))
|
||||
|
||||
|
||||
# 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(BotPresence(bot))
|
||||
@@ -6,18 +6,17 @@ 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
|
||||
|
||||
|
||||
class RegisterVerificationChannel(commands.Cog, name="Register"):
|
||||
"""Bot command for registering various channels to the bot."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
def __init__(self, bot: commands.Bot) -> None:
|
||||
self.bot = bot
|
||||
|
||||
@commands.command(name="register")
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def register_highscores(self, ctx: commands.Context, registration_type: str):
|
||||
async def register_highscores(self, ctx: commands.Context, registration_type: str) -> None:
|
||||
"""A command which registers current channel as for various uses.
|
||||
Usage:
|
||||
```
|
||||
@@ -29,16 +28,17 @@ class RegisterVerificationChannel(commands.Cog, name="Register"):
|
||||
"""
|
||||
# respond to the message
|
||||
channel_id = ctx.channel.id
|
||||
guild = highscores_data.get_guild(ctx.guild.id)
|
||||
|
||||
if registration_type == "verify":
|
||||
await ctx.send(f"Registered <#{channel_id}> as channel to post verifications in.")
|
||||
highscores_data["verification_channel_id"] = channel_id
|
||||
guild.verification_channel = channel_id
|
||||
elif registration_type == "highscore":
|
||||
await ctx.send(f"Registered <#{channel_id}> as channel to post highscores in.")
|
||||
highscores_data["highscore_channel_id"] = channel_id
|
||||
guild.highscore_channel = channel_id
|
||||
elif registration_type == "submission":
|
||||
await ctx.send(f"Registered <#{channel_id}> as channel to post submissions in.")
|
||||
highscores_data["submission_channel_id"] = channel_id
|
||||
guild.submission_channel = channel_id
|
||||
else:
|
||||
embed = Embed(
|
||||
title="Register command help", description="How to use the register command."
|
||||
@@ -56,12 +56,14 @@ class RegisterVerificationChannel(commands.Cog, name="Register"):
|
||||
)
|
||||
embed.add_field(name="?register help", value="Use to show this message.")
|
||||
await ctx.reply(embed=embed)
|
||||
# return, don't need to save data
|
||||
return
|
||||
|
||||
save_highscores_data(highscores_data)
|
||||
highscores_data.save_guild_data(guild)
|
||||
|
||||
|
||||
# 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):
|
||||
def setup(bot: commands.Bot) -> None:
|
||||
"""Adds function to bot"""
|
||||
bot.add_cog(RegisterVerificationChannel(bot))
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
"""
|
||||
Bot command to submit a score
|
||||
"""
|
||||
|
||||
from nextcord.ext import commands
|
||||
|
||||
from highscores import highscores_data # pylint: disable=import-error
|
||||
from utilities.utils import submit_score # pylint: disable=import-error
|
||||
from .verification_view import VerificationView
|
||||
|
||||
|
||||
class Score(commands.Cog, name="Score"):
|
||||
"""Submits a score."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
"""Called when the cog is loaded"""
|
||||
self.bot.add_view(VerificationView())
|
||||
|
||||
@commands.command(name="score")
|
||||
async def score(self, ctx: commands.Context, boss_name: str, category: str, score: str):
|
||||
"""A command which calls a function to submit the score to highscores.
|
||||
Gathers required information from command and passes on.
|
||||
Usage:
|
||||
```
|
||||
?score "Boss Name" "Category" "score"
|
||||
This command still works if you prefer to use it over the ui.
|
||||
```
|
||||
"""
|
||||
verification_channel_id = highscores_data["verification_channel_id"]
|
||||
channel = self.bot.get_channel(verification_channel_id)
|
||||
|
||||
error_response = "Registered Verification channel does not exist or was never registered. \
|
||||
Contact server admins."
|
||||
assert channel is not None, await ctx.send(error_response)
|
||||
|
||||
verification_string = f"{ctx.author.display_name}:{boss_name}:{category}:{score}"
|
||||
|
||||
await channel.send(
|
||||
content=verification_string,
|
||||
files=[await attch.to_file() for attch in ctx.message.attachments],
|
||||
view=VerificationView(),
|
||||
)
|
||||
|
||||
|
||||
# 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(Score(bot))
|
||||
@@ -1,40 +0,0 @@
|
||||
"""View for verification buttons"""
|
||||
|
||||
import nextcord
|
||||
from utilities.utils import submit_score # pylint: disable=import-error
|
||||
|
||||
|
||||
class VerificationView(nextcord.ui.View):
|
||||
"""Defines views for verifying score submissions"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(timeout=None)
|
||||
|
||||
@nextcord.ui.button(
|
||||
label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-score-command"
|
||||
)
|
||||
async def approve_button(
|
||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||
): # pylint: disable=unused-argument
|
||||
"""Button for approving score submission."""
|
||||
content = interaction.message.content.split(":")
|
||||
user = content[0]
|
||||
boss_name = content[1]
|
||||
category = content[2]
|
||||
score = content[3]
|
||||
|
||||
await submit_score(interaction, user, boss_name, category, score)
|
||||
await interaction.message.delete()
|
||||
await interaction.channel.send(
|
||||
f"Approved: {boss_name} {category} {user} {score}",
|
||||
files=[await attch.to_file() for attch in interaction.message.attachments],
|
||||
)
|
||||
|
||||
@nextcord.ui.button(
|
||||
label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-score-command"
|
||||
)
|
||||
async def deny_button(
|
||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||
): # pylint: disable=unused-argument
|
||||
"""Button for denying score submission."""
|
||||
await interaction.message.delete()
|
||||
@@ -4,7 +4,8 @@ Cog for creating submission process.
|
||||
|
||||
from nextcord.ext import commands
|
||||
|
||||
from .submission_views import SubmissionButton
|
||||
from .submission_views import SubmissionCreateButton
|
||||
from .verification_view import VerificationView
|
||||
|
||||
|
||||
class SubmissionCog(commands.Cog, name="Submission Cog"):
|
||||
@@ -16,7 +17,8 @@ class SubmissionCog(commands.Cog, name="Submission Cog"):
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
"""Called when cog is loaded"""
|
||||
self.bot.add_view(SubmissionButton(self.bot))
|
||||
self.bot.add_view(SubmissionCreateButton(self.bot))
|
||||
self.bot.add_view(VerificationView())
|
||||
|
||||
|
||||
# This function will be called when this extension is loaded.
|
||||
|
||||
@@ -1,52 +1,70 @@
|
||||
"""Views used for submission process."""
|
||||
|
||||
from typing import Optional
|
||||
from enum import Enum
|
||||
|
||||
import nextcord
|
||||
from nextcord import Embed
|
||||
from nextcord.ext import commands
|
||||
|
||||
from utilities.data_storage import open_message_map # pylint: disable=import-error
|
||||
from highscores import highscores_data # pylint: disable=import-error
|
||||
from highscores import submission_messages # pylint: disable=import-error
|
||||
from highscores import ( # pylint: disable=import-error
|
||||
highscores_data,
|
||||
highscores_message_map,
|
||||
submission_objects,
|
||||
)
|
||||
from .verification_view import VerificationView
|
||||
|
||||
|
||||
class SubmissionButton(nextcord.ui.View):
|
||||
"""Defines view for score submission button."""
|
||||
class SubmissionState(Enum):
|
||||
"""Enum for which state a submission is in"""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
super().__init__(timeout=None)
|
||||
self._bot = bot
|
||||
CATEGORY = 1
|
||||
SCORE = 2
|
||||
PROOF = 3
|
||||
NAME = 4
|
||||
SUBMIT = 5
|
||||
VERIFY = 6
|
||||
|
||||
@nextcord.ui.button(label="Submit", style=nextcord.ButtonStyle.primary, custom_id="submit")
|
||||
async def submit_button(
|
||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||
): # pylint: disable=unused-argument
|
||||
"""Button for score submission."""
|
||||
highscores_message_map = open_message_map()
|
||||
boss_name = highscores_message_map[str(interaction.message.id)]
|
||||
embed = nextcord.Embed(title="Highscores Submission")
|
||||
embed.add_field(name="Boss", value=boss_name, inline=False)
|
||||
embed.add_field(name="User", value=interaction.user.display_name, inline=False)
|
||||
channel = self._bot.get_channel(highscores_data["submission_channel_id"])
|
||||
submission_message = await channel.send(
|
||||
f"<@{interaction.user.id}>",
|
||||
view=SubmissionDropdownView(
|
||||
self._bot, interaction, await self._category_select_options(boss_name)
|
||||
),
|
||||
embed=embed,
|
||||
)
|
||||
|
||||
# a user should only have 1 submission active at once.
|
||||
submission_messages[interaction.user.id] = submission_message.id
|
||||
def get_submission_embed(userid: int) -> nextcord.Embed:
|
||||
"""Creates an embed based off of the submission state and fields filled out."""
|
||||
usersubmission: dict = submission_objects[userid]
|
||||
state: SubmissionState = usersubmission["submission_state"]
|
||||
|
||||
async def _category_select_options(self, boss_name: str) -> "list[nextcord.SelectOption]":
|
||||
options: list[nextcord.SelectOption] = [] # pylint: disable=unsubscriptable-object
|
||||
boss_dict = highscores_data[boss_name]
|
||||
for category in boss_dict["categories"].items():
|
||||
options.append(nextcord.SelectOption(label=category[0]))
|
||||
if state is SubmissionState.CATEGORY:
|
||||
description = "Step 1: Choose your category!"
|
||||
elif state is SubmissionState.SCORE:
|
||||
description = "Step 2: Input your score!"
|
||||
elif state is SubmissionState.PROOF:
|
||||
description = "Step 3: Submit your proof!"
|
||||
elif state is SubmissionState.NAME:
|
||||
description = "Step 4 (Optional): Change name on submission! (proceed to next if skipping)"
|
||||
elif state is SubmissionState.SUBMIT:
|
||||
description = "Step 5: Submit if everything looks correct!"
|
||||
elif state is SubmissionState.VERIFY:
|
||||
description = "Review fields and accept."
|
||||
|
||||
return options
|
||||
embed = Embed(title="Highscores Submission", description=description)
|
||||
embed.add_field(name="User Name", value=usersubmission["username"], inline=False)
|
||||
embed.add_field(name="Boss", value=usersubmission["boss_name"], inline=False)
|
||||
if usersubmission["category"]:
|
||||
embed.add_field(name="Category", value=usersubmission["category"], inline=False)
|
||||
if usersubmission["score"]:
|
||||
embed.add_field(name="Score", value=usersubmission["score"], inline=False)
|
||||
return embed
|
||||
|
||||
|
||||
def category_select_options(guild_id: int, boss_name: str) -> "list[nextcord.SelectOption]":
|
||||
"""Returns list of categories for a given boss."""
|
||||
options: "list[nextcord.SelectOption]" = []
|
||||
category_list = highscores_data.get_guild(guild_id).get_table(boss_name).categories
|
||||
for category in category_list:
|
||||
options.append(nextcord.SelectOption(label=category.name))
|
||||
|
||||
return options
|
||||
|
||||
|
||||
############ Items used in submission process ############
|
||||
|
||||
|
||||
class SubmissionDropdown(nextcord.ui.Select):
|
||||
@@ -63,60 +81,198 @@ class SubmissionDropdown(nextcord.ui.Select):
|
||||
self._bot = bot
|
||||
|
||||
async def callback(self, interaction: nextcord.Interaction):
|
||||
embed = interaction.message.embeds[0]
|
||||
embed.add_field(name="Category", value=self.values[0], inline=False)
|
||||
submission_objects[interaction.user.id]["category"] = self.values[0]
|
||||
embed = get_submission_embed(interaction.user.id)
|
||||
await interaction.message.edit(
|
||||
embed=embed,
|
||||
)
|
||||
|
||||
|
||||
class SubmissionDropdownView(nextcord.ui.View):
|
||||
"""Defines submission dropdown process view"""
|
||||
class BackButton(nextcord.ui.Button):
|
||||
"""Defines view for back button."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
bot: commands.Bot,
|
||||
prev_interaction: nextcord.Interaction,
|
||||
options: "list[nextcord.SelectOption]",
|
||||
*,
|
||||
timeout: Optional[float] = 180,
|
||||
):
|
||||
super().__init__(timeout=timeout)
|
||||
self.add_item(SubmissionDropdown(bot, options))
|
||||
self._prev_interaction = prev_interaction
|
||||
self.bot = bot
|
||||
def __init__(self, bot: commands.Bot):
|
||||
super().__init__(label="Back", style=nextcord.ButtonStyle.primary, custom_id="back")
|
||||
self._bot = bot
|
||||
|
||||
async def interaction_check(self, interaction: nextcord.Interaction) -> bool:
|
||||
return self._prev_interaction.user == interaction.user
|
||||
async def callback(self, interaction: nextcord.Interaction):
|
||||
state: SubmissionState = submission_objects[interaction.user.id]["submission_state"]
|
||||
state = SubmissionState(state.value - 1)
|
||||
submission_objects[interaction.user.id]["submission_state"] = state
|
||||
embed = get_submission_embed(interaction.user.id)
|
||||
await interaction.edit(embed=embed, view=SubmissionView(self._bot, interaction.user.id))
|
||||
|
||||
@nextcord.ui.button(
|
||||
label="Submit Score", style=nextcord.ButtonStyle.green, custom_id="submit-score"
|
||||
)
|
||||
async def submit_button(
|
||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||
): # pylint: disable=unused-argument
|
||||
"""Defines button to submit a user's score."""
|
||||
verification_channel_id = highscores_data["verification_channel_id"]
|
||||
channel = self.bot.get_channel(verification_channel_id)
|
||||
|
||||
class CancelButton(nextcord.ui.Button):
|
||||
"""Deletes message to cancel interaction.."""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(label="Cancel", style=nextcord.ButtonStyle.red, custom_id="cancel")
|
||||
|
||||
async def callback(self, interaction: nextcord.Interaction):
|
||||
submission_objects.pop(interaction.user.id)
|
||||
await interaction.message.delete()
|
||||
|
||||
|
||||
class NextButton(nextcord.ui.Button):
|
||||
"""Defines view for next button."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
super().__init__(label="Next", style=nextcord.ButtonStyle.primary, custom_id="next")
|
||||
self._bot = bot
|
||||
|
||||
async def callback(self, interaction: nextcord.Interaction):
|
||||
# check if fields have been filled out for each state
|
||||
state: SubmissionState = submission_objects[interaction.user.id]["submission_state"]
|
||||
if (
|
||||
state == SubmissionState.CATEGORY
|
||||
and not submission_objects[interaction.user.id]["category"]
|
||||
):
|
||||
await interaction.send("Please choose a category.", ephemeral=True)
|
||||
elif (
|
||||
state == SubmissionState.SCORE and not submission_objects[interaction.user.id]["score"]
|
||||
):
|
||||
await interaction.send("Please send a score.", ephemeral=True)
|
||||
elif state == SubmissionState.PROOF and not len(interaction.message.attachments) > 0:
|
||||
await interaction.send("Please attach picture for proof.", ephemeral=True)
|
||||
else:
|
||||
state = SubmissionState(state.value + 1)
|
||||
submission_objects[interaction.user.id]["submission_state"] = state
|
||||
embed = get_submission_embed(interaction.user.id)
|
||||
await interaction.edit(embed=embed, view=SubmissionView(self._bot, interaction.user.id))
|
||||
|
||||
|
||||
class SubmitButton(nextcord.ui.Button):
|
||||
"""Defines button to submit a user's score."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
super().__init__(label="Submit", style=nextcord.ButtonStyle.green, custom_id="submit")
|
||||
self._bot = bot
|
||||
|
||||
async def callback(self, interaction: nextcord.Interaction):
|
||||
verification_channel_id = highscores_data.get_guild(
|
||||
interaction.guild_id
|
||||
).verification_channel
|
||||
channel = interaction.guild.get_channel(verification_channel_id)
|
||||
|
||||
error_response = "Registered Verification channel does not exist or was never registered. \
|
||||
Contact server admins."
|
||||
assert channel is not None, await channel.send(error_response)
|
||||
|
||||
submission_objects[interaction.user.id]["submission_state"] = SubmissionState.VERIFY
|
||||
|
||||
embed = get_submission_embed(interaction.user.id)
|
||||
|
||||
await channel.send(
|
||||
files=[await attch.to_file() for attch in interaction.message.attachments],
|
||||
view=VerificationView(),
|
||||
embed=interaction.message.embeds[0],
|
||||
embed=embed,
|
||||
content=f"Submission from {interaction.user.display_name}",
|
||||
)
|
||||
await interaction.message.edit(content=f"<@{interaction.user.id}> Submitted!", view=None)
|
||||
submission_messages.pop(interaction.user.id)
|
||||
submission_objects.pop(interaction.user.id)
|
||||
|
||||
|
||||
############ Submission Views ############
|
||||
|
||||
|
||||
class SubmissionCreateButton(nextcord.ui.View):
|
||||
"""Defines view for score submission button."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
super().__init__(timeout=None)
|
||||
self._bot = bot
|
||||
|
||||
@nextcord.ui.button(
|
||||
label="Cancel", style=nextcord.ButtonStyle.red, custom_id="cancel-submission"
|
||||
label="Submit", style=nextcord.ButtonStyle.primary, custom_id="submitcreate"
|
||||
)
|
||||
async def cancel_button(
|
||||
async def submitcreate_button(
|
||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||
): # pylint: disable=unused-argument
|
||||
"""Deletes message to cancel interaction."""
|
||||
submission_messages.pop(interaction.user.id)
|
||||
await interaction.message.delete()
|
||||
"""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
|
||||
|
||||
boss_name = highscores_message_map[interaction.guild.id][interaction.message.id]
|
||||
channel = interaction.guild.get_channel(
|
||||
highscores_data.get_guild(interaction.guild_id).submission_channel
|
||||
)
|
||||
|
||||
# a user should only have 1 submission active at once.
|
||||
# submitting with dummy message_id until message created
|
||||
# split username on pipe.
|
||||
submission_objects[interaction.user.id] = {
|
||||
"message_id": 0,
|
||||
"guild_id": interaction.guild_id,
|
||||
"submission_state": SubmissionState.CATEGORY,
|
||||
"boss_name": boss_name,
|
||||
"score": "",
|
||||
"category": "",
|
||||
"username": interaction.user.display_name.split("|")[0][
|
||||
: highscores_data.get_guild(interaction.guild_id).username_length
|
||||
],
|
||||
}
|
||||
|
||||
embed = get_submission_embed(interaction.user.id)
|
||||
|
||||
submission_message = await channel.send(
|
||||
f"<@{interaction.user.id}>",
|
||||
view=SubmissionView(
|
||||
self._bot,
|
||||
interaction.user.id,
|
||||
),
|
||||
embed=embed,
|
||||
)
|
||||
|
||||
# update the message_id once its created
|
||||
submission_objects[interaction.user.id]["message_id"] = submission_message.id
|
||||
|
||||
|
||||
class SubmissionView(nextcord.ui.View):
|
||||
"""Defines view submitting. Adjusts to all states."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
bot: commands.Bot,
|
||||
submission_user: int,
|
||||
*,
|
||||
timeout: Optional[float] = 300,
|
||||
):
|
||||
super().__init__(timeout=timeout)
|
||||
self._submission_user = submission_user
|
||||
self._bot = bot
|
||||
self._state = submission_objects[self._submission_user]["submission_state"]
|
||||
self._boss_name = submission_objects[self._submission_user]["boss_name"]
|
||||
self._guild_id = submission_objects[self._submission_user]["guild_id"]
|
||||
|
||||
# add items depending on given state
|
||||
if self._state is SubmissionState.CATEGORY:
|
||||
self.add_item(
|
||||
SubmissionDropdown(bot, category_select_options(self._guild_id, self._boss_name))
|
||||
)
|
||||
self.add_item(CancelButton())
|
||||
self.add_item(NextButton(self._bot))
|
||||
elif (
|
||||
self._state is SubmissionState.SCORE
|
||||
or self._state is SubmissionState.PROOF
|
||||
or self._state is SubmissionState.NAME
|
||||
):
|
||||
self.add_item(BackButton(self._bot))
|
||||
self.add_item(NextButton(self._bot))
|
||||
elif self._state is SubmissionState.SUBMIT:
|
||||
self.add_item(BackButton(self._bot))
|
||||
self.add_item(SubmitButton(self._bot))
|
||||
|
||||
async def interaction_check(self, interaction: nextcord.Interaction) -> bool:
|
||||
check = self._submission_user == interaction.user.id
|
||||
|
||||
if not check:
|
||||
await interaction.send("This is not your submission.", ephemeral=True)
|
||||
|
||||
return check
|
||||
|
||||
async def on_timeout(self) -> None:
|
||||
# remove user from submission objects after time out. Allows user to start new submission.
|
||||
submission_objects.pop(self._submission_user)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
"""View for verification buttons"""
|
||||
|
||||
import nextcord
|
||||
from data.score import Score, ScoreTime # pylint: disable=import-error
|
||||
|
||||
from highscores import highscores_data # pylint: disable=import-error
|
||||
from utilities.utils import submit_score # pylint: disable=import-error
|
||||
|
||||
|
||||
@@ -10,6 +13,15 @@ class VerificationView(nextcord.ui.View):
|
||||
def __init__(self):
|
||||
super().__init__(timeout=None)
|
||||
|
||||
@nextcord.ui.button(
|
||||
label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-button-submission"
|
||||
)
|
||||
async def deny_button(
|
||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||
): # pylint: disable=unused-argument
|
||||
"""Button for denying score submission."""
|
||||
await interaction.message.delete()
|
||||
|
||||
@nextcord.ui.button(
|
||||
label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-button-submission"
|
||||
)
|
||||
@@ -26,21 +38,26 @@ class VerificationView(nextcord.ui.View):
|
||||
category = field["value"]
|
||||
elif field["name"] == "Score":
|
||||
score = field["value"]
|
||||
elif field["name"] == "User":
|
||||
elif field["name"] == "User Name":
|
||||
user = field["value"]
|
||||
|
||||
try:
|
||||
await submit_score(interaction, user, boss_name, category, score)
|
||||
submission_guild = highscores_data.get_guild(interaction.guild_id)
|
||||
submission_table = submission_guild.get_table(boss_name)
|
||||
submission_category = submission_table.get_category(category)
|
||||
if submission_category.time_record:
|
||||
submission_score: ScoreTime = ScoreTime(user, float(score))
|
||||
else:
|
||||
submission_score: Score = Score(user, int(score))
|
||||
|
||||
await submit_score(
|
||||
interaction,
|
||||
submission_guild,
|
||||
submission_table,
|
||||
submission_category,
|
||||
submission_score,
|
||||
)
|
||||
await interaction.message.edit(f"Approved by <@{interaction.user.id}>.", view=None)
|
||||
except UnboundLocalError:
|
||||
await interaction.send("Instruct user to submit with all fields.")
|
||||
await interaction.message.edit(view=None)
|
||||
|
||||
@nextcord.ui.button(
|
||||
label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-button-submission"
|
||||
)
|
||||
async def deny_button(
|
||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||
): # pylint: disable=unused-argument
|
||||
"""Button for denying score submission."""
|
||||
await interaction.message.delete()
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
"""File for Category class."""
|
||||
|
||||
import json
|
||||
|
||||
from data.score import Score, ScoreTime # pylint: disable=import-error
|
||||
|
||||
|
||||
class Category:
|
||||
"""Stores a category's information and relative scores."""
|
||||
|
||||
def __init__(self, name: str) -> None:
|
||||
"""
|
||||
Default constructor for Category class. Creates empty category and populates with defaults.
|
||||
|
||||
Args:
|
||||
name (str): Category's name
|
||||
"""
|
||||
self._name: str = name
|
||||
self._ascending: bool = False
|
||||
self._time_record: bool = False
|
||||
self._scores_map: dict = {}
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""
|
||||
Returns Category class as a string for printing.
|
||||
|
||||
Returns:
|
||||
str: Category class as a string
|
||||
"""
|
||||
return self.to_str()
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, name: str, data: dict):
|
||||
"""
|
||||
Creates a Category class from the passed data.
|
||||
|
||||
Args:
|
||||
name (str): Category name
|
||||
data (dict): Rest of Category data in dictionary format
|
||||
|
||||
Returns:
|
||||
Category: Populated Category object
|
||||
"""
|
||||
category = cls(name)
|
||||
category.ascending = data["ascending"]
|
||||
category.time_record = data["time_record"]
|
||||
for user, score in data["scores"].items():
|
||||
if category.time_record:
|
||||
category.add_score(ScoreTime(user, score))
|
||||
else:
|
||||
category.add_score(Score(user, score))
|
||||
|
||||
return category
|
||||
|
||||
@property
|
||||
def ascending(self) -> bool:
|
||||
"""
|
||||
Getter for is ascending.
|
||||
|
||||
Returns:
|
||||
bool: is ascending
|
||||
"""
|
||||
return self._ascending
|
||||
|
||||
@ascending.setter
|
||||
def ascending(self, ascending: bool) -> None:
|
||||
"""
|
||||
Setter for is ascending.
|
||||
|
||||
Args:
|
||||
ascending (bool): is ascending
|
||||
"""
|
||||
self._ascending = ascending
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""
|
||||
Getter for name.
|
||||
|
||||
Returns:
|
||||
str: name
|
||||
"""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def time_record(self) -> bool:
|
||||
"""
|
||||
Getter for is time record.
|
||||
|
||||
Returns:
|
||||
bool: is time record
|
||||
"""
|
||||
return self._time_record
|
||||
|
||||
@time_record.setter
|
||||
def time_record(self, time_record: bool) -> None:
|
||||
"""
|
||||
Setter for is time record.
|
||||
|
||||
Args:
|
||||
time_record (bool): is time record
|
||||
"""
|
||||
self._time_record = time_record
|
||||
|
||||
@property
|
||||
def scores(self) -> "list[Score]":
|
||||
"""
|
||||
Getter for Scores list.
|
||||
|
||||
Returns:
|
||||
list[Score]: List of Scores in this Category
|
||||
"""
|
||||
return self._scores_map.values()
|
||||
|
||||
def add_score(self, score: Score) -> None:
|
||||
"""
|
||||
Adds score to dictionary storage map. Sorts dictionary by score value.
|
||||
|
||||
Args:
|
||||
score (Score): Score to be added
|
||||
"""
|
||||
if score.user in self._scores_map:
|
||||
self._scores_map[score.user].value = score.value
|
||||
else:
|
||||
self._scores_map[score.user] = score
|
||||
|
||||
self._scores_map = dict(
|
||||
sorted(self._scores_map.items(), key=lambda x: x[1].value, reverse=not self.ascending)
|
||||
)
|
||||
|
||||
def clear(self) -> None:
|
||||
"""
|
||||
Clears all Scores tracked in score map.
|
||||
This is a test function and shouldn't really be used.
|
||||
"""
|
||||
self._scores_map.clear()
|
||||
|
||||
def get_user_score(self, user: str) -> Score:
|
||||
"""
|
||||
Gets a user's score. Returns None if user is not found.
|
||||
|
||||
Args:
|
||||
user (str): Name of score to find
|
||||
|
||||
Returns:
|
||||
Score: User's Score or None
|
||||
"""
|
||||
if user in self._scores_map:
|
||||
return self._scores_map[user]
|
||||
return None
|
||||
|
||||
def remove_score(self, score: str) -> None:
|
||||
"""
|
||||
Removes a user's score from dictionary storage.
|
||||
|
||||
Args:
|
||||
score (str): user whose score to remove
|
||||
"""
|
||||
score = self._scores_map.pop(score)
|
||||
del score
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
"""
|
||||
Saves category data as a python dictionary.
|
||||
Does not include category name. It should be the key of above data structure.
|
||||
|
||||
Returns:
|
||||
dict: Category class in dictionary format
|
||||
"""
|
||||
data = {}
|
||||
data["ascending"] = self.ascending
|
||||
data["time_record"] = self.time_record
|
||||
data["scores"] = {}
|
||||
for score in self.scores:
|
||||
data["scores"][score.user] = score.value
|
||||
|
||||
return data
|
||||
|
||||
def to_str(self) -> str:
|
||||
"""
|
||||
Returns Category object as a string.
|
||||
|
||||
Returns:
|
||||
str: string of json representation of Category
|
||||
"""
|
||||
return json.dumps(self.to_dict(), indent=4)
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
"""File for Guild class."""
|
||||
|
||||
import json
|
||||
|
||||
from data.table import Table # pylint: disable=import-error
|
||||
|
||||
|
||||
class Guild:
|
||||
"""Stores a guild's information."""
|
||||
|
||||
def __init__(self, guild_id: int) -> None:
|
||||
"""
|
||||
Default constructor for Guild class. Initializes channel ids as 0 as they won't be
|
||||
registered yet. Sets default username length of 12. Default highscores size to 3.
|
||||
|
||||
Args:
|
||||
guild_id (int): Discord Guild id of new Guild
|
||||
"""
|
||||
self._guild_id: int = guild_id
|
||||
self._highscore_channel_id: int = 0
|
||||
self._submission_channel_id: int = 0
|
||||
self._table_map: dict = {}
|
||||
self._username_length: int = 12
|
||||
self._verification_channel_id: int = 0
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""
|
||||
Returns Guild class as a string for printing.
|
||||
|
||||
Returns:
|
||||
str: Guild class as a string
|
||||
"""
|
||||
return self.to_str()
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, guild_id: int, data: dict):
|
||||
"""
|
||||
Creates a Guild class from the passed data.
|
||||
|
||||
Args:
|
||||
guild_id (int): Guild's id
|
||||
data (dict): Rest of Guild data in dictionary format
|
||||
|
||||
Returns:
|
||||
Guild: Populated Guild object
|
||||
"""
|
||||
guild = cls(guild_id)
|
||||
guild.highscore_channel = data["highscore_channel_id"]
|
||||
guild.submission_channel = data["submission_channel_id"]
|
||||
guild.username_length = data["username_length"]
|
||||
guild.verification_channel = data["verification_channel_id"]
|
||||
|
||||
for table_name, table_data in data["tables"].items():
|
||||
table = Table.from_dict(table_name, table_data)
|
||||
guild.add_table(table)
|
||||
|
||||
return guild
|
||||
|
||||
@property
|
||||
def guild_id(self) -> int:
|
||||
"""
|
||||
Getter for Guild id
|
||||
|
||||
Returns:
|
||||
int: Guild id
|
||||
"""
|
||||
return self._guild_id
|
||||
|
||||
@property
|
||||
def highscore_channel(self) -> int:
|
||||
"""
|
||||
Getter for highscore channel id.
|
||||
|
||||
Returns:
|
||||
int: highscore channel id
|
||||
"""
|
||||
return self._highscore_channel_id
|
||||
|
||||
@highscore_channel.setter
|
||||
def highscore_channel(self, channel: int) -> None:
|
||||
"""
|
||||
Setter for highscore channel id.
|
||||
|
||||
Args:
|
||||
channel (int): highscore channel id
|
||||
"""
|
||||
self._highscore_channel_id = channel
|
||||
|
||||
@property
|
||||
def submission_channel(self) -> int:
|
||||
"""
|
||||
Getter for submission channel id.
|
||||
|
||||
Returns:
|
||||
int: submission channel id
|
||||
"""
|
||||
return self._submission_channel_id
|
||||
|
||||
@submission_channel.setter
|
||||
def submission_channel(self, channel: id) -> None:
|
||||
"""
|
||||
Setter fro submission channel id.
|
||||
|
||||
Args:
|
||||
channel (id): submission channel id
|
||||
"""
|
||||
self._submission_channel_id = channel
|
||||
|
||||
@property
|
||||
def tables(self) -> "list[Table]":
|
||||
"""
|
||||
Getter for Tables list.
|
||||
|
||||
Returns:
|
||||
list[Table]: List of Tables in this Guild
|
||||
"""
|
||||
return self._table_map.values()
|
||||
|
||||
@property
|
||||
def username_length(self) -> int:
|
||||
"""
|
||||
Getter for username length.
|
||||
|
||||
Returns:
|
||||
int: username length
|
||||
"""
|
||||
return self._username_length
|
||||
|
||||
@username_length.setter
|
||||
def username_length(self, length: int) -> None:
|
||||
"""
|
||||
Setter for username length.
|
||||
|
||||
Args:
|
||||
length (int): username length
|
||||
"""
|
||||
self._username_length = length
|
||||
|
||||
@property
|
||||
def verification_channel(self) -> int:
|
||||
"""
|
||||
Getter for verification channel id.
|
||||
|
||||
Returns:
|
||||
int: verification channel id
|
||||
"""
|
||||
return self._verification_channel_id
|
||||
|
||||
@verification_channel.setter
|
||||
def verification_channel(self, channel: int) -> None:
|
||||
"""
|
||||
Setter for verification channel id
|
||||
|
||||
Args:
|
||||
channel (int): verification channel id
|
||||
"""
|
||||
self._verification_channel_id = channel
|
||||
|
||||
def add_table(self, table: Table) -> None:
|
||||
"""
|
||||
Adds a Table to table map. Shouldn't exist already.
|
||||
|
||||
Args:
|
||||
table (Table): new Table to add
|
||||
"""
|
||||
if table.name not in self._table_map:
|
||||
self._table_map[table.name] = table
|
||||
|
||||
def get_table(self, table_name: str) -> Table:
|
||||
"""
|
||||
Getter for specific Table. Returns None if Table is not found.
|
||||
|
||||
Args:
|
||||
table_name (str): Name of Table to find
|
||||
|
||||
Returns:
|
||||
Table: Table corresponding to Name. None if not found.
|
||||
"""
|
||||
if table_name in self._table_map:
|
||||
return self._table_map[table_name]
|
||||
return None
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
"""
|
||||
Creates python dictionary object from class data.
|
||||
Does not include guild_id in dict, it should be the key of above data structure.
|
||||
|
||||
Returns:
|
||||
dict: Guild class in dictionary format
|
||||
"""
|
||||
data: dict = {}
|
||||
|
||||
data["highscore_channel_id"] = self.highscore_channel
|
||||
data["submission_channel_id"] = self.submission_channel
|
||||
data["tables"] = {}
|
||||
data["username_length"] = self.username_length
|
||||
data["verification_channel_id"] = self.verification_channel
|
||||
|
||||
for table in self.tables:
|
||||
data["tables"][table.name] = table.to_dict()
|
||||
|
||||
return data
|
||||
|
||||
def to_str(self) -> str:
|
||||
"""
|
||||
Returns Guild object as a string.
|
||||
|
||||
Returns:
|
||||
str: string of json representation of Guild
|
||||
"""
|
||||
return json.dumps(self.to_dict(), indent=4)
|
||||
@@ -0,0 +1,153 @@
|
||||
"""Class and functions for storing and retrieving highscores data."""
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
from data.guild import Guild # pylint: disable=import-error
|
||||
from data.table import Table # pylint: disable=import-error
|
||||
from data.category import Category # pylint: disable=import-error
|
||||
|
||||
|
||||
HIGHSCORES_BACKUP_DIR = "deleted_backups"
|
||||
HIGHSCORES_CONFIG_DIR = "example_config"
|
||||
HIGHSCORES_DATA_DIR = "highscores_data"
|
||||
|
||||
|
||||
class HighscoresData:
|
||||
"""Class for storing and retrieving highscores data."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""
|
||||
Default constructor for Highscores Data. Opens up known highscores data on creation.
|
||||
"""
|
||||
self._guild_map: dict = {}
|
||||
|
||||
# Ensure that data directories exist.
|
||||
if not os.path.exists(HIGHSCORES_BACKUP_DIR):
|
||||
os.mkdir(HIGHSCORES_BACKUP_DIR)
|
||||
if not os.path.exists(HIGHSCORES_DATA_DIR):
|
||||
os.mkdir(HIGHSCORES_DATA_DIR)
|
||||
self.open_highscores_data()
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""
|
||||
Returns Highscores class as a string for printing.
|
||||
Returns:
|
||||
str: Highscores class as a string
|
||||
"""
|
||||
data: dict = {}
|
||||
for guild_id, guild_obj in self._guild_map.items():
|
||||
data[guild_id] = guild_obj.to_dict()
|
||||
return "Highscores Data\n" + json.dumps(data, indent=4)
|
||||
|
||||
@property
|
||||
def guilds(self) -> "list[Guild]":
|
||||
"""
|
||||
Getter for Guilds list.
|
||||
|
||||
Returns:
|
||||
list[Guild]: List of Guilds tracked by Highscores Bot
|
||||
"""
|
||||
return self._guild_map.values()
|
||||
|
||||
def add_configuration(self, guild_id: int, config_str: str) -> None:
|
||||
"""
|
||||
Adds an example configuration to a Guild. Uses guild id to know which guild and
|
||||
config name to open a file in example_config.
|
||||
|
||||
Args:
|
||||
guild_id (int): Guild id to add config to
|
||||
config_str (str): Config name to add
|
||||
"""
|
||||
config = self._open_highscores_config(config_str)
|
||||
guild = self.get_guild(guild_id)
|
||||
|
||||
for table_name, categorys in config["tables"].items():
|
||||
table_obj = Table(table_name)
|
||||
table_obj.size = config["table_size"]
|
||||
for category_name in categorys:
|
||||
category = Category(category_name)
|
||||
category.ascending = config["categories"][category.name]["ascending"]
|
||||
category.time_record = config["categories"][category.name]["is_time_record"]
|
||||
table_obj.add_category(category)
|
||||
|
||||
guild.add_table(table_obj)
|
||||
|
||||
def add_guild(self, guild_id: int) -> None:
|
||||
"""
|
||||
Creates a new Guild and adds to Guild map.
|
||||
|
||||
Args:
|
||||
guild_id (int): Guild Id to add
|
||||
"""
|
||||
guild: Guild = Guild(guild_id)
|
||||
self._guild_map[guild_id] = guild
|
||||
|
||||
def get_guild(self, guild_id: int) -> Guild:
|
||||
"""
|
||||
Getter for Guild object that corresponds with the guild_id.
|
||||
|
||||
Args:
|
||||
guild_id (int): id of Guild to retrieve.
|
||||
|
||||
Returns:
|
||||
Guild: Guild object for guild_id
|
||||
"""
|
||||
return self._guild_map[guild_id]
|
||||
|
||||
def remove_guild(self, guild_id: int) -> None:
|
||||
"""
|
||||
Removes a guild's data from object. Saves backup.
|
||||
|
||||
Args:
|
||||
guild_id (int): guild id to remove
|
||||
"""
|
||||
self._guild_map.pop(guild_id)
|
||||
|
||||
os.rename(
|
||||
f"{HIGHSCORES_DATA_DIR}/{guild_id}.json", f"{HIGHSCORES_BACKUP_DIR}/{guild_id}.json"
|
||||
)
|
||||
|
||||
def _open_highscores_config(self, config: str) -> dict:
|
||||
"""
|
||||
Opens the highscores config file and returns in dictionary format.
|
||||
Will be replaced when config class is created.
|
||||
|
||||
Args:
|
||||
config (str): Name of config to load.
|
||||
|
||||
Returns:
|
||||
dict: dict of highscores config
|
||||
"""
|
||||
with open(f"{HIGHSCORES_CONFIG_DIR}/{config}.json", encoding="utf-8", mode="r") as file:
|
||||
return json.load(file)
|
||||
|
||||
def open_highscores_data(self):
|
||||
"""
|
||||
Opens all saved highscores data in the HIGHSCORES_DATA_DIR dir. Creates a Guild object from
|
||||
each file and adds to guild map.
|
||||
"""
|
||||
for data_file in os.listdir(HIGHSCORES_DATA_DIR):
|
||||
guild_id: int = int(data_file.split(".", maxsplit=1)[0])
|
||||
with open(f"{HIGHSCORES_DATA_DIR}/{data_file}", encoding="utf-8", mode="r") as file:
|
||||
guild_obj: Guild = Guild.from_dict(guild_id, json.load(file))
|
||||
self._guild_map[guild_obj.guild_id] = guild_obj
|
||||
|
||||
def save_all_data(self) -> None:
|
||||
"""
|
||||
Calls save_guild_data for each guild tracked in guild map.
|
||||
"""
|
||||
for guild in self.guilds:
|
||||
self.save_guild_data(guild)
|
||||
|
||||
def save_guild_data(self, guild: Guild) -> None:
|
||||
"""
|
||||
Saves a guild to its own json file.
|
||||
|
||||
Args:
|
||||
guild (Guild): Guild to save
|
||||
"""
|
||||
with open(
|
||||
f"{HIGHSCORES_DATA_DIR}/{guild.guild_id}.json", encoding="utf-8", mode="w"
|
||||
) as file:
|
||||
file.write(guild.to_str()) # should use str function
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
"""File for Score classes"""
|
||||
|
||||
import time
|
||||
|
||||
|
||||
class Score:
|
||||
"""Parent class for Scores. Stores common information for a Score."""
|
||||
|
||||
# no user setter, it should never change.
|
||||
|
||||
def __init__(self, user: str, value: int) -> None:
|
||||
"""
|
||||
Default constructor for Score class.
|
||||
|
||||
Args:
|
||||
user (str): Score's user
|
||||
value (int): Score's value
|
||||
"""
|
||||
self._user: str = user
|
||||
self._value: int = value
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""
|
||||
Returns Score class as a string for printing.
|
||||
|
||||
Returns:
|
||||
str: Score class as a string
|
||||
"""
|
||||
return self.to_str()
|
||||
|
||||
@property
|
||||
def user(self) -> str:
|
||||
"""
|
||||
Getter for score user.
|
||||
|
||||
Returns:
|
||||
str: user
|
||||
"""
|
||||
return self._user
|
||||
|
||||
@property
|
||||
def value(self) -> int:
|
||||
"""
|
||||
Getter for score value.
|
||||
|
||||
Returns:
|
||||
int: value
|
||||
"""
|
||||
return self._value
|
||||
|
||||
@value.setter
|
||||
def value(self, value: int) -> None:
|
||||
"""
|
||||
Setter for score value.
|
||||
|
||||
Args:
|
||||
value (int): score value input
|
||||
"""
|
||||
self._value = value
|
||||
|
||||
def get_str(self) -> str:
|
||||
"""
|
||||
Gets score's value as string.
|
||||
|
||||
Returns:
|
||||
str: Score's value
|
||||
"""
|
||||
return str(self._value)
|
||||
|
||||
def to_str(self) -> str:
|
||||
"""
|
||||
Returns Score object as a string.
|
||||
|
||||
Returns:
|
||||
str: string of json representation of Score
|
||||
"""
|
||||
return f"{self.user}: {self.get_str()}"
|
||||
|
||||
|
||||
class ScoreTime(Score):
|
||||
"""Class for a time based score. Inherits from Score."""
|
||||
|
||||
def __init__(self, user: str, score: float) -> None: # pylint: disable=super-init-not-called
|
||||
"""
|
||||
Default constructor for ScoreTime class.
|
||||
|
||||
Args:
|
||||
user (str): Score's user
|
||||
score (float): Score's value
|
||||
"""
|
||||
# store time score as seconds.
|
||||
self._user: str = user
|
||||
self._score: float = score
|
||||
|
||||
@property
|
||||
def value(self) -> float:
|
||||
"""
|
||||
Getter for score value.
|
||||
|
||||
Returns:
|
||||
float: value
|
||||
"""
|
||||
return self._score
|
||||
|
||||
@value.setter
|
||||
def value(self, value: float) -> None:
|
||||
"""
|
||||
Setter for score value.
|
||||
|
||||
Args:
|
||||
value (float): value
|
||||
"""
|
||||
self._score = value
|
||||
|
||||
def get_str(self) -> str:
|
||||
"""
|
||||
Gets score's value as string. Turns seconds into MM:SS.ms format.
|
||||
|
||||
Returns:
|
||||
str: value in time format.
|
||||
"""
|
||||
milliseconds = round((self.value - int(self.value)) * 10)
|
||||
return time.strftime(f"%-M:%S.{milliseconds}", time.gmtime(self.value))
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
"""File for Table class."""
|
||||
|
||||
import json
|
||||
|
||||
from data.category import Category # pylint: disable=import-error
|
||||
|
||||
|
||||
class Table:
|
||||
"""Stores a table's information a list of categories."""
|
||||
|
||||
def __init__(self, name: str) -> None:
|
||||
"""
|
||||
Default constructor for Table class.
|
||||
Creates object and fills out class variables with defaults.
|
||||
|
||||
Args:
|
||||
name (str): Table's name
|
||||
"""
|
||||
self._name: str = name
|
||||
self._message_id: int = 0
|
||||
self._categories_map: dict = {}
|
||||
self._size = 3
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""
|
||||
Returns Table class as a string for printing.
|
||||
|
||||
Returns:
|
||||
str: Table class as a string
|
||||
"""
|
||||
return self.to_str()
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, table_name: str, data: dict):
|
||||
"""
|
||||
Creates a Table class from the passed data.
|
||||
|
||||
Args:
|
||||
table_name (str): Table name
|
||||
data (dict): Rest of Table data in dictionary format
|
||||
|
||||
Returns:
|
||||
Table: Populated Table object
|
||||
"""
|
||||
table = cls(table_name)
|
||||
|
||||
table.message_id = data["message_id"]
|
||||
table.size = data["table_size"]
|
||||
|
||||
for cat_name, cat in data["categories"].items():
|
||||
category = Category.from_dict(cat_name, cat)
|
||||
table.add_category(category)
|
||||
|
||||
return table
|
||||
|
||||
@property
|
||||
def categories(self) -> "list[Category]":
|
||||
"""
|
||||
Getter for Categories list.
|
||||
|
||||
Returns:
|
||||
list[Category]: List of Categories in this Table
|
||||
"""
|
||||
return self._categories_map.values()
|
||||
|
||||
@property
|
||||
def message_id(self) -> int:
|
||||
"""
|
||||
Getter for message id
|
||||
|
||||
Returns:
|
||||
int: message id
|
||||
"""
|
||||
return self._message_id
|
||||
|
||||
@message_id.setter
|
||||
def message_id(self, m_id: int) -> None:
|
||||
"""
|
||||
Setter for message id.
|
||||
|
||||
Args:
|
||||
m_id (int): message id
|
||||
"""
|
||||
self._message_id = m_id
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""
|
||||
Getter for name.
|
||||
|
||||
Returns:
|
||||
str: name
|
||||
"""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def size(self) -> int:
|
||||
"""
|
||||
Getter for size of table.
|
||||
|
||||
Returns:
|
||||
int: Size of table
|
||||
"""
|
||||
return self._size
|
||||
|
||||
@size.setter
|
||||
def size(self, size: int) -> None:
|
||||
"""
|
||||
Setter for size of table.
|
||||
|
||||
Args:
|
||||
size (int): New size of table
|
||||
"""
|
||||
self._size = size
|
||||
|
||||
def add_category(self, category: Category) -> None:
|
||||
"""
|
||||
Adds a Category to categories map. Shouldn't exist already.
|
||||
|
||||
Args:
|
||||
category (Category): New Category to add
|
||||
"""
|
||||
if category.name not in self._categories_map:
|
||||
self._categories_map[category.name] = category
|
||||
|
||||
def get_category(self, category_name: str) -> Category:
|
||||
"""
|
||||
Getter for specific category. Returns None if not found.
|
||||
|
||||
Args:
|
||||
category_name (str): name of category to return
|
||||
|
||||
Returns:
|
||||
Category: Category corresponding to name. None if not found.
|
||||
"""
|
||||
if category_name in self._categories_map:
|
||||
return self._categories_map[category_name]
|
||||
return None
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
"""
|
||||
Saves Table as a python dictionary.
|
||||
Does not include table name. It should be the key of above data structure.
|
||||
|
||||
Returns:
|
||||
dict: Table class in dictionary format
|
||||
"""
|
||||
data = {}
|
||||
data["message_id"] = self.message_id
|
||||
data["table_size"] = self.size
|
||||
data["categories"] = {}
|
||||
for category in self.categories:
|
||||
data["categories"][category.name] = category.to_dict()
|
||||
|
||||
return data
|
||||
|
||||
def to_str(self) -> str:
|
||||
"""
|
||||
Returns Table object as a string.
|
||||
|
||||
Returns:
|
||||
str: string of json representation of Table
|
||||
"""
|
||||
return json.dumps(self.to_dict(), indent=4)
|
||||
Executable
+335
@@ -0,0 +1,335 @@
|
||||
{
|
||||
"tables": {
|
||||
"The Ambassador": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Araxxi": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Arch-Glacor": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Enrage",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Astellarn": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"The Barrows Brothers": [
|
||||
"Kill Count",
|
||||
"Spooned Log"
|
||||
],
|
||||
"The Barrows: Rise of the Six": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Beastmaster Durzag": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Black Stone Dragon": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Chaos Elemental": [
|
||||
"Kill Count",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Commander Zilyana": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Corporeal Beast": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Crassian Leviathan": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Croesus": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Dagannoth Kings": [
|
||||
"Kill Count",
|
||||
"Spooned Log"
|
||||
],
|
||||
"General Graardor": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Giant Mole": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Gregorovic": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Har-Aken": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Helwyr": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Kalphite King": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Kalphite Queen": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Kerapac": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"King Black Dragon": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Kree'arra": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"K'ril Tsutsaroth": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Legiones": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"The Magister": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Masuta the Ascended": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Nex": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Nex - Angel of Death": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Queen Black Dragon": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Raksha": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Duo Kill Count",
|
||||
"Duo Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Rex Matriarchs": [
|
||||
"Kill Count",
|
||||
"Spooned Log"
|
||||
],
|
||||
"The Sanctum Guardian": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Seiryu the Azure Serpent": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Solak": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Taraket the Necromancer": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Telos": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Enrage",
|
||||
"Spooned Log"
|
||||
],
|
||||
"The Twin Furies": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"TzKal-Zuk": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"TzTok-Jad": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Verak Lith": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Vindicta & Gorvek": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Vorago": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Yakamaru": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Zamorak, Lord of Chaos (solo)": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Enrage",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Zamorak, Lord of Chaos (group)": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Enrage"
|
||||
]
|
||||
},
|
||||
"categories": {
|
||||
"Duo Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Duo Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Enrage": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Group Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Group Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Hardmode Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Hardmode Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Solo Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Solo Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"table_size": 3
|
||||
}
|
||||
@@ -1,844 +0,0 @@
|
||||
{
|
||||
"highscore_table": {
|
||||
"The Ambassador": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Group Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Group Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Araxxi": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Arch-Glacor": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Hardmode Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Hardmode Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Enrage": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Astellarn": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Group Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Group Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"The Barrows Brothers": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"The Barrows: Rise of the Six": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Beastmaster Durzag": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Black Stone Dragon": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Group Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Group Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Chaos Elemental": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Commander Zilyana": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Hardmode Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Hardmode Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Corporeal Beast": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Crassian Leviathan": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Group Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Group Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Croesus": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Dagannoth Kings": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"General Graardor": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Hardmode Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Hardmode Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Giant Mole": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Hardmode Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Hardmode Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Gregorovic": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Hardmode Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Hardmode Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Har-Aken": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Helwyr": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Hardmode Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Hardmode Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Kalphite King": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Kalphite Queen": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Kerapac": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Hardmode Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Hardmode Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"King Black Dragon": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Kree'arra": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Hardmode Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Hardmode Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"K'ril Tsutsaroth": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Hardmode Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Hardmode Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Legiones": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"The Magister": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Masuta the Ascended": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Group Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Group Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Nex": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Nex - Angel of Death": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Queen Black Dragon": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Raksha": {
|
||||
"Solo Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Solo Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Duo Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Duo Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Rex Matriarchs": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"The Sanctum Guardian": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Group Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Group Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Seiryu the Azure Serpent": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Group Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Group Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Solak": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Taraket the Necromancer": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Group Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Group Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Telos": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Enrage": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"The Twin Furies": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Hardmode Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Hardmode Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"TzKal-Zuk": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Hardmode Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Hardmode Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"TzTok-Jad": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Verak Lith": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Group Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Group Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Vindicta & Gorvek": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Hardmode Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Hardmode Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Vorago": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Hardmode Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Hardmode Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Yakamaru": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"Zamorak, Lord of Chaos (solo)": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Enrage": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
}
|
||||
,
|
||||
"Zamorak, Lord of Chaos (group)": {
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Enrage": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"highscore_size": 3
|
||||
}
|
||||
+15
-14
@@ -4,14 +4,13 @@ main file for pvm-highscores bot
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
|
||||
import config
|
||||
from utilities.data_storage import open_highscores_config
|
||||
from utilities.data_storage import open_highscores_data
|
||||
from utilities.data_storage import open_message_map
|
||||
from data.highscores_data import HighscoresData
|
||||
|
||||
logger = logging.getLogger("nextcord")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
@@ -20,22 +19,30 @@ handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(me
|
||||
logger.addHandler(handler)
|
||||
|
||||
|
||||
highscores_config = open_highscores_config()
|
||||
highscores_data = open_highscores_data()
|
||||
highscores_message_map = open_message_map()
|
||||
highscores_data: HighscoresData = HighscoresData()
|
||||
highscores_message_map = {}
|
||||
|
||||
submission_messages: dict = {}
|
||||
for guild in highscores_data.guilds:
|
||||
highscores_message_map[guild.guild_id] = {}
|
||||
for table in guild.tables:
|
||||
highscores_message_map[guild.guild_id][table.message_id] = table.name
|
||||
|
||||
submission_objects: dict = {}
|
||||
|
||||
|
||||
def main():
|
||||
"""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
|
||||
# These need to be enabled in the developer portal as well
|
||||
intents = nextcord.Intents.default()
|
||||
|
||||
# Required in order to read messages (eg. prefix commands)
|
||||
intents.message_content = True # pylint: disable=assigning-non-slot
|
||||
intents.messages = True # pylint: disable=assigning-non-slot
|
||||
|
||||
# To enable the guilds priveleged intent:
|
||||
# intents.guilds = True
|
||||
@@ -43,15 +50,9 @@ def main():
|
||||
# To enable the members priveleged intent:
|
||||
# intents.members = True
|
||||
|
||||
# Set custom status to "Listening to ?help"
|
||||
activity = nextcord.Activity(
|
||||
type=nextcord.ActivityType.listening, name=f"{config.BOT_PREFIX}help"
|
||||
)
|
||||
|
||||
bot = commands.Bot(
|
||||
commands.when_mentioned_or(config.BOT_PREFIX),
|
||||
intents=intents,
|
||||
activity=activity,
|
||||
)
|
||||
|
||||
# Get the modules of all cogs whose directory structure is ./cogs/<module_name>
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
"""Functions for retreiving and storing highscores data and configurations."""
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
HIGHSCORES_CONFIG_FILE = "highscores_config.json"
|
||||
HIGHSCORES_DATA_FILE = "highscores_data.json"
|
||||
HIGHSCORES_MESSAGE_MAP_FILE = "highscores_message_map.json"
|
||||
|
||||
|
||||
def open_highscores_config():
|
||||
"""
|
||||
Opens the highscores config file and returns.
|
||||
@return: dict of highscores config.
|
||||
"""
|
||||
# Load bot config
|
||||
with open(HIGHSCORES_CONFIG_FILE, encoding="utf-8", mode="r") as file:
|
||||
return json.load(file)
|
||||
|
||||
|
||||
def open_highscores_data():
|
||||
"""
|
||||
Opens a highscores_data.json file if one exists, otherwise creates a skeleton of the data.
|
||||
@return: dict of highscores 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
|
||||
data = {"highscore_channel_id": -1, "verification_channel_id": -1}
|
||||
config: dict = open_highscores_config()
|
||||
for boss, categories in config["highscore_table"].items():
|
||||
data[boss] = {"message_id": 0}
|
||||
boss_categories = {}
|
||||
for category, category_config in categories.items(): # pylint: disable=unused-variable
|
||||
rank_list = []
|
||||
boss_categories[category] = rank_list
|
||||
data[boss]["categories"] = boss_categories
|
||||
return data
|
||||
|
||||
|
||||
def open_message_map():
|
||||
"""
|
||||
Opens a highscore_message_map.json file if one exists. Otherwise returns empty dict.
|
||||
@return: dict message_map of message to boss.
|
||||
"""
|
||||
if os.path.exists(HIGHSCORES_MESSAGE_MAP_FILE):
|
||||
with open(HIGHSCORES_MESSAGE_MAP_FILE, encoding="utf-8", mode="r") as file:
|
||||
message_map = json.load(file)
|
||||
else:
|
||||
# create the json object
|
||||
message_map = {}
|
||||
return message_map
|
||||
|
||||
|
||||
def save_highscores_data(data):
|
||||
"""
|
||||
Saves the highscores data dict into a json file.
|
||||
@param data: dict of highscores data.
|
||||
"""
|
||||
with open(HIGHSCORES_DATA_FILE, encoding="utf-8", mode="w") as file:
|
||||
file.write(json.dumps(data, indent=4))
|
||||
|
||||
|
||||
def save_message_map(message_map):
|
||||
"""
|
||||
Saves the highscores message mao data dict into a json file.
|
||||
@param map: dict map of message to boss.
|
||||
"""
|
||||
with open(HIGHSCORES_MESSAGE_MAP_FILE, encoding="utf-8", mode="w") as file:
|
||||
file.write(json.dumps(message_map, indent=4))
|
||||
+80
-108
@@ -3,52 +3,78 @@ Contains various utlity functions for highscores bot
|
||||
"""
|
||||
|
||||
import nextcord
|
||||
from highscores import highscores_config # pylint: disable=import-error
|
||||
from highscores import highscores_data # pylint: disable=import-error
|
||||
from highscores import highscores_message_map # pylint: disable=import-error
|
||||
from utilities.data_storage import save_highscores_data # pylint: disable=import-error
|
||||
from utilities.data_storage import save_message_map # pylint: disable=import-error
|
||||
from highscores import highscores_data, highscores_message_map # pylint: disable=import-error
|
||||
from data.score import Score # pylint: disable=import-error
|
||||
from data.guild import Guild # pylint: disable=import-error
|
||||
from data.category import Category # pylint: disable=import-error
|
||||
from data.table import Table # pylint: disable=import-error
|
||||
|
||||
|
||||
def format_highscore_message(boss_name: str):
|
||||
def format_highscore_message(guild: Guild, table: Table) -> str:
|
||||
"""
|
||||
returns a formatted string for a boss's highscore
|
||||
@param boss: the dictionary object for the boss
|
||||
@return the formatted string
|
||||
Creates a formatted string for a boss's highscore discord message.
|
||||
This formatted string is in discord's code block to ensure monospace text.
|
||||
Loops through each category to build the message one place at a time.
|
||||
|
||||
Args:
|
||||
guild (Guild): Guild object that is posting the message.
|
||||
table (Table): Table object that contains the contents of the message.
|
||||
|
||||
Returns:
|
||||
str: Formatted string for discord message
|
||||
"""
|
||||
ret_string = f"**{boss_name}**\n```"
|
||||
boss_data = highscores_data[boss_name]
|
||||
ret_string = f"**{table.name}**\n```"
|
||||
|
||||
# Gather all categories and add to string
|
||||
for key, value in boss_data["categories"].items():
|
||||
ret_string += f"{key}".ljust(25, " ")
|
||||
for category in table.categories:
|
||||
ret_string += f"{category.name}".ljust(26, " ")
|
||||
ret_string += "\n"
|
||||
|
||||
highscore_size = highscores_config["highscore_size"]
|
||||
|
||||
# list rankings in a single line. Start with first place for each category and then continue
|
||||
for i in range(highscore_size):
|
||||
for key, value in boss_data["categories"].items():
|
||||
if len(value) > i:
|
||||
score = value[i]
|
||||
ret_string += f"{i+1}: {score[0]} - {score[1]}".ljust(25, " ")
|
||||
for i in range(table.size):
|
||||
for category in table.categories:
|
||||
if len(category.scores) > i:
|
||||
# pad username to max length.
|
||||
# have to convert category.scores into list to make it subscriptable. no idea why.
|
||||
username: str = list(category.scores)[i].user.ljust(guild.username_length, " ")
|
||||
|
||||
score: str = list(category.scores)[i].get_str()
|
||||
|
||||
# pad score to correct length
|
||||
# MM:SS.ms is 7 characters long
|
||||
if category.time_record:
|
||||
# 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, " ")
|
||||
|
||||
ret_string += f"{i+1}: {username} - {score}".ljust(26, " ")
|
||||
else:
|
||||
ret_string += f"{i+1}: submit your score".ljust(25, " ")
|
||||
ret_string += f"{i+1}: submit your score".ljust(26, " ")
|
||||
ret_string += "\n"
|
||||
|
||||
return ret_string + "```"
|
||||
|
||||
|
||||
async def send_highscore_message(channel, boss_name: str) -> nextcord.Message:
|
||||
async def send_highscore_message(
|
||||
channel: nextcord.TextChannel, guild: Guild, table: Table
|
||||
) -> nextcord.Message:
|
||||
"""
|
||||
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_name)
|
||||
Function takes care of checking if a message exists for a table.
|
||||
Creates and sends/edits the message.
|
||||
|
||||
message_id = highscores_data[boss_name]["message_id"]
|
||||
Args:
|
||||
channel (nextcord.TextChannel): Discord channel object where message is sent
|
||||
guild (Guild): Guild object for Guild that is posting the message
|
||||
table (Table): Table to post to the message
|
||||
|
||||
Returns:
|
||||
nextcord.Message: Message object that was posted with table contents
|
||||
"""
|
||||
highscore_string = format_highscore_message(guild, table)
|
||||
|
||||
message_id = table.message_id
|
||||
try:
|
||||
message: nextcord.Message = await channel.fetch_message(message_id)
|
||||
await message.edit(content=highscore_string)
|
||||
@@ -56,96 +82,42 @@ async def send_highscore_message(channel, boss_name: str) -> nextcord.Message:
|
||||
# message doesn't exist.
|
||||
message: nextcord.Message = await channel.send(highscore_string)
|
||||
message_id = message.id
|
||||
highscores_data[boss_name]["message_id"] = message_id
|
||||
table.message_id = message_id
|
||||
# save message -> boss_name in message_map
|
||||
highscores_message_map[str(message_id)] = boss_name
|
||||
save_message_map(highscores_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 channel.guild.id in highscores_message_map:
|
||||
highscores_message_map[channel.guild.id] = {}
|
||||
highscores_message_map[channel.guild.id][message_id] = table.name
|
||||
|
||||
return message
|
||||
|
||||
|
||||
async def submit_score(
|
||||
interaction: nextcord.Interaction, user: str, boss_name: str, category: str, score: str
|
||||
):
|
||||
interaction: nextcord.Interaction, guild: Guild, table: Table, category: Category, score: Score
|
||||
) -> None:
|
||||
"""
|
||||
Adds a score to the high scores and sorts. Removes a score if larger than size limit.
|
||||
@param boss: the boss to add score to
|
||||
@param category: the category to add score to
|
||||
@param user: user who submitted score
|
||||
@param score: score to add
|
||||
Adds passed score to table. Then updates table message by calling send_highscore_message.
|
||||
Ensures that a highscores channel exists.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that caused the score submission
|
||||
guild (Guild): Guild to submit score to
|
||||
table (Table): Table to submit score to
|
||||
category (Category): Category to submit score to
|
||||
score (Score): Score to submit
|
||||
"""
|
||||
|
||||
boss_category_config = highscores_config["highscore_table"][boss_name][category]
|
||||
|
||||
# capping to 12 characters because runescape names are 12 characters long.
|
||||
# Splitting on pipe. My discord has multiple names on account split by pipe.
|
||||
user = user.split("|")[0][:12]
|
||||
|
||||
# strip leading zeros and colon from score
|
||||
score = score.lstrip("0:")
|
||||
|
||||
# create score tuple for either time or int
|
||||
# define sort index
|
||||
if boss_category_config["is_time_record"]:
|
||||
if score.find(":") == -1:
|
||||
score_seconds = float(score)
|
||||
else:
|
||||
minutes = score.split(":")[0]
|
||||
seconds = score.split(":")[1]
|
||||
score_seconds = int(minutes) * 60 + float(seconds)
|
||||
score_tuple = (user, score, score_seconds)
|
||||
sort_index = 2
|
||||
|
||||
else:
|
||||
score_tuple = (user, int(score))
|
||||
sort_index = 1
|
||||
|
||||
scores: "list[tuple]" = highscores_data[boss_name]["categories"][category]
|
||||
|
||||
# if user is in an existing tuple, delete it.
|
||||
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
|
||||
users_scores.sort(
|
||||
key=lambda x: x[sort_index],
|
||||
reverse=not boss_category_config["ascending"],
|
||||
)
|
||||
|
||||
for index, tup in enumerate(users_scores):
|
||||
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 boss_category_config["ascending"],
|
||||
)
|
||||
|
||||
# enforce highscore size
|
||||
while len(scores) > highscores_config["highscore_size"]:
|
||||
scores.pop()
|
||||
highscores_data[boss_name]["categories"][category] = scores
|
||||
category.add_score(score)
|
||||
highscores_data.save_guild_data(guild)
|
||||
|
||||
# edit message
|
||||
highscore_channel_id = highscores_data["highscore_channel_id"]
|
||||
print(f"Editting message {highscore_channel_id}")
|
||||
channel = interaction.guild.get_channel(highscore_channel_id)
|
||||
print(f"Editting message {guild.highscore_channel}")
|
||||
channel = interaction.guild.get_channel(guild.highscore_channel)
|
||||
|
||||
error_response = 'Registered Highscores channel does not exist or was never registered. \
|
||||
Register with "?register" command.'
|
||||
error_response = "Registered Highscores channel does not exist or was never registered."
|
||||
error_response += 'Register with "?register" command.'
|
||||
assert channel is not None, await interaction.send(error_response, ephemeral=True)
|
||||
|
||||
await send_highscore_message(channel, boss_name)
|
||||
|
||||
# save data
|
||||
save_highscores_data(highscores_data)
|
||||
await send_highscore_message(channel, guild, table)
|
||||
|
||||
Reference in New Issue
Block a user