Compare commits
15
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
618100dc27 | ||
|
|
af0f5c6eba | ||
|
|
7f7af124fe | ||
|
|
46bce400af | ||
|
|
b681d7a923 | ||
|
|
ec086448ea | ||
|
|
476b0e89ef | ||
|
|
fa39949b1a | ||
|
|
f1290af45b | ||
|
|
10954ef117 | ||
|
|
0540f7a9eb | ||
|
|
a4aab09360 | ||
|
|
af7518c1a2 | ||
|
|
5be029fb57 | ||
|
|
d82999b141 |
@@ -13,7 +13,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Install Docker
|
- name: Install Docker
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Install Docker
|
- name: Install Docker
|
||||||
|
|||||||
Vendored
+2
-1
@@ -7,7 +7,8 @@
|
|||||||
"imcompiling",
|
"imcompiling",
|
||||||
"iterrows",
|
"iterrows",
|
||||||
"nextcord",
|
"nextcord",
|
||||||
"ondelete"
|
"ondelete",
|
||||||
|
"pylance's"
|
||||||
],
|
],
|
||||||
"python.analysis.diagnosticSeverityOverrides": {
|
"python.analysis.diagnosticSeverityOverrides": {
|
||||||
"reportOptionalMemberAccess": "warning",
|
"reportOptionalMemberAccess": "warning",
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
FROM python:3.12.3-slim
|
FROM python:3.12.3-slim
|
||||||
|
|
||||||
# install uv
|
# install uv
|
||||||
COPY --from=ghcr.io/astral-sh/uv:0.6.6 /uv /uvx /bin/
|
COPY --from=ghcr.io/astral-sh/uv:0.6.9 /uv /uvx /bin/
|
||||||
|
|
||||||
RUN apt-get update && apt-get -y upgrade && apt-get -y install sqlite3
|
RUN apt-get update && apt-get -y upgrade && apt-get -y install sqlite3
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ class CreateCog(commands.Cog, name="Create Cog"):
|
|||||||
min_value=1,
|
min_value=1,
|
||||||
max_value=30,
|
max_value=30,
|
||||||
),
|
),
|
||||||
channel: nextcord.TextChannel | None = nextcord.SlashOption(
|
channel: nextcord.TextChannel | nextcord.Thread | None = nextcord.SlashOption(
|
||||||
description="Channel to post Group in. If left empty, defaults to current channel.",
|
description="Channel to post Group in. If left empty, defaults to current channel.",
|
||||||
required=False,
|
required=False,
|
||||||
default=None,
|
default=None,
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class DeleteCog(commands.Cog, name="Delete Cog"):
|
|||||||
async def channel_messages(
|
async def channel_messages(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
channel: nextcord.TextChannel | None = nextcord.SlashOption(
|
channel: nextcord.TextChannel | nextcord.Thread | None = nextcord.SlashOption(
|
||||||
description="Channel to clear of messages.",
|
description="Channel to clear of messages.",
|
||||||
required=False,
|
required=False,
|
||||||
default=None,
|
default=None,
|
||||||
@@ -54,7 +54,7 @@ class DeleteCog(commands.Cog, name="Delete Cog"):
|
|||||||
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:
|
||||||
if isinstance(interaction.channel, nextcord.TextChannel):
|
if isinstance(interaction.channel, nextcord.TextChannel | nextcord.Thread):
|
||||||
channel = interaction.channel
|
channel = interaction.channel
|
||||||
else:
|
else:
|
||||||
# This should never happen.
|
# This should never happen.
|
||||||
|
|||||||
@@ -251,6 +251,10 @@ 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 interaction.guild is None or interaction.channel is None:
|
||||||
|
agon_logger.warning("Set command was called with an interaction that had no guild or channel.")
|
||||||
|
return
|
||||||
|
|
||||||
channel_id = interaction.channel.id if not channel else channel.id
|
channel_id = interaction.channel.id if not channel else channel.id
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
@@ -262,11 +266,14 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
if (group := session.scalar(stmt)) is None:
|
if (group := session.scalar(stmt)) is None:
|
||||||
await interaction.response.send_message("Group or Category was not found.", ephemeral=True)
|
await interaction.response.send_message("Group or Category was not found.", ephemeral=True)
|
||||||
return
|
return
|
||||||
|
old_channel_id = group.channel_id
|
||||||
group.channel_id = channel_id
|
group.channel_id = channel_id
|
||||||
session.commit()
|
session.commit()
|
||||||
# TODO(imcompiling): delete the message and call send_highscore_message to send a new one. Bug needs fixed
|
|
||||||
# first.
|
old_channel = interaction.guild.get_channel(old_channel_id)
|
||||||
# 082
|
if old_channel and isinstance(old_channel, nextcord.TextChannel | nextcord.Thread) and group.message_id:
|
||||||
|
await old_channel.get_partial_message(group.message_id).delete()
|
||||||
|
|
||||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
||||||
|
|
||||||
@group.subcommand(
|
@group.subcommand(
|
||||||
|
|||||||
@@ -18,13 +18,116 @@ from agon.utils import autofill_categories, autofill_groups, submit_score
|
|||||||
class SubmissionCog(commands.Cog):
|
class SubmissionCog(commands.Cog):
|
||||||
"""Class holds command for submitting a score."""
|
"""Class holds command for submitting a score."""
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
return
|
|
||||||
|
|
||||||
# TODO(imcompiling): fix too many return statements when reworking command.
|
|
||||||
# https://gitea.cheezers.org/imcompiling/agon/issues/76
|
|
||||||
@nextcord.slash_command()
|
@nextcord.slash_command()
|
||||||
async def submit( # noqa: PLR0911, PLR0913
|
async def submit(self, interaction: nextcord.Interaction) -> None:
|
||||||
|
"""Parent slash command for submitting scores. Never called."""
|
||||||
|
|
||||||
|
@submit.subcommand(name="int", description="Submit an integer type score.")
|
||||||
|
async def integer( # noqa: PLR0911, PLR0913
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
group_id: str = nextcord.SlashOption(name="group", required=True, description="Group to submit score to."),
|
||||||
|
category_id: str = nextcord.SlashOption(
|
||||||
|
name="category", required=True, description="Category to submit score to."
|
||||||
|
),
|
||||||
|
score: int = nextcord.SlashOption(required=True, description="Score to submit", min_value=0),
|
||||||
|
proof: nextcord.Attachment = nextcord.SlashOption(
|
||||||
|
required=False, description="Proof for submission. Only needed if score requires verification."
|
||||||
|
),
|
||||||
|
username: str = nextcord.SlashOption(
|
||||||
|
required=False, description="Modified username if submitting under not your discord name."
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Submit a highscore.
|
||||||
|
|
||||||
|
Sets the username if one isn't passed in. Checks if a submission needs verified. Ensures that the score is
|
||||||
|
following the correct format. Then either creates the verification request or submits score if verification
|
||||||
|
isn't required.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction of the command.
|
||||||
|
group_id (str): Is SlashOption. Group that the score category belongs in.
|
||||||
|
category_id (str): Is SlashOption. Category to submit the score in.
|
||||||
|
score (str): Is SlashOption. The score.
|
||||||
|
proof (nextcord.Attachment): Is SlashOption. Picture to provide proof of score.
|
||||||
|
username (str, optional): Is SlashOption. Username to associate with the score.
|
||||||
|
"""
|
||||||
|
if interaction.guild is None or interaction.user is None or interaction.guild_id is None:
|
||||||
|
# Type checking for pylance's sake.
|
||||||
|
await interaction.response.send_message("Error with guild or user.", ephemeral=True)
|
||||||
|
return
|
||||||
|
# fill out username if not passed in
|
||||||
|
if username is None:
|
||||||
|
username = interaction.user.display_name
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
|
stmt = (
|
||||||
|
select(Category)
|
||||||
|
.where(col(Category.group_id) == int(group_id))
|
||||||
|
.where(col(Category.id) == int(category_id))
|
||||||
|
)
|
||||||
|
if (category := session.scalar(stmt)) is None:
|
||||||
|
await interaction.response.send_message("Category not found.", ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
# check if verification is required. if no picture, deny
|
||||||
|
if category.is_validated and proof is None:
|
||||||
|
await interaction.response.send_message(
|
||||||
|
"This category required verification. Please attach a picture and re-submit.", ephemeral=True
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Create submission verification request or submit score if verification not needed.
|
||||||
|
if not category.is_validated:
|
||||||
|
await submit_score(interaction, int(group_id), int(category_id), username, score)
|
||||||
|
await interaction.response.send_message("Score has been submitted!", ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
stmt = select(col(Guild.verification_channel)).where(col(Guild.id) == interaction.guild_id)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
if not isinstance(channel, nextcord.TextChannel | nextcord.Thread):
|
||||||
|
await interaction.response.send_message("An error happened with submission.")
|
||||||
|
agon_logger.error(
|
||||||
|
"Channel id %s in guild %s is does not correspond to a TextChannel.", channel.id, channel.guild.id
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Send the verification message to admins
|
||||||
|
verification_message = await channel.send(
|
||||||
|
file=await proof.to_file(),
|
||||||
|
view=VerificationView(),
|
||||||
|
embeds=[self.create_embed(interaction, group_id, category_id, score, username, session)],
|
||||||
|
content=f"Submission from <@{interaction.user.id}>.",
|
||||||
|
)
|
||||||
|
await interaction.response.send_message(content="Score submitted!", ephemeral=True)
|
||||||
|
|
||||||
|
# Save the submission data for later use.
|
||||||
|
submission: Submission = Submission(
|
||||||
|
category_id=int(category_id),
|
||||||
|
group_id=int(group_id),
|
||||||
|
guild_id=interaction.guild_id,
|
||||||
|
message_id=verification_message.id,
|
||||||
|
score=score,
|
||||||
|
user_id=interaction.user.id,
|
||||||
|
username=username,
|
||||||
|
)
|
||||||
|
|
||||||
|
session.add(submission)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
@nextcord.slash_command()
|
||||||
|
async def old_submit( # noqa: PLR0911, PLR0913
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
group_id: str = nextcord.SlashOption(name="group", required=True, description="Group to submit score to."),
|
group_id: str = nextcord.SlashOption(name="group", required=True, description="Group to submit score to."),
|
||||||
@@ -80,9 +183,7 @@ class SubmissionCog(commands.Cog):
|
|||||||
if (
|
if (
|
||||||
verified_score := await self.verify_score(interaction, score, is_time_record=category.is_time_record)
|
verified_score := await self.verify_score(interaction, score, is_time_record=category.is_time_record)
|
||||||
) is None:
|
) is None:
|
||||||
# This response message will be filled out better once command is split up to
|
# Verify score handles responding. Might change when submit is split up.
|
||||||
# know which type it expects...
|
|
||||||
await interaction.response.send_message("Format was incorrect.", ephemeral=True)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Create submission verification request or submit score if verification not needed.
|
# Create submission verification request or submit score if verification not needed.
|
||||||
@@ -103,7 +204,7 @@ class SubmissionCog(commands.Cog):
|
|||||||
await interaction.response.send_message(error_response, ephemeral=True)
|
await interaction.response.send_message(error_response, ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not isinstance(channel, nextcord.TextChannel):
|
if not isinstance(channel, nextcord.TextChannel | nextcord.Thread):
|
||||||
await interaction.response.send_message("An error happened with submission.")
|
await interaction.response.send_message("An error happened with submission.")
|
||||||
agon_logger.error(
|
agon_logger.error(
|
||||||
"Channel id %s in guild %s is does not correspond to a TextChannel.", channel.id, channel.guild.id
|
"Channel id %s in guild %s is does not correspond to a TextChannel.", channel.id, channel.guild.id
|
||||||
@@ -138,7 +239,7 @@ class SubmissionCog(commands.Cog):
|
|||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
group_id: str,
|
group_id: str,
|
||||||
category_id: str,
|
category_id: str,
|
||||||
score: str,
|
score: str | float,
|
||||||
username: str,
|
username: str,
|
||||||
session: Session,
|
session: Session,
|
||||||
) -> nextcord.Embed:
|
) -> nextcord.Embed:
|
||||||
@@ -149,7 +250,7 @@ class SubmissionCog(commands.Cog):
|
|||||||
interaction (nextcord.Interaction): Discord interaction of the command.
|
interaction (nextcord.Interaction): Discord interaction of the command.
|
||||||
group_id (str): Used to get group name.
|
group_id (str): Used to get group name.
|
||||||
category_id (str): Used to get category name.
|
category_id (str): Used to get category name.
|
||||||
score (str): Score to set.
|
score (str | float): Score to set.
|
||||||
username (str): Username to set.
|
username (str): Username to set.
|
||||||
session (Session): Open connection to database.
|
session (Session): Open connection to database.
|
||||||
|
|
||||||
@@ -172,6 +273,8 @@ class SubmissionCog(commands.Cog):
|
|||||||
select(col(Category.name)).where(col(Category.group_id) == group_id).where(col(Category.id) == category_id)
|
select(col(Category.name)).where(col(Category.group_id) == group_id).where(col(Category.id) == category_id)
|
||||||
)
|
)
|
||||||
embed.add_field(name="Category", value=session.scalar(stmt), inline=False)
|
embed.add_field(name="Category", value=session.scalar(stmt), inline=False)
|
||||||
|
if not isinstance(score, str):
|
||||||
|
score = str(score)
|
||||||
embed.add_field(name="Score", value=score, inline=False)
|
embed.add_field(name="Score", value=score, inline=False)
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
@@ -216,7 +319,7 @@ class SubmissionCog(commands.Cog):
|
|||||||
|
|
||||||
return score
|
return score
|
||||||
|
|
||||||
@submit.on_autocomplete("group_id")
|
@integer.on_autocomplete("group_id")
|
||||||
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
|
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
|
||||||
"""
|
"""
|
||||||
Autocomplete function for group names.
|
Autocomplete function for group names.
|
||||||
@@ -227,7 +330,7 @@ class SubmissionCog(commands.Cog):
|
|||||||
"""
|
"""
|
||||||
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
||||||
|
|
||||||
@submit.on_autocomplete("category_id")
|
@integer.on_autocomplete("category_id")
|
||||||
async def category_autocomplete(self, interaction: nextcord.Interaction, category_id: str, group_id: str) -> None:
|
async def category_autocomplete(self, interaction: nextcord.Interaction, category_id: str, group_id: str) -> None:
|
||||||
"""
|
"""
|
||||||
Autocomplete function for category names.
|
Autocomplete function for category names.
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class DeleteConfirmView(nextcord.ui.Modal):
|
|||||||
session.delete(group)
|
session.delete(group)
|
||||||
# delete the message related to group
|
# delete the message related to group
|
||||||
channel = interaction.guild.get_channel(group.channel_id)
|
channel = interaction.guild.get_channel(group.channel_id)
|
||||||
if not isinstance(channel, nextcord.TextChannel):
|
if not isinstance(channel, nextcord.TextChannel | nextcord.Thread):
|
||||||
return
|
return
|
||||||
message: nextcord.Message = await channel.fetch_message(group.message_id)
|
message: nextcord.Message = await channel.fetch_message(group.message_id)
|
||||||
await message.delete()
|
await message.delete()
|
||||||
|
|||||||
+13
-7
@@ -342,11 +342,13 @@ async def send_highscore_message(session: Session, guild: nextcord.Guild, group:
|
|||||||
group (CategoryGroup): group to post to the message.
|
group (CategoryGroup): group to post to the message.
|
||||||
"""
|
"""
|
||||||
highscore_string = format_highscore_message(session, group)
|
highscore_string = format_highscore_message(session, group)
|
||||||
channel = guild.get_channel(group.channel_id)
|
if (channel := guild.get_channel(group.channel_id)) is None:
|
||||||
|
agon_logger.error("Channel id %s in guild %s does not exist.", group.channel_id, guild.id)
|
||||||
|
return
|
||||||
|
|
||||||
if not isinstance(channel, nextcord.TextChannel):
|
if not isinstance(channel, nextcord.TextChannel | nextcord.Thread):
|
||||||
agon_logger.error(
|
agon_logger.error(
|
||||||
"Channel id %s in guild %s is does not correspond to a TextChannel.", channel.id, channel.guild.id
|
"Channel id %s in guild %s is does not correspond to a TextChannel or Thread.", channel.id, channel.guild.id
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -356,10 +358,14 @@ async def send_highscore_message(session: Session, guild: nextcord.Guild, group:
|
|||||||
group.message_id = message.id
|
group.message_id = message.id
|
||||||
session.commit()
|
session.commit()
|
||||||
else:
|
else:
|
||||||
# TODO(imcompiling): check what happens when message is deleted.
|
try:
|
||||||
# https://gitea.cheezers.org/imcompiling/agon/issues/83
|
message: nextcord.Message = await channel.fetch_message(group.message_id)
|
||||||
message: nextcord.Message = await channel.fetch_message(group.message_id)
|
await message.edit(content=highscore_string)
|
||||||
await message.edit(content=highscore_string)
|
except nextcord.NotFound:
|
||||||
|
# Message was deleted on discord's side.
|
||||||
|
message: nextcord.Message = await channel.send(highscore_string)
|
||||||
|
group.message_id = message.id
|
||||||
|
session.commit()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user