Small rewrite to consolidate autofill_user function. Sort imports in message_management.py.

This commit is contained in:
alwayscompiling
2022-11-22 17:02:18 -05:00
parent a0c5527bf6
commit 03c7a9303a
2 changed files with 28 additions and 28 deletions
+9 -17
View File
@@ -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))