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))
|
stmt = select(CategoryGroup).where(CategoryGroup.GroupId.in_(group_ids))
|
||||||
|
|
||||||
for group in session.scalars(stmt):
|
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)
|
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.delete(session.scalar(stmt))
|
||||||
session.commit()
|
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(
|
await interaction.response.send_message(
|
||||||
f'User "{user_name}" removed from "{category_name}".', ephemeral=True
|
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.delete(score)
|
||||||
session.commit()
|
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(
|
await interaction.response.send_message(
|
||||||
f'User "{user_name}" removed from all categories in {group.GroupName}.', ephemeral=True
|
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)
|
group = session.scalar(stmt)
|
||||||
|
|
||||||
channel = interaction.guild.get_channel(group.ChannelId)
|
message: nextcord.Message = await send_highscore_message(session, interaction.guild, group)
|
||||||
|
|
||||||
message: nextcord.Message = await send_highscore_message(session, channel, group)
|
|
||||||
await message.edit(view=SubmissionCreateButton(self._bot))
|
await message.edit(view=SubmissionCreateButton(self._bot))
|
||||||
|
|
||||||
await interaction.response.send_message(f"Updated table {group.GroupName}!", ephemeral=True)
|
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)
|
await interaction.response.defer(ephemeral=True)
|
||||||
|
|
||||||
for group in session.scalars(stmt):
|
for group in session.scalars(stmt):
|
||||||
channel = interaction.guild.get_channel(group.ChannelId)
|
message: nextcord.Message = await send_highscore_message(session, interaction.guild, group)
|
||||||
|
|
||||||
# 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)
|
|
||||||
await message.edit(view=SubmissionCreateButton(self._bot))
|
await message.edit(view=SubmissionCreateButton(self._bot))
|
||||||
|
|
||||||
await interaction.send(f"Posted all groups in {interaction.guild.name}'s highscores.", ephemeral=True)
|
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))
|
stmt = select(CategoryGroup).where(CategoryGroup.GroupId.in_(group_ids))
|
||||||
|
|
||||||
for group in session.scalars(stmt):
|
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 = interaction.message.content
|
||||||
content += f"\nApproved by <@{interaction.user.id}>."
|
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))
|
return time.strftime(f"%-M:%S.{milliseconds}", time.gmtime(time_in))
|
||||||
|
|
||||||
|
|
||||||
async def send_highscore_message(
|
async def send_highscore_message(session: Session, guild: nextcord.Guild, group: CategoryGroup) -> nextcord.Message:
|
||||||
session: Session, channel: nextcord.TextChannel, group: CategoryGroup
|
|
||||||
) -> nextcord.Message:
|
|
||||||
"""
|
"""
|
||||||
Function takes care of checking if a message exists for a group.
|
Function takes care of checking if a message exists for a group.
|
||||||
Creates and sends/edits the message.
|
Creates and sends/edits the message.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
session (Session): The sqlalchemy session being used for this function call.
|
session (Session): The sqlalchemy session being used for this function call.
|
||||||
channel (nextcord.TextChannel): Discord channel object where message is sent
|
guild (nextcord.Guild): the nextcord.Guild object requesting this message.
|
||||||
group (CategoryGroup): group to post to the message
|
group (CategoryGroup): group to post to the message.
|
||||||
|
|
||||||
Returns:
|
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)
|
highscore_string = format_highscore_message(session, group)
|
||||||
|
channel = guild.get_channel(group.ChannelId)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
message: nextcord.Message = await channel.fetch_message(group.MessageId)
|
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)
|
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == group_id)
|
||||||
group = session.scalar(stmt)
|
group = session.scalar(stmt)
|
||||||
|
|
||||||
# edit message
|
await send_highscore_message(session, interaction.guild, group)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
def add_preset_configuration(guild_id: int, config_str: str) -> None:
|
def add_preset_configuration(guild_id: int, config_str: str) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user