Compare commits
20
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5eb637a3a8 | ||
|
|
f722eb1a83 | ||
|
|
7759bbc648 | ||
|
|
65de7baeda | ||
|
|
e243404480 | ||
|
|
1959e11e5c | ||
|
|
c25d354fc0 | ||
|
|
e5d90a71d9 | ||
|
|
785a4eff46 | ||
|
|
627112b114 | ||
|
|
9b3bd9d02c | ||
|
|
2c56c614f3 | ||
|
|
3ccaa7004e | ||
|
|
289113661f | ||
|
|
74ce22dd26 | ||
|
|
170ce1cbfb | ||
|
|
e1b761e848 | ||
|
|
68592a7df8 | ||
|
|
b28938f66a | ||
|
|
3abbff13d5 |
Vendored
+2
-2
@@ -10,8 +10,8 @@
|
||||
"ondelete"
|
||||
],
|
||||
"python.analysis.diagnosticSeverityOverrides": {
|
||||
"reportOptionalMemberAccess": false,
|
||||
"reportOptionalMemberAccess": "warning",
|
||||
"reportArgumentType": "information",
|
||||
"reportAttributeAccessIssue": "warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ class GetCog(commands.Cog, name="Get command."):
|
||||
return
|
||||
|
||||
await interaction.response.send_message(
|
||||
f"{category.name} is sorted in {'ascending' if category.is_ascending else 'descending'} order.",
|
||||
f"**{category.name}** is sorted in **{'ascending' if category.is_ascending else 'descending'}** order.",
|
||||
ephemeral=True,
|
||||
)
|
||||
|
||||
@@ -109,7 +109,9 @@ class GetCog(commands.Cog, name="Get command."):
|
||||
await interaction.response.send_message("Group or Category was not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
await interaction.response.send_message(f"{category.name} has a size of {category.size}.", ephemeral=True)
|
||||
await interaction.response.send_message(
|
||||
f"**{category.name}** has a size of **{category.size}**.", ephemeral=True
|
||||
)
|
||||
|
||||
@get.subcommand(description="Commands for getting group information.")
|
||||
async def group(self, interaction: nextcord.Interaction) -> None:
|
||||
@@ -136,7 +138,7 @@ class GetCog(commands.Cog, name="Get command."):
|
||||
return
|
||||
|
||||
await interaction.response.send_message(
|
||||
f"{group.name} has a pad length of {group.pad_length}.", ephemeral=True
|
||||
f"**{group.name}** has a pad length of **{group.pad_length}**.", ephemeral=True
|
||||
)
|
||||
|
||||
@group.subcommand(description="Get the username length of a group.")
|
||||
@@ -162,7 +164,7 @@ class GetCog(commands.Cog, name="Get command."):
|
||||
return
|
||||
|
||||
await interaction.response.send_message(
|
||||
f"{group.name} has a username length of {group.username_length}.", ephemeral=True
|
||||
f"**{group.name}** has a username length of **{group.username_length}**.", ephemeral=True
|
||||
)
|
||||
|
||||
@is_ascending.on_autocomplete("category_id")
|
||||
|
||||
+37
-22
@@ -22,7 +22,7 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
async def set(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash command for setting settings. Never called."""
|
||||
|
||||
@set.subcommand("Commands for editing a category.")
|
||||
@set.subcommand(description="Commands for editing a category.")
|
||||
async def category(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash subcommand for setting category settings. Never called."""
|
||||
|
||||
@@ -54,7 +54,6 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
await interaction.response.send_message("Category or Group was not found.", ephemeral=True)
|
||||
return
|
||||
category.size = size
|
||||
# session.add(category) test if this is needed. SQLAlchemy can do the update without adding.
|
||||
session.commit()
|
||||
|
||||
# Use the relationship to get group category is in.
|
||||
@@ -67,7 +66,9 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
return
|
||||
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
await interaction.response.send_message(f"{category.name} size has been updated to {size}.", ephemeral=True)
|
||||
await interaction.response.send_message(
|
||||
f"**{category.name}** size has been updated to **{size}**.", ephemeral=True
|
||||
)
|
||||
|
||||
@category.subcommand(description="Update the is_ascending value for a category.")
|
||||
async def is_ascending(
|
||||
@@ -99,7 +100,6 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
await interaction.response.send_message("Category or Group was not found.", ephemeral=True)
|
||||
return
|
||||
category.is_ascending = ascending
|
||||
# session.add(category) test if this is needed. SQLAlchemy can do the update without adding.
|
||||
session.commit()
|
||||
|
||||
# Use the relationship to get group category is in.
|
||||
@@ -113,7 +113,7 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
await interaction.response.send_message(
|
||||
f"{category.name} is_ascending has been updated to {ascending}.", ephemeral=True
|
||||
f"**{category.name}** is_ascending has been updated to **{ascending}**.", ephemeral=True
|
||||
)
|
||||
|
||||
@category.subcommand(description="Update the is_validated value for a category.")
|
||||
@@ -146,12 +146,11 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
await interaction.response.send_message("Category or Group was not found.", ephemeral=True)
|
||||
return
|
||||
category.is_validated = validated
|
||||
# session.add(category) test if this is needed. SQLAlchemy can do the update without adding.
|
||||
session.commit()
|
||||
|
||||
await interaction.response.send_message(
|
||||
f"{category.name} is_validated has been updated to {validated}.", ephemeral=True
|
||||
)
|
||||
await interaction.response.send_message(
|
||||
f"**{category.name}** is_validated has been updated to **{validated}**.", ephemeral=True
|
||||
)
|
||||
|
||||
@category.subcommand(name="name", description="Change the name of a category.")
|
||||
async def category_name(
|
||||
@@ -182,7 +181,6 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
return
|
||||
old_name = category.name
|
||||
category.name = name
|
||||
# session.add(category) test if this is needed. SQLAlchemy can do the update without adding.
|
||||
session.commit()
|
||||
|
||||
# Use the relationship to get group category is in.
|
||||
@@ -195,7 +193,9 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
return
|
||||
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
await interaction.response.send_message(f"{old_name} has been updated to {category.name}.", ephemeral=True)
|
||||
await interaction.response.send_message(
|
||||
f"**{old_name}** has been updated to **{category.name}**.", ephemeral=True
|
||||
)
|
||||
|
||||
@set.subcommand(description="Commands for editing a group.")
|
||||
async def group(self, interaction: nextcord.Interaction) -> None:
|
||||
@@ -228,7 +228,7 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
session.commit()
|
||||
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
await interaction.response.send_message(f"{old_name} has been updated to {group.name}.", ephemeral=True)
|
||||
await interaction.response.send_message(f"**{old_name}** has been updated to **{group.name}**.", ephemeral=True)
|
||||
|
||||
@group.subcommand(description="Registers the channel for a Group's messages.")
|
||||
async def output_channel(
|
||||
@@ -259,9 +259,14 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||
.where(col(CategoryGroup.id) == int(group_id))
|
||||
)
|
||||
group = session.scalar(stmt)
|
||||
group.ChannelId = channel_id
|
||||
if (group := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group or Category was not found.", ephemeral=True)
|
||||
return
|
||||
group.channel_id = channel_id
|
||||
session.commit()
|
||||
# TODO(imcompiling): delete the message and call send_highscore_message to send a new one. Bug needs fixed
|
||||
# first.
|
||||
# 082
|
||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
||||
|
||||
@group.subcommand(
|
||||
@@ -296,10 +301,11 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
if (group := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
||||
return
|
||||
group.PadLength = length
|
||||
|
||||
group.pad_length = length
|
||||
session.commit()
|
||||
await interaction.response.send_message(
|
||||
f"Category pad length set to {length} for {group.name}", ephemeral=True
|
||||
f"Category pad length set to **{length}** for **{group.name}**.", ephemeral=True
|
||||
)
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
|
||||
@@ -328,7 +334,9 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = select(Guild).where(col(Guild.id) == interaction.guild_id)
|
||||
guild = session.scalar(stmt)
|
||||
if (guild := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Guild was not found.", ephemeral=True)
|
||||
return
|
||||
guild.submission_channel = channel_id
|
||||
session.commit()
|
||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
||||
@@ -358,10 +366,15 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||
.where(col(CategoryGroup.id) == int(group_id))
|
||||
)
|
||||
group = session.scalar(stmt)
|
||||
group.UsernameLength = length
|
||||
if (group := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group or Category was not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
group.username_length = length
|
||||
session.commit()
|
||||
await interaction.response.send_message(f"Username length set to {length}.", ephemeral=True)
|
||||
await interaction.response.send_message(
|
||||
f"Username length for **{group.name}** set to **{length}**.", ephemeral=True
|
||||
)
|
||||
|
||||
@set.subcommand(description="Registers the channel for verification messages.")
|
||||
async def verify_channel(
|
||||
@@ -386,8 +399,10 @@ class SetCog(commands.Cog, name="Set command."):
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = select(Guild).where(col(Guild.id) == interaction.guild_id)
|
||||
guild = session.scalar(stmt)
|
||||
guild.VerificationChannel = channel_id
|
||||
if (guild := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Guild was not found.", ephemeral=True)
|
||||
return
|
||||
guild.verification_channel = channel_id
|
||||
session.commit()
|
||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
||||
|
||||
|
||||
@@ -64,10 +64,7 @@ class SubmissionCog(commands.Cog):
|
||||
.where(col(Category.group_id) == int(group_id))
|
||||
.where(col(Category.id) == int(category_id))
|
||||
)
|
||||
|
||||
category: Category | None = session.scalar(stmt)
|
||||
|
||||
if category is None:
|
||||
if (category := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Category not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
@@ -79,10 +76,13 @@ class SubmissionCog(commands.Cog):
|
||||
return
|
||||
|
||||
# check with regex if score is in correct format
|
||||
verified_score = await self.verify_score(interaction, score, is_time_record=category.is_time_record)
|
||||
|
||||
# check if verify_score was successful. It replies with corrections required itself.
|
||||
if verified_score is None:
|
||||
if (
|
||||
verified_score := await self.verify_score(interaction, score, is_time_record=category.is_time_record)
|
||||
) is None:
|
||||
# This response message will be filled out better once command is split up to
|
||||
# know which type it expects...
|
||||
await interaction.response.send_message("Format was incorrect.", ephemeral=True)
|
||||
return
|
||||
|
||||
# Create submission verification request or submit score if verification not needed.
|
||||
@@ -92,16 +92,13 @@ class SubmissionCog(commands.Cog):
|
||||
return
|
||||
|
||||
stmt = select(col(Guild.verification_channel)).where(col(Guild.id) == interaction.guild_id)
|
||||
verification_channel_id: int | None = session.scalar(stmt)
|
||||
|
||||
if verification_channel_id is None:
|
||||
if (verification_channel_id := session.scalar(stmt)) is None:
|
||||
error_response = "No verification channel was registered. Contact server admins."
|
||||
await interaction.response.send_message(error_response, ephemeral=True)
|
||||
return
|
||||
|
||||
channel = interaction.guild.get_channel(verification_channel_id)
|
||||
|
||||
if channel is None:
|
||||
if (channel := interaction.guild.get_channel(verification_channel_id)) is None:
|
||||
error_response = "Registered Verification channel does not exist. Contact server admins."
|
||||
await interaction.response.send_message(error_response, ephemeral=True)
|
||||
return
|
||||
|
||||
@@ -26,10 +26,9 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
||||
"""
|
||||
with Session(engine) as session:
|
||||
stmt = select(Guild).where(col(Guild.id == guild.id))
|
||||
guild_data = session.scalar(stmt)
|
||||
|
||||
# just in case check if the guild already exists
|
||||
if guild_data is None:
|
||||
if (guild_data := session.scalar(stmt)) is None:
|
||||
new_guild = Guild(id=guild.id, name=guild.name)
|
||||
session.add(new_guild)
|
||||
else:
|
||||
|
||||
@@ -31,7 +31,7 @@ class GuildData(commands.Cog, name="Guild Data"):
|
||||
with Session(engine) as session:
|
||||
for guild in self.bot.guilds:
|
||||
# update given guild name for guild id
|
||||
stmt = select(Guild).where(col(Guild.id == guild.id))
|
||||
stmt = select(Guild).where(col(Guild.id) == guild.id)
|
||||
guild_data = session.scalar(stmt)
|
||||
|
||||
# just in case checking if the guild doesn't exist.
|
||||
@@ -39,6 +39,6 @@ class GuildData(commands.Cog, name="Guild Data"):
|
||||
new_guild = Guild(id=guild.id, name=guild.name)
|
||||
session.add(new_guild)
|
||||
else:
|
||||
guild_data.GuildName = guild.name
|
||||
guild_data.name = guild.name
|
||||
|
||||
session.commit()
|
||||
|
||||
@@ -39,9 +39,7 @@ class VerificationView(nextcord.ui.View):
|
||||
.where(col(Submission.message_id) == interaction.message.id)
|
||||
)
|
||||
|
||||
submission = session.scalar(stmt)
|
||||
|
||||
if submission is None:
|
||||
if (submission := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Could not find submission data in database.", ephemeral=True)
|
||||
await interaction.message.delete()
|
||||
return
|
||||
|
||||
@@ -2,13 +2,16 @@
|
||||
|
||||
from sqlmodel import SQLModel, create_engine
|
||||
from utilities import config
|
||||
from utilities.logger import agon_logger
|
||||
|
||||
from . import models # noqa: F401 - Need this import for creating the models.
|
||||
|
||||
if config.ENVIRONMENT == "prod":
|
||||
url = f"mysql+pymysql://{config.SQL_USER}:{config.SQL_PASS}@{config.SQL_HOST}/{config.SQL_DB}"
|
||||
agon_logger.info("Connected to prod database.")
|
||||
else:
|
||||
url = "sqlite:///database.db"
|
||||
agon_logger.info("Connected to local dev database.")
|
||||
engine = create_engine(url)
|
||||
|
||||
# Don't need to create all when connected to prod.
|
||||
|
||||
+3
-3
@@ -65,7 +65,7 @@ def autofill_groups(guild_id: int, group_begin: str) -> "dict[str, str]":
|
||||
"""
|
||||
with Session(engine) as session:
|
||||
# Select all groups in guild.
|
||||
stmt = select(CategoryGroup).wherecol((CategoryGroup.guild_id) == guild_id)
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.guild_id) == guild_id)
|
||||
|
||||
# dict has to have key values of same type for discord.
|
||||
group_dict: dict[str, str] = {group.name: str(group.id) for group in session.scalars(stmt)}
|
||||
@@ -353,7 +353,7 @@ async def send_highscore_message(session: Session, guild: nextcord.Guild, group:
|
||||
if group.message_id is None:
|
||||
# message doesn't exist.
|
||||
message: nextcord.Message = await channel.send(highscore_string)
|
||||
group.MessageId = message.id
|
||||
group.message_id = message.id
|
||||
session.commit()
|
||||
else:
|
||||
# TODO(imcompiling): check what happens when message is deleted.
|
||||
@@ -398,7 +398,7 @@ async def submit_score(
|
||||
existing_score = session.scalar(stmt)
|
||||
|
||||
if existing_score:
|
||||
existing_score.Score = score_f
|
||||
existing_score.score = score_f
|
||||
else:
|
||||
score_obj = Score(username=username, score=score_f, category_id=category_id)
|
||||
session.add(score_obj)
|
||||
|
||||
Reference in New Issue
Block a user