Changed send_highscore_message to take guild rather than channel.
This commit is contained in:
@@ -120,7 +120,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GroupId.in_(group_ids))
|
||||
|
||||
for group in session.scalars(stmt):
|
||||
await send_highscore_message(session, interaction.guild.get_channel(group.ChannelId), group)
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
|
||||
await interaction.send(f'User "{user_name}" was removed from all tables.', ephemeral=True)
|
||||
|
||||
@@ -163,7 +163,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
session.delete(session.scalar(stmt))
|
||||
session.commit()
|
||||
|
||||
await send_highscore_message(session, interaction.guild.get_channel(group.ChannelId), group)
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
await interaction.response.send_message(
|
||||
f'User "{user_name}" removed from "{category_name}".', ephemeral=True
|
||||
)
|
||||
@@ -194,7 +194,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
session.delete(score)
|
||||
session.commit()
|
||||
|
||||
await send_highscore_message(session, interaction.guild.get_channel(group.ChannelId), group)
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
await interaction.response.send_message(
|
||||
f'User "{user_name}" removed from all categories in {group.GroupName}.', ephemeral=True
|
||||
)
|
||||
|
||||
@@ -55,9 +55,7 @@ class RefreshCog(commands.Cog, name="Refresh Cog"):
|
||||
)
|
||||
group = session.scalar(stmt)
|
||||
|
||||
channel = interaction.guild.get_channel(group.ChannelId)
|
||||
|
||||
message: nextcord.Message = await send_highscore_message(session, channel, group)
|
||||
message: nextcord.Message = await send_highscore_message(session, interaction.guild, group)
|
||||
await message.edit(view=SubmissionCreateButton(self._bot))
|
||||
|
||||
await interaction.response.send_message(f"Updated table {group.GroupName}!", ephemeral=True)
|
||||
@@ -88,14 +86,7 @@ class RefreshCog(commands.Cog, name="Refresh Cog"):
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
|
||||
for group in session.scalars(stmt):
|
||||
channel = interaction.guild.get_channel(group.ChannelId)
|
||||
|
||||
# Error checking for registered highscore channel
|
||||
error_response = "Registered Highscores channel does not exist or was never registered. "
|
||||
error_response += 'Use "/register" to register channels.'
|
||||
assert channel is not None, await interaction.response(error_response, ephemeral=True)
|
||||
|
||||
message: nextcord.Message = await send_highscore_message(session, channel, group)
|
||||
message: nextcord.Message = await send_highscore_message(session, interaction.guild, group)
|
||||
await message.edit(view=SubmissionCreateButton(self._bot))
|
||||
|
||||
await interaction.send(f"Posted all groups in {interaction.guild.name}'s highscores.", ephemeral=True)
|
||||
|
||||
@@ -63,7 +63,7 @@ class UpdateUsernameVerifyView(nextcord.ui.View):
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GroupId.in_(group_ids))
|
||||
|
||||
for group in session.scalars(stmt):
|
||||
await send_highscore_message(session, interaction.guild.get_channel(group.ChannelId), group)
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
|
||||
content = interaction.message.content
|
||||
content += f"\nApproved by <@{interaction.user.id}>."
|
||||
|
||||
+6
-14
@@ -298,23 +298,22 @@ def get_time_str(time_in: float) -> str:
|
||||
return time.strftime(f"%-M:%S.{milliseconds}", time.gmtime(time_in))
|
||||
|
||||
|
||||
async def send_highscore_message(
|
||||
session: Session, channel: nextcord.TextChannel, group: CategoryGroup
|
||||
) -> nextcord.Message:
|
||||
async def send_highscore_message(session: Session, guild: nextcord.Guild, group: CategoryGroup) -> nextcord.Message:
|
||||
"""
|
||||
Function takes care of checking if a message exists for a group.
|
||||
Creates and sends/edits the message.
|
||||
|
||||
Args:
|
||||
session (Session): The sqlalchemy session being used for this function call.
|
||||
channel (nextcord.TextChannel): Discord channel object where message is sent
|
||||
group (CategoryGroup): group to post to the message
|
||||
guild (nextcord.Guild): the nextcord.Guild object requesting this message.
|
||||
group (CategoryGroup): group to post to the message.
|
||||
|
||||
Returns:
|
||||
nextcord.Message: Message object that was posted with group contents
|
||||
nextcord.Message: Message object that was posted with group contents.
|
||||
"""
|
||||
|
||||
highscore_string = format_highscore_message(session, group)
|
||||
channel = guild.get_channel(group.ChannelId)
|
||||
|
||||
try:
|
||||
message: nextcord.Message = await channel.fetch_message(group.MessageId)
|
||||
@@ -367,14 +366,7 @@ async def submit_score(
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == group_id)
|
||||
group = session.scalar(stmt)
|
||||
|
||||
# edit message
|
||||
channel = interaction.guild.get_channel(group.ChannelId)
|
||||
|
||||
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(session, channel, group)
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
|
||||
|
||||
def add_preset_configuration(guild_id: int, config_str: str) -> None:
|
||||
|
||||
Reference in New Issue
Block a user