48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
"""
|
|
Bot command to post the highscores
|
|
"""
|
|
|
|
from nextcord.ext import commands
|
|
import nextcord
|
|
|
|
from cogs.submission.submission_views import SubmissionCreateButton # pylint: disable=import-error
|
|
from highscores import highscores_data # pylint: disable=import-error
|
|
from utilities.utils import send_highscore_message # pylint: disable=import-error
|
|
|
|
|
|
class PostHighscores(commands.Cog, name="Post Highscores"):
|
|
"""Posts Highscores."""
|
|
|
|
def __init__(self, bot: commands.Bot):
|
|
self.bot = bot
|
|
|
|
@commands.command(name="post-scores")
|
|
@commands.has_permissions(administrator=True)
|
|
async def post_highscores(self, ctx: commands.Context):
|
|
"""
|
|
A command which posts the highscore in the designated channel.
|
|
Sends warning if no channel has been registered.
|
|
Usage:
|
|
```
|
|
?post-scores
|
|
```
|
|
"""
|
|
highscore_channel_id = highscores_data.get_guild_highscores_channel(ctx.guild.id)
|
|
print(f"Printing out highscores information in channel {highscore_channel_id}")
|
|
channel = ctx.guild.get_channel(highscore_channel_id)
|
|
|
|
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 table in highscores_data.get_table_names(ctx.guild.id):
|
|
message: nextcord.Message = await send_highscore_message(channel, table, ctx.guild.id)
|
|
await message.edit(view=SubmissionCreateButton(self.bot))
|
|
|
|
|
|
# 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(PostHighscores(bot))
|