Get table names from data. Update post scores to use HighscoresData class.
This commit is contained in:
@@ -6,9 +6,7 @@ from nextcord.ext import commands
|
|||||||
import nextcord
|
import nextcord
|
||||||
|
|
||||||
from cogs.submission.submission_views import SubmissionCreateButton # pylint: disable=import-error
|
from cogs.submission.submission_views import SubmissionCreateButton # pylint: disable=import-error
|
||||||
from highscores import highscores_config # pylint: disable=import-error
|
|
||||||
from highscores import highscores_data # 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
|
from utilities.utils import send_highscore_message # pylint: disable=import-error
|
||||||
|
|
||||||
|
|
||||||
@@ -29,24 +27,18 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
|
|||||||
?post-scores
|
?post-scores
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
guild_data = highscores_data[str(ctx.guild.id)]
|
highscore_channel_id = highscores_data.get_guild_channel_id(ctx.guild.id)
|
||||||
highscore_channel_id = guild_data["highscore_channel_id"]
|
|
||||||
print(f"Printing out highscores information in channel {highscore_channel_id}")
|
print(f"Printing out highscores information in channel {highscore_channel_id}")
|
||||||
channel = ctx.guild.get_channel(highscore_channel_id)
|
channel = ctx.guild.get_channel(highscore_channel_id)
|
||||||
|
|
||||||
error_response = 'Registered Highscores channel does not exist or was never registered. \n\
|
error_response = "Registered Highscores channel does not exist or was never registered. "
|
||||||
Register with "?register" command.'
|
error_response += 'Register with "?register" command.'
|
||||||
assert channel is not None, await ctx.send(error_response)
|
assert channel is not None, await ctx.send(error_response)
|
||||||
|
|
||||||
for boss, categories in highscores_config[ # pylint: disable=unused-variable
|
for table in highscores_data.get_table_names(ctx.guild.id):
|
||||||
"tables"
|
message: nextcord.Message = await send_highscore_message(channel, table, ctx.guild.id)
|
||||||
].items():
|
|
||||||
message: nextcord.Message = await send_highscore_message(channel, boss, guild_data)
|
|
||||||
await message.edit(view=SubmissionCreateButton(self.bot))
|
await message.edit(view=SubmissionCreateButton(self.bot))
|
||||||
|
|
||||||
# Saving in case new message was sent.
|
|
||||||
save_highscores_data(highscores_data)
|
|
||||||
|
|
||||||
|
|
||||||
# This function will be called when this extension is loaded.
|
# This function will be called when this extension is loaded.
|
||||||
# It is necessary to add these functions to the bot.
|
# It is necessary to add these functions to the bot.
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ class HighscoresData:
|
|||||||
@param table: table to get category data from
|
@param table: table to get category data from
|
||||||
@returns: list of tuples containing all category and relative score data.
|
@returns: list of tuples containing all category and relative score data.
|
||||||
"""
|
"""
|
||||||
return self._data[str(guild_id)][table]["categories"].items()
|
return self._data[str(guild_id)]["tables"][table]["categories"].items()
|
||||||
|
|
||||||
def get_config_highscore_size(self) -> int:
|
def get_config_highscore_size(self) -> int:
|
||||||
"""
|
"""
|
||||||
@@ -149,6 +149,22 @@ class HighscoresData:
|
|||||||
"""
|
"""
|
||||||
return self._data[str(guild_id)]["tables"][table]["message_id"]
|
return self._data[str(guild_id)]["tables"][table]["message_id"]
|
||||||
|
|
||||||
|
def get_table_names(self, guild_id) -> "list[str]":
|
||||||
|
"""
|
||||||
|
Returns a list of table names.
|
||||||
|
|
||||||
|
@param guild_id: guild id to retrieve from.
|
||||||
|
@returns: list of table names
|
||||||
|
"""
|
||||||
|
tables: "list[str]" = []
|
||||||
|
|
||||||
|
for table, data in self._data[str(guild_id)][ # pylint: disable=unused-variable
|
||||||
|
"tables"
|
||||||
|
].items():
|
||||||
|
tables.append(table)
|
||||||
|
|
||||||
|
return tables
|
||||||
|
|
||||||
def remove_guild(self, guild_id: int, guild_name: str) -> None:
|
def remove_guild(self, guild_id: int, guild_name: str) -> None:
|
||||||
"""
|
"""
|
||||||
Removes a guild's data from object. Saves backup.
|
Removes a guild's data from object. Saves backup.
|
||||||
|
|||||||
Reference in New Issue
Block a user