Compare commits

...
5 changed files with 46 additions and 46 deletions
+12 -22
View File
@@ -1,29 +1,21 @@
""" """Commands for helping a user."""
Commands for helping a user.
"""
import nextcord import nextcord
from nextcord.ext import commands from nextcord.ext import commands
class HelpCog(commands.Cog, name="Help commands."): class HelpCog(commands.Cog, name="Help commands."):
""" """Class holds commands for getting help."""
Class holds commands for getting help.
"""
def __init__(self) -> None: def __init__(self) -> None:
""" """Default constructor for HelpCog class. Does nothing."""
Default constructor for HelpCog class. Does nothing.
"""
@nextcord.slash_command() @nextcord.slash_command()
async def help(self, interaction: nextcord.Interaction): async def help(self, interaction: nextcord.Interaction):
""" """Parent slash command for help. Never called."""
Parent slash command for help. Never called.
"""
@help.subcommand(description="Describes how to get started with Agon.") @help.subcommand(description="Describes how to get started with Agon.")
async def setup(self, interaction: nextcord.Interaction): async def setup(self, interaction: nextcord.Interaction) -> None:
""" """
Sends a message describing how to get started with Agon. Sends a message describing how to get started with Agon.
@@ -31,15 +23,13 @@ class HelpCog(commands.Cog, name="Help commands."):
interaction (nextcord.Interaction): Interaction that invoked the command. interaction (nextcord.Interaction): Interaction that invoked the command.
""" """
# I hate this but don't want indents in the string. # I hate this but don't want indents in the string.
# pylint: disable=line-too-long
help_str: str = """Welcome to Agon! Three simple steps are needed to get started.
1.) Set a channel to recieve submission verifications with "/set verify_channel."
This channel is used to allow moderators to check if a submission is real/valid.
2.) Set a channel for submissions to be posted in with "/set submission_channel." help_str: str = "Welcome to Agon! Three simple steps are needed to get started."
This channel will be where all user submission messages are sent. help_str += '1.) Set a channel to receive submission verifications with "/set verify_channel."\n'
help_str += "This channel is used to allow moderators to check if a submission is real/valid.\n\n"
3.) Set up your highscore tables! Use "/create group" to first create a group message in the channel you would like and then use "/create category" to create a category in that group message!""" help_str += '2.) Set up your highscore tables! Use "/create group" to first create a group message in the'
# pylint: enable=line-too-long help_str += 'channel you would like and then use "/create category" to create a category in that group message!'
help_str += "\n\n"
help_str += '3.) Users can then submit scores with the "/submit" command.'
await interaction.response.send_message(content=help_str) await interaction.response.send_message(content=help_str)
+3 -1
View File
@@ -103,7 +103,9 @@ class SetCog(commands.Cog, name="Set command."):
f"Category pad length set to {length} for {group.GroupName}", ephemeral=True f"Category pad length set to {length} for {group.GroupName}", ephemeral=True
) )
@set.subcommand(description="Registers the channel for submission messages.") @set.subcommand(
description="Registers the channel for submission messages. Currently this information is deprecated."
)
async def submission_channel( async def submission_channel(
self, self,
interaction: nextcord.Interaction, interaction: nextcord.Interaction,
+7 -3
View File
@@ -20,7 +20,7 @@ class SubmissionCog(commands.Cog):
return return
@nextcord.slash_command(guild_ids=GUILDS) @nextcord.slash_command(guild_ids=GUILDS)
async def submit( async def submit( # noqa: 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."),
@@ -28,6 +28,9 @@ class SubmissionCog(commands.Cog):
name="category", required=True, description="Category to submit score to." name="category", required=True, description="Category to submit score to."
), ),
score: str = nextcord.SlashOption(required=True, description="Score to submit"), score: str = nextcord.SlashOption(required=True, description="Score to submit"),
proof: nextcord.Attachment = nextcord.SlashOption(
required=False, description="Proof for submission. Only needed if score requires verification."
),
username: str = nextcord.SlashOption( username: str = nextcord.SlashOption(
required=False, description="Modified username if submitting under not your discord name." required=False, description="Modified username if submitting under not your discord name."
), ),
@@ -58,7 +61,7 @@ class SubmissionCog(commands.Cog):
category: Category = session.scalar(stmt) category: Category = session.scalar(stmt)
# check if verification is required. if no picture, deny # check if verification is required. if no picture, deny
if category.IsValidated and not len(interaction.message.attachments) > 0: if category.IsValidated and proof is None:
await interaction.response.send_message( await interaction.response.send_message(
"This category required verification. Please attach a picture and re-submit.", ephemeral=True "This category required verification. Please attach a picture and re-submit.", ephemeral=True
) )
@@ -98,7 +101,7 @@ class SubmissionCog(commands.Cog):
# Send the verification message to admins # Send the verification message to admins
verification_message = await channel.send( verification_message = await channel.send(
files=[await attach.to_file() for attach in interaction.message.attachments], file=await proof.to_file(),
view=VerificationView(), view=VerificationView(),
embeds=[self.create_embed(interaction, group_id, category_id, verified_score, username, session)], embeds=[self.create_embed(interaction, group_id, category_id, verified_score, username, session)],
content=f"Submission from <@{interaction.user.id}>.", content=f"Submission from <@{interaction.user.id}>.",
@@ -112,6 +115,7 @@ class SubmissionCog(commands.Cog):
GuildId=interaction.guild_id, GuildId=interaction.guild_id,
MessageId=verification_message.id, MessageId=verification_message.id,
Score=verified_score, Score=verified_score,
UserId=interaction.user.id,
UserName=username, UserName=username,
) )
+20 -17
View File
@@ -1,6 +1,10 @@
"""View for verification buttons.""" """View for verification buttons."""
import nextcord import nextcord
from sqlalchemy import select
from sqlalchemy.orm import Session
from database_setup.sql_data_classes import Submission, engine
# pylint: disable=import-error # pylint: disable=import-error
from utilities.utils import submit_score from utilities.utils import submit_score
@@ -20,25 +24,24 @@ class VerificationView(nextcord.ui.View):
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-button-submission") @nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-button-submission")
async def approve_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002 async def approve_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
"""Button for approving score submission.""" """Button for approving score submission."""
for embed in interaction.message.embeds: with Session(engine) as session:
content = embed.to_dict() stmt = (
select(Submission)
.where(Submission.GuildId == interaction.guild_id)
.where(Submission.MessageId == interaction.message.id)
)
for field in content["fields"]: submission = session.scalar(stmt)
if field["name"] == "GroupId":
group_id = int(field["value"])
elif field["name"] == "CategoryId":
category_id = int(field["value"])
elif field["name"] == "Score":
score = field["value"]
elif field["name"] == "User Name":
user = field["value"]
try: if submission is None:
await submit_score(interaction, group_id, category_id, user, score) await interaction.response.send_message("Could not find submission data in database.", ephemeral=True)
await interaction.message.delete()
return
await submit_score(
interaction, submission.GroupId, submission.CategoryId, submission.UserName, submission.Score
)
content = interaction.message.content content = interaction.message.content
content += f"\nApproved by <@{interaction.user.id}>." content += f"\nApproved by <@{interaction.user.id}>."
# remove the bot information embed. it should always be the first one. # remove the bot information embed. it should always be the first one.
await interaction.message.edit(content=content, view=None, embed=interaction.message.embeds[0]) await interaction.message.edit(content=content, view=None)
except UnboundLocalError:
await interaction.send("Instruct user to submit with all fields.")
await interaction.message.edit(view=None)
+4 -3
View File
@@ -4,7 +4,7 @@ use highscores;
CREATE TABLE Guilds( CREATE TABLE Guilds(
GuildId bigint unsigned not null unique, GuildId bigint unsigned not null unique,
GuildName varchar(95) not null, GuildName varchar(95) not null,
SubmissionChannel bigint unsigned, SubmissionChannel bigint unsigned, -- deprecated, is not used anymore.
VerificationChannel bigint unsigned, VerificationChannel bigint unsigned,
Active boolean DEFAULT true, Active boolean DEFAULT true,
PRIMARY KEY (GuildId) PRIMARY KEY (GuildId)
@@ -47,9 +47,10 @@ CREATE TABLE Scores(
CREATE TABLE Submissions( CREATE TABLE Submissions(
CategoryId int unsigned not null, CategoryId int unsigned not null,
GroupId int unsigned not null, GroupId int unsigned not null,
GuildId int unsigned not null, GuildId bigint unsigned not null,
MessageId int unsigned not null, MessageId bigint unsigned not null,
Score varchar(30) not null, -- Score is stored as a string until converted during submission Score varchar(30) not null, -- Score is stored as a string until converted during submission
UserId bigint unsigned not null,
UserName varchar(30) not null, UserName varchar(30) not null,
PRIMARY KEY (CategoryId, UserName) -- one submission a category per user. PRIMARY KEY (CategoryId, UserName) -- one submission a category per user.
); );