Small rewrite to consolidate autofill_user function. Sort imports in message_management.py.
This commit is contained in:
@@ -4,12 +4,12 @@ Commands for managing/displaying the highscores messages.
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from nextcord.ext import commands
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
|
||||
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, autofill_tables # pylint: disable=import-error
|
||||
from utilities.utils import autofill_tables, send_highscore_message # pylint: disable=import-error
|
||||
|
||||
|
||||
class MessageManagementCog(commands.Cog, name="Message Management"):
|
||||
@@ -40,17 +40,13 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
||||
"""
|
||||
guild = highscores_data.get_guild(interaction.guild_id)
|
||||
|
||||
highscores_channel: nextcord.TextChannel = interaction.guild.get_channel(
|
||||
guild.highscore_channel
|
||||
)
|
||||
highscores_channel: nextcord.TextChannel = interaction.guild.get_channel(guild.highscore_channel)
|
||||
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
|
||||
for table in guild.tables:
|
||||
try:
|
||||
table_message: nextcord.Message = await highscores_channel.fetch_message(
|
||||
table.message_id
|
||||
)
|
||||
table_message: nextcord.Message = await highscores_channel.fetch_message(table.message_id)
|
||||
await table_message.delete()
|
||||
except nextcord.NotFound:
|
||||
# silently ignore that messages are not found. They got deleted already.
|
||||
@@ -85,9 +81,9 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
||||
# Error checking for tables existing
|
||||
# TODO fill out response string once functionality created.
|
||||
error_response = "No tables have been created for this guild. Please create some tables."
|
||||
assert (
|
||||
len(highscores_data.get_guild(interaction.guild_id).tables) > 0
|
||||
), await interaction.send(error_response, ephemeral=True)
|
||||
assert len(highscores_data.get_guild(interaction.guild_id).tables) > 0, await interaction.send(
|
||||
error_response, ephemeral=True
|
||||
)
|
||||
|
||||
# awaiting response because posting scores takes a while
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
@@ -109,9 +105,7 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
||||
async def refresh_table(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
table_name: Optional[str] = nextcord.SlashOption(
|
||||
description="Name of table.", required=True
|
||||
),
|
||||
table_name: Optional[str] = nextcord.SlashOption(description="Name of table.", required=True),
|
||||
) -> None:
|
||||
"""
|
||||
Refreshes a table given by user.
|
||||
@@ -140,6 +134,4 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
||||
table (str): String to run autocomplete compared to.
|
||||
"""
|
||||
|
||||
await interaction.response.send_autocomplete(
|
||||
autofill_tables(interaction.guild_id, table_name)
|
||||
)
|
||||
await interaction.response.send_autocomplete(autofill_tables(interaction.guild_id, table_name))
|
||||
|
||||
Reference in New Issue
Block a user