Squashed commit of the following:
commit3627419e12Merge:2db744d3446ce9Author: alwayscompiling <[email protected]> Date: Tue Dec 6 22:36:51 2022 -0500 Merge branch '45-sql-connection-timing-out' into develop commit3446ce9ca2Author: alwayscompiling <[email protected]> Date: Tue Dec 6 22:27:05 2022 -0500 Change session usage to on use basis. commit2db744d170Author: alwayscompiling <[email protected]> Date: Sun Dec 4 21:44:54 2022 -0500 Add restart policy. commitfa33be1b4aAuthor: alwayscompiling <[email protected]> Date: Sun Dec 4 21:25:57 2022 -0500 Renamed docker compose file.
This commit is contained in:
@@ -7,10 +7,11 @@ from typing import Optional
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
# pylint: disable=import-error
|
||||
from cogs.submission.submission_views import SubmissionCreateButton
|
||||
from utilities.sql_alchemy_connection import CategoryGroup, session
|
||||
from utilities.sql_data_classes import CategoryGroup, engine
|
||||
from utilities.utils import autofill_groups, send_highscore_message
|
||||
|
||||
|
||||
@@ -55,23 +56,24 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
||||
if not channel:
|
||||
channel = interaction.channel
|
||||
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
.where(CategoryGroup.ChannelId == channel.id)
|
||||
)
|
||||
# TODO test when nothing in channel
|
||||
groups = session.scalars(stmt)
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
.where(CategoryGroup.ChannelId == channel.id)
|
||||
)
|
||||
# TODO test when nothing in channel
|
||||
groups = session.scalars(stmt)
|
||||
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
|
||||
for group in groups:
|
||||
try:
|
||||
table_message: nextcord.Message = await channel.fetch_message(group.MessageId)
|
||||
await table_message.delete()
|
||||
except nextcord.NotFound:
|
||||
# silently ignore that messages are not found. They got deleted already.
|
||||
pass
|
||||
for group in groups:
|
||||
try:
|
||||
table_message: nextcord.Message = await channel.fetch_message(group.MessageId)
|
||||
await table_message.delete()
|
||||
except nextcord.NotFound:
|
||||
# silently ignore that messages are not found. They got deleted already.
|
||||
pass
|
||||
|
||||
await interaction.send("Table messages deleted.", ephemeral=True)
|
||||
|
||||
@@ -90,21 +92,23 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
"""
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
|
||||
# awaiting response because posting scores takes a while
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
with Session(engine) as session:
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
|
||||
for group in session.scalars(stmt):
|
||||
channel = interaction.guild.get_channel(group.ChannelId)
|
||||
# awaiting response because posting scores takes a while
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
|
||||
# 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)
|
||||
for group in session.scalars(stmt):
|
||||
channel = interaction.guild.get_channel(group.ChannelId)
|
||||
|
||||
message: nextcord.Message = await send_highscore_message(channel, group)
|
||||
await message.edit(view=SubmissionCreateButton(self.bot))
|
||||
# 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 interaction.send(f"Posted all groups in {interaction.guild.name}'s highscores.", ephemeral=True)
|
||||
|
||||
@@ -125,19 +129,20 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
||||
group_id (str): Str representation of Group id to refresh. Is SlashOption.
|
||||
"""
|
||||
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
.where(CategoryGroup.GroupId == int(group_id))
|
||||
)
|
||||
group = session.scalar(stmt)
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
.where(CategoryGroup.GroupId == int(group_id))
|
||||
)
|
||||
group = session.scalar(stmt)
|
||||
|
||||
channel = interaction.guild.get_channel(group.ChannelId)
|
||||
channel = interaction.guild.get_channel(group.ChannelId)
|
||||
|
||||
message: nextcord.Message = await send_highscore_message(channel, group)
|
||||
await message.edit(view=SubmissionCreateButton(self.bot))
|
||||
message: nextcord.Message = await send_highscore_message(session, channel, group)
|
||||
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)
|
||||
|
||||
@refresh_group.on_autocomplete("group_id")
|
||||
async def refresh_table_autofill(self, interaction: nextcord.Interaction, group_id: str):
|
||||
|
||||
Reference in New Issue
Block a user