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:
@@ -6,9 +6,10 @@ from enum import Enum
|
|||||||
|
|
||||||
from nextcord import Embed
|
from nextcord import Embed
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from utilities.sql_alchemy_connection import Category, CategoryGroup, session
|
from utilities.sql_data_classes import Category, CategoryGroup, engine
|
||||||
|
|
||||||
|
|
||||||
class SubmissionState(Enum):
|
class SubmissionState(Enum):
|
||||||
@@ -199,6 +200,7 @@ class Submission:
|
|||||||
.where(CategoryGroup.GuildId == self.guild_id)
|
.where(CategoryGroup.GuildId == self.guild_id)
|
||||||
.where(CategoryGroup.GroupId == self.group_id)
|
.where(CategoryGroup.GroupId == self.group_id)
|
||||||
)
|
)
|
||||||
|
with Session(engine) as session:
|
||||||
embed.add_field(name="Group", value=session.scalar(stmt), inline=False)
|
embed.add_field(name="Group", value=session.scalar(stmt), inline=False)
|
||||||
if self.category_id:
|
if self.category_id:
|
||||||
stmt = (
|
stmt = (
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ from typing import Optional
|
|||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
from sqlalchemy import distinct, select
|
from sqlalchemy import distinct, select
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from utilities.sql_alchemy_connection import Category, CategoryGroup, Guild, Score, session
|
from utilities.sql_data_classes import Category, CategoryGroup, Guild, Score, engine
|
||||||
from utilities.utils import (
|
from utilities.utils import (
|
||||||
autofill_categories,
|
autofill_categories,
|
||||||
autofill_groups,
|
autofill_groups,
|
||||||
@@ -70,6 +71,7 @@ class DataManagementCog(commands.Cog, name="Table Management"):
|
|||||||
user_name (str): User to remove from highscores
|
user_name (str): User to remove from highscores
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
stmt = select(distinct(Score.CategoryId)).where(Score.UserName == user_name)
|
stmt = select(distinct(Score.CategoryId)).where(Score.UserName == user_name)
|
||||||
category_ids: "list[int]" = list(session.scalars(stmt))
|
category_ids: "list[int]" = list(session.scalars(stmt))
|
||||||
|
|
||||||
@@ -83,7 +85,7 @@ class DataManagementCog(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(interaction.guild.get_channel(group.ChannelId), group)
|
await send_highscore_message(session, interaction.guild.get_channel(group.ChannelId), 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)
|
||||||
|
|
||||||
@@ -107,6 +109,7 @@ class DataManagementCog(commands.Cog, name="Table Management"):
|
|||||||
user_name (str): The user to remove. Is SlashOption.
|
user_name (str): The user to remove. Is SlashOption.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == int(group_id))
|
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == int(group_id))
|
||||||
group = session.scalar(stmt)
|
group = session.scalar(stmt)
|
||||||
|
|
||||||
@@ -119,8 +122,10 @@ class DataManagementCog(commands.Cog, name="Table Management"):
|
|||||||
session.delete(session.scalar(stmt))
|
session.delete(session.scalar(stmt))
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
await send_highscore_message(interaction.guild.get_channel(group.ChannelId), group)
|
await send_highscore_message(session, interaction.guild.get_channel(group.ChannelId), group)
|
||||||
await interaction.response.send_message(f'User "{user_name}" removed from "{category_name}".', ephemeral=True)
|
await interaction.response.send_message(
|
||||||
|
f'User "{user_name}" removed from "{category_name}".', ephemeral=True
|
||||||
|
)
|
||||||
|
|
||||||
@user.subcommand(description="Deletes a user's scores from entire group.")
|
@user.subcommand(description="Deletes a user's scores from entire group.")
|
||||||
async def from_group(
|
async def from_group(
|
||||||
@@ -138,6 +143,7 @@ class DataManagementCog(commands.Cog, name="Table Management"):
|
|||||||
user_name (str): The user to remove. Is SlashOption.
|
user_name (str): The user to remove. Is SlashOption.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == int(group_id))
|
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == int(group_id))
|
||||||
group = session.scalar(stmt)
|
group = session.scalar(stmt)
|
||||||
category_ids = select(Category.CategoryId).where(Category.GroupId == int(group_id))
|
category_ids = select(Category.CategoryId).where(Category.GroupId == int(group_id))
|
||||||
@@ -147,7 +153,7 @@ class DataManagementCog(commands.Cog, name="Table Management"):
|
|||||||
session.delete(score)
|
session.delete(score)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
await send_highscore_message(interaction.guild.get_channel(group.ChannelId), group)
|
await send_highscore_message(session, interaction.guild.get_channel(group.ChannelId), 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
|
||||||
)
|
)
|
||||||
@@ -215,6 +221,8 @@ class DataManagementCog(commands.Cog, name="Table Management"):
|
|||||||
old_username (str): Username to replace.
|
old_username (str): Username to replace.
|
||||||
new_username (str): Username to replace old with.
|
new_username (str): Username to replace old with.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
stmt = select(Guild.VerificationChannel).where(Guild.GuildId == interaction.guild_id)
|
stmt = select(Guild.VerificationChannel).where(Guild.GuildId == interaction.guild_id)
|
||||||
verify_channel = interaction.guild.get_channel(session.scalar(stmt))
|
verify_channel = interaction.guild.get_channel(session.scalar(stmt))
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ from typing import Optional
|
|||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from cogs.submission.submission_views import SubmissionCreateButton
|
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
|
from utilities.utils import autofill_groups, send_highscore_message
|
||||||
|
|
||||||
|
|
||||||
@@ -55,6 +56,7 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
|||||||
if not channel:
|
if not channel:
|
||||||
channel = interaction.channel
|
channel = interaction.channel
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CategoryGroup)
|
select(CategoryGroup)
|
||||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||||
@@ -90,6 +92,8 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
|||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
stmt = select(CategoryGroup).where(CategoryGroup.GuildId == interaction.guild_id)
|
stmt = select(CategoryGroup).where(CategoryGroup.GuildId == interaction.guild_id)
|
||||||
|
|
||||||
# awaiting response because posting scores takes a while
|
# awaiting response because posting scores takes a while
|
||||||
@@ -103,7 +107,7 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
|||||||
error_response += 'Use "/register" to register channels.'
|
error_response += 'Use "/register" to register channels.'
|
||||||
assert channel is not None, await interaction.response(error_response, ephemeral=True)
|
assert channel is not None, await interaction.response(error_response, ephemeral=True)
|
||||||
|
|
||||||
message: nextcord.Message = await send_highscore_message(channel, 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.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)
|
||||||
@@ -125,6 +129,7 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
|||||||
group_id (str): Str representation of Group id to refresh. Is SlashOption.
|
group_id (str): Str representation of Group id to refresh. Is SlashOption.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CategoryGroup)
|
select(CategoryGroup)
|
||||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||||
@@ -134,7 +139,7 @@ class MessageManagementCog(commands.Cog, name="Message Management"):
|
|||||||
|
|
||||||
channel = interaction.guild.get_channel(group.ChannelId)
|
channel = interaction.guild.get_channel(group.ChannelId)
|
||||||
|
|
||||||
message: nextcord.Message = await send_highscore_message(channel, 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)
|
||||||
|
|||||||
+11
-1
@@ -7,9 +7,10 @@ from typing import Optional
|
|||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from utilities.sql_alchemy_connection import CategoryGroup, Guild, session
|
from utilities.sql_data_classes import CategoryGroup, Guild, engine
|
||||||
from utilities.utils import autofill_groups
|
from utilities.utils import autofill_groups
|
||||||
|
|
||||||
|
|
||||||
@@ -49,6 +50,7 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
length (int): Number of characters. Is SlashOption. Defaults to 26.
|
length (int): Number of characters. Is SlashOption. Defaults to 26.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CategoryGroup)
|
select(CategoryGroup)
|
||||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||||
@@ -84,9 +86,11 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
channel (nextcord.abc.GuildChannel, optional): Channel to register
|
channel (nextcord.abc.GuildChannel, optional): Channel to register
|
||||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not channel:
|
if not channel:
|
||||||
channel = interaction.channel
|
channel = interaction.channel
|
||||||
channel_id = channel.id
|
channel_id = channel.id
|
||||||
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CategoryGroup)
|
select(CategoryGroup)
|
||||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||||
@@ -116,8 +120,11 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
channel Optional[nextcord.abc.GuildChannel], optional): Channel to register
|
channel Optional[nextcord.abc.GuildChannel], optional): Channel to register
|
||||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not channel:
|
if not channel:
|
||||||
channel = interaction.channel
|
channel = interaction.channel
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
channel_id = channel.id
|
channel_id = channel.id
|
||||||
stmt = select(Guild).where(Guild.GuildId == interaction.guild_id)
|
stmt = select(Guild).where(Guild.GuildId == interaction.guild_id)
|
||||||
guild = session.scalar(stmt)
|
guild = session.scalar(stmt)
|
||||||
@@ -142,6 +149,7 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
length (int): Number of characters. Is SlashOption. Defaults to 12.
|
length (int): Number of characters. Is SlashOption. Defaults to 12.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CategoryGroup)
|
select(CategoryGroup)
|
||||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||||
@@ -171,9 +179,11 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
channel (Optional[nextcord.abc.GuildChannel]): Channel to register
|
channel (Optional[nextcord.abc.GuildChannel]): Channel to register
|
||||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not channel:
|
if not channel:
|
||||||
channel = interaction.channel
|
channel = interaction.channel
|
||||||
channel_id = channel.id
|
channel_id = channel.id
|
||||||
|
with Session(engine) as session:
|
||||||
stmt = select(Guild).where(Guild.GuildId == interaction.guild_id)
|
stmt = select(Guild).where(Guild.GuildId == interaction.guild_id)
|
||||||
guild = session.scalar(stmt)
|
guild = session.scalar(stmt)
|
||||||
guild.VerificationChannel = channel_id
|
guild.VerificationChannel = channel_id
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from sqlalchemy import distinct, exc, select
|
from sqlalchemy import distinct, exc, select
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from utilities.sql_alchemy_connection import Category, CategoryGroup, Score, session
|
from utilities.sql_data_classes import Category, CategoryGroup, Score, engine
|
||||||
from utilities.utils import send_highscore_message
|
from utilities.utils import send_highscore_message
|
||||||
|
|
||||||
|
|
||||||
@@ -43,6 +44,7 @@ class UpdateUsernameVerifyView(nextcord.ui.View):
|
|||||||
interaction (nextcord.Interaction): Interaction with the button
|
interaction (nextcord.Interaction): Interaction with the button
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
try:
|
try:
|
||||||
embed_content = interaction.message.embeds[0].to_dict()
|
embed_content = interaction.message.embeds[0].to_dict()
|
||||||
old_username: str = embed_content["fields"][0]["value"]
|
old_username: str = embed_content["fields"][0]["value"]
|
||||||
@@ -61,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(interaction.guild.get_channel(group.ChannelId), group)
|
await send_highscore_message(session, interaction.guild.get_channel(group.ChannelId), group)
|
||||||
|
|
||||||
content = interaction.message.content
|
content = interaction.message.content
|
||||||
content += f"\nApproved by <@{interaction.user.id}>."
|
content += f"\nApproved by <@{interaction.user.id}>."
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ Defines cog for guild listeners. Contains functions for various guild events.
|
|||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from utilities.sql_alchemy_connection import Guild, session
|
from utilities.sql_data_classes import Guild, engine
|
||||||
from utilities.utils import add_preset_configuration
|
from utilities.utils import add_preset_configuration
|
||||||
|
|
||||||
|
|
||||||
@@ -19,7 +20,10 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
|||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_guild_join(self, guild: nextcord.Guild):
|
async def on_guild_join(self, guild: nextcord.Guild):
|
||||||
"""Listener for Guild Join. Creates skeleton for new guild joined and saves it."""
|
"""Listener for Guild Join. Creates skeleton for new guild joined and saves it."""
|
||||||
|
|
||||||
new_guild = Guild(GuildId=guild.id)
|
new_guild = Guild(GuildId=guild.id)
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
session.add(new_guild)
|
session.add(new_guild)
|
||||||
session.commit()
|
session.commit()
|
||||||
# This add config will be removed eventually. Config adding will have to be controlled by commands.
|
# This add config will be removed eventually. Config adding will have to be controlled by commands.
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ import re
|
|||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import aliased
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from classes.submission import SubmissionState
|
from classes.submission import SubmissionState
|
||||||
from highscores import submission_objects
|
from highscores import submission_objects
|
||||||
from utilities.sql_alchemy_connection import Category, CategoryGroup, Guild, session
|
from utilities.sql_data_classes import Category, Guild, engine
|
||||||
|
|
||||||
|
|
||||||
class SubmissionListener(commands.Cog, name="Message Listener"):
|
class SubmissionListener(commands.Cog, name="Message Listener"):
|
||||||
@@ -33,6 +33,8 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
|
|||||||
if submission_objects.has_user(message.author.id):
|
if submission_objects.has_user(message.author.id):
|
||||||
submission = submission_objects.get_user_submission(message.author.id)
|
submission = submission_objects.get_user_submission(message.author.id)
|
||||||
message_id = submission.message_id
|
message_id = submission.message_id
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
stmt = select(Guild.SubmissionChannel).where(Guild.GuildId == guild_id)
|
stmt = select(Guild.SubmissionChannel).where(Guild.GuildId == guild_id)
|
||||||
submission_channel_id = session.scalar(stmt)
|
submission_channel_id = session.scalar(stmt)
|
||||||
submission_message: nextcord.Message = (
|
submission_message: nextcord.Message = (
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ from typing import Optional
|
|||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import aliased
|
from sqlalchemy.orm import Session, aliased
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from classes.submission import Submission, SubmissionState
|
from classes.submission import Submission, SubmissionState
|
||||||
from utilities.sql_alchemy_connection import Category, Guild, CategoryGroup, session
|
|
||||||
from highscores import submission_objects
|
from highscores import submission_objects
|
||||||
|
from utilities.sql_data_classes import Category, CategoryGroup, Guild, engine
|
||||||
|
|
||||||
from .verification_view import VerificationView
|
from .verification_view import VerificationView
|
||||||
|
|
||||||
@@ -18,6 +18,8 @@ from .verification_view import VerificationView
|
|||||||
def category_select_options(group_id: int) -> "list[nextcord.SelectOption]":
|
def category_select_options(group_id: int) -> "list[nextcord.SelectOption]":
|
||||||
"""Returns list of categories for a given boss."""
|
"""Returns list of categories for a given boss."""
|
||||||
options: "list[nextcord.SelectOption]" = []
|
options: "list[nextcord.SelectOption]" = []
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
subq = select(CategoryGroup).where(CategoryGroup.GroupId == group_id).subquery()
|
subq = select(CategoryGroup).where(CategoryGroup.GroupId == group_id).subquery()
|
||||||
cat_group_alias = aliased(CategoryGroup, subq)
|
cat_group_alias = aliased(CategoryGroup, subq)
|
||||||
stmt = select(Category).where(Category.GroupId == cat_group_alias.GroupId)
|
stmt = select(Category).where(Category.GroupId == cat_group_alias.GroupId)
|
||||||
@@ -110,6 +112,7 @@ class SubmitButton(nextcord.ui.Button):
|
|||||||
self._bot = bot
|
self._bot = bot
|
||||||
|
|
||||||
async def callback(self, interaction: nextcord.Interaction):
|
async def callback(self, interaction: nextcord.Interaction):
|
||||||
|
with Session(engine) as session:
|
||||||
stmt = select(Guild.VerificationChannel).where(Guild.GuildId == interaction.guild_id)
|
stmt = select(Guild.VerificationChannel).where(Guild.GuildId == interaction.guild_id)
|
||||||
verification_channel_id = session.scalar(stmt)
|
verification_channel_id = session.scalar(stmt)
|
||||||
channel = interaction.guild.get_channel(verification_channel_id)
|
channel = interaction.guild.get_channel(verification_channel_id)
|
||||||
@@ -148,11 +151,13 @@ class SubmissionCreateButton(nextcord.ui.View):
|
|||||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||||
): # pylint: disable=unused-argument
|
): # pylint: disable=unused-argument
|
||||||
"""Button for score submission."""
|
"""Button for score submission."""
|
||||||
|
|
||||||
# Don't allow a user to start a new submission if one already exists
|
# Don't allow a user to start a new submission if one already exists
|
||||||
if submission_objects.has_user(interaction.user.id):
|
if submission_objects.has_user(interaction.user.id):
|
||||||
await interaction.send("Please finish in progress submission first.", ephemeral=True)
|
await interaction.send("Please finish in progress submission first.", ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CategoryGroup.GroupId)
|
select(CategoryGroup.GroupId)
|
||||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
version: "3"
|
version: "3"
|
||||||
services:
|
services:
|
||||||
sqldb:
|
sqldb:
|
||||||
|
restart: unless-stopped
|
||||||
image: "highscores_db"
|
image: "highscores_db"
|
||||||
container_name: "Highscores-DataBase"
|
container_name: "Highscores-DataBase"
|
||||||
volumes:
|
volumes:
|
||||||
+2
-1
@@ -9,7 +9,8 @@ import sys
|
|||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
import utilities.config as config
|
# pylint: disable=import-error
|
||||||
|
from utilities import config
|
||||||
from classes.submission import SubmissionMap
|
from classes.submission import SubmissionMap
|
||||||
|
|
||||||
logger = logging.getLogger("nextcord")
|
logger = logging.getLogger("nextcord")
|
||||||
|
|||||||
@@ -3,17 +3,15 @@ Simple file to set up the sqlalchemy connection to database.
|
|||||||
"""
|
"""
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.ext.automap import automap_base
|
from sqlalchemy.ext.automap import automap_base
|
||||||
from sqlalchemy.orm import Session
|
|
||||||
|
|
||||||
import utilities.config as config
|
# pylint: disable=import-error
|
||||||
|
from utilities import config
|
||||||
|
|
||||||
# connect with sql alchemy and autoload schema
|
# connect with sql alchemy and autoload schema
|
||||||
url = f"mysql://{config.SQL_USER}:{config.SQL_PASS}@{config.SQL_HOST}/{config.SQL_DB}"
|
url = f"mysql://{config.SQL_USER}:{config.SQL_PASS}@{config.SQL_HOST}/{config.SQL_DB}"
|
||||||
engine = create_engine(url)
|
engine = create_engine(url)
|
||||||
connection = engine.connect()
|
|
||||||
Base = automap_base()
|
Base = automap_base()
|
||||||
Base.prepare(autoload_with=engine)
|
Base.prepare(autoload_with=engine)
|
||||||
session = Session(engine)
|
|
||||||
|
|
||||||
# define the classes
|
# define the classes
|
||||||
Guild = Base.classes.Guilds
|
Guild = Base.classes.Guilds
|
||||||
+21
-7
@@ -8,10 +8,10 @@ import time
|
|||||||
import nextcord
|
import nextcord
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from sqlalchemy import distinct, select
|
from sqlalchemy import distinct, select
|
||||||
from sqlalchemy.orm import aliased
|
from sqlalchemy.orm import Session, aliased
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from utilities.sql_alchemy_connection import Category, CategoryGroup, Guild, Score, engine, session
|
from utilities.sql_data_classes import Category, CategoryGroup, Guild, Score, engine
|
||||||
|
|
||||||
MAX_LINE_LENGTH = 142
|
MAX_LINE_LENGTH = 142
|
||||||
|
|
||||||
@@ -30,6 +30,7 @@ def autofill_categories(guild_id: int, group_id: int, category_begin: str) -> "d
|
|||||||
dict[str, str]: List of all category names that start with category_begin.
|
dict[str, str]: List of all category names that start with category_begin.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
# search database for all category names
|
# search database for all category names
|
||||||
subq = (
|
subq = (
|
||||||
select(CategoryGroup)
|
select(CategoryGroup)
|
||||||
@@ -65,6 +66,7 @@ def autofill_groups(guild_id: int, group_begin: str) -> "dict[str, str]":
|
|||||||
dict[str, str]: Dict of group names and ids where group name start with group_begin. Key is name, value is id.
|
dict[str, str]: Dict of group names and ids where group name start with group_begin. Key is name, value is id.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
# Select all groups in guild.
|
# Select all groups in guild.
|
||||||
stmt = select(CategoryGroup).where(CategoryGroup.GuildId == guild_id)
|
stmt = select(CategoryGroup).where(CategoryGroup.GuildId == guild_id)
|
||||||
|
|
||||||
@@ -98,6 +100,7 @@ def autofill_users_in_group_category(guild_id: int, group_id: int, category_id:
|
|||||||
list[str]: List of users that start with user_begin.
|
list[str]: List of users that start with user_begin.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
# get all categories in the group
|
# get all categories in the group
|
||||||
subq = (
|
subq = (
|
||||||
select(CategoryGroup)
|
select(CategoryGroup)
|
||||||
@@ -146,6 +149,8 @@ def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]":
|
|||||||
Returns:
|
Returns:
|
||||||
list[str]: All users with submissions in the guild.
|
list[str]: All users with submissions in the guild.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
group_ids = select(CategoryGroup.GroupId).where(CategoryGroup.GuildId == guild_id)
|
group_ids = select(CategoryGroup.GroupId).where(CategoryGroup.GuildId == guild_id)
|
||||||
category_ids = select(Category.CategoryId).where(Category.GroupId.in_(group_ids))
|
category_ids = select(Category.CategoryId).where(Category.GroupId.in_(group_ids))
|
||||||
stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(category_ids))
|
stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(category_ids))
|
||||||
@@ -161,18 +166,20 @@ def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]":
|
|||||||
return users
|
return users
|
||||||
|
|
||||||
|
|
||||||
def format_highscore_message(group: CategoryGroup) -> str:
|
def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
||||||
"""
|
"""
|
||||||
Creates a formatted string for a boss's highscore discord message.
|
Creates a formatted string for a boss's highscore discord message.
|
||||||
This formatted string is in discord's code block to ensure monospace text.
|
This formatted string is in discord's code block to ensure monospace text.
|
||||||
Loops through each category to build the message one place at a time.
|
Loops through each category to build the message one place at a time.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
group (group): group object that contains the contents of the message.
|
session (Session): the sqlalchemy session used for this function call.
|
||||||
|
group (CategoryGroup): group object that contains the contents of the message.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
str: Formatted string for discord message
|
str: Formatted string for discord message
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ret_string = f"**{group.GroupName}**\n```"
|
ret_string = f"**{group.GroupName}**\n```"
|
||||||
|
|
||||||
stmt = select(Guild).where(Guild.GuildId == group.GuildId)
|
stmt = select(Guild).where(Guild.GuildId == group.GuildId)
|
||||||
@@ -291,19 +298,23 @@ 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(channel: nextcord.TextChannel, group: CategoryGroup) -> nextcord.Message:
|
async def send_highscore_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.
|
||||||
channel (nextcord.TextChannel): Discord channel object where message is sent
|
channel (nextcord.TextChannel): Discord channel object where message is sent
|
||||||
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(group)
|
|
||||||
|
highscore_string = format_highscore_message(session, group)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
message: nextcord.Message = await channel.fetch_message(group.MessageId)
|
message: nextcord.Message = await channel.fetch_message(group.MessageId)
|
||||||
@@ -332,6 +343,7 @@ async def submit_score(
|
|||||||
score (str): Score to submit. Need to convert to correct type.
|
score (str): Score to submit. Need to convert to correct type.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
stmt = select(Category.IsTimeRecord).where(Category.CategoryId == category_id)
|
stmt = select(Category.IsTimeRecord).where(Category.CategoryId == category_id)
|
||||||
is_time_record = session.scalar(stmt)
|
is_time_record = session.scalar(stmt)
|
||||||
|
|
||||||
@@ -362,7 +374,7 @@ async def submit_score(
|
|||||||
error_response += 'Register with "/register" command.'
|
error_response += 'Register with "/register" command.'
|
||||||
assert channel is not None, await interaction.send(error_response, ephemeral=True)
|
assert channel is not None, await interaction.send(error_response, ephemeral=True)
|
||||||
|
|
||||||
await send_highscore_message(channel, group)
|
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:
|
||||||
@@ -374,6 +386,8 @@ def add_preset_configuration(guild_id: int, config_str: str) -> None:
|
|||||||
guild_id (int): Guild id to add config to
|
guild_id (int): Guild id to add config to
|
||||||
config_str (str): Config name to add
|
config_str (str): Config name to add
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
with open(f"example_config/{config_str}.json", encoding="utf-8", mode="r") as file:
|
with open(f"example_config/{config_str}.json", encoding="utf-8", mode="r") as file:
|
||||||
config = json.load(file)
|
config = json.load(file)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user