Move all files into agon module.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
"""Cog for creating submission process."""
|
||||
|
||||
from nextcord.ext import commands
|
||||
|
||||
from .submission_views import SubmissionCreateButton
|
||||
from .verification_view import VerificationView
|
||||
|
||||
|
||||
class SubmissionCog(commands.Cog, name="Submission Cog"):
|
||||
"""Constructs submission method."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self) -> None:
|
||||
"""Called when cog is loaded."""
|
||||
self.bot.add_view(SubmissionCreateButton(self.bot))
|
||||
self.bot.add_view(VerificationView())
|
||||
|
||||
|
||||
# This function will be called when this extension is loaded.
|
||||
# It is necessary to add these functions to the bot.
|
||||
def setup(bot: commands.Bot) -> None:
|
||||
"""Adds function to bot."""
|
||||
bot.add_cog(SubmissionCog(bot))
|
||||
@@ -0,0 +1,23 @@
|
||||
"""Views used for submission process."""
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
|
||||
|
||||
class SubmissionCreateButton(nextcord.ui.View):
|
||||
"""Defines view for score submission button."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
super().__init__(timeout=None)
|
||||
self._bot = bot
|
||||
|
||||
@nextcord.ui.button(label="Submit", style=nextcord.ButtonStyle.primary, custom_id="submitcreate")
|
||||
async def submitcreate_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
|
||||
"""
|
||||
Button for score submission.
|
||||
|
||||
Is deprecated, sends response telling user to use the new command instead.
|
||||
"""
|
||||
await interaction.response.send_message(
|
||||
"This feature has been deprecated. Please use the '/submit' slash command instead.", ephemeral=True
|
||||
)
|
||||
@@ -0,0 +1,54 @@
|
||||
"""View for verification buttons."""
|
||||
|
||||
import nextcord
|
||||
from sqlalchemy import delete, select
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlmodel import col
|
||||
|
||||
from database.db import engine
|
||||
from database.models import Submission
|
||||
from utilities.utils import submit_score
|
||||
|
||||
|
||||
class VerificationView(nextcord.ui.View):
|
||||
"""Defines views for verifying score submissions."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__(timeout=None)
|
||||
|
||||
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-button-submission")
|
||||
async def deny_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
|
||||
"""Button for denying score submission."""
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
delete(Submission)
|
||||
.where(col(Submission.guild_id) == interaction.guild_id)
|
||||
.where(col(Submission.message_id) == interaction.message.id)
|
||||
)
|
||||
session.execute(stmt)
|
||||
session.commit()
|
||||
await interaction.message.delete()
|
||||
|
||||
@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
|
||||
"""Button for approving score submission."""
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(Submission)
|
||||
.where(col(Submission.guild_id) == interaction.guild_id)
|
||||
.where(col(Submission.message_id) == interaction.message.id)
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
await submit_score(
|
||||
interaction, submission.group_id, submission.category_id, submission.username, submission.score
|
||||
)
|
||||
session.delete(submission)
|
||||
session.commit()
|
||||
content = interaction.message.content
|
||||
content += f"\nApproved by <@{interaction.user.id}>."
|
||||
await interaction.message.edit(content=content, view=None)
|
||||
Reference in New Issue
Block a user