Compare commits
152
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ffb7fa9a7 | ||
|
|
2566bee0ce | ||
|
|
3d113a06d4 | ||
|
|
2e3b8c86da | ||
|
|
058e3aefa1 | ||
|
|
7a4ba3a5af | ||
|
|
2f5f25ea75 | ||
|
|
fd476ce512 | ||
|
|
9588cdc8a0 | ||
|
|
17769022bc | ||
|
|
a46dc0388c | ||
|
|
553f79425f | ||
|
|
72cd6e9fd1 | ||
|
|
f63984e25a | ||
|
|
48a91dca3d | ||
|
|
5eb637a3a8 | ||
|
|
f722eb1a83 | ||
|
|
7759bbc648 | ||
|
|
65de7baeda | ||
|
|
e243404480 | ||
|
|
f735e6d846 | ||
|
|
9fbaf7bcf6 | ||
|
|
1959e11e5c | ||
|
|
c25d354fc0 | ||
|
|
e5d90a71d9 | ||
|
|
785a4eff46 | ||
|
|
627112b114 | ||
|
|
9b3bd9d02c | ||
|
|
2c56c614f3 | ||
|
|
3ccaa7004e | ||
|
|
289113661f | ||
|
|
74ce22dd26 | ||
|
|
170ce1cbfb | ||
|
|
e1b761e848 | ||
|
|
68592a7df8 | ||
|
|
b28938f66a | ||
|
|
adab97f505 | ||
|
|
edf51aac2d | ||
|
|
dbc6474fc3 | ||
|
|
ed68c4174f | ||
|
|
3abbff13d5 | ||
|
|
304b089113 | ||
|
|
29a163ec46 | ||
|
|
76fbba739f | ||
|
|
7204e882f1 | ||
|
|
a8d775ca09 | ||
|
|
983b9b6f34 | ||
|
|
84c910b19c | ||
|
|
1fcb25193d | ||
|
|
f52b2fe49f | ||
|
|
24a9fa998a | ||
|
|
4785271ebb | ||
|
|
f9d765ad92 | ||
|
|
50868988c0 | ||
|
|
81ae867a43 | ||
|
|
2649ceb6bb | ||
|
|
6e02bc877f | ||
|
|
f61ad83e11 | ||
|
|
feeb47d3da | ||
|
|
0ff1b07096 | ||
|
|
8674eed0c5 | ||
|
|
e2ddd5412a | ||
|
|
f37844c953 | ||
|
|
d703c76704 | ||
|
|
6e25d4e75a | ||
|
|
0702198f0a | ||
|
|
43df7aeda7 | ||
|
|
c8becb8203 | ||
|
|
44d813504a | ||
|
|
3fc8910c9a | ||
|
|
563b6ab888 | ||
|
|
d7e44d3a22 | ||
|
|
a99b488ae1 | ||
|
|
85d0077107 | ||
|
|
9510c9eddc | ||
|
|
9550d1a68b | ||
|
|
b04819aa36 | ||
|
|
f43dccb12d | ||
|
|
9cf05f44d0 | ||
|
|
f6ae34c9e6 | ||
|
|
528af14e00 | ||
|
|
dbe652dcce | ||
|
|
1658638938 | ||
|
|
63db4c1dd2 | ||
|
|
43f51f7f07 | ||
|
|
f74b08b02e | ||
|
|
9dd07bef93 | ||
|
|
231c700946 | ||
|
|
37daa0e657 | ||
|
|
6dfd3acad0 | ||
|
|
ce3ed3c001 | ||
|
|
0ad425b982 | ||
|
|
cf5629a6dd | ||
|
|
37fb9c1abb | ||
|
|
157b8d4f3f | ||
|
|
1c3fb231b7 | ||
|
|
b72dd35e04 | ||
|
|
0b2a1cd293 | ||
|
|
f1f0c0c6de | ||
|
|
36eae17751 | ||
|
|
7a57b75ca3 | ||
|
|
0ea9ef5b41 | ||
|
|
e13790ba08 | ||
|
|
171a1b0840 | ||
|
|
8604ba2547 | ||
|
|
bd365d575f | ||
|
|
0e262d5972 | ||
|
|
774e6ffedf | ||
|
|
de2542ece6 | ||
|
|
c29194a30a | ||
|
|
8870d93a44 | ||
|
|
6a26440c4d | ||
|
|
2735d6877f | ||
|
|
117f5655d7 | ||
|
|
c808bb2610 | ||
|
|
5e7b3790eb | ||
|
|
07ea150ad3 | ||
|
|
9280bbfbca | ||
|
|
abf076fceb | ||
|
|
0c0997624f | ||
|
|
67090e0d6f | ||
|
|
385129c434 | ||
|
|
327126307d | ||
|
|
36dad683d8 | ||
|
|
9be9279239 | ||
|
|
ffc5c20fec | ||
|
|
65453eb7d6 | ||
|
|
2ad1c808c2 | ||
|
|
3898e5e494 | ||
|
|
b16132d61b | ||
|
|
d3aaf642bd | ||
|
|
1902c486fd | ||
|
|
7e90e7c819 | ||
|
|
279d3f4885 | ||
|
|
2c0f7f91c1 | ||
|
|
d699f8b3e7 | ||
|
|
56ced3f8a2 | ||
|
|
ed4f8681c8 | ||
|
|
d52008c536 | ||
|
|
8d0d0acc3b | ||
|
|
9a1c3db7f9 | ||
|
|
96d78213ff | ||
|
|
cdb54658ee | ||
|
|
4ce37ee3ea | ||
|
|
c62b87c7f7 | ||
|
|
ba04858328 | ||
|
|
a12fca6220 | ||
|
|
136702654e | ||
|
|
23adad403a | ||
|
|
3a72d9f0e7 | ||
|
|
da0acb2827 | ||
|
|
0baffe96f3 |
@@ -1,2 +1,5 @@
|
||||
.*
|
||||
Dockerfile
|
||||
LICENSE
|
||||
README.md
|
||||
renovate.json
|
||||
|
||||
@@ -2,7 +2,11 @@ name: build_develop
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
branches:
|
||||
- "*"
|
||||
- "!main"
|
||||
paths-ignore:
|
||||
- "README.md"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -15,12 +19,14 @@ jobs:
|
||||
- name: Install Docker
|
||||
uses: https://github.com/papodaca/install-docker-action@v1
|
||||
- name: Log into container registry
|
||||
uses: docker/login-action@v2
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: gitea.cheezers.org
|
||||
username: imcompiling
|
||||
password: ${{ secrets.PASSWORD }}
|
||||
- name: set env
|
||||
run: echo "GIT_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_ENV
|
||||
- name: Build Docker Image
|
||||
run: docker build -t gitea.cheezers.org/imcompiling/agon:develop .
|
||||
run: docker build -t gitea.cheezers.org/imcompiling/agon:${{env.GIT_BRANCH}} .
|
||||
- name: Push Docker Image
|
||||
run: docker push gitea.cheezers.org/imcompiling/agon:develop
|
||||
run: docker push gitea.cheezers.org/imcompiling/agon:${{env.GIT_BRANCH}}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
name: build_latest
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths-ignore:
|
||||
- "README.md"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Install Docker
|
||||
uses: https://github.com/papodaca/install-docker-action@v1
|
||||
- name: Log into container registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: gitea.cheezers.org
|
||||
username: imcompiling
|
||||
password: ${{ secrets.PASSWORD }}
|
||||
- name: Build Docker Image
|
||||
run: docker build -t gitea.cheezers.org/imcompiling/agon:latest .
|
||||
- name: Push Docker Image
|
||||
run: docker push gitea.cheezers.org/imcompiling/agon:latest
|
||||
@@ -9,13 +9,13 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Install Docker
|
||||
uses: https://github.com/papodaca/install-docker-action@v1
|
||||
- name: Log into container registry
|
||||
uses: docker/login-action@v2
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: gitea.cheezers.org
|
||||
username: imcompiling
|
||||
@@ -23,8 +23,6 @@ jobs:
|
||||
- name: Set env
|
||||
run: echo "GIT_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
- name: Build Docker Images
|
||||
run: docker build -t gitea.cheezers.org/imcompiling/agon:latest -t gitea.cheezers.org/imcompiling/agon:${{env.GIT_TAG}} .
|
||||
- name: Push Latest Image
|
||||
run: docker push gitea.cheezers.org/imcompiling/agon:latest
|
||||
run: docker build -t gitea.cheezers.org/imcompiling/agon:${{env.GIT_TAG}} .
|
||||
- name: Push Tagged Image
|
||||
run: docker push gitea.cheezers.org/imcompiling/agon:${{env.GIT_TAG}}
|
||||
|
||||
+1
-3
@@ -125,9 +125,6 @@ dmypy.json
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# IDE
|
||||
.vscode/
|
||||
|
||||
# logging
|
||||
nextcord.log
|
||||
|
||||
@@ -138,3 +135,4 @@ deleted_backups/
|
||||
highscores_data/
|
||||
TODO.txt
|
||||
sql_tester.py
|
||||
/database
|
||||
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"kevinrose.vsc-python-indent",
|
||||
"charliermarsh.ruff",
|
||||
"donjayamanne.python-extension-pack"
|
||||
]
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python: Module",
|
||||
"type": "debugpy",
|
||||
"request": "launch",
|
||||
"module": "agon",
|
||||
"justMyCode": true
|
||||
}
|
||||
]
|
||||
}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"dotenv",
|
||||
"gmtime",
|
||||
"highscore",
|
||||
"highscores",
|
||||
"imcompiling",
|
||||
"iterrows",
|
||||
"nextcord",
|
||||
"ondelete"
|
||||
],
|
||||
"python.analysis.diagnosticSeverityOverrides": {
|
||||
"reportOptionalMemberAccess": "warning",
|
||||
"reportArgumentType": "information",
|
||||
"reportAttributeAccessIssue": "warning"
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
FROM python:3.12.3-slim
|
||||
|
||||
# install uv
|
||||
COPY --from=ghcr.io/astral-sh/uv:0.4.30 /uv /uvx /bin/
|
||||
COPY --from=ghcr.io/astral-sh/uv:0.6.6 /uv /uvx /bin/
|
||||
|
||||
RUN apt-get update && apt-get -y upgrade && apt-get -y install sqlite3
|
||||
|
||||
# Copy project to image
|
||||
ADD . /agon
|
||||
ADD . /home
|
||||
|
||||
# Sync the project into a new environment, using the frozen lockfile
|
||||
WORKDIR /agon
|
||||
WORKDIR /home
|
||||
RUN uv sync --frozen --no-dev
|
||||
|
||||
CMD ["uv", "run", "./main.py"]
|
||||
CMD ["uv", "run", "--frozen", "--no-dev", "-m", "agon"]
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
"""Empty init file for off_cooldown_bot module."""
|
||||
@@ -0,0 +1,14 @@
|
||||
"""Starts the app for agon."""
|
||||
|
||||
import logging
|
||||
|
||||
from .app import run
|
||||
|
||||
nextcord_logger = logging.getLogger("nextcord")
|
||||
nextcord_logger.setLevel(logging.DEBUG)
|
||||
nextcord_handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w")
|
||||
nextcord_handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
|
||||
nextcord_logger.addHandler(nextcord_handler)
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
"""Main file for Agon bot."""
|
||||
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
|
||||
from . import config
|
||||
from .logger import agon_logger
|
||||
|
||||
|
||||
def run() -> None:
|
||||
"""Main function for bot."""
|
||||
min_python_version = (3, 12)
|
||||
if sys.version_info < min_python_version:
|
||||
agon_logger.error("ERROR: Python version must be >= 3.12")
|
||||
sys.exit()
|
||||
|
||||
# Allows privileged intents for monitoring members joining, roles editing, and role assignments
|
||||
# These need to be enabled in the developer portal as well
|
||||
intents = nextcord.Intents.default()
|
||||
|
||||
bot = commands.Bot(
|
||||
commands.when_mentioned_or(config.BOT_PREFIX),
|
||||
intents=intents,
|
||||
)
|
||||
|
||||
# Get the modules of all cogs whose directory structure is ./cogs/<module_name>
|
||||
for folder in pathlib.Path("./agon/cogs").iterdir():
|
||||
bot.load_extension(f"agon.cogs.{folder.name}")
|
||||
|
||||
@bot.listen()
|
||||
async def on_ready() -> None:
|
||||
"""When Discord is connected."""
|
||||
if bot.user is None:
|
||||
agon_logger.error("Discord connection failed.")
|
||||
return
|
||||
agon_logger.info("%s has connected to Discord!", bot.user.name)
|
||||
|
||||
# Run Discord bot
|
||||
bot.run(config.DISCORD_TOKEN)
|
||||
@@ -0,0 +1,28 @@
|
||||
"""Cog loader. Adds all command cogs to the bot."""
|
||||
|
||||
from nextcord.ext import commands
|
||||
|
||||
from agon.cogs.commands.create import CreateCog
|
||||
from agon.cogs.commands.delete import DeleteCog
|
||||
from agon.cogs.commands.get import GetCog
|
||||
from agon.cogs.commands.help import HelpCog
|
||||
from agon.cogs.commands.refresh import RefreshCog
|
||||
from agon.cogs.commands.set import SetCog
|
||||
from agon.cogs.commands.submission import SubmissionCog
|
||||
from agon.cogs.commands.update import UpdateCog
|
||||
from agon.cogs.commands.view import ViewCog
|
||||
|
||||
|
||||
# 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 all command classes to bot."""
|
||||
bot.add_cog(CreateCog(bot))
|
||||
bot.add_cog(DeleteCog())
|
||||
bot.add_cog(GetCog())
|
||||
bot.add_cog(HelpCog())
|
||||
bot.add_cog(RefreshCog(bot))
|
||||
bot.add_cog(SetCog())
|
||||
bot.add_cog(SubmissionCog())
|
||||
bot.add_cog(UpdateCog(bot))
|
||||
bot.add_cog(ViewCog())
|
||||
@@ -1,48 +1,38 @@
|
||||
"""
|
||||
Commands for creating items in bot.
|
||||
"""
|
||||
"""Commands for creating items in bot."""
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import exc, select
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlmodel import col
|
||||
|
||||
# pylint: disable=import-error
|
||||
from cogs.submission.submission_views import SubmissionCreateButton
|
||||
from database_setup.sql_data_classes import Category, CategoryGroup, engine
|
||||
from utilities.utils import MAX_LINE_LENGTH, autofill_groups, send_highscore_message
|
||||
from agon.database.db import engine
|
||||
from agon.database.models import Category, CategoryGroup
|
||||
from agon.utils import MAX_LINE_LENGTH, autofill_groups, send_highscore_message
|
||||
|
||||
|
||||
class CreateCog(commands.Cog, name="Create Cog"):
|
||||
"""
|
||||
Class holds commands for creating things.
|
||||
"""
|
||||
"""Class holds commands for creating things."""
|
||||
|
||||
def __init__(self, bot: commands.Bot) -> None:
|
||||
"""
|
||||
Default constructor for CreateCog class.
|
||||
"""
|
||||
"""Default constructor for CreateCog class."""
|
||||
self._bot = bot
|
||||
|
||||
@nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True))
|
||||
async def create(self, interaction: nextcord.Interaction):
|
||||
"""
|
||||
Parent slash command for creating things. Never called.
|
||||
"""
|
||||
async def create(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash command for creating things. Never called."""
|
||||
|
||||
# need all these arguments because discord command.
|
||||
# pylint: disable=too-many-arguments
|
||||
@create.subcommand(description="Create a new Category. Must not exist already in Group.")
|
||||
async def category(
|
||||
async def category( # noqa: PLR0913 need all these arguments because discord command.
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Group to add Category to.", required=True),
|
||||
category_name: str = nextcord.SlashOption(description="Name of new Category.", required=True),
|
||||
is_ascending: bool = nextcord.SlashOption(description="If lower value is a better score.", required=True),
|
||||
is_time_record: bool = nextcord.SlashOption(
|
||||
is_ascending: bool = nextcord.SlashOption(description="If lower value is a better score.", required=True), # noqa: FBT001
|
||||
is_time_record: bool = nextcord.SlashOption( # noqa: FBT001
|
||||
description="If the score should be shown in time format. Cannot be changed.", required=True
|
||||
),
|
||||
is_validated: bool = nextcord.SlashOption(
|
||||
is_validated: bool = nextcord.SlashOption( # noqa: FBT001
|
||||
description="If scores need to be validated before posted.", required=True
|
||||
),
|
||||
size: int = nextcord.SlashOption(
|
||||
@@ -50,8 +40,9 @@ class CreateCog(commands.Cog, name="Create Cog"):
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Creates a new category to be placed into group_id group. Fails if the category name already exists within the
|
||||
group. Then calls send_highscore_message().
|
||||
Creates a new category to be placed into group_id group.
|
||||
|
||||
Fails if the category name already exists within the group. Then calls send_highscore_message().
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction for the command.
|
||||
@@ -63,34 +54,32 @@ class CreateCog(commands.Cog, name="Create Cog"):
|
||||
size (int): How many sores to show in the category message. Is SlashOption.
|
||||
"""
|
||||
new_category = Category(
|
||||
CategoryName=category_name,
|
||||
GroupId=int(group_id),
|
||||
Size=size,
|
||||
IsAscending=is_ascending,
|
||||
IsTimeRecord=is_time_record,
|
||||
IsValidated=is_validated,
|
||||
name=category_name,
|
||||
group_id=int(group_id),
|
||||
size=size,
|
||||
is_ascending=is_ascending,
|
||||
is_time_record=is_time_record,
|
||||
is_validated=is_validated,
|
||||
)
|
||||
|
||||
# Open connection to engine and add new category.
|
||||
with Session(engine) as session:
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == int(group_id))
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == int(group_id))
|
||||
group = session.scalar(stmt)
|
||||
try:
|
||||
session.add(new_category)
|
||||
session.commit()
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
await interaction.response.send_message(
|
||||
f'"{category_name}" has been added to "{group.GroupName}"!', ephemeral=True
|
||||
f'"{category_name}" has been added to "{group.name}"!', ephemeral=True
|
||||
)
|
||||
except exc.IntegrityError:
|
||||
# Category name already exists in group
|
||||
session.rollback()
|
||||
await interaction.response.send_message(
|
||||
f'"{category_name}" already exists in "{group.GroupName}". Please rename.', ephemeral=True
|
||||
f'"{category_name}" already exists in "{group.name}". Please rename.', ephemeral=True
|
||||
)
|
||||
|
||||
# need all these arguments because discord command.
|
||||
# pylint: disable=too-many-arguments
|
||||
@create.subcommand(description="Create a new Category Group. Must not exist already for Guild.")
|
||||
async def group(
|
||||
self,
|
||||
@@ -110,16 +99,16 @@ class CreateCog(commands.Cog, name="Create Cog"):
|
||||
min_value=1,
|
||||
max_value=30,
|
||||
),
|
||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
||||
channel: nextcord.TextChannel | None = nextcord.SlashOption(
|
||||
description="Channel to post Group in. If left empty, defaults to current channel.",
|
||||
required=False,
|
||||
channel_types=[nextcord.ChannelType.text],
|
||||
default=None,
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Creates a new category group to be placed into the database with the guild's id. Fails if the category group
|
||||
name already exists within the guild. Then calls send_highscore_message().
|
||||
Creates a new category group to be placed into the database with the guild's id.
|
||||
|
||||
Fails if the category group name already exists within the guild. Then calls send_highscore_message().
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction for the command.
|
||||
@@ -131,22 +120,23 @@ class CreateCog(commands.Cog, name="Create Cog"):
|
||||
"""
|
||||
# if no channel provided, use current channel.
|
||||
if channel is None:
|
||||
channel = interaction.channel
|
||||
channel_id: int = interaction.channel.id
|
||||
else:
|
||||
channel_id: int = channel.id
|
||||
|
||||
new_group = CategoryGroup(
|
||||
GroupName=group_name,
|
||||
ChannelId=channel.id,
|
||||
GuildId=interaction.guild_id,
|
||||
PadLength=pad_length,
|
||||
UsernameLength=username_length,
|
||||
name=group_name,
|
||||
channel_id=channel_id,
|
||||
guild_id=interaction.guild_id,
|
||||
pad_length=pad_length,
|
||||
username_length=username_length,
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
try:
|
||||
session.add(new_group)
|
||||
session.commit()
|
||||
message: nextcord.Message = await send_highscore_message(session, interaction.guild, new_group)
|
||||
await message.edit(view=SubmissionCreateButton(self._bot))
|
||||
await send_highscore_message(session, interaction.guild, new_group)
|
||||
await interaction.response.send_message(f'"{group_name}" has been created!', ephemeral=True)
|
||||
except exc.IntegrityError:
|
||||
# Category Group already exists in guild
|
||||
@@ -156,9 +146,9 @@ class CreateCog(commands.Cog, name="Create Cog"):
|
||||
)
|
||||
|
||||
@category.on_autocomplete("group_id")
|
||||
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str):
|
||||
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
|
||||
"""
|
||||
Collects list of table names and compares to input table name for autocomplete assistance.
|
||||
Collects list of group names and compares to input group name for autocomplete assistance.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with command.
|
||||
@@ -1,15 +1,14 @@
|
||||
"""
|
||||
Commands for deleting groups/categories/scores in database and messages in discord..
|
||||
"""
|
||||
"""Commands for deleting groups/categories/scores in database and messages in discord."""
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import distinct, select
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlmodel import col
|
||||
|
||||
# pylint: disable=import-error
|
||||
from database_setup.sql_data_classes import Category, CategoryGroup, Score, engine
|
||||
from utilities.utils import (
|
||||
from agon.database.db import engine
|
||||
from agon.database.models import Category, CategoryGroup, Score
|
||||
from agon.utils import (
|
||||
autofill_categories,
|
||||
autofill_groups,
|
||||
autofill_users_in_group_category,
|
||||
@@ -20,41 +19,33 @@ from utilities.utils import (
|
||||
from .views.delete_confirm import DeleteConfirmView, create_delete_id
|
||||
|
||||
|
||||
class DeleteCog(commands.Cog, name="Table Management"):
|
||||
"""
|
||||
Class holds commands for deleting.
|
||||
"""
|
||||
class DeleteCog(commands.Cog, name="Delete Cog"):
|
||||
"""Class holds commands for deleting."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""
|
||||
Default constructor for DeleteCog class.
|
||||
"""
|
||||
"""Default constructor for DeleteCog class."""
|
||||
|
||||
@nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True))
|
||||
async def delete(self, interaction: nextcord.Interaction):
|
||||
"""
|
||||
Parent slash command for deleting things. Never called.
|
||||
"""
|
||||
async def delete(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash command for deleting things. Never called."""
|
||||
|
||||
@delete.subcommand()
|
||||
async def all(self, interaction: nextcord.Interaction):
|
||||
"""
|
||||
Subcommand parent for deleting all of a thing. Never called.
|
||||
"""
|
||||
async def all(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Subcommand parent for deleting all of a thing. Never called."""
|
||||
|
||||
@all.subcommand(description="Clears highscores channel of all table messages. Does not change data.")
|
||||
@all.subcommand(description="Clears highscores channel of all highscore messages. Does not change data.")
|
||||
async def channel_messages(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
||||
channel: nextcord.TextChannel | None = nextcord.SlashOption(
|
||||
description="Channel to clear of messages.",
|
||||
required=False,
|
||||
channel_types=[nextcord.ChannelType.text],
|
||||
default=None,
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Deletes all group messages from channel. Does not change data.
|
||||
|
||||
Does not delete highscores channel id. Uses current channel if not supplied a channel.
|
||||
|
||||
Args:
|
||||
@@ -63,13 +54,18 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
Is a SlashOption. Limited to text channels. Defaults to None.
|
||||
"""
|
||||
if not channel:
|
||||
if isinstance(interaction.channel, nextcord.TextChannel):
|
||||
channel = interaction.channel
|
||||
else:
|
||||
# This should never happen.
|
||||
await interaction.response.send_message("Channel is not a text channel somehow.", ephemeral=True)
|
||||
return
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
.where(CategoryGroup.ChannelId == channel.id)
|
||||
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||
.where(col(CategoryGroup.channel_id) == channel.id)
|
||||
)
|
||||
# TODO test when nothing in channel
|
||||
groups = session.scalars(stmt)
|
||||
@@ -77,17 +73,18 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
|
||||
for group in groups:
|
||||
if group.message_id is not None:
|
||||
try:
|
||||
table_message: nextcord.Message = await channel.fetch_message(group.MessageId)
|
||||
await table_message.delete()
|
||||
message: nextcord.Message = await channel.fetch_message(group.message_id)
|
||||
await message.delete()
|
||||
except nextcord.NotFound:
|
||||
# silently ignore that messages are not found. They got deleted already.
|
||||
pass
|
||||
|
||||
await interaction.send("Table messages deleted.", ephemeral=True)
|
||||
await interaction.send("Highscore messages deleted.", ephemeral=True)
|
||||
|
||||
@all.subcommand(
|
||||
description="Removes all of a user's scores. Warning: data is destroyed, use with case.",
|
||||
description="Removes all of a user's scores. Warning: data is destroyed, use with care.",
|
||||
)
|
||||
async def users(
|
||||
self,
|
||||
@@ -95,34 +92,35 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
user_name: str = nextcord.SlashOption(
|
||||
description="User to remove scores for. Note: This is not always a user's discord name.", required=True
|
||||
),
|
||||
):
|
||||
) -> None:
|
||||
"""
|
||||
Searches all of guild's scores data for any score from the user. Removes. Updates table
|
||||
message is user was removed from that table.
|
||||
Searches all of guild's scores data for any score from the user and removes.
|
||||
|
||||
Updates highscore message if user was removed from that Category Group.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
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(col(Score.category_id))).where(col(Score.username) == user_name)
|
||||
category_ids: list[int] = list(session.scalars(stmt))
|
||||
|
||||
stmt = select(Score).where(Score.UserName == user_name)
|
||||
stmt = select(Score).where(col(Score.username) == user_name)
|
||||
for score in session.scalars(stmt):
|
||||
session.delete(score)
|
||||
session.commit()
|
||||
|
||||
group_ids = select(Category.GroupId).where(Category.CategoryId.in_(category_ids))
|
||||
group_ids = select(col(Category.group_id)).where(col(Category.id).in_(category_ids))
|
||||
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GroupId.in_(group_ids))
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id).in_(group_ids))
|
||||
|
||||
for group in session.scalars(stmt):
|
||||
await send_highscore_message(session, interaction.guild, 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 Category Groups.', ephemeral=True)
|
||||
|
||||
@delete.subcommand(description="Delete a category from a group. Deletion is perminant.")
|
||||
@delete.subcommand(description="Delete a category from a group. Deletion is permanent.")
|
||||
async def category(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
@@ -141,7 +139,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
DeleteConfirmView(custom_id=create_delete_id(int(group_id), int(category_id)))
|
||||
)
|
||||
|
||||
@delete.subcommand(description="Delete a group. Deletion is perminant.")
|
||||
@delete.subcommand(description="Delete a group. Deletion is permanent.")
|
||||
async def group(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
@@ -157,10 +155,8 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
await interaction.response.send_modal(DeleteConfirmView(custom_id=create_delete_id(int(group_id))))
|
||||
|
||||
@delete.subcommand()
|
||||
async def user(self, interaction: nextcord.Interaction):
|
||||
"""
|
||||
Subcommand parent for deleting user information. Never called.
|
||||
"""
|
||||
async def user(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Subcommand parent for deleting user information. Never called."""
|
||||
|
||||
@user.subcommand(description="Deletes a user's scores from a category.")
|
||||
async def from_category(
|
||||
@@ -171,7 +167,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
name="category", description="Category to delete user from.", required=True
|
||||
),
|
||||
user_name: str = nextcord.SlashOption(description="User to delete.", required=True),
|
||||
):
|
||||
) -> None:
|
||||
"""
|
||||
Removes a user from a category. Uses autofill functions to fill out group_id, category_id, and user_name.
|
||||
|
||||
@@ -182,13 +178,15 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
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(col(CategoryGroup.id) == int(group_id))
|
||||
group = session.scalar(stmt)
|
||||
|
||||
stmt = select(Category.CategoryName).where(Category.CategoryId == int(category_id))
|
||||
stmt = select(col(Category.name)).where(col(Category.id) == int(category_id))
|
||||
category_name = session.scalar(stmt)
|
||||
|
||||
stmt = select(Score).where(Score.CategoryId == int(category_id)).where(Score.UserName == user_name)
|
||||
stmt = (
|
||||
select(Score).where(col(Score.category_id) == int(category_id)).where(col(Score.username) == user_name)
|
||||
)
|
||||
|
||||
# there should only be one because category id and username are a composite primary key in score
|
||||
session.delete(session.scalar(stmt))
|
||||
@@ -205,9 +203,9 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Group to delete user from.", required=True),
|
||||
user_name: str = nextcord.SlashOption(description="User to delete.", required=True),
|
||||
):
|
||||
) -> None:
|
||||
"""
|
||||
Removes user from a goup. Uses autofill functions to fill out group_id and user_name.
|
||||
Removes user from a group. Uses autofill functions to fill out group_id and user_name.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
@@ -215,10 +213,10 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
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(col(CategoryGroup.id) == int(group_id))
|
||||
group = session.scalar(stmt)
|
||||
category_ids = select(Category.CategoryId).where(Category.GroupId == int(group_id))
|
||||
stmt = select(Score).where(Score.CategoryId.in_(category_ids)).where(Score.UserName == user_name)
|
||||
category_ids = select(col(Category.id)).where(col(Category.group_id) == int(group_id))
|
||||
stmt = select(Score).where(col(Score.category_id).in_(category_ids)).where(col(Score.username) == user_name)
|
||||
|
||||
for score in session.scalars(stmt):
|
||||
session.delete(score)
|
||||
@@ -226,16 +224,16 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
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.name}.', ephemeral=True
|
||||
)
|
||||
|
||||
@from_category.on_autocomplete("group_id")
|
||||
@from_group.on_autocomplete("group_id")
|
||||
@category.on_autocomplete("group_id")
|
||||
@group.on_autocomplete("group_id")
|
||||
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str):
|
||||
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
|
||||
"""
|
||||
Autocomplete function for table names.
|
||||
Autocomplete function for group names.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
@@ -245,7 +243,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
|
||||
@from_category.on_autocomplete("category_id")
|
||||
@category.on_autocomplete("category_id")
|
||||
async def category_autocomplete(self, interaction: nextcord.Interaction, category_id: str, group_id: str):
|
||||
async def category_autocomplete(self, interaction: nextcord.Interaction, category_id: str, group_id: str) -> None:
|
||||
"""
|
||||
Autocomplete function for category names.
|
||||
|
||||
@@ -262,7 +260,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
@from_group.on_autocomplete("user_name")
|
||||
async def user_autocomplete(
|
||||
self, interaction: nextcord.Interaction, user_name: str, group_id: str, category_id: str | None = None
|
||||
):
|
||||
) -> None:
|
||||
"""
|
||||
Autocomplete functions for user names.
|
||||
|
||||
@@ -274,17 +272,17 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
||||
"""
|
||||
await interaction.response.send_autocomplete(
|
||||
autofill_users_in_group_category(
|
||||
interaction.guild_id, int(group_id), category_id if category_id else 0, user_name
|
||||
interaction.guild_id, int(group_id), int(category_id) if category_id else 0, user_name
|
||||
)
|
||||
)
|
||||
|
||||
@users.on_autocomplete("user_name")
|
||||
async def all_users_autocomplete(self, interaction: nextcord.Interaction, username: str):
|
||||
async def all_users_autocomplete(self, interaction: nextcord.Interaction, username: str) -> None:
|
||||
"""
|
||||
Sends response from autofill_users_in_guild back to update_username for autocompletion of old_username.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with command.
|
||||
old_username (str): String to run autocompletion against.
|
||||
username (str): String to run autocompletion against.
|
||||
"""
|
||||
await interaction.response.send_autocomplete(autofill_users_in_guild(interaction.guild_id, username))
|
||||
@@ -0,0 +1,199 @@
|
||||
"""Get command hierarchy."""
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlmodel import Session, col, select
|
||||
|
||||
from agon.database.db import engine
|
||||
from agon.database.models import Category, CategoryGroup
|
||||
from agon.utils import autofill_categories, autofill_groups
|
||||
|
||||
|
||||
class GetCog(commands.Cog, name="Get command."):
|
||||
"""Class holds commands for setting variables in guild's database."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Default constructor for SetCog class. Does nothing."""
|
||||
|
||||
@nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True))
|
||||
async def get(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash command for getting. Never called."""
|
||||
|
||||
@get.subcommand(description="Commands for getting category information.")
|
||||
async def category(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash subcommand for getting category information. Never called."""
|
||||
|
||||
@category.subcommand(description="Get whether a category is sorted in ascending or descending order.")
|
||||
async def is_ascending(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Group that Category is in.", required=True),
|
||||
category_id: str = nextcord.SlashOption(
|
||||
name="category", description="Category to information from.", required=True
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Command to view how a category is sorted.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (str): String representation of Group id get information from. Is SlashOption.
|
||||
category_id (str): String representation of Category id to get information from. Is SlashOption.
|
||||
"""
|
||||
stmt = (
|
||||
select(Category).where(col(Category.group_id) == int(group_id)).where(col(Category.id) == int(category_id))
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
if (category := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group or Category was not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
await interaction.response.send_message(
|
||||
f"**{category.name}** is sorted in **{'ascending' if category.is_ascending else 'descending'}** order.",
|
||||
ephemeral=True,
|
||||
)
|
||||
|
||||
@category.subcommand(description="Get whether a category required validation.")
|
||||
async def is_validated(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Group that Category is in.", required=True),
|
||||
category_id: str = nextcord.SlashOption(
|
||||
name="category", description="Category to information from.", required=True
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Command to view if a category required photo validation.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (str): String representation of Group id get information from. Is SlashOption.
|
||||
category_id (str): String representation of Category id to get information from. Is SlashOption.
|
||||
"""
|
||||
stmt = (
|
||||
select(Category).where(col(Category.group_id) == int(group_id)).where(col(Category.id) == int(category_id))
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
if (category := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group or Category was not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
await interaction.response.send_message(
|
||||
f"{category.name} does {'not ' if not category.is_validated else ''} require validation.",
|
||||
ephemeral=True,
|
||||
)
|
||||
|
||||
@category.subcommand(description="Get the size for a category.")
|
||||
async def size(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Group that Category is in.", required=True),
|
||||
category_id: str = nextcord.SlashOption(name="category", description="Category to get size of.", required=True),
|
||||
) -> None:
|
||||
"""
|
||||
Command to view a category's size.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (str): String representation of Group id get information from. Is SlashOption.
|
||||
category_id (str): String representation of Category id to get information from. Is SlashOption.
|
||||
"""
|
||||
stmt = (
|
||||
select(Category).where(col(Category.group_id) == int(group_id)).where(col(Category.id) == int(category_id))
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
if (category := session.scalar(stmt)) is None:
|
||||
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
|
||||
)
|
||||
|
||||
@get.subcommand(description="Commands for getting group information.")
|
||||
async def group(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash subcommand for getting group information. Never called."""
|
||||
|
||||
@group.subcommand(description="Get the pad length of a group.")
|
||||
async def pad_length(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Group to get pad length of.", required=True),
|
||||
) -> None:
|
||||
"""
|
||||
Command to view a group's pad length.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (str): String representation of Group id get information from. Is SlashOption.
|
||||
"""
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == int(group_id))
|
||||
|
||||
with Session(engine) as session:
|
||||
if (group := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
await interaction.response.send_message(
|
||||
f"**{group.name}** has a pad length of **{group.pad_length}**.", ephemeral=True
|
||||
)
|
||||
|
||||
@group.subcommand(description="Get the username length of a group.")
|
||||
async def username_length(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(
|
||||
name="group", description="Group to get username length of.", required=True
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Command to view a group's username length.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (str): String representation of Group id get information from. Is SlashOption.
|
||||
"""
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == int(group_id))
|
||||
|
||||
with Session(engine) as session:
|
||||
if (group := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
await interaction.response.send_message(
|
||||
f"**{group.name}** has a username length of **{group.username_length}**.", ephemeral=True
|
||||
)
|
||||
|
||||
@is_ascending.on_autocomplete("category_id")
|
||||
@is_validated.on_autocomplete("category_id")
|
||||
@size.on_autocomplete("category_id")
|
||||
async def category_autocomplete(self, interaction: nextcord.Interaction, category_id: str, group_id: str) -> None:
|
||||
"""
|
||||
Autocomplete function for category names.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
category_id (str): String to be autocompleted with Category name.
|
||||
group_id (str): Group to find Category from.
|
||||
"""
|
||||
await interaction.response.send_autocomplete(
|
||||
autofill_categories(interaction.guild_id, int(group_id), category_id)
|
||||
)
|
||||
|
||||
@is_ascending.on_autocomplete("group_id")
|
||||
@is_validated.on_autocomplete("group_id")
|
||||
@pad_length.on_autocomplete("group_id")
|
||||
@size.on_autocomplete("group_id")
|
||||
@username_length.on_autocomplete("group_id")
|
||||
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
|
||||
"""
|
||||
Sends results from autofill_groups back to group_output_channel for autocompletion of group_id.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with command.
|
||||
group_id (str): String to run autocompletion against.
|
||||
"""
|
||||
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
||||
@@ -0,0 +1,35 @@
|
||||
"""Commands for helping a user."""
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
|
||||
|
||||
class HelpCog(commands.Cog, name="Help commands."):
|
||||
"""Class holds commands for getting help."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Default constructor for HelpCog class. Does nothing."""
|
||||
|
||||
@nextcord.slash_command()
|
||||
async def help(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash command for help. Never called."""
|
||||
|
||||
@help.subcommand(description="Describes how to get started with Agon.")
|
||||
async def setup(self, interaction: nextcord.Interaction) -> None:
|
||||
"""
|
||||
Sends a message describing how to get started with Agon.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
"""
|
||||
# I hate this but don't want indents in the string.
|
||||
|
||||
help_str: str = "Welcome to Agon! Three simple steps are needed to get started."
|
||||
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"
|
||||
help_str += '2.) Set up your highscores! Use "/create group" to first create a group message in the'
|
||||
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)
|
||||
@@ -1,26 +1,22 @@
|
||||
"""
|
||||
Commands for refreshing highscore messages.
|
||||
"""
|
||||
"""Commands for refreshing highscore messages."""
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlmodel import col
|
||||
|
||||
# pylint: disable=import-error
|
||||
from cogs.submission.submission_views import SubmissionCreateButton
|
||||
from database_setup.sql_data_classes import CategoryGroup, engine
|
||||
from utilities.utils import autofill_groups, send_highscore_message
|
||||
from agon.database.db import engine
|
||||
from agon.database.models import CategoryGroup
|
||||
from agon.utils import autofill_groups, send_highscore_message
|
||||
|
||||
|
||||
class RefreshCog(commands.Cog, name="Refresh Cog"):
|
||||
"""
|
||||
Class holds commands for refreshing.
|
||||
"""
|
||||
"""Class holds commands for refreshing."""
|
||||
|
||||
def __init__(self, bot: commands.Bot) -> None:
|
||||
"""
|
||||
Default constructor for RefreshCog class
|
||||
Default constructor for RefreshCog class.
|
||||
|
||||
Args:
|
||||
bot (commands.Bot): Bot object. Required to register submission button view.
|
||||
@@ -28,19 +24,17 @@ class RefreshCog(commands.Cog, name="Refresh Cog"):
|
||||
self._bot = bot
|
||||
|
||||
@nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True))
|
||||
async def refresh(self, interaction: nextcord.Interaction):
|
||||
"""
|
||||
Parent slash command for refreshing things. Never called.
|
||||
"""
|
||||
async def refresh(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash command for refreshing things. Never called."""
|
||||
|
||||
@refresh.subcommand(description="Manually refresh a table. Use when changing settings or data manually changed.")
|
||||
@refresh.subcommand(description="Manually refresh a group. Use when changing settings or data manually changed.")
|
||||
async def group(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Name of Group.", required=True),
|
||||
) -> None:
|
||||
"""
|
||||
Refreshes a table given by user.
|
||||
Refreshes a group given by user.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
@@ -49,50 +43,44 @@ class RefreshCog(commands.Cog, name="Refresh Cog"):
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
.where(CategoryGroup.GroupId == int(group_id))
|
||||
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||
.where(col(CategoryGroup.id) == int(group_id))
|
||||
)
|
||||
group = session.scalar(stmt)
|
||||
|
||||
message: nextcord.Message = await send_highscore_message(session, interaction.guild, group)
|
||||
await message.edit(view=SubmissionCreateButton(self._bot))
|
||||
|
||||
await interaction.response.send_message(f"Updated table {group.GroupName}!", ephemeral=True)
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
await interaction.response.send_message(f"Updated group {group.name}!", ephemeral=True)
|
||||
|
||||
@refresh.subcommand()
|
||||
async def all(self, interaction: nextcord.Interaction):
|
||||
"""
|
||||
Subcommand parent for refreshing all things. Never called.
|
||||
"""
|
||||
async def all(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Subcommand parent for refreshing all things. Never called."""
|
||||
|
||||
@all.subcommand(description="Triggers post/update of highscores to registered highscore channels.")
|
||||
async def groups(self, interaction: nextcord.Interaction) -> None:
|
||||
"""
|
||||
A command which posts the highscore in the registered channel.
|
||||
Sends warning if no channel has been registered.
|
||||
|
||||
Either creates new messages for each table if one doesn't exist
|
||||
or edits the existing message.
|
||||
Sends warning if no channel has been registered. Either creates new messages for each group if one doesn't
|
||||
exist or edits the existing message.
|
||||
|
||||
Args:
|
||||
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(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||
|
||||
# awaiting response because posting scores takes a while
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
|
||||
for group in session.scalars(stmt):
|
||||
message: nextcord.Message = await send_highscore_message(session, interaction.guild, group)
|
||||
await message.edit(view=SubmissionCreateButton(self._bot))
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
|
||||
await interaction.send(f"Posted all groups in {interaction.guild.name}'s highscores.", ephemeral=True)
|
||||
|
||||
@group.on_autocomplete("group_id")
|
||||
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str):
|
||||
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
|
||||
"""
|
||||
Collects list of table names and compares to input table name for autocomplete assistance.
|
||||
Collects list of group names and compares to input group name for autocomplete assistance.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with command.
|
||||
@@ -0,0 +1,442 @@
|
||||
"""Set command hierarchy."""
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlmodel import col
|
||||
|
||||
from agon.database.db import engine
|
||||
from agon.database.models import Category, CategoryGroup, Guild
|
||||
from agon.logger import agon_logger
|
||||
from agon.utils import MAX_LINE_LENGTH, autofill_categories, autofill_groups, send_highscore_message
|
||||
|
||||
|
||||
class SetCog(commands.Cog, name="Set command."):
|
||||
"""Class holds commands for setting variables in guild's database."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Default constructor for SetCog class. Does nothing."""
|
||||
|
||||
@nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True))
|
||||
async def set(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash command for setting settings. Never called."""
|
||||
|
||||
@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."""
|
||||
|
||||
@category.subcommand(description="Update the number of entries to show for a category.", name="size")
|
||||
async def category_size(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Group that Category is in.", required=True),
|
||||
category_id: str = nextcord.SlashOption(
|
||||
name="category", description="Category to update size of.", required=True
|
||||
),
|
||||
size: int = nextcord.SlashOption(description="Number of entries to show for the category.", required=True),
|
||||
) -> None:
|
||||
"""
|
||||
Command to update a category's size.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
||||
category_id (str): String representation of Category id to register channel to. Is SlashOption.
|
||||
size (int): Size to set. Is SlashOption.
|
||||
"""
|
||||
stmt = (
|
||||
select(Category).where(col(Category.group_id) == int(group_id)).where(col(Category.id) == int(category_id))
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
if (category := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Category or Group was not found.", ephemeral=True)
|
||||
return
|
||||
category.size = size
|
||||
session.commit()
|
||||
|
||||
# Use the relationship to get group category is in.
|
||||
if (group := category.category_group) is None:
|
||||
agon_logger.warning(f"{category.name}:{category.id} group relationship was None.")
|
||||
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == group_id)
|
||||
if (group := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
||||
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
|
||||
)
|
||||
|
||||
@category.subcommand(description="Update the is_ascending value for a category.")
|
||||
async def is_ascending(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Group that Category is in.", required=True),
|
||||
category_id: str = nextcord.SlashOption(
|
||||
name="category", description="Category to update is_ascending of.", required=True
|
||||
),
|
||||
ascending: bool = nextcord.SlashOption( # noqa: FBT001
|
||||
description="Whether the scores are sorted ascending or not.", required=True
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Command to update a category's is_ascending boolean.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
||||
category_id (str): String representation of Category id to register channel to. Is SlashOption.
|
||||
ascending (bool): Boolean to set. Determines whether scores are sorted ascending or not. Is SlashOption.
|
||||
"""
|
||||
stmt = (
|
||||
select(Category).where(col(Category.group_id) == int(group_id)).where(col(Category.id) == int(category_id))
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
if (category := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Category or Group was not found.", ephemeral=True)
|
||||
return
|
||||
category.is_ascending = ascending
|
||||
session.commit()
|
||||
|
||||
# Use the relationship to get group category is in.
|
||||
if (group := category.category_group) is None:
|
||||
agon_logger.warning(f"{category.name}:{category.id} group relationship was None.")
|
||||
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == group_id)
|
||||
if (group := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
@category.subcommand(description="Update the is_validated value for a category.")
|
||||
async def is_validated(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Group that Category is in.", required=True),
|
||||
category_id: str = nextcord.SlashOption(
|
||||
name="category", description="Category to update is_ascending of.", required=True
|
||||
),
|
||||
validated: bool = nextcord.SlashOption( # noqa: FBT001
|
||||
description="Whether the scores need to be validated.", required=True
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Command to update a category's is_validated boolean.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
||||
category_id (str): String representation of Category id to register channel to. Is SlashOption.
|
||||
validated (bool): Boolean to set. Determines whether scores are validated or not. Is SlashOption.
|
||||
"""
|
||||
stmt = (
|
||||
select(Category).where(col(Category.group_id) == int(group_id)).where(col(Category.id) == int(category_id))
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
if (category := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Category or Group was not found.", ephemeral=True)
|
||||
return
|
||||
category.is_validated = validated
|
||||
session.commit()
|
||||
|
||||
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(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Group that Category is in.", required=True),
|
||||
category_id: str = nextcord.SlashOption(
|
||||
name="category", description="Category to update the name of.", required=True
|
||||
),
|
||||
name: str = nextcord.SlashOption(description="Name to update to.", required=True, min_length=1, max_length=30),
|
||||
) -> None:
|
||||
"""
|
||||
Command to update a category's name.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
||||
category_id (str): String representation of Category id to register channel to. Is SlashOption.
|
||||
name (str): The name to update the category's name to. Is SlashOption.
|
||||
"""
|
||||
stmt = (
|
||||
select(Category).where(col(Category.group_id) == int(group_id)).where(col(Category.id) == int(category_id))
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
if (category := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Category or Group was not found.", ephemeral=True)
|
||||
return
|
||||
old_name = category.name
|
||||
category.name = name
|
||||
session.commit()
|
||||
|
||||
# Use the relationship to get group category is in.
|
||||
if (group := category.category_group) is None:
|
||||
agon_logger.warning(f"{category.name}:{category.id} group relationship was None.")
|
||||
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == group_id)
|
||||
if (group := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
||||
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
|
||||
)
|
||||
|
||||
@set.subcommand(description="Commands for editing a group.")
|
||||
async def group(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash subcommand for setting group settings. Never called."""
|
||||
|
||||
@group.subcommand(name="name", description="Change the name of a Group.")
|
||||
async def group_name(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Group that Category is in.", required=True),
|
||||
name: str = nextcord.SlashOption(description="Name to update to.", required=True, min_length=1, max_length=50),
|
||||
) -> None:
|
||||
"""
|
||||
Command to update a group's name.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
||||
name (str): The name to update the group's name to. Is SlashOption.
|
||||
"""
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == int(group_id))
|
||||
|
||||
with Session(engine) as session:
|
||||
if (group := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
||||
return
|
||||
old_name = group.name
|
||||
group.name = name
|
||||
# session.add(group) test if this is needed. SQLAlchemy can do the update without adding.
|
||||
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)
|
||||
|
||||
@group.subcommand(description="Registers the channel for a Group's messages.")
|
||||
async def output_channel(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Group to assign to channel.", required=True),
|
||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
||||
description="Channel to register",
|
||||
required=False,
|
||||
channel_types=[nextcord.ChannelType.text],
|
||||
default=None,
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Command function to register a CategoryGroup's output channel.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
||||
channel (nextcord.abc.GuildChannel, optional): Channel to register.
|
||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||
"""
|
||||
channel_id = interaction.channel.id if not channel else channel.id
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||
.where(col(CategoryGroup.id) == int(group_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(
|
||||
description="Set character length for a category. Can cut off username/score. Affects all categories."
|
||||
)
|
||||
async def pad_length(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(name="group", description="Group to assign pad length to.", required=True),
|
||||
length: int = nextcord.SlashOption(
|
||||
description="Number of characters alloted to a category.",
|
||||
required=True,
|
||||
default=26,
|
||||
min_value=7,
|
||||
max_value=MAX_LINE_LENGTH,
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Changes guild's category pad length.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||
group_id (str): String representation of Group id to set pad length in. Is SlashOption.
|
||||
length (int): Number of characters. Is SlashOption. Defaults to 26.
|
||||
"""
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||
.where(col(CategoryGroup.id) == int(group_id))
|
||||
)
|
||||
if (group := session.scalar(stmt)) is None:
|
||||
await interaction.response.send_message("Group was not found.", ephemeral=True)
|
||||
return
|
||||
|
||||
group.pad_length = length
|
||||
session.commit()
|
||||
await interaction.response.send_message(
|
||||
f"Category pad length set to **{length}** for **{group.name}**.", ephemeral=True
|
||||
)
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
|
||||
@group.subcommand(
|
||||
description="Registers the channel for submission messages. Currently this information is deprecated."
|
||||
)
|
||||
async def submission_channel(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
||||
description="Channel to register",
|
||||
required=False,
|
||||
channel_types=[nextcord.ChannelType.text],
|
||||
default=None,
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Command function to register the submission message channel.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||
channel (nextcord.abc.GuildChannel): Channel to register
|
||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||
"""
|
||||
channel_id = interaction.channel.id if not channel else channel.id
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = select(Guild).where(col(Guild.id) == interaction.guild_id)
|
||||
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)
|
||||
|
||||
@group.subcommand(description="Set username length for a Group of Categories.")
|
||||
async def username_length(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(
|
||||
name="group", description="Group to change username length of.", required=True
|
||||
),
|
||||
length: int = nextcord.SlashOption(
|
||||
description="Number of characters.", required=True, default=12, min_value=1, max_value=30
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Changes guild's username length limit.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||
group_id (str): String representation of Group id to set username length in. Is SlashOption.
|
||||
length (int): Number of characters. Is SlashOption. Defaults to 12.
|
||||
"""
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||
.where(col(CategoryGroup.id) == int(group_id))
|
||||
)
|
||||
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 for **{group.name}** set to **{length}**.", ephemeral=True
|
||||
)
|
||||
|
||||
@set.subcommand(description="Registers the channel for verification messages.")
|
||||
async def verify_channel(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
||||
description="Channel to register",
|
||||
required=False,
|
||||
channel_types=[nextcord.ChannelType.text],
|
||||
default=None,
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Command function to register the verification message channel.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||
channel (Optional[nextcord.abc.GuildChannel]): Channel to register
|
||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||
"""
|
||||
channel_id = interaction.channel.id if not channel else channel.id
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = select(Guild).where(col(Guild.id) == interaction.guild_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)
|
||||
|
||||
@category_name.on_autocomplete("category_id")
|
||||
@category_size.on_autocomplete("category_id")
|
||||
@is_ascending.on_autocomplete("category_id")
|
||||
@is_validated.on_autocomplete("category_id")
|
||||
async def category_autocomplete(self, interaction: nextcord.Interaction, category_id: str, group_id: str) -> None:
|
||||
"""
|
||||
Autocomplete function for category names.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
category_id (str): String to be autocompleted with Category name.
|
||||
group_id (str): Group to find Category from.
|
||||
"""
|
||||
await interaction.response.send_autocomplete(
|
||||
autofill_categories(interaction.guild_id, int(group_id), category_id)
|
||||
)
|
||||
|
||||
@category_name.on_autocomplete("group_id")
|
||||
@category_size.on_autocomplete("group_id")
|
||||
@group_name.on_autocomplete("group_id")
|
||||
@is_ascending.on_autocomplete("group_id")
|
||||
@is_validated.on_autocomplete("group_id")
|
||||
@output_channel.on_autocomplete("group_id")
|
||||
@pad_length.on_autocomplete("group_id")
|
||||
@username_length.on_autocomplete("group_id")
|
||||
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
|
||||
"""
|
||||
Sends results from autofill_groups back to group_output_channel for autocompletion of group_id.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with command.
|
||||
group_id (str): String to run autocompletion against.
|
||||
"""
|
||||
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
||||
@@ -0,0 +1,242 @@
|
||||
"""Contains command for submitting a score."""
|
||||
|
||||
import re
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlmodel import col
|
||||
|
||||
from agon.cogs.submission.verification_view import VerificationView
|
||||
from agon.database.db import engine
|
||||
from agon.database.models import Category, CategoryGroup, Guild, Submission
|
||||
from agon.logger import agon_logger
|
||||
from agon.utils import autofill_categories, autofill_groups, submit_score
|
||||
|
||||
|
||||
class SubmissionCog(commands.Cog):
|
||||
"""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()
|
||||
async def submit( # 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: 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(
|
||||
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.
|
||||
"""
|
||||
# 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
|
||||
|
||||
# check with regex if score is in correct format
|
||||
# check if verify_score was successful. It replies with corrections required itself.
|
||||
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.
|
||||
if not category.is_validated:
|
||||
await submit_score(interaction, int(group_id), int(category_id), username, verified_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):
|
||||
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, verified_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=verified_score,
|
||||
user_id=interaction.user.id,
|
||||
username=username,
|
||||
)
|
||||
|
||||
session.add(submission)
|
||||
session.commit()
|
||||
|
||||
def create_embed( # noqa: PLR0913
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str,
|
||||
category_id: str,
|
||||
score: str,
|
||||
username: str,
|
||||
session: Session,
|
||||
) -> nextcord.Embed:
|
||||
"""
|
||||
Creates an embed containing submission data for human verification.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Discord interaction of the command.
|
||||
group_id (str): Used to get group name.
|
||||
category_id (str): Used to get category name.
|
||||
score (str): Score to set.
|
||||
username (str): Username to set.
|
||||
session (Session): Open connection to database.
|
||||
|
||||
Returns:
|
||||
nextcord.Embed: Embed containing human readable submission data.
|
||||
"""
|
||||
embed = nextcord.Embed(title="Highscores Submission", description="Review fields and accept.")
|
||||
embed.add_field(name="User Name", value=username, inline=False)
|
||||
|
||||
# Get group name from database
|
||||
stmt = (
|
||||
select(col(CategoryGroup.name))
|
||||
.where(col(CategoryGroup.guild_id) == interaction.guild_id)
|
||||
.where(col(CategoryGroup.id) == group_id)
|
||||
)
|
||||
embed.add_field(name="Group", value=session.scalar(stmt), inline=False)
|
||||
|
||||
# Get category name from database
|
||||
stmt = (
|
||||
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="Score", value=score, inline=False)
|
||||
return embed
|
||||
|
||||
async def verify_score(self, interaction: nextcord.Interaction, score: str, *, is_time_record: bool) -> str | None:
|
||||
"""
|
||||
Uses regex to verify that scores are in the correct format.
|
||||
|
||||
Handles responding to the interaction if the format is incorrect. Also standardizes the time record.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Discord interaction of the command.
|
||||
score (str): String representation of the score being verified.
|
||||
is_time_record (bool): Whether the score needs to be verified/formatted as a time record.
|
||||
|
||||
Returns:
|
||||
str | None: String of corrected score. None if formatted incorrectly.
|
||||
"""
|
||||
time_regex = re.search("^([0-9]{1,2}:[0-9]|[0-9])?[0-9](\\.[0-9])?$", score)
|
||||
int_regex = re.search("^[0-9]+$", score)
|
||||
if time_regex is None and is_time_record:
|
||||
await interaction.response.send_message(
|
||||
"Time record must follow format MM:SS.ms, SS.ms, or SS.", ephemeral=True
|
||||
)
|
||||
return None
|
||||
if int_regex is None and not is_time_record:
|
||||
await interaction.response.send_message("Number record must only be number.", ephemeral=True)
|
||||
return None
|
||||
if is_time_record:
|
||||
# standardize time score format.
|
||||
if re.search("^[1-9]?[0-9]:[0-9]{2}(\\.[0-9])?$", score):
|
||||
# score is already fine.
|
||||
pass
|
||||
elif re.search("^[0-9]{2}(\\.[0-9])?$", score):
|
||||
# need to add leading colon and 0
|
||||
score = "0:" + score
|
||||
elif re.search("^[0-9](\\.[0-9])?$", score):
|
||||
# need to add 0 in seconds and leading colon and 0
|
||||
score = "0:0" + score
|
||||
elif re.search("^[0]?[0-9]:[0-9]{2}(\\.[0-9])?$", score):
|
||||
# if there is a minute 10ths place 0, remove
|
||||
score = score.lstrip("0")
|
||||
|
||||
return score
|
||||
|
||||
@submit.on_autocomplete("group_id")
|
||||
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
|
||||
"""
|
||||
Autocomplete function for group names.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (str): String to be autocompleted with Group name.
|
||||
"""
|
||||
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
||||
|
||||
@submit.on_autocomplete("category_id")
|
||||
async def category_autocomplete(self, interaction: nextcord.Interaction, category_id: str, group_id: str) -> None:
|
||||
"""
|
||||
Autocomplete function for category names.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
category_id (str): String to be autocompleted with Category name.
|
||||
group_id (str): Group to find Category from.
|
||||
"""
|
||||
await interaction.response.send_autocomplete(
|
||||
autofill_categories(interaction.guild_id, int(group_id), category_id)
|
||||
)
|
||||
@@ -1,23 +1,20 @@
|
||||
"""
|
||||
Commands for updating information/variables held in database.
|
||||
"""
|
||||
"""Commands for updating information/variables held in database."""
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlmodel import col
|
||||
|
||||
# pylint: disable=import-error
|
||||
from database_setup.sql_data_classes import Guild, engine
|
||||
from utilities.utils import autofill_users_in_guild
|
||||
from agon.database.db import engine
|
||||
from agon.database.models import Guild
|
||||
from agon.utils import autofill_users_in_guild
|
||||
|
||||
from .views.update_username_verify import UpdateUsernameVerifyView
|
||||
|
||||
|
||||
class UpdateCog(commands.Cog, name="Update commands."):
|
||||
"""
|
||||
Class holds commands and views needed for updating things in bot.
|
||||
"""
|
||||
"""Class holds commands and views needed for updating things in bot."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
"""
|
||||
@@ -29,17 +26,13 @@ class UpdateCog(commands.Cog, name="Update commands."):
|
||||
self._bot: commands.Bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
"""
|
||||
Called when cog is loaded. Adds views required for DataManagement commands.
|
||||
"""
|
||||
async def on_ready(self) -> None:
|
||||
"""Called when cog is loaded. Adds views required for DataManagement commands."""
|
||||
self._bot.add_view(UpdateUsernameVerifyView())
|
||||
|
||||
@nextcord.slash_command()
|
||||
async def update(self, interaction: nextcord.Interaction):
|
||||
"""
|
||||
Parent slash command for updating things. Never called.
|
||||
"""
|
||||
async def update(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash command for updating things. Never called."""
|
||||
|
||||
@update.subcommand(description="Request a username update. Admins must approve.")
|
||||
async def username(
|
||||
@@ -47,10 +40,11 @@ class UpdateCog(commands.Cog, name="Update commands."):
|
||||
interaction: nextcord.Interaction,
|
||||
old_username: str = nextcord.SlashOption(description="Username currently stored in highscores.", required=True),
|
||||
new_username: str = nextcord.SlashOption(description="Username to update to.", required=True),
|
||||
):
|
||||
) -> None:
|
||||
"""
|
||||
Creates a request to send to admins for changing a username. Uses
|
||||
UpdateUsernameVerifyView to do the work.
|
||||
Creates a request to send to admins for changing a username.
|
||||
|
||||
Uses UpdateUsernameVerifyView to do the work.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||
@@ -58,9 +52,13 @@ class UpdateCog(commands.Cog, name="Update commands."):
|
||||
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(col(Guild.verification_channel)).where(col(Guild.id) == interaction.guild_id)
|
||||
verify_channel = interaction.guild.get_channel(session.scalar(stmt))
|
||||
|
||||
if not isinstance(verify_channel, nextcord.TextChannel):
|
||||
await interaction.send("Verification channel not set. Cannot process request.", ephemeral=True)
|
||||
return
|
||||
|
||||
embed: nextcord.Embed = nextcord.Embed(title="Username change request.")
|
||||
embed.add_field(name="Old Username", value=old_username)
|
||||
embed.add_field(name="New Username", value=new_username)
|
||||
@@ -72,12 +70,12 @@ class UpdateCog(commands.Cog, name="Update commands."):
|
||||
await interaction.send("Request sent to admins for verification.", ephemeral=True)
|
||||
|
||||
@username.on_autocomplete("old_username")
|
||||
async def all_users_autocomplete(self, interaction: nextcord.Interaction, username: str):
|
||||
async def all_users_autocomplete(self, interaction: nextcord.Interaction, username: str) -> None:
|
||||
"""
|
||||
Sends response from autofill_users_in_guild back to update_username for autocompletion of old_username.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with command.
|
||||
old_username (str): String to run autocompletion against.
|
||||
username (str): String to run autocompletion against.
|
||||
"""
|
||||
await interaction.response.send_autocomplete(autofill_users_in_guild(interaction.guild_id, username))
|
||||
@@ -1,33 +1,26 @@
|
||||
"""
|
||||
View command heirarchy.
|
||||
"""
|
||||
"""View command hierarchy."""
|
||||
|
||||
import nextcord
|
||||
import pandas as pd
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlmodel import col
|
||||
|
||||
# pylint: disable=import-error
|
||||
from database_setup.sql_data_classes import Category, CategoryGroup, Score, engine
|
||||
from utilities.utils import MAX_LINE_LENGTH, autofill_categories, autofill_groups, format_score_string
|
||||
from agon.database.db import engine
|
||||
from agon.database.models import Category, CategoryGroup, Score
|
||||
from agon.utils import MAX_LINE_LENGTH, autofill_categories, autofill_groups, format_score_string
|
||||
|
||||
|
||||
class ViewCog(commands.Cog, name="View Command"):
|
||||
"""
|
||||
Class holds commands for viewing data.
|
||||
"""
|
||||
"""Class holds commands for viewing data."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""
|
||||
Default constructor for ViewCog class. Does nothing.
|
||||
"""
|
||||
"""Default constructor for ViewCog class. Does nothing."""
|
||||
|
||||
@nextcord.slash_command()
|
||||
async def view(self, interaction: nextcord.Interaction):
|
||||
"""
|
||||
Parent slash command for view. Never called.
|
||||
"""
|
||||
async def view(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash command for view. Never called."""
|
||||
|
||||
@view.subcommand(description="Lists all scores for a given category.")
|
||||
async def leaderboard(
|
||||
@@ -39,10 +32,12 @@ class ViewCog(commands.Cog, name="View Command"):
|
||||
category_id: str = nextcord.SlashOption(
|
||||
name="category", description="Category to show leaderboard.", required=True
|
||||
),
|
||||
):
|
||||
) -> None:
|
||||
"""
|
||||
Gathers all users that have a submission in the group/category combo and returns a message with them
|
||||
in ranked order.
|
||||
Create message with leaderboard of a group and category.
|
||||
|
||||
Gathers all users that have a submission in the group/category combo and returns a
|
||||
message with them in ranked order.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
@@ -53,17 +48,17 @@ class ViewCog(commands.Cog, name="View Command"):
|
||||
|
||||
# get group, category, and all scores sorted correctly.
|
||||
with Session(engine) as session:
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == int(group_id))
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == int(group_id))
|
||||
group = session.scalar(stmt)
|
||||
|
||||
stmt = select(Category).where(Category.CategoryId == int(category_id))
|
||||
stmt = select(Category).where(col(Category.id) == int(category_id))
|
||||
category = session.scalar(stmt)
|
||||
|
||||
d_f = pd.read_sql_query(
|
||||
sql=session.query(Score).where(Score.CategoryId == category_id).statement, con=engine
|
||||
sql=session.query(Score).where(col(Score.category_id) == category_id).statement, con=engine
|
||||
)
|
||||
|
||||
scores = d_f.sort_values("Score", ascending=category.IsAscending).reset_index()
|
||||
scores = d_f.sort_values("Score", ascending=category.is_ascending).reset_index()
|
||||
|
||||
# get the longest string
|
||||
longest_str: int = scores.UserName.map(len).max()
|
||||
@@ -71,11 +66,16 @@ class ViewCog(commands.Cog, name="View Command"):
|
||||
for i, row in scores.iterrows():
|
||||
str_list.append(
|
||||
format_score_string(
|
||||
row["UserName"], row["Score"], longest_str, category.IsTimeRecord, i + 1, MAX_LINE_LENGTH
|
||||
row["UserName"],
|
||||
row["Score"],
|
||||
longest_str,
|
||||
category.is_time_record,
|
||||
i + 1, # type: ignore[reportOperatorIssue]
|
||||
MAX_LINE_LENGTH,
|
||||
)
|
||||
)
|
||||
|
||||
message_str: str = f"**{group.GroupName} {category.CategoryName} Leaderboard!**\n```"
|
||||
message_str: str = f"**{group.name} {category.name} Leaderboard!**\n```"
|
||||
if len(str_list) == 0:
|
||||
message_str += "No Submissions!"
|
||||
else:
|
||||
@@ -87,9 +87,9 @@ class ViewCog(commands.Cog, name="View Command"):
|
||||
await interaction.response.send_message(content=message_str)
|
||||
|
||||
@leaderboard.on_autocomplete("group_id")
|
||||
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str):
|
||||
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str) -> None:
|
||||
"""
|
||||
Autocomplete function for table names.
|
||||
Autocomplete function for group names.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
@@ -98,7 +98,7 @@ class ViewCog(commands.Cog, name="View Command"):
|
||||
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
||||
|
||||
@leaderboard.on_autocomplete("category_id")
|
||||
async def category_autocomplete(self, interaction: nextcord.Interaction, category_id: str, group_id: str):
|
||||
async def category_autocomplete(self, interaction: nextcord.Interaction, category_id: str, group_id: str) -> None:
|
||||
"""
|
||||
Autocomplete function for category names.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
"""Package for views used in commands."""
|
||||
+20
-17
@@ -1,23 +1,19 @@
|
||||
"""
|
||||
Contains view and helper functions for confirming and processing deletes.
|
||||
"""
|
||||
"""Contains view and helper functions for confirming and processing deletes."""
|
||||
|
||||
import nextcord
|
||||
from sqlalchemy import delete, select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
# pylint: disable=import-error
|
||||
from database_setup.sql_data_classes import Category, CategoryGroup, engine
|
||||
from utilities.utils import send_highscore_message
|
||||
from agon.database.db import engine
|
||||
from agon.database.models import Category, CategoryGroup
|
||||
from agon.utils import send_highscore_message
|
||||
|
||||
|
||||
class DeleteConfirmView(nextcord.ui.Modal):
|
||||
"""
|
||||
View modal popup for confirming deletions.
|
||||
"""
|
||||
"""View modal popup for confirming deletions."""
|
||||
|
||||
def __init__(self, custom_id: str):
|
||||
super().__init__(title="Warning, deletion is perminant.", custom_id=custom_id)
|
||||
super().__init__(title="Warning, deletion is permanent.", custom_id=custom_id)
|
||||
|
||||
self.checker = nextcord.ui.TextInput(
|
||||
label='Type "delete" to confirm deletion.',
|
||||
@@ -27,7 +23,12 @@ class DeleteConfirmView(nextcord.ui.Modal):
|
||||
)
|
||||
self.add_item(self.checker)
|
||||
|
||||
async def callback(self, interaction: nextcord.Interaction):
|
||||
async def callback(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Action for confirming deletion.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): User interaction object with the modal.
|
||||
"""
|
||||
if self.checker.value.lower() != "delete":
|
||||
await interaction.response.send_message('Response was not "delete". Canceling delete.')
|
||||
return
|
||||
@@ -35,21 +36,23 @@ class DeleteConfirmView(nextcord.ui.Modal):
|
||||
del_vals = parse_delete_id(self.custom_id)
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == del_vals["group_id"])
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.id == del_vals["group_id"])
|
||||
group = session.scalar(stmt)
|
||||
if del_vals["category_id"] is None:
|
||||
# delete entire group
|
||||
session.delete(group)
|
||||
# delete the message related to group
|
||||
channel: nextcord.TextChannel = interaction.guild.get_channel(group.ChannelId)
|
||||
message: nextcord.Message = await channel.fetch_message(group.MessageId)
|
||||
channel = interaction.guild.get_channel(group.channel_id)
|
||||
if not isinstance(channel, nextcord.TextChannel):
|
||||
return
|
||||
message: nextcord.Message = await channel.fetch_message(group.message_id)
|
||||
await message.delete()
|
||||
|
||||
else:
|
||||
stmt = (
|
||||
delete(Category)
|
||||
.where(Category.GroupId == del_vals["group_id"])
|
||||
.where(Category.CategoryId == del_vals["category_id"])
|
||||
.where(Category.group_id == del_vals["group_id"])
|
||||
.where(Category.id == del_vals["category_id"])
|
||||
)
|
||||
session.execute(stmt)
|
||||
# update the message
|
||||
@@ -78,7 +81,7 @@ def parse_delete_id(delete_id: str) -> dict:
|
||||
Returns a dict containing the values of a delete id.
|
||||
|
||||
Args:
|
||||
id (str): the delete id
|
||||
delete_id (str): the delete id
|
||||
|
||||
Returns:
|
||||
dict: dict containing values from a delete id.
|
||||
+17
-17
@@ -3,23 +3,22 @@
|
||||
import nextcord
|
||||
from sqlalchemy import distinct, exc, select
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlmodel import col
|
||||
|
||||
# pylint: disable=import-error
|
||||
from database_setup.sql_data_classes import Category, CategoryGroup, Score, engine
|
||||
from utilities.utils import send_highscore_message
|
||||
from agon.database.db import engine
|
||||
from agon.database.models import Category, CategoryGroup, Score
|
||||
from agon.utils import send_highscore_message
|
||||
|
||||
|
||||
class UpdateUsernameVerifyView(nextcord.ui.View):
|
||||
"""Defines view for allowing a username update."""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Default constructor for UpdateUsernameVerifyView. Calls super constructor with no timeout.
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
"""Default constructor for UpdateUsernameVerifyView. Calls super constructor with no timeout."""
|
||||
super().__init__(timeout=None)
|
||||
|
||||
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-username-update")
|
||||
async def deny_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): # pylint: disable=unused-argument
|
||||
async def deny_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
|
||||
"""
|
||||
Button for denying username update. Deletes message.
|
||||
|
||||
@@ -30,10 +29,11 @@ class UpdateUsernameVerifyView(nextcord.ui.View):
|
||||
await interaction.message.delete()
|
||||
|
||||
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-username-update")
|
||||
async def approve_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): # pylint: disable=unused-argument
|
||||
async def approve_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
|
||||
"""
|
||||
Button for approving username update. Tells guild data to update username, then updates
|
||||
message to show it is complete.
|
||||
Button for approving username update.
|
||||
|
||||
Tells guild data to update username, then updates message to show it is complete.
|
||||
|
||||
Args:
|
||||
button (nextcord.ui.Button): unused
|
||||
@@ -42,20 +42,20 @@ class UpdateUsernameVerifyView(nextcord.ui.View):
|
||||
with Session(engine) as session:
|
||||
try:
|
||||
embed_content = interaction.message.embeds[0].to_dict()
|
||||
old_username: str = embed_content["fields"][0]["value"]
|
||||
new_username: str = embed_content["fields"][1]["value"]
|
||||
old_username: str = embed_content["fields"][0]["value"] # type: ignore reportTypedDictNotRequiredAccess
|
||||
new_username: str = embed_content["fields"][1]["value"] # type: ignore reportTypedDictNotRequiredAccess
|
||||
|
||||
stmt = select(distinct(Score.CategoryId)).where(Score.UserName == old_username)
|
||||
stmt = select(distinct(col(Score.category_id))).where(col(Score.username) == old_username)
|
||||
category_ids: list[int] = list(session.scalars(stmt))
|
||||
|
||||
stmt = select(Score).where(Score.UserName == old_username)
|
||||
stmt = select(Score).where(col(Score.username) == old_username)
|
||||
for score in session.scalars(stmt):
|
||||
score.UserName = new_username
|
||||
session.commit()
|
||||
|
||||
group_ids = select(Category.GroupId).where(Category.CategoryId.in_(category_ids))
|
||||
group_ids = select(col(Category.group_id)).where(col(Category.id).in_(category_ids))
|
||||
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GroupId.in_(group_ids))
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id).in_(group_ids))
|
||||
|
||||
for group in session.scalars(stmt):
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
@@ -1,14 +1,13 @@
|
||||
"""
|
||||
Defines cog for guild listeners. Contains functions for various guild events.
|
||||
"""
|
||||
"""Defines cog for guild listeners. Contains functions for various guild events."""
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlmodel import col
|
||||
|
||||
# pylint: disable=import-error
|
||||
from database_setup.sql_data_classes import Guild, engine
|
||||
from agon.database.db import engine
|
||||
from agon.database.models import Guild
|
||||
|
||||
|
||||
class GuildListener(commands.Cog, name="Guild Listener"):
|
||||
@@ -18,7 +17,7 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_join(self, guild: nextcord.Guild):
|
||||
async def on_guild_join(self, guild: nextcord.Guild) -> None:
|
||||
"""
|
||||
Listener for Guild Join. Adds guild to database.
|
||||
|
||||
@@ -26,12 +25,11 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
||||
guild (nextcord.Guild): Guild that was joined.
|
||||
"""
|
||||
with Session(engine) as session:
|
||||
stmt = select(Guild).where(Guild.GuildId == guild.id)
|
||||
guild_data = session.scalar(stmt)
|
||||
stmt = select(Guild).where(col(Guild.id == guild.id))
|
||||
|
||||
# just in case check if the guild already exists
|
||||
if guild_data is None:
|
||||
new_guild = Guild(GuildId=guild.id, GuildName=guild.name)
|
||||
if (guild_data := session.scalar(stmt)) is None:
|
||||
new_guild = Guild(id=guild.id, name=guild.name)
|
||||
session.add(new_guild)
|
||||
else:
|
||||
guild_data.GuildName = guild.name
|
||||
@@ -45,7 +43,7 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
||||
await imcompiling.send(f'Agon has joined server "{guild.name}"!')
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_remove(self, guild: nextcord.Guild):
|
||||
async def on_guild_remove(self, guild: nextcord.Guild) -> None:
|
||||
"""
|
||||
Listens to when the bot has been removed from a guild. Update's the database to record the active flag as false.
|
||||
|
||||
@@ -53,7 +51,7 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
||||
guild (nextcord.Guild): Guild that was left.
|
||||
"""
|
||||
with Session(engine) as session:
|
||||
stmt = select(Guild).where(Guild.GuildId == guild.id)
|
||||
stmt = select(Guild).where(col(Guild.id == guild.id))
|
||||
guild_data = session.scalar(stmt)
|
||||
guild_data.Active = False
|
||||
session.commit()
|
||||
@@ -66,6 +64,6 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
||||
|
||||
# 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):
|
||||
"""Adds function to bot"""
|
||||
def setup(bot: commands.Bot) -> None:
|
||||
"""Adds function to bot."""
|
||||
bot.add_cog(GuildListener(bot))
|
||||
@@ -1,6 +1,4 @@
|
||||
"""
|
||||
Initializing code for all loops.
|
||||
"""
|
||||
"""Initializing code for all loops."""
|
||||
|
||||
from nextcord.ext import commands
|
||||
|
||||
@@ -10,7 +8,7 @@ from .guild_data import GuildData
|
||||
|
||||
# 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):
|
||||
"""Adds function to bot"""
|
||||
def setup(bot: commands.Bot) -> None:
|
||||
"""Adds function to bot."""
|
||||
bot.add_cog(BotPresence(bot))
|
||||
bot.add_cog(GuildData(bot))
|
||||
@@ -1,6 +1,4 @@
|
||||
"""
|
||||
Functions for controlling the bot's presence. Also contains the loop.
|
||||
"""
|
||||
"""Functions for controlling the bot's presence. Also contains the loop."""
|
||||
|
||||
import random
|
||||
|
||||
@@ -11,27 +9,26 @@ from nextcord.ext import commands, tasks
|
||||
class BotPresence(commands.Cog, name="Bot Presence"):
|
||||
"""Class for bot presence functions."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
def __init__(self, bot: commands.Bot) -> None:
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_join(self, guild: nextcord.Guild): # pylint: disable=unused-argument
|
||||
async def on_guild_join(self, guild: nextcord.Guild) -> None: # noqa: ARG002
|
||||
"""Listener for Guild Join. Updated presence on guild join."""
|
||||
await self.change_presence()
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
async def on_ready(self) -> None:
|
||||
"""Starts the loop when bot is ready."""
|
||||
await self.bot.wait_until_ready()
|
||||
# pylint doesn't recognize that periodic_change_presense is subclassed from tasks.loop.
|
||||
self.periodic_change_presence.start() # pylint: disable=no-member
|
||||
self.periodic_change_presence.start()
|
||||
|
||||
@tasks.loop(minutes=2)
|
||||
async def periodic_change_presence(self):
|
||||
async def periodic_change_presence(self) -> None:
|
||||
"""Loops every 2 minutes and changes presence."""
|
||||
await self.change_presence()
|
||||
|
||||
async def change_presence(self):
|
||||
async def change_presence(self) -> None:
|
||||
"""Randomly chooses a presence and updates bot's presence."""
|
||||
statuses = [
|
||||
"Now with slash commands!",
|
||||
@@ -41,7 +38,7 @@ class BotPresence(commands.Cog, name="Bot Presence"):
|
||||
"That's a lot of damage!",
|
||||
]
|
||||
|
||||
status = random.choice(statuses)
|
||||
status = random.choice(statuses) # noqa: S311
|
||||
|
||||
status += f" | {len(self.bot.guilds)} servers"
|
||||
|
||||
@@ -1,48 +1,44 @@
|
||||
"""
|
||||
Contains a loop that updates guild data in the database periodically.
|
||||
"""
|
||||
"""Contains a loop that updates guild data in the database periodically."""
|
||||
|
||||
from nextcord.ext import commands, tasks
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlmodel import col
|
||||
|
||||
# pylint: disable=import-error
|
||||
from database_setup.sql_data_classes import Guild, engine
|
||||
from agon.database.db import engine
|
||||
from agon.database.models import Guild
|
||||
|
||||
|
||||
class GuildData(commands.Cog, name="Guild Data"):
|
||||
"""Class to contain loop."""
|
||||
|
||||
def __init__(self, bot: commands.bot) -> None:
|
||||
def __init__(self, bot: commands.Bot) -> None:
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
async def on_ready(self) -> None:
|
||||
"""Starts the loop when bot is ready."""
|
||||
await self.bot.wait_until_ready()
|
||||
# pylint doesn't recognize that periodic_update_guild_data is subclassed from tasks.loop.
|
||||
await self.periodic_update_guild_data.start() # pylint: disable=no-member
|
||||
await self.periodic_update_guild_data.start()
|
||||
|
||||
@tasks.loop(hours=24)
|
||||
async def periodic_update_guild_data(self):
|
||||
async def periodic_update_guild_data(self) -> None:
|
||||
"""Loops every day, calls update_guild_data."""
|
||||
self.update_guild_data()
|
||||
|
||||
def update_guild_data(self):
|
||||
"""
|
||||
Updates all known guild's data in the database.
|
||||
"""
|
||||
def update_guild_data(self) -> None:
|
||||
"""Updates all known guild's data in the database."""
|
||||
with Session(engine) as session:
|
||||
for guild in self.bot.guilds:
|
||||
# update given guild name for guild id
|
||||
stmt = select(Guild).where(Guild.GuildId == 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.
|
||||
if guild_data is None:
|
||||
new_guild = Guild(GuildId=guild.id, GuildName=guild.name)
|
||||
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()
|
||||
@@ -1,6 +1,4 @@
|
||||
"""
|
||||
Cog for creating submission process.
|
||||
"""
|
||||
"""Cog for creating submission process."""
|
||||
|
||||
from nextcord.ext import commands
|
||||
|
||||
@@ -15,14 +13,14 @@ class SubmissionCog(commands.Cog, name="Submission Cog"):
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
"""Called when cog is loaded"""
|
||||
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):
|
||||
"""Adds function to 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 agon.database.db import engine
|
||||
from agon.database.models import Submission
|
||||
from agon.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)
|
||||
@@ -1,6 +1,4 @@
|
||||
"""
|
||||
Loads environment variables for use in bot.
|
||||
"""
|
||||
"""Loads environment variables for use in bot."""
|
||||
|
||||
import os
|
||||
|
||||
@@ -15,3 +13,4 @@ SQL_DB = os.getenv("SQL_DB", "")
|
||||
SQL_HOST = os.getenv("SQL_HOST", "")
|
||||
SQL_PASS = os.getenv("SQL_PASS", "")
|
||||
SQL_USER = os.getenv("SQL_USER", "")
|
||||
ENVIRONMENT: str = os.getenv("ENVIRONMENT", "prod")
|
||||
@@ -0,0 +1 @@
|
||||
"""Package for database interaction."""
|
||||
@@ -0,0 +1,19 @@
|
||||
"""Simple file to set up the sqlmodel connection to database."""
|
||||
|
||||
from sqlmodel import SQLModel, create_engine
|
||||
|
||||
from agon import config
|
||||
from agon.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/database.db"
|
||||
agon_logger.info("Connected to local dev database.")
|
||||
engine = create_engine(url)
|
||||
|
||||
# Don't need to create all when connected to prod.
|
||||
SQLModel.metadata.create_all(engine)
|
||||
@@ -0,0 +1,186 @@
|
||||
"""File holds all model definitions of SQL tables."""
|
||||
|
||||
from sqlalchemy.dialects.mysql import BIGINT, BOOLEAN, FLOAT, INTEGER, SMALLINT, VARCHAR
|
||||
from sqlmodel import Column, Field, ForeignKey, Relationship, SQLModel, UniqueConstraint
|
||||
|
||||
|
||||
class Guild(SQLModel, table=True):
|
||||
"""
|
||||
Represents a Guild entity in the database.
|
||||
|
||||
Attributes:
|
||||
id (int): The unique identifier for the guild.
|
||||
name (str): The name of the guild.
|
||||
submission_channel (int): The ID of the submission channel associated with the guild.
|
||||
verification_channel (int): The ID of the verification channel associated with the guild.
|
||||
active (bool): Indicates whether the guild is active. Defaults to True.
|
||||
category_groups (list[CategoryGroup]): A list of category groups associated with the guild.
|
||||
"""
|
||||
|
||||
__tablename__: str = "Guilds"
|
||||
|
||||
id: int = Field(sa_column=Column("GuildId", BIGINT(unsigned=True), primary_key=True, nullable=False))
|
||||
name: str = Field(sa_column=Column("GuildName", VARCHAR), max_length=95)
|
||||
# deprecated, not currently used.
|
||||
submission_channel: int | None = Field(
|
||||
sa_column=Column("SubmissionChannel", BIGINT(unsigned=True), nullable=True), default=None
|
||||
)
|
||||
verification_channel: int | None = Field(
|
||||
sa_column=Column("VerificationChannel", BIGINT(unsigned=True), nullable=True), default=None
|
||||
)
|
||||
active: bool = Field(sa_column=Column("Active", BOOLEAN), default=True)
|
||||
|
||||
category_groups: list["CategoryGroup"] = Relationship(back_populates="guild", cascade_delete=True)
|
||||
|
||||
|
||||
class CategoryGroup(SQLModel, table=True):
|
||||
"""
|
||||
Represents a category group in the database.
|
||||
|
||||
Attributes:
|
||||
id (int | None): The primary key of the category group.
|
||||
name (str): The name of the category group, with a maximum length of 50 characters.
|
||||
channel_id (int): The ID of the channel associated with the category group.
|
||||
guild_id (int): The ID of the guild associated with the category group.
|
||||
message_id (int): The ID of the message associated with the category group.
|
||||
pad_length (int): The padding length for the category group, default is 12.
|
||||
username_length (int): The username length for the category group, default is 12.
|
||||
guild (Guild | None): The guild relationship back-populated from the Guild model.
|
||||
|
||||
Table Constraints:
|
||||
__table_args__: Unique constraint on guild_id and name to ensure unique category groups within a guild.
|
||||
"""
|
||||
|
||||
__tablename__: str = "CategoryGroups"
|
||||
|
||||
id: int | None = Field(sa_column=Column("GroupId", INTEGER, primary_key=True), default=None)
|
||||
name: str = Field(sa_column=Column("GroupName", VARCHAR), max_length=50)
|
||||
channel_id: int = Field(sa_column=Column("ChannelId", BIGINT(unsigned=True)))
|
||||
guild_id: int = Field(
|
||||
sa_column=Column(
|
||||
"GuildId",
|
||||
BIGINT(unsigned=True),
|
||||
ForeignKey("Guilds.GuildId", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
)
|
||||
)
|
||||
message_id: int | None = Field(sa_column=Column("MessageId", BIGINT(unsigned=True)), default=None)
|
||||
pad_length: int = Field(default=12, sa_column=Column("PadLength", SMALLINT(unsigned=True)))
|
||||
username_length: int = Field(default=12, sa_column=Column("UsernameLength", SMALLINT(unsigned=True)))
|
||||
|
||||
__table_args__ = (UniqueConstraint("GuildId", "GroupName", name="UniqueGuildCategoryGroup"),)
|
||||
|
||||
guild: Guild | None = Relationship(back_populates="category_groups")
|
||||
categories: list["Category"] | None = Relationship(back_populates="category_group", cascade_delete=True)
|
||||
|
||||
|
||||
class Category(SQLModel, table=True):
|
||||
"""
|
||||
Represents a category in the database.
|
||||
|
||||
Attributes:
|
||||
id (int): The unique identifier for the category. Primary key.
|
||||
name (str): The name of the category with a maximum length of 30 characters.
|
||||
group_id (int): The identifier of the group to which the category belongs.
|
||||
Foreign key referencing CategoryGroups.id.
|
||||
size (int): The size attribute of the category, default is 3.
|
||||
is_ascending (bool): Indicates if the category is in ascending order. Default is True.
|
||||
is_time_record (bool): Indicates if the category is a time record. Default is False.
|
||||
is_validated (bool): Indicates if the category is validated. Default is True.
|
||||
category_group (CategoryGroup | None): The relationship to the CategoryGroup model.
|
||||
scores (list["Score"] | None): The relationship to the Score model with cascade delete enabled.
|
||||
|
||||
Table Constraints:
|
||||
__table_args__: Unique constraint on group_id and name to ensure unique category names within a group.
|
||||
"""
|
||||
|
||||
__tablename__: str = "Categories"
|
||||
|
||||
id: int = Field(sa_column=Column("CategoryId", INTEGER, primary_key=True), default=None)
|
||||
name: str = Field(sa_column=Column("CategoryName", VARCHAR), max_length=30)
|
||||
group_id: int = Field(
|
||||
sa_column=Column(
|
||||
"GroupId",
|
||||
INTEGER(unsigned=True),
|
||||
ForeignKey("CategoryGroups.GroupId", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
)
|
||||
)
|
||||
size: int = Field(sa_column=Column("Size", SMALLINT(unsigned=True), nullable=False), default=3)
|
||||
is_ascending: bool = Field(sa_column=Column("IsAscending", BOOLEAN, nullable=False), default=True)
|
||||
is_time_record: bool = Field(sa_column=Column("IsTimeRecord", BOOLEAN, nullable=False), default=False)
|
||||
is_validated: bool = Field(sa_column=Column("IsValidated", BOOLEAN, nullable=False), default=True)
|
||||
|
||||
__table_args__ = (UniqueConstraint("GroupId", "CategoryName", name="UniqueCategoryInGroup"),)
|
||||
|
||||
category_group: CategoryGroup | None = Relationship(back_populates="categories")
|
||||
scores: list["Score"] | None = Relationship(back_populates="category", cascade_delete=True)
|
||||
|
||||
|
||||
class Score(SQLModel, table=True):
|
||||
"""
|
||||
Represents a score entry in the database.
|
||||
|
||||
Attributes:
|
||||
username (str): The username associated with the score. This is a primary key.
|
||||
score (float): The score value.
|
||||
category_id (int): The ID of the category this score belongs to. This is a primary key and a foreign key
|
||||
referencing the Categories table.
|
||||
category (Category | None): The relationship to the Category model, back-populated by the scores attribute
|
||||
in the Category model.
|
||||
"""
|
||||
|
||||
__tablename__: str = "Scores"
|
||||
|
||||
username: str = Field(sa_column=Column("UserName", VARCHAR, primary_key=True, nullable=False), max_length=30)
|
||||
score: float = Field(sa_column=Column("Score", FLOAT, nullable=False))
|
||||
category_id: int = Field(
|
||||
sa_column=Column(
|
||||
"CategoryId",
|
||||
INTEGER(unsigned=True),
|
||||
ForeignKey("Categories.CategoryId", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
primary_key=True,
|
||||
),
|
||||
)
|
||||
|
||||
category: Category | None = Relationship(back_populates="scores")
|
||||
|
||||
|
||||
class Submission(SQLModel, table=True):
|
||||
"""
|
||||
Represents a submission in the database.
|
||||
|
||||
Attributes:
|
||||
category_id (int): The ID of the category. This is a primary key.
|
||||
group_id (int): The ID of the group.
|
||||
guild_id (int): The ID of the guild.
|
||||
message_id (int): The ID of the message.
|
||||
score (str): The score of the submission, with a maximum length of 30 characters.
|
||||
user_id (int): The ID of the user.
|
||||
username (str): The username of the user. This is a primary key.
|
||||
"""
|
||||
|
||||
__tablename__: str = "Submissions"
|
||||
|
||||
category_id: int = Field(
|
||||
sa_column=Column(
|
||||
"CategoryId",
|
||||
INTEGER(unsigned=True),
|
||||
nullable=False,
|
||||
primary_key=True,
|
||||
),
|
||||
)
|
||||
group_id: int = Field(
|
||||
sa_column=Column(
|
||||
"GroupId",
|
||||
INTEGER(unsigned=True),
|
||||
nullable=False,
|
||||
)
|
||||
)
|
||||
guild_id: int = Field(sa_column=Column("GuildId", BIGINT(unsigned=True), nullable=False))
|
||||
message_id: int = Field(sa_column=Column("MessageId", BIGINT(unsigned=True), nullable=False))
|
||||
# Score is stored as a string until converted during submission.
|
||||
score: str = Field(sa_column=Column("Score", VARCHAR, nullable=False), max_length=30)
|
||||
user_id: int = Field(sa_column=Column("UserId", BIGINT(unsigned=True), nullable=False))
|
||||
username: str = Field(sa_column=Column("UserName", VARCHAR, nullable=False, primary_key=True), max_length=30)
|
||||
@@ -0,0 +1,10 @@
|
||||
"""Creates logger for Agon bot."""
|
||||
|
||||
import logging
|
||||
import sys
|
||||
|
||||
agon_logger = logging.getLogger("default")
|
||||
agon_logger.setLevel(logging.INFO)
|
||||
handler = logging.StreamHandler(sys.stdout)
|
||||
handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
|
||||
agon_logger.addHandler(handler)
|
||||
@@ -1,17 +1,16 @@
|
||||
"""
|
||||
Contains various utlity functions for highscores bot
|
||||
"""
|
||||
"""Contains various utility functions for highscores bot."""
|
||||
|
||||
import json
|
||||
import time
|
||||
|
||||
import nextcord
|
||||
import pandas as pd
|
||||
from sqlalchemy import distinct, select
|
||||
from sqlalchemy.orm import Session, aliased
|
||||
from sqlmodel import col
|
||||
|
||||
# pylint: disable=import-error
|
||||
from database_setup.sql_data_classes import Category, CategoryGroup, Guild, Score, engine
|
||||
from agon.database.db import engine
|
||||
from agon.database.models import Category, CategoryGroup, Guild, Score
|
||||
from agon.logger import agon_logger
|
||||
|
||||
MAX_LINE_LENGTH = 142
|
||||
|
||||
@@ -19,6 +18,7 @@ MAX_LINE_LENGTH = 142
|
||||
def autofill_categories(guild_id: int, group_id: int, category_begin: str) -> "dict[str, str]":
|
||||
"""
|
||||
Returns all category names that start with category_begin.
|
||||
|
||||
If category_begin is empty, returns list of all category names.
|
||||
|
||||
Args:
|
||||
@@ -33,20 +33,19 @@ def autofill_categories(guild_id: int, group_id: int, category_begin: str) -> "d
|
||||
# search database for all category names
|
||||
subq = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == guild_id)
|
||||
.where(CategoryGroup.GroupId == group_id)
|
||||
.where(col(CategoryGroup.guild_id) == guild_id)
|
||||
.where(col(CategoryGroup.id) == group_id)
|
||||
.subquery()
|
||||
)
|
||||
cat_group_alias = aliased(CategoryGroup, subq)
|
||||
stmt = select(Category).where(Category.GroupId == cat_group_alias.GroupId)
|
||||
categories_dict: dict[str, str] = {cat.CategoryName: str(cat.CategoryId) for cat in session.scalars(stmt)}
|
||||
stmt = select(Category).where(col(Category.group_id) == cat_group_alias.id)
|
||||
categories_dict: dict[str, str] = {cat.name: str(cat.id) for cat in session.scalars(stmt)}
|
||||
|
||||
# if string empty, return all category names
|
||||
if not category_begin:
|
||||
return dict(list(categories_dict.items())[:25])
|
||||
|
||||
# else find all categories that start with category_begin
|
||||
# TODO is it better to have sql handle the starts with or python?
|
||||
categories: dict[str, str] = {
|
||||
cat_name: cat_id for cat_name, cat_id in categories_dict.items() if category_begin.lower() in cat_name.lower()
|
||||
}
|
||||
@@ -66,10 +65,10 @@ 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).where(CategoryGroup.GuildId == 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.GroupName: str(group.GroupId) for group in session.scalars(stmt)}
|
||||
group_dict: dict[str, str] = {group.name: str(group.id) for group in session.scalars(stmt)}
|
||||
|
||||
# if string empty, return all group names
|
||||
if not group_begin:
|
||||
@@ -85,8 +84,10 @@ def autofill_groups(guild_id: int, group_begin: str) -> "dict[str, str]":
|
||||
|
||||
def autofill_users_in_group_category(guild_id: int, group_id: int, category_id: int, user_begin: str) -> "list[str]":
|
||||
"""
|
||||
Returns list of users that match user_begin. Either all users in group or just users in category if category is
|
||||
not None. Might be expensive due to unioning all users in group.
|
||||
Returns list of users that match user_begin.
|
||||
|
||||
Either all users in group or just users in category if category is not None. Might be expensive due to union-ing all
|
||||
users in group.
|
||||
|
||||
Args:
|
||||
guild_id (int): Guild id corresponding to group and category.
|
||||
@@ -101,27 +102,27 @@ def autofill_users_in_group_category(guild_id: int, group_id: int, category_id:
|
||||
# get all categories in the group
|
||||
subq = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == guild_id)
|
||||
.where(CategoryGroup.GroupId == group_id)
|
||||
.where(col(CategoryGroup.guild_id) == guild_id)
|
||||
.where(col(CategoryGroup.id) == group_id)
|
||||
.subquery()
|
||||
)
|
||||
category_group = aliased(CategoryGroup, subq)
|
||||
|
||||
# If no category id, get all users in group.
|
||||
if category_id == 0:
|
||||
subq = select(Category.CategoryId).where(Category.GroupId == category_group.GroupId)
|
||||
stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(subq))
|
||||
subq = select(col(Category.id)).where(col(Category.group_id) == category_group.id)
|
||||
stmt = select(distinct(col(Score.username))).where(col(Score.category_id).in_(subq))
|
||||
|
||||
else:
|
||||
# get all users in category_id
|
||||
subq = (
|
||||
select(Category)
|
||||
.where(Category.GroupId == category_group.GroupId)
|
||||
.where(Category.CategoryId == category_id)
|
||||
.where(col(Category.group_id) == category_group.id)
|
||||
.where(col(Category.id) == category_id)
|
||||
.subquery()
|
||||
)
|
||||
category = aliased(Category, subq)
|
||||
stmt = select(distinct(Score.UserName)).where(Score.CategoryId == category.CategoryId)
|
||||
stmt = select(distinct(col(Score.username))).where(col(Score.category_id) == category.id)
|
||||
|
||||
users_list: list[str] = list(session.scalars(stmt))
|
||||
|
||||
@@ -147,9 +148,9 @@ def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]":
|
||||
list[str]: All users with submissions in the guild.
|
||||
"""
|
||||
with Session(engine) as session:
|
||||
group_ids = select(CategoryGroup.GroupId).where(CategoryGroup.GuildId == guild_id)
|
||||
category_ids = select(Category.CategoryId).where(Category.GroupId.in_(group_ids))
|
||||
stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(category_ids))
|
||||
group_ids = select(col(CategoryGroup.id)).where(col(CategoryGroup.guild_id) == guild_id)
|
||||
category_ids = select(col(Category.id)).where(col(Category.group_id).in_(group_ids))
|
||||
stmt = select(distinct(col(Score.username))).where(col(Score.category_id).in_(category_ids))
|
||||
users_list: list[str] = list(session.scalars(stmt))
|
||||
|
||||
# if string empty, return all users
|
||||
@@ -162,9 +163,12 @@ def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]":
|
||||
return users[:25]
|
||||
|
||||
|
||||
# TODO(imcompiling): #73 Address complexity warning.
|
||||
# 073
|
||||
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 category's highscore discord message.
|
||||
|
||||
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.
|
||||
|
||||
@@ -175,34 +179,34 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
||||
Returns:
|
||||
str: Formatted string for discord message
|
||||
"""
|
||||
ret_string = f"**{group.GroupName}**\n```"
|
||||
ret_string = f"**{group.name}**\n```"
|
||||
|
||||
stmt = select(Guild).where(Guild.GuildId == group.GuildId)
|
||||
stmt = select(Guild).where(col(Guild.id) == group.guild_id)
|
||||
|
||||
# Get all categories in the group
|
||||
subq = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == group.GuildId)
|
||||
.where(CategoryGroup.GroupName == group.GroupName)
|
||||
.where(col(CategoryGroup.guild_id) == group.guild_id)
|
||||
.where(col(CategoryGroup.name) == group.name)
|
||||
.subquery()
|
||||
)
|
||||
cat_group_alias = aliased(CategoryGroup, subq)
|
||||
stmt = select(Category).where(Category.GroupId == cat_group_alias.GroupId)
|
||||
stmt = select(Category).where(col(Category.group_id) == cat_group_alias.id)
|
||||
|
||||
# set up a map for the categories
|
||||
# also grab the max category size
|
||||
categories = []
|
||||
categories: list[Category] = []
|
||||
category_ids = []
|
||||
max_cat_size: int = 0
|
||||
pad_length = group.PadLength
|
||||
pad_length = group.pad_length
|
||||
for cat in session.scalars(stmt):
|
||||
max_cat_size = max(cat.Size, max_cat_size)
|
||||
max_cat_size = max(cat.size, max_cat_size)
|
||||
categories.append(cat)
|
||||
category_ids.append(cat.CategoryId)
|
||||
category_ids.append(cat.id)
|
||||
|
||||
# get all scores in category group, load into data frame.
|
||||
d_f = pd.read_sql_query(
|
||||
sql=session.query(Score).where(Score.CategoryId.in_(category_ids)).statement,
|
||||
sql=session.query(Score).where(col(Score.category_id).in_(category_ids)).statement,
|
||||
con=engine,
|
||||
)
|
||||
|
||||
@@ -211,18 +215,17 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
||||
str_list: list[str] = ["" for i in range(max_cat_size + 1)]
|
||||
groups_df = d_f.groupby("CategoryId")
|
||||
|
||||
# TODO figure out how to have less nests.
|
||||
for category in categories:
|
||||
# category name string
|
||||
str_list[0] += f"{category.CategoryName}".ljust(pad_length, " ")
|
||||
str_list[0] += f"{category.name}".ljust(pad_length, " ")
|
||||
|
||||
# ensure there is data to print
|
||||
if category.CategoryId in groups_df.indices:
|
||||
group_df = groups_df.get_group(category.CategoryId)
|
||||
if category.id in groups_df.indices:
|
||||
group_df = groups_df.get_group(category.id)
|
||||
|
||||
# process data. Want each group sorted correctly and only top X results
|
||||
processed_group = (
|
||||
group_df.sort_values("Score", ascending=category.IsAscending).head(category.Size).reset_index()
|
||||
group_df.sort_values("Score", ascending=category.is_ascending).head(category.size).reset_index()
|
||||
)
|
||||
|
||||
# add each score to list
|
||||
@@ -234,19 +237,19 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
||||
str_list[ind + 1] += format_score_string(
|
||||
username,
|
||||
score,
|
||||
group.UsernameLength,
|
||||
category.IsTimeRecord,
|
||||
group.username_length,
|
||||
category.is_time_record,
|
||||
ind + 1,
|
||||
pad_length,
|
||||
)
|
||||
# if not enough entries, pad out
|
||||
elif ind + 1 <= category.Size:
|
||||
elif ind + 1 <= category.size:
|
||||
str_list[ind + 1] += f"{ind + 1}: ".ljust(pad_length, " ")
|
||||
else:
|
||||
str_list[ind + 1] += "".ljust(pad_length, " ")
|
||||
else:
|
||||
for ind in range(max_cat_size):
|
||||
if ind + 1 <= category.Size:
|
||||
if ind + 1 <= category.size:
|
||||
str_list[ind + 1] += f"{ind + 1}: ".ljust(pad_length, " ")
|
||||
else:
|
||||
str_list[ind + 1] += "".ljust(pad_length, " ")
|
||||
@@ -267,14 +270,14 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
||||
ret_string += string.rstrip() + "\n"
|
||||
|
||||
# add extra newline at category split unless there is already a space.
|
||||
if ((ind + 1) % (max_cat_size + 1)) == 0:
|
||||
# checking inside the other if to ensure called as little as possible.
|
||||
if not ret_string.endswith("\n\n"):
|
||||
if ((ind + 1) % (max_cat_size + 1)) == 0 and not ret_string.endswith("\n\n"):
|
||||
ret_string += "\n"
|
||||
|
||||
return ret_string + "```"
|
||||
|
||||
|
||||
# TODO(imcompiling): rework into two functions to remove the boolean and reduce function arguments.
|
||||
# 084
|
||||
def format_score_string(
|
||||
username: str,
|
||||
score: float,
|
||||
@@ -303,13 +306,13 @@ def format_score_string(
|
||||
if is_time_record:
|
||||
# MM:SS.ms is 7 characters long
|
||||
# if there are single digit minutes, add a space for formatting.
|
||||
score = get_time_str(score)
|
||||
if score.find(":") and len(score.split(":", maxsplit=1)[0]) < 2:
|
||||
score = " " + score
|
||||
formatted_score = get_time_str(score)
|
||||
if formatted_score.find(":") and len(formatted_score.split(":", maxsplit=1)[0]) < 2: # noqa: PLR2004
|
||||
formatted_score = " " + formatted_score
|
||||
else:
|
||||
score = str(int(score)).rjust(7, " ")
|
||||
formatted_score = str(int(score)).rjust(7, " ")
|
||||
|
||||
return f"{rank}: {username} - {score}".ljust(pad_length, " ")
|
||||
return f"{rank}: {username} - {formatted_score}".ljust(pad_length, " ")
|
||||
|
||||
|
||||
def get_time_str(time_in: float) -> str:
|
||||
@@ -327,32 +330,38 @@ def get_time_str(time_in: float) -> str:
|
||||
return time.strftime(f"%-M:%S.{milliseconds}", time.gmtime(time_in))
|
||||
|
||||
|
||||
async def send_highscore_message(session: Session, guild: nextcord.Guild, group: CategoryGroup) -> nextcord.Message:
|
||||
async def send_highscore_message(session: Session, guild: nextcord.Guild, group: CategoryGroup) -> None:
|
||||
"""
|
||||
Function takes care of checking if a message exists for a group.
|
||||
|
||||
Creates and sends/edits the message.
|
||||
|
||||
Args:
|
||||
session (Session): The sqlalchemy session being used for this function call.
|
||||
guild (nextcord.Guild): the nextcord.Guild object requesting this message.
|
||||
group (CategoryGroup): group to post to the message.
|
||||
|
||||
Returns:
|
||||
nextcord.Message: Message object that was posted with group contents.
|
||||
"""
|
||||
highscore_string = format_highscore_message(session, group)
|
||||
channel = guild.get_channel(group.ChannelId)
|
||||
channel = guild.get_channel(group.channel_id)
|
||||
|
||||
if group.MessageId is None:
|
||||
if not isinstance(channel, nextcord.TextChannel):
|
||||
agon_logger.error(
|
||||
"Channel id %s in guild %s is does not correspond to a TextChannel.", channel.id, channel.guild.id
|
||||
)
|
||||
return
|
||||
|
||||
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:
|
||||
message: nextcord.Message = await channel.fetch_message(group.MessageId)
|
||||
# TODO(imcompiling): check what happens when message is deleted.
|
||||
# https://gitea.cheezers.org/imcompiling/agon/issues/83
|
||||
message: nextcord.Message = await channel.fetch_message(group.message_id)
|
||||
await message.edit(content=highscore_string)
|
||||
|
||||
return message
|
||||
return
|
||||
|
||||
|
||||
async def submit_score(
|
||||
@@ -364,65 +373,38 @@ async def submit_score(
|
||||
) -> None:
|
||||
"""
|
||||
Adds passed score to group. Then updates group message by calling send_highscore_message.
|
||||
|
||||
Ensures that a highscores channel exists.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that caused the score submission.
|
||||
group (CategoryGroup): group to submit score to.
|
||||
category_id (Category): Category to submit score to.
|
||||
group_id (int): group id to submit score to.
|
||||
category_id (int): Category id to submit score to.
|
||||
username (str): The user who submitted the score.
|
||||
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(col(Category.is_time_record)).where(col(Category.id) == category_id)
|
||||
is_time_record = session.scalar(stmt)
|
||||
|
||||
if is_time_record:
|
||||
minutes = float(score.split(":", maxsplit=1)[0])
|
||||
seconds = float(score.split(":", maxsplit=1)[1])
|
||||
score = (minutes * 60) + seconds
|
||||
score_f = (minutes * 60) + seconds
|
||||
else:
|
||||
score = float(score)
|
||||
score_f = float(score)
|
||||
|
||||
stmt = select(Score).where(Score.UserName == username).where(Score.CategoryId == category_id)
|
||||
stmt = select(Score).where(col(Score.username) == username).where(col(Score.category_id) == category_id)
|
||||
existing_score = session.scalar(stmt)
|
||||
|
||||
if existing_score:
|
||||
existing_score.Score = score
|
||||
existing_score.score = score_f
|
||||
else:
|
||||
score_obj = Score(UserName=username, Score=score, CategoryId=category_id)
|
||||
score_obj = Score(username=username, score=score_f, category_id=category_id)
|
||||
session.add(score_obj)
|
||||
session.commit()
|
||||
|
||||
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == group_id)
|
||||
stmt = select(CategoryGroup).where(col(CategoryGroup.id) == group_id)
|
||||
group = session.scalar(stmt)
|
||||
|
||||
await send_highscore_message(session, interaction.guild, group)
|
||||
|
||||
|
||||
def add_preset_configuration(guild_id: int, config_str: str) -> None:
|
||||
"""
|
||||
Adds an example configuration to a Guild. Uses guild id to know which guild and
|
||||
config name to open a file in example_config.
|
||||
|
||||
Args:
|
||||
guild_id (int): Guild id to add config to
|
||||
config_str (str): Config name to add
|
||||
"""
|
||||
with Session(engine) as session:
|
||||
with open(f"example_config/{config_str}.json", encoding="utf-8") as file:
|
||||
config = json.load(file)
|
||||
|
||||
for group_name, categorys in config["tables"].items():
|
||||
group_obj = CategoryGroup(GroupName=group_name, GuildId=guild_id)
|
||||
session.add(group_obj)
|
||||
for category_name in categorys:
|
||||
cat_obj = Category(
|
||||
CategoryName=category_name,
|
||||
Size=config["table_size"],
|
||||
IsTimeRecord=config["categories"][category_name]["is_time_record"],
|
||||
IsAscending=config["categories"][category_name]["ascending"],
|
||||
)
|
||||
session.add(cat_obj)
|
||||
|
||||
session.commit()
|
||||
@@ -1,280 +0,0 @@
|
||||
"""
|
||||
Contains classes and enum for tracking data on submissions.
|
||||
"""
|
||||
|
||||
from enum import Enum
|
||||
|
||||
from nextcord import Embed
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
# pylint: disable=import-error
|
||||
from database_setup.sql_data_classes import Category, CategoryGroup, engine
|
||||
|
||||
|
||||
class SubmissionState(Enum):
|
||||
"""
|
||||
Enum for which state a submission is in
|
||||
"""
|
||||
|
||||
CATEGORY = 1
|
||||
SCORE = 2
|
||||
PROOF = 3
|
||||
NAME = 4
|
||||
SUBMIT = 5
|
||||
VERIFY = 6
|
||||
|
||||
|
||||
# TODO remake into a data class
|
||||
class Submission:
|
||||
"""
|
||||
Class for an individual submission. Contains submission information such as
|
||||
guild id, message id, table, category, username, score and submission state.
|
||||
"""
|
||||
|
||||
def __init__(self, guild_id: int, group_id: int, username: str) -> None:
|
||||
"""
|
||||
Default constructor for Submission. Just need to know guild_id, table, and username.
|
||||
Score and category are defaulted at empty, message id is 0, and submission state
|
||||
is SubmissionState.CATEGORY.
|
||||
"""
|
||||
self._category_id: int = 0
|
||||
self._guild_id: int = guild_id
|
||||
self._message_id: int = 0
|
||||
self._score: str = ""
|
||||
self._submission_state: SubmissionState = SubmissionState.CATEGORY
|
||||
self._group_id: int = group_id
|
||||
self._username: str = username
|
||||
|
||||
@property
|
||||
def category_id(self) -> int:
|
||||
"""
|
||||
Getter for Submission's Category id.
|
||||
|
||||
Returns:
|
||||
int: Category id.
|
||||
"""
|
||||
return self._category_id
|
||||
|
||||
@category_id.setter
|
||||
def category_id(self, category: int) -> None:
|
||||
"""
|
||||
Setter for Submission's Category id.
|
||||
|
||||
Args:
|
||||
category (int): Category id
|
||||
"""
|
||||
self._category_id = category
|
||||
|
||||
@property
|
||||
def guild_id(self) -> int:
|
||||
"""
|
||||
Getter for guild id Submission is happening in. Will not change.
|
||||
|
||||
Returns:
|
||||
int: guild id
|
||||
"""
|
||||
return self._guild_id
|
||||
|
||||
@property
|
||||
def message_id(self) -> int:
|
||||
"""
|
||||
Getter for message id that Submission has a view on.
|
||||
|
||||
Returns:
|
||||
int: message id
|
||||
"""
|
||||
return self._message_id
|
||||
|
||||
@message_id.setter
|
||||
def message_id(self, m_id: int) -> None:
|
||||
"""
|
||||
Setter for message id that Submission has a view on.
|
||||
|
||||
Args:
|
||||
m_id (int): message id
|
||||
"""
|
||||
self._message_id = m_id
|
||||
|
||||
@property
|
||||
def score(self) -> str:
|
||||
"""
|
||||
Getter for score.
|
||||
|
||||
Returns:
|
||||
str: score
|
||||
"""
|
||||
return self._score
|
||||
|
||||
@score.setter
|
||||
def score(self, score: str) -> None:
|
||||
"""
|
||||
Setter for score.
|
||||
|
||||
Args:
|
||||
score (str): score
|
||||
"""
|
||||
self._score = score
|
||||
|
||||
@property
|
||||
def submission_state(self) -> SubmissionState:
|
||||
"""
|
||||
Getter for state Submission is in.
|
||||
|
||||
Returns:
|
||||
SubmissionState: State the Submission is in
|
||||
"""
|
||||
return self._submission_state
|
||||
|
||||
@submission_state.setter
|
||||
def submission_state(self, state: SubmissionState) -> None:
|
||||
"""
|
||||
Setter for state Submission is in.
|
||||
|
||||
Args:
|
||||
state (SubmissionState): State to change to
|
||||
"""
|
||||
self._submission_state = state
|
||||
|
||||
@property
|
||||
def group_id(self) -> str:
|
||||
"""
|
||||
Getter for group Submission is for.
|
||||
|
||||
Returns:
|
||||
str: group id
|
||||
"""
|
||||
return self._group_id
|
||||
|
||||
@group_id.setter
|
||||
def group_id(self, table: str) -> None:
|
||||
"""
|
||||
Getter for table Submission is for.
|
||||
|
||||
Args:
|
||||
table (str): group id
|
||||
"""
|
||||
self._group_id = table
|
||||
|
||||
@property
|
||||
def username(self) -> str:
|
||||
"""
|
||||
Getter for Submission owner's username.
|
||||
|
||||
Returns:
|
||||
str: Submission owner's username
|
||||
"""
|
||||
return self._username
|
||||
|
||||
@username.setter
|
||||
def username(self, username: str) -> None:
|
||||
"""
|
||||
Setter for Submission owner's username.
|
||||
|
||||
Args:
|
||||
username (str): Submission owner's username
|
||||
"""
|
||||
self._username = username
|
||||
|
||||
def get_embeds(self) -> "list[Embed]":
|
||||
"""Creates an embed based off of the submission state and fields filled out."""
|
||||
state: SubmissionState = self.submission_state
|
||||
|
||||
if state is SubmissionState.CATEGORY:
|
||||
description = "Step 1: Choose your category!"
|
||||
elif state is SubmissionState.SCORE:
|
||||
description = "Step 2: Send a message to input your score!"
|
||||
elif state is SubmissionState.PROOF:
|
||||
description = "Step 3: Send a message with a picture attached to submit your proof!"
|
||||
elif state is SubmissionState.NAME:
|
||||
description = (
|
||||
"Step 4 (Optional): Send a message to change name on submission! (proceed to next if skipping)"
|
||||
)
|
||||
elif state is SubmissionState.SUBMIT:
|
||||
description = "Step 5: Submit if everything looks correct!"
|
||||
elif state is SubmissionState.VERIFY:
|
||||
description = "Review fields and accept."
|
||||
|
||||
embed = Embed(title="Highscores Submission", description=description)
|
||||
embed.add_field(name="User Name", value=self.username, inline=False)
|
||||
stmt = (
|
||||
select(CategoryGroup.GroupName)
|
||||
.where(CategoryGroup.GuildId == self.guild_id)
|
||||
.where(CategoryGroup.GroupId == self.group_id)
|
||||
)
|
||||
with Session(engine) as session:
|
||||
embed.add_field(name="Group", value=session.scalar(stmt), inline=False)
|
||||
if self.category_id:
|
||||
stmt = (
|
||||
select(Category.CategoryName)
|
||||
.where(Category.GroupId == self.group_id)
|
||||
.where(Category.CategoryId == self.category_id)
|
||||
)
|
||||
embed.add_field(name="Category", value=session.scalar(stmt), inline=False)
|
||||
if self.score:
|
||||
embed.add_field(name="Score", value=self.score, inline=False)
|
||||
|
||||
embeds = [embed]
|
||||
|
||||
if state is SubmissionState.VERIFY:
|
||||
embed = Embed(title="Bot Information", description="Please disregard.")
|
||||
embed.add_field(name="GroupId", value=self.group_id)
|
||||
embed.add_field(name="CategoryId", value=self.category_id)
|
||||
embeds.append(embed)
|
||||
return embeds
|
||||
|
||||
|
||||
class SubmissionMap:
|
||||
"""
|
||||
Tracks all active submission.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""
|
||||
Default constructor for SubmissionMap. Created empty map.
|
||||
"""
|
||||
self._submission_map: dict = {}
|
||||
|
||||
def add_submission(self, user_id: int, submission: Submission) -> None:
|
||||
"""
|
||||
Adds new submission to submission map. User id is used as a key, a user should only
|
||||
have one submission at a time.
|
||||
|
||||
Args:
|
||||
user_id (int): User id of submitter. Unique, used as key.
|
||||
submission (Submission): Submission object
|
||||
"""
|
||||
self._submission_map[user_id] = submission
|
||||
|
||||
def get_user_submission(self, user_id: int) -> Submission:
|
||||
"""
|
||||
Getter for a user's Submission.
|
||||
|
||||
Args:
|
||||
user_id (int): user id
|
||||
|
||||
Returns:
|
||||
Submission: user's submission
|
||||
"""
|
||||
return self._submission_map[user_id]
|
||||
|
||||
def has_user(self, user_id: int) -> bool:
|
||||
"""
|
||||
Tells if user has an active submission in submission map.
|
||||
|
||||
Args:
|
||||
user_id (int): user id
|
||||
|
||||
Returns:
|
||||
bool: bool indicating if user id is in submission map
|
||||
"""
|
||||
return user_id in self._submission_map
|
||||
|
||||
def remove_user_submission(self, user_id: int) -> None:
|
||||
"""
|
||||
Removes a user's Submission. Use when Submission is complete.
|
||||
|
||||
Args:
|
||||
user_id (int): user id to identify user's Submission
|
||||
"""
|
||||
self._submission_map.pop(user_id)
|
||||
@@ -1,28 +0,0 @@
|
||||
"""
|
||||
Cog loader. Adds all command cogs to the bot.
|
||||
"""
|
||||
|
||||
from nextcord.ext import commands
|
||||
|
||||
from .create import CreateCog
|
||||
from .delete import DeleteCog
|
||||
from .help import HelpCog
|
||||
from .refresh import RefreshCog
|
||||
from .set import SetCog
|
||||
from .update import UpdateCog
|
||||
from .view import ViewCog
|
||||
|
||||
|
||||
# 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):
|
||||
"""
|
||||
Adds all command classes to bot.
|
||||
"""
|
||||
bot.add_cog(CreateCog(bot))
|
||||
bot.add_cog(DeleteCog())
|
||||
bot.add_cog(HelpCog())
|
||||
bot.add_cog(RefreshCog(bot))
|
||||
bot.add_cog(SetCog())
|
||||
bot.add_cog(UpdateCog(bot))
|
||||
bot.add_cog(ViewCog())
|
||||
@@ -1,45 +0,0 @@
|
||||
"""
|
||||
Commands for helping a user.
|
||||
"""
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
|
||||
|
||||
class HelpCog(commands.Cog, name="Help commands."):
|
||||
"""
|
||||
Class holds commands for getting help.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""
|
||||
Default constructor for HelpCog class. Does nothing.
|
||||
"""
|
||||
|
||||
@nextcord.slash_command()
|
||||
async def help(self, interaction: nextcord.Interaction):
|
||||
"""
|
||||
Parent slash command for help. Never called.
|
||||
"""
|
||||
|
||||
@help.subcommand(description="Describes how to get started with Agon.")
|
||||
async def setup(self, interaction: nextcord.Interaction):
|
||||
"""
|
||||
Sends a message describing how to get started with Agon.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
"""
|
||||
# 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."
|
||||
This channel will be where all user submission messages are sent.
|
||||
|
||||
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!"""
|
||||
# pylint: enable=line-too-long
|
||||
|
||||
await interaction.response.send_message(content=help_str)
|
||||
@@ -1,205 +0,0 @@
|
||||
"""
|
||||
Set command heirarchy.
|
||||
"""
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
# pylint: disable=import-error
|
||||
from database_setup.sql_data_classes import CategoryGroup, Guild, engine
|
||||
from utilities.utils import MAX_LINE_LENGTH, autofill_groups
|
||||
|
||||
|
||||
class SetCog(commands.Cog, name="Set command."):
|
||||
"""
|
||||
Class holds commands for setting variables in guild's database.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""
|
||||
Default constructor for SetCog class. Does nothing.
|
||||
"""
|
||||
|
||||
@nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True))
|
||||
async def set(self, interaction: nextcord.Interaction):
|
||||
"""
|
||||
Parent slash command for setting settings. Never called.
|
||||
"""
|
||||
|
||||
@set.subcommand(description="Registers the channel for a Category Group's messages.")
|
||||
async def group_output_channel(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(
|
||||
name="group", description="Category Group to assign to channel.", required=True
|
||||
),
|
||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
||||
description="Channel to register",
|
||||
required=False,
|
||||
channel_types=[nextcord.ChannelType.text],
|
||||
default=None,
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Command function to register a CategoryGroup's output channel.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
||||
channel (nextcord.abc.GuildChannel, optional): Channel to register
|
||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||
"""
|
||||
if not channel:
|
||||
channel = interaction.channel
|
||||
channel_id = channel.id
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
.where(CategoryGroup.GroupId == int(group_id))
|
||||
)
|
||||
group = session.scalar(stmt)
|
||||
group.ChannelId = channel_id
|
||||
session.commit()
|
||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
||||
|
||||
@set.subcommand(
|
||||
description="Set character length for a category. Can cut off username/score. Affects all categories."
|
||||
)
|
||||
async def pad_length(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(
|
||||
name="group", description="Category Group to assign pad length to.", required=True
|
||||
),
|
||||
length: int = nextcord.SlashOption(
|
||||
description="Number of characters alloted to a category.",
|
||||
required=True,
|
||||
default=26,
|
||||
min_value=7,
|
||||
max_value=MAX_LINE_LENGTH,
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Changes guild's category pad length.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||
group_id (str): String representation of Group id to set pad length in. Is SlashOption.
|
||||
length (int): Number of characters. Is SlashOption. Defaults to 26.
|
||||
"""
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
.where(CategoryGroup.GroupId == int(group_id))
|
||||
)
|
||||
group = session.scalar(stmt)
|
||||
group.PadLength = length
|
||||
session.commit()
|
||||
await interaction.response.send_message(
|
||||
f"Category pad length set to {length} for {group.GroupName}", ephemeral=True
|
||||
)
|
||||
|
||||
@set.subcommand(description="Registers the channel for submission messages.")
|
||||
async def submission_channel(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
||||
description="Channel to register",
|
||||
required=False,
|
||||
channel_types=[nextcord.ChannelType.text],
|
||||
default=None,
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Command function to register the submission message channel.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||
channel Optional[nextcord.abc.GuildChannel], optional): Channel to register
|
||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||
"""
|
||||
if not channel:
|
||||
channel = interaction.channel
|
||||
|
||||
with Session(engine) as session:
|
||||
channel_id = channel.id
|
||||
stmt = select(Guild).where(Guild.GuildId == interaction.guild_id)
|
||||
guild = session.scalar(stmt)
|
||||
guild.SubmissionChannel = channel_id
|
||||
session.commit()
|
||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
||||
|
||||
@set.subcommand(description="Set username length for a Group of Categories.")
|
||||
async def username_length(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
group_id: str = nextcord.SlashOption(
|
||||
name="group", description="Group to change username length of.", required=True
|
||||
),
|
||||
length: int = nextcord.SlashOption(
|
||||
description="Number of characters.", required=True, default=12, min_value=1, max_value=30
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Changes guild's username length limit.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||
length (int): Number of characters. Is SlashOption. Defaults to 12.
|
||||
"""
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
.where(CategoryGroup.GroupId == int(group_id))
|
||||
)
|
||||
group = session.scalar(stmt)
|
||||
group.UsernameLength = length
|
||||
session.commit()
|
||||
await interaction.response.send_message(f"Username length set to {length}.", ephemeral=True)
|
||||
|
||||
@set.subcommand(description="Registers the channel for verification messages.")
|
||||
async def verify_channel(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
||||
description="Channel to register",
|
||||
required=False,
|
||||
channel_types=[nextcord.ChannelType.text],
|
||||
default=None,
|
||||
),
|
||||
) -> None:
|
||||
"""
|
||||
Command function to register the verification message channel.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||
channel (Optional[nextcord.abc.GuildChannel]): Channel to register
|
||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||
"""
|
||||
if not channel:
|
||||
channel = interaction.channel
|
||||
channel_id = channel.id
|
||||
with Session(engine) as session:
|
||||
stmt = select(Guild).where(Guild.GuildId == interaction.guild_id)
|
||||
guild = session.scalar(stmt)
|
||||
guild.VerificationChannel = channel_id
|
||||
session.commit()
|
||||
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
|
||||
|
||||
@group_output_channel.on_autocomplete("group_id")
|
||||
@pad_length.on_autocomplete("group_id")
|
||||
@username_length.on_autocomplete("group_id")
|
||||
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str):
|
||||
"""
|
||||
Sends results from autofill_groups back to group_output_channel for autocompletion of group_id.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with command.
|
||||
group_id (str): String to run autocompletion against.
|
||||
"""
|
||||
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
||||
@@ -1,121 +0,0 @@
|
||||
"""
|
||||
Defines cog for on message listener.
|
||||
"""
|
||||
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
# pylint: disable=import-error
|
||||
from classes.submission import SubmissionState
|
||||
from main import submission_objects
|
||||
from database_setup.sql_data_classes import Category, Guild, engine
|
||||
|
||||
|
||||
class SubmissionListener(commands.Cog, name="Message Listener"):
|
||||
"""Sets up message listener."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self, message: nextcord.Message):
|
||||
"""Listener for message creation. Adds score and attachments to submission."""
|
||||
# don't want to process any messages from bot.
|
||||
if message.author.id == self.bot.user.id:
|
||||
return
|
||||
|
||||
await birthday_action(message)
|
||||
|
||||
guild_id = message.guild.id
|
||||
|
||||
if submission_objects.has_user(message.author.id):
|
||||
submission = submission_objects.get_user_submission(message.author.id)
|
||||
message_id = submission.message_id
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = select(Guild.SubmissionChannel).where(Guild.GuildId == guild_id)
|
||||
submission_channel_id = session.scalar(stmt)
|
||||
submission_message: nextcord.Message = (
|
||||
await self.bot.get_guild(guild_id).get_channel(submission_channel_id).fetch_message(message_id)
|
||||
)
|
||||
|
||||
# need check if correct user and correct channel
|
||||
if message.channel.id == submission_channel_id:
|
||||
state = submission.submission_state
|
||||
if state == SubmissionState.SCORE and message.content:
|
||||
stmt = select(Category.IsTimeRecord).where(Category.CategoryId == submission.category_id)
|
||||
|
||||
# check with regex if score matches correctly
|
||||
is_time_record = session.scalar(stmt)
|
||||
|
||||
time_regex = re.search("^([0-9]{1,2}:[0-9]|[0-9])?[0-9](\\.[0-9])?$", message.content)
|
||||
int_regex = re.search("^[0-9]+$", message.content)
|
||||
if time_regex is None and is_time_record:
|
||||
embeds = submission_message.embeds[0]
|
||||
embeds.add_field(
|
||||
name="Error",
|
||||
value="Time record must follow format MM:SS.ms, SS.ms, or SS.",
|
||||
)
|
||||
elif int_regex is None and not is_time_record:
|
||||
embeds = submission_message.embeds[0]
|
||||
embeds.add_field(name="Error", value="Number record must only be number.")
|
||||
else:
|
||||
score = message.content
|
||||
if is_time_record:
|
||||
# standardize time score format.
|
||||
if re.search("^[1-9]?[0-9]:[0-9]{2}(\\.[0-9])?$", score):
|
||||
# score is already fine.
|
||||
pass
|
||||
elif re.search("^[0-9]{2}(\\.[0-9])?$", score):
|
||||
# need to add leading colon and 0
|
||||
score = "0:" + score
|
||||
elif re.search("^[0-9](\\.[0-9])?$", score):
|
||||
# need to add 0 in seconds and leading colon and 0
|
||||
score = "0:0" + score
|
||||
elif re.search("^[0]?[0-9]:[0-9]{2}(\\.[0-9])?$", score):
|
||||
# if there is a minute 10ths place 0, remove
|
||||
score = score.lstrip("0")
|
||||
submission.score = score
|
||||
embeds = submission.get_embeds()
|
||||
await submission_message.edit(
|
||||
embeds=embeds,
|
||||
)
|
||||
elif state == SubmissionState.PROOF and len(message.attachments) > 0:
|
||||
await submission_message.edit(
|
||||
files=[await attch.to_file() for attch in message.attachments],
|
||||
)
|
||||
elif state == SubmissionState.NAME and message.content:
|
||||
submission.username = message.content
|
||||
embeds = submission.get_embeds()
|
||||
await submission_message.edit(
|
||||
embeds=embeds,
|
||||
)
|
||||
|
||||
await message.delete()
|
||||
|
||||
|
||||
# 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):
|
||||
"""Adds function to bot"""
|
||||
bot.add_cog(SubmissionListener(bot))
|
||||
|
||||
|
||||
async def birthday_action(message: nextcord.Message) -> None:
|
||||
"""
|
||||
Does the birthday thing, currently for chris only.
|
||||
|
||||
Args:
|
||||
message (nextcord.Message): The message to check for birthday thing.
|
||||
"""
|
||||
today = datetime.today()
|
||||
birthday = datetime(today.year, 7, 31)
|
||||
chris = 642330132958281750
|
||||
if today.date() == birthday.date():
|
||||
if message.author.id == chris or chris in message.raw_mentions:
|
||||
await message.add_reaction("🎂")
|
||||
@@ -1,231 +0,0 @@
|
||||
"""Views used for submission process."""
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session, aliased
|
||||
|
||||
# pylint: disable=import-error
|
||||
from classes.submission import Submission, SubmissionState
|
||||
from main import submission_objects
|
||||
from database_setup.sql_data_classes import Category, CategoryGroup, Guild, engine
|
||||
|
||||
from .verification_view import VerificationView
|
||||
|
||||
|
||||
def category_select_options(group_id: int) -> "list[nextcord.SelectOption]":
|
||||
"""Returns list of categories for a given boss."""
|
||||
options: list[nextcord.SelectOption] = []
|
||||
|
||||
with Session(engine) as session:
|
||||
subq = select(CategoryGroup).where(CategoryGroup.GroupId == group_id).subquery()
|
||||
cat_group_alias = aliased(CategoryGroup, subq)
|
||||
stmt = select(Category).where(Category.GroupId == cat_group_alias.GroupId)
|
||||
categories_list = session.scalars(stmt)
|
||||
for category in categories_list:
|
||||
options.append(nextcord.SelectOption(label=category.CategoryName, value=str(category.CategoryId)))
|
||||
|
||||
return options
|
||||
|
||||
|
||||
############ Items used in submission process ############
|
||||
|
||||
|
||||
class SubmissionDropdown(nextcord.ui.Select):
|
||||
"""Defines dropdown menu for submission"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
bot: commands.Bot,
|
||||
options: "list[nextcord.SelectOption]",
|
||||
):
|
||||
super().__init__(placeholder="Choose submission category.", min_values=1, max_values=1, options=options)
|
||||
self._bot = bot
|
||||
|
||||
async def callback(self, interaction: nextcord.Interaction):
|
||||
submission = submission_objects.get_user_submission(interaction.user.id)
|
||||
submission.category_id = self.values[0]
|
||||
embeds = submission.get_embeds()
|
||||
await interaction.message.edit(
|
||||
embeds=embeds,
|
||||
)
|
||||
|
||||
|
||||
class BackButton(nextcord.ui.Button):
|
||||
"""Defines view for back button."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
super().__init__(label="Back", style=nextcord.ButtonStyle.primary, custom_id="back")
|
||||
self._bot = bot
|
||||
|
||||
async def callback(self, interaction: nextcord.Interaction):
|
||||
submission = submission_objects.get_user_submission(interaction.user.id)
|
||||
state: SubmissionState = submission.submission_state
|
||||
state = SubmissionState(state.value - 1)
|
||||
submission.submission_state = state
|
||||
embeds = submission.get_embeds()
|
||||
await interaction.edit(embeds=embeds, view=SubmissionView(self._bot, interaction.user.id))
|
||||
|
||||
|
||||
class CancelButton(nextcord.ui.Button):
|
||||
"""Deletes message to cancel interaction.."""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(label="Cancel", style=nextcord.ButtonStyle.red, custom_id="cancel")
|
||||
|
||||
async def callback(self, interaction: nextcord.Interaction):
|
||||
submission_objects.remove_user_submission(interaction.user.id)
|
||||
await interaction.message.delete()
|
||||
|
||||
|
||||
class NextButton(nextcord.ui.Button):
|
||||
"""Defines view for next button."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
super().__init__(label="Next", style=nextcord.ButtonStyle.primary, custom_id="next")
|
||||
self._bot = bot
|
||||
|
||||
async def callback(self, interaction: nextcord.Interaction):
|
||||
# check if fields have been filled out for each state
|
||||
submission = submission_objects.get_user_submission(interaction.user.id)
|
||||
state: SubmissionState = submission.submission_state
|
||||
if state == SubmissionState.CATEGORY and not submission.category_id:
|
||||
await interaction.send("Please choose a category.", ephemeral=True)
|
||||
elif state == SubmissionState.SCORE and not submission.score:
|
||||
await interaction.send("Please send a score.", ephemeral=True)
|
||||
elif state == SubmissionState.PROOF and not len(interaction.message.attachments) > 0:
|
||||
await interaction.send("Please attach picture for proof.", ephemeral=True)
|
||||
else:
|
||||
state = SubmissionState(state.value + 1)
|
||||
submission.submission_state = state
|
||||
embeds = submission.get_embeds()
|
||||
await interaction.edit(embeds=embeds, view=SubmissionView(self._bot, interaction.user.id))
|
||||
|
||||
|
||||
class SubmitButton(nextcord.ui.Button):
|
||||
"""Defines button to submit a user's score."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
super().__init__(label="Submit", style=nextcord.ButtonStyle.green, custom_id="submit")
|
||||
self._bot = bot
|
||||
|
||||
async def callback(self, interaction: nextcord.Interaction):
|
||||
with Session(engine) as session:
|
||||
stmt = select(Guild.VerificationChannel).where(Guild.GuildId == interaction.guild_id)
|
||||
verification_channel_id = session.scalar(stmt)
|
||||
channel = interaction.guild.get_channel(verification_channel_id)
|
||||
submission = submission_objects.get_user_submission(interaction.user.id)
|
||||
|
||||
error_response = "Registered Verification channel does not exist or was never registered. \
|
||||
Contact server admins."
|
||||
assert channel is not None, await channel.send(error_response)
|
||||
|
||||
submission.submission_state = SubmissionState.VERIFY
|
||||
|
||||
embeds = submission.get_embeds()
|
||||
|
||||
await channel.send(
|
||||
files=[await attch.to_file() for attch in interaction.message.attachments],
|
||||
view=VerificationView(),
|
||||
embeds=embeds,
|
||||
content=f"Submission from <@{interaction.user.id}>.",
|
||||
)
|
||||
await interaction.message.edit(content=f"<@{interaction.user.id}> Submitted!", view=None)
|
||||
submission_objects.remove_user_submission(interaction.user.id)
|
||||
|
||||
|
||||
############ Submission Views ############
|
||||
|
||||
|
||||
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): # pylint: disable=unused-argument
|
||||
"""Button for score submission."""
|
||||
# Don't allow a user to start a new submission if one already exists
|
||||
if submission_objects.has_user(interaction.user.id):
|
||||
await interaction.send("Please finish in progress submission first.", ephemeral=True)
|
||||
return
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CategoryGroup.GroupId)
|
||||
.where(CategoryGroup.GuildId == interaction.guild_id)
|
||||
.where(CategoryGroup.MessageId == interaction.message.id)
|
||||
)
|
||||
group_id = session.scalar(stmt)
|
||||
|
||||
stmt = select(Guild.SubmissionChannel).where(Guild.GuildId == interaction.guild_id)
|
||||
channel = interaction.guild.get_channel(session.scalar(stmt))
|
||||
|
||||
# a user should only have 1 submission active at once.
|
||||
# split username on pipe. Decided to store whole username...
|
||||
username: str = interaction.user.display_name.split("|")[0]
|
||||
submission: Submission = Submission(interaction.guild_id, group_id, username)
|
||||
|
||||
submission_objects.add_submission(interaction.user.id, submission)
|
||||
|
||||
embeds = submission.get_embeds()
|
||||
|
||||
submission_message = await channel.send(
|
||||
f"<@{interaction.user.id}>",
|
||||
view=SubmissionView(
|
||||
self._bot,
|
||||
interaction.user.id,
|
||||
),
|
||||
embeds=embeds,
|
||||
)
|
||||
|
||||
# update the message_id once its created
|
||||
submission.message_id = submission_message.id
|
||||
|
||||
|
||||
class SubmissionView(nextcord.ui.View):
|
||||
"""Defines view submitting. Adjusts to all states."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
bot: commands.Bot,
|
||||
submission_user: int,
|
||||
*,
|
||||
timeout: float | None = 300,
|
||||
):
|
||||
super().__init__(timeout=timeout)
|
||||
self._submission_user = submission_user
|
||||
self._bot = bot
|
||||
self._state = submission_objects.get_user_submission(self._submission_user).submission_state
|
||||
self._group_id = submission_objects.get_user_submission(self._submission_user).group_id
|
||||
self._guild_id = submission_objects.get_user_submission(self._submission_user).guild_id
|
||||
|
||||
# add items depending on given state
|
||||
if self._state is SubmissionState.CATEGORY:
|
||||
self.add_item(SubmissionDropdown(bot, category_select_options(self._group_id)))
|
||||
self.add_item(CancelButton())
|
||||
self.add_item(NextButton(self._bot))
|
||||
elif (
|
||||
self._state is SubmissionState.SCORE
|
||||
or self._state is SubmissionState.PROOF
|
||||
or self._state is SubmissionState.NAME
|
||||
):
|
||||
self.add_item(BackButton(self._bot))
|
||||
self.add_item(NextButton(self._bot))
|
||||
elif self._state is SubmissionState.SUBMIT:
|
||||
self.add_item(BackButton(self._bot))
|
||||
self.add_item(SubmitButton(self._bot))
|
||||
|
||||
async def interaction_check(self, interaction: nextcord.Interaction) -> bool:
|
||||
check = self._submission_user == interaction.user.id
|
||||
|
||||
if not check:
|
||||
await interaction.send("This is not your submission.", ephemeral=True)
|
||||
|
||||
return check
|
||||
|
||||
# async def on_timeout(self) -> None:
|
||||
# # remove user from submission objects after time out. Allows user to start new submission.
|
||||
# submission_objects.remove_user_submission(self._submission_user)
|
||||
@@ -1,44 +0,0 @@
|
||||
"""View for verification buttons"""
|
||||
|
||||
import nextcord
|
||||
|
||||
# pylint: disable=import-error
|
||||
from utilities.utils import submit_score
|
||||
|
||||
|
||||
class VerificationView(nextcord.ui.View):
|
||||
"""Defines views for verifying score submissions"""
|
||||
|
||||
def __init__(self):
|
||||
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): # pylint: disable=unused-argument
|
||||
"""Button for denying score submission."""
|
||||
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): # pylint: disable=unused-argument
|
||||
"""Button for approving score submission."""
|
||||
for embed in interaction.message.embeds:
|
||||
content = embed.to_dict()
|
||||
|
||||
for field in content["fields"]:
|
||||
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:
|
||||
await submit_score(interaction, group_id, category_id, user, score)
|
||||
content = interaction.message.content
|
||||
content += f"\nApproved by <@{interaction.user.id}>."
|
||||
# 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])
|
||||
except UnboundLocalError:
|
||||
await interaction.send("Instruct user to submit with all fields.")
|
||||
await interaction.message.edit(view=None)
|
||||
@@ -1,13 +0,0 @@
|
||||
"""Small script to create the database if it doesn't already exist."""
|
||||
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
|
||||
if not Path("database/dakiny.db").exists():
|
||||
with sqlite3.connect("database/dakiny.db") as con:
|
||||
cur = con.cursor()
|
||||
|
||||
with Path("database_setup/database.sql", encoding="utf-8").open() as file:
|
||||
database_script = file.read()
|
||||
cur.executescript(database_script)
|
||||
con.commit()
|
||||
@@ -1,7 +0,0 @@
|
||||
[tool.ruff]
|
||||
# Extend the `pyproject.toml` file in the parent directory...
|
||||
extend = "../pyproject.toml"
|
||||
|
||||
[tool.ruff.lint]
|
||||
# ignore implicit-namespace-package in this directory.
|
||||
ignore = ["INP001"]
|
||||
@@ -1,17 +0,0 @@
|
||||
"""Simple file to set up the sqlalchemy connection to database."""
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.automap import automap_base
|
||||
from utilities import config
|
||||
|
||||
# connect with sql alchemy and autoload schema
|
||||
url = f"mysql+pymysql://{config.SQL_USER}:{config.SQL_PASS}@{config.SQL_HOST}/{config.SQL_DB}"
|
||||
engine = create_engine(url)
|
||||
Base = automap_base()
|
||||
Base.prepare(autoload_with=engine)
|
||||
|
||||
# define the classes
|
||||
Guild = Base.classes.Guilds
|
||||
CategoryGroup = Base.classes.CategoryGroups
|
||||
Category = Base.classes.Categories
|
||||
Score = Base.classes.Scores
|
||||
@@ -1,335 +0,0 @@
|
||||
{
|
||||
"tables": {
|
||||
"The Ambassador": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Araxxi": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Arch-Glacor": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Enrage",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Astellarn": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"The Barrows Brothers": [
|
||||
"Kill Count",
|
||||
"Spooned Log"
|
||||
],
|
||||
"The Barrows: Rise of the Six": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Beastmaster Durzag": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Black Stone Dragon": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Chaos Elemental": [
|
||||
"Kill Count",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Commander Zilyana": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Corporeal Beast": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Crassian Leviathan": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Croesus": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Dagannoth Kings": [
|
||||
"Kill Count",
|
||||
"Spooned Log"
|
||||
],
|
||||
"General Graardor": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Giant Mole": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Gregorovic": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Har-Aken": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Helwyr": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Kalphite King": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Kalphite Queen": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Kerapac": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"King Black Dragon": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Kree'arra": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"K'ril Tsutsaroth": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Legiones": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"The Magister": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Masuta the Ascended": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Nex": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Nex - Angel of Death": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Queen Black Dragon": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Raksha": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Duo Kill Count",
|
||||
"Duo Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Rex Matriarchs": [
|
||||
"Kill Count",
|
||||
"Spooned Log"
|
||||
],
|
||||
"The Sanctum Guardian": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Seiryu the Azure Serpent": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Solak": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Taraket the Necromancer": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Telos": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Enrage",
|
||||
"Spooned Log"
|
||||
],
|
||||
"The Twin Furies": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"TzKal-Zuk": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"TzTok-Jad": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Verak Lith": [
|
||||
"Solo Kill Count",
|
||||
"Solo Kill Time",
|
||||
"Group Kill Count",
|
||||
"Group Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Vindicta & Gorvek": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Vorago": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Hardmode Kill Count",
|
||||
"Hardmode Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Yakamaru": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Zamorak, Lord of Chaos (solo)": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Enrage",
|
||||
"Spooned Log"
|
||||
],
|
||||
"Zamorak, Lord of Chaos (group)": [
|
||||
"Kill Count",
|
||||
"Kill Time",
|
||||
"Enrage"
|
||||
]
|
||||
},
|
||||
"categories": {
|
||||
"Duo Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Duo Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Enrage": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Group Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Group Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Hardmode Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Hardmode Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Solo Kill Count": {
|
||||
"ascending": false,
|
||||
"is_time_record": false
|
||||
},
|
||||
"Solo Kill Time": {
|
||||
"ascending": true,
|
||||
"is_time_record": true
|
||||
},
|
||||
"Spooned Log": {
|
||||
"ascending": true,
|
||||
"is_time_record": false
|
||||
}
|
||||
},
|
||||
"table_size": 3
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
CREATE DATABASE highscores;
|
||||
use highscores;
|
||||
|
||||
CREATE TABLE Guilds(
|
||||
GuildId bigint unsigned not null unique,
|
||||
GuildName varchar(95) not null,
|
||||
SubmissionChannel bigint unsigned,
|
||||
VerificationChannel bigint unsigned,
|
||||
Active boolean DEFAULT true,
|
||||
PRIMARY KEY (GuildId)
|
||||
);
|
||||
|
||||
CREATE TABLE CategoryGroups(
|
||||
GroupId int unsigned not null unique AUTO_INCREMENT,
|
||||
GroupName varchar(50) not null,
|
||||
ChannelId bigint unsigned,
|
||||
GuildId bigint unsigned not null,
|
||||
MessageId bigint unsigned,
|
||||
PadLength smallint not null DEFAULT 26,
|
||||
UsernameLength smallint DEFAULT 12,
|
||||
CONSTRAINT UniqueGuildCategoryGroup UNIQUE (GuildId, GroupName),
|
||||
FOREIGN KEY (GuildId) REFERENCES Guilds(GuildId) ON DELETE CASCADE,
|
||||
PRIMARY KEY (GroupId)
|
||||
);
|
||||
|
||||
CREATE TABLE Categories(
|
||||
CategoryId int unsigned not null unique AUTO_INCREMENT,
|
||||
CategoryName varchar(30) not null,
|
||||
GroupId int unsigned not null,
|
||||
Size smallint not null DEFAULT 3,
|
||||
IsAscending boolean not null DEFAULT true,
|
||||
IsTimeRecord boolean not null DEFAULT false,
|
||||
IsValidated boolean not null DEFAULT true,
|
||||
CONSTRAINT UniqueCategoryInGroup UNIQUE (GroupId, CategoryName),
|
||||
FOREIGN KEY (GroupId) REFERENCES CategoryGroups(GroupId) ON DELETE CASCADE,
|
||||
PRIMARY Key (CategoryId)
|
||||
);
|
||||
|
||||
CREATE TABLE Scores(
|
||||
UserName varchar(30) not null,
|
||||
Score float not null, -- Maybe should have time and int scores?? timestamp type?
|
||||
CategoryId int unsigned not null,
|
||||
FOREIGN KEY (CategoryId) REFERENCES Categories(CategoryId) ON DELETE CASCADE,
|
||||
PRIMARY KEY (CategoryId, UserName)
|
||||
);
|
||||
@@ -1,66 +0,0 @@
|
||||
"""
|
||||
main file for highscores bot
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
|
||||
from classes.submission import SubmissionMap
|
||||
|
||||
# pylint: disable=import-error
|
||||
from utilities import config
|
||||
|
||||
logger = logging.getLogger("nextcord")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w")
|
||||
handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
|
||||
logger.addHandler(handler)
|
||||
|
||||
submission_objects: SubmissionMap = SubmissionMap()
|
||||
|
||||
|
||||
def main():
|
||||
"""Main function for bot."""
|
||||
min_python_version = (3, 8)
|
||||
if sys.version_info < min_python_version:
|
||||
print("ERROR: Python version must be >= 3.8")
|
||||
sys.exit()
|
||||
|
||||
# Allows privileged intents for monitoring members joining, roles editing, and role assignments
|
||||
# These need to be enabled in the developer portal as well
|
||||
intents = nextcord.Intents.default()
|
||||
|
||||
# Required in order to read messages (eg. prefix commands)
|
||||
intents.message_content = True # pylint: disable=assigning-non-slot
|
||||
|
||||
# To enable the guilds priveleged intent:
|
||||
# intents.guilds = True
|
||||
|
||||
# To enable the members priveleged intent:
|
||||
# intents.members = True
|
||||
|
||||
bot = commands.Bot(
|
||||
commands.when_mentioned_or(config.BOT_PREFIX),
|
||||
intents=intents,
|
||||
)
|
||||
|
||||
# Get the modules of all cogs whose directory structure is ./cogs/<module_name>
|
||||
for folder in os.listdir("cogs"):
|
||||
bot.load_extension(f"cogs.{folder}")
|
||||
|
||||
@bot.listen()
|
||||
async def on_ready():
|
||||
"""When Discord is connected"""
|
||||
assert bot.user is not None
|
||||
print(f"{bot.user.name} has connected to Discord!")
|
||||
|
||||
# Run Discord bot
|
||||
bot.run(config.DISCORD_TOKEN)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+1
-2
@@ -11,7 +11,7 @@ dependencies = [
|
||||
"pymysql>=1.1.1",
|
||||
"python-dotenv>=1.0.1",
|
||||
"setuptools>=75.3.0",
|
||||
"sqlalchemy>=2.0.35",
|
||||
"sqlmodel>=0.0.22",
|
||||
]
|
||||
requires-python = ">=3.12"
|
||||
|
||||
@@ -47,7 +47,6 @@ exclude = [
|
||||
"node_modules",
|
||||
"site-packages",
|
||||
"venv",
|
||||
"dakiny-messages", # Don't need to lint this git repo.
|
||||
]
|
||||
|
||||
# Same as Black.
|
||||
|
||||
+11
-1
@@ -3,6 +3,10 @@
|
||||
"lockFileMaintenance": {
|
||||
"automerge": true
|
||||
},
|
||||
"major": {
|
||||
"automerge": false,
|
||||
"automergeType": "pr"
|
||||
},
|
||||
"minor": {
|
||||
"automerge": true,
|
||||
"automergeType": "branch"
|
||||
@@ -15,5 +19,11 @@
|
||||
"automerge": true,
|
||||
"automergeType": "branch"
|
||||
},
|
||||
"ignoreTests": true
|
||||
"ignoreTests": true,
|
||||
"dockerfile": {
|
||||
"minor": {
|
||||
"automerge": false,
|
||||
"automergeType": "pr"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ dependencies = [
|
||||
{ name = "pymysql" },
|
||||
{ name = "python-dotenv" },
|
||||
{ name = "setuptools" },
|
||||
{ name = "sqlalchemy" },
|
||||
{ name = "sqlmodel" },
|
||||
]
|
||||
|
||||
[package.dev-dependencies]
|
||||
@@ -28,7 +28,7 @@ requires-dist = [
|
||||
{ name = "pymysql", specifier = ">=1.1.1" },
|
||||
{ name = "python-dotenv", specifier = ">=1.0.1" },
|
||||
{ name = "setuptools", specifier = ">=75.3.0" },
|
||||
{ name = "sqlalchemy", specifier = ">=2.0.35" },
|
||||
{ name = "sqlmodel", specifier = ">=0.0.22" },
|
||||
]
|
||||
|
||||
[package.metadata.requires-dev]
|
||||
@@ -102,6 +102,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/76/ac/a7305707cb852b7e16ff80eaf5692309bde30e2b1100a1fcacdc8f731d97/aiosignal-1.3.1-py3-none-any.whl", hash = "sha256:f8376fb07dd1e86a584e4fcdec80b36b7f81aac666ebc724e2c090300dd83b17", size = 7617 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "annotated-types"
|
||||
version = "0.7.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/ee/67/531ea369ba64dcff5ec9c3402f9f51bf748cec26dde048a2f973a4eea7f5/annotated_types-0.7.0.tar.gz", hash = "sha256:aff07c09a53a08bc8cfccb9c85b05f1aa9a2a6f23728d790723543408344ce89", size = 16081 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/78/b6/6307fbef88d9b5ee7421e68d78a9f162e0da4900bc5f5793f6d3d0e34fb8/annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53", size = 13643 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "attrs"
|
||||
version = "24.2.0"
|
||||
@@ -425,6 +434,59 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/13/a3/a812df4e2dd5696d1f351d58b8fe16a405b234ad2886a0dab9183fb78109/pycparser-2.22-py3-none-any.whl", hash = "sha256:c3702b6d3dd8c7abc1afa565d7e63d53a1d0bd86cdc24edd75470f4de499cfcc", size = 117552 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pydantic"
|
||||
version = "2.10.6"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "annotated-types" },
|
||||
{ name = "pydantic-core" },
|
||||
{ name = "typing-extensions" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/b7/ae/d5220c5c52b158b1de7ca89fc5edb72f304a70a4c540c84c8844bf4008de/pydantic-2.10.6.tar.gz", hash = "sha256:ca5daa827cce33de7a42be142548b0096bf05a7e7b365aebfa5f8eeec7128236", size = 761681 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/f4/3c/8cc1cc84deffa6e25d2d0c688ebb80635dfdbf1dbea3e30c541c8cf4d860/pydantic-2.10.6-py3-none-any.whl", hash = "sha256:427d664bf0b8a2b34ff5dd0f5a18df00591adcee7198fbd71981054cef37b584", size = 431696 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pydantic-core"
|
||||
version = "2.27.2"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "typing-extensions" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/fc/01/f3e5ac5e7c25833db5eb555f7b7ab24cd6f8c322d3a3ad2d67a952dc0abc/pydantic_core-2.27.2.tar.gz", hash = "sha256:eb026e5a4c1fee05726072337ff51d1efb6f59090b7da90d30ea58625b1ffb39", size = 413443 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/d6/74/51c8a5482ca447871c93e142d9d4a92ead74de6c8dc5e66733e22c9bba89/pydantic_core-2.27.2-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:9e0c8cfefa0ef83b4da9588448b6d8d2a2bf1a53c3f1ae5fca39eb3061e2f0b0", size = 1893127 },
|
||||
{ url = "https://files.pythonhosted.org/packages/d3/f3/c97e80721735868313c58b89d2de85fa80fe8dfeeed84dc51598b92a135e/pydantic_core-2.27.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:83097677b8e3bd7eaa6775720ec8e0405f1575015a463285a92bfdfe254529ef", size = 1811340 },
|
||||
{ url = "https://files.pythonhosted.org/packages/9e/91/840ec1375e686dbae1bd80a9e46c26a1e0083e1186abc610efa3d9a36180/pydantic_core-2.27.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:172fce187655fece0c90d90a678424b013f8fbb0ca8b036ac266749c09438cb7", size = 1822900 },
|
||||
{ url = "https://files.pythonhosted.org/packages/f6/31/4240bc96025035500c18adc149aa6ffdf1a0062a4b525c932065ceb4d868/pydantic_core-2.27.2-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:519f29f5213271eeeeb3093f662ba2fd512b91c5f188f3bb7b27bc5973816934", size = 1869177 },
|
||||
{ url = "https://files.pythonhosted.org/packages/fa/20/02fbaadb7808be578317015c462655c317a77a7c8f0ef274bc016a784c54/pydantic_core-2.27.2-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:05e3a55d124407fffba0dd6b0c0cd056d10e983ceb4e5dbd10dda135c31071d6", size = 2038046 },
|
||||
{ url = "https://files.pythonhosted.org/packages/06/86/7f306b904e6c9eccf0668248b3f272090e49c275bc488a7b88b0823444a4/pydantic_core-2.27.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9c3ed807c7b91de05e63930188f19e921d1fe90de6b4f5cd43ee7fcc3525cb8c", size = 2685386 },
|
||||
{ url = "https://files.pythonhosted.org/packages/8d/f0/49129b27c43396581a635d8710dae54a791b17dfc50c70164866bbf865e3/pydantic_core-2.27.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6fb4aadc0b9a0c063206846d603b92030eb6f03069151a625667f982887153e2", size = 1997060 },
|
||||
{ url = "https://files.pythonhosted.org/packages/0d/0f/943b4af7cd416c477fd40b187036c4f89b416a33d3cc0ab7b82708a667aa/pydantic_core-2.27.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:28ccb213807e037460326424ceb8b5245acb88f32f3d2777427476e1b32c48c4", size = 2004870 },
|
||||
{ url = "https://files.pythonhosted.org/packages/35/40/aea70b5b1a63911c53a4c8117c0a828d6790483f858041f47bab0b779f44/pydantic_core-2.27.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:de3cd1899e2c279b140adde9357c4495ed9d47131b4a4eaff9052f23398076b3", size = 1999822 },
|
||||
{ url = "https://files.pythonhosted.org/packages/f2/b3/807b94fd337d58effc5498fd1a7a4d9d59af4133e83e32ae39a96fddec9d/pydantic_core-2.27.2-cp312-cp312-musllinux_1_1_armv7l.whl", hash = "sha256:220f892729375e2d736b97d0e51466252ad84c51857d4d15f5e9692f9ef12be4", size = 2130364 },
|
||||
{ url = "https://files.pythonhosted.org/packages/fc/df/791c827cd4ee6efd59248dca9369fb35e80a9484462c33c6649a8d02b565/pydantic_core-2.27.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a0fcd29cd6b4e74fe8ddd2c90330fd8edf2e30cb52acda47f06dd615ae72da57", size = 2158303 },
|
||||
{ url = "https://files.pythonhosted.org/packages/9b/67/4e197c300976af185b7cef4c02203e175fb127e414125916bf1128b639a9/pydantic_core-2.27.2-cp312-cp312-win32.whl", hash = "sha256:1e2cb691ed9834cd6a8be61228471d0a503731abfb42f82458ff27be7b2186fc", size = 1834064 },
|
||||
{ url = "https://files.pythonhosted.org/packages/1f/ea/cd7209a889163b8dcca139fe32b9687dd05249161a3edda62860430457a5/pydantic_core-2.27.2-cp312-cp312-win_amd64.whl", hash = "sha256:cc3f1a99a4f4f9dd1de4fe0312c114e740b5ddead65bb4102884b384c15d8bc9", size = 1989046 },
|
||||
{ url = "https://files.pythonhosted.org/packages/bc/49/c54baab2f4658c26ac633d798dab66b4c3a9bbf47cff5284e9c182f4137a/pydantic_core-2.27.2-cp312-cp312-win_arm64.whl", hash = "sha256:3911ac9284cd8a1792d3cb26a2da18f3ca26c6908cc434a18f730dc0db7bfa3b", size = 1885092 },
|
||||
{ url = "https://files.pythonhosted.org/packages/41/b1/9bc383f48f8002f99104e3acff6cba1231b29ef76cfa45d1506a5cad1f84/pydantic_core-2.27.2-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:7d14bd329640e63852364c306f4d23eb744e0f8193148d4044dd3dacdaacbd8b", size = 1892709 },
|
||||
{ url = "https://files.pythonhosted.org/packages/10/6c/e62b8657b834f3eb2961b49ec8e301eb99946245e70bf42c8817350cbefc/pydantic_core-2.27.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:82f91663004eb8ed30ff478d77c4d1179b3563df6cdb15c0817cd1cdaf34d154", size = 1811273 },
|
||||
{ url = "https://files.pythonhosted.org/packages/ba/15/52cfe49c8c986e081b863b102d6b859d9defc63446b642ccbbb3742bf371/pydantic_core-2.27.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:71b24c7d61131bb83df10cc7e687433609963a944ccf45190cfc21e0887b08c9", size = 1823027 },
|
||||
{ url = "https://files.pythonhosted.org/packages/b1/1c/b6f402cfc18ec0024120602bdbcebc7bdd5b856528c013bd4d13865ca473/pydantic_core-2.27.2-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:fa8e459d4954f608fa26116118bb67f56b93b209c39b008277ace29937453dc9", size = 1868888 },
|
||||
{ url = "https://files.pythonhosted.org/packages/bd/7b/8cb75b66ac37bc2975a3b7de99f3c6f355fcc4d89820b61dffa8f1e81677/pydantic_core-2.27.2-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ce8918cbebc8da707ba805b7fd0b382816858728ae7fe19a942080c24e5b7cd1", size = 2037738 },
|
||||
{ url = "https://files.pythonhosted.org/packages/c8/f1/786d8fe78970a06f61df22cba58e365ce304bf9b9f46cc71c8c424e0c334/pydantic_core-2.27.2-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:eda3f5c2a021bbc5d976107bb302e0131351c2ba54343f8a496dc8783d3d3a6a", size = 2685138 },
|
||||
{ url = "https://files.pythonhosted.org/packages/a6/74/d12b2cd841d8724dc8ffb13fc5cef86566a53ed358103150209ecd5d1999/pydantic_core-2.27.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bd8086fa684c4775c27f03f062cbb9eaa6e17f064307e86b21b9e0abc9c0f02e", size = 1997025 },
|
||||
{ url = "https://files.pythonhosted.org/packages/a0/6e/940bcd631bc4d9a06c9539b51f070b66e8f370ed0933f392db6ff350d873/pydantic_core-2.27.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:8d9b3388db186ba0c099a6d20f0604a44eabdeef1777ddd94786cdae158729e4", size = 2004633 },
|
||||
{ url = "https://files.pythonhosted.org/packages/50/cc/a46b34f1708d82498c227d5d80ce615b2dd502ddcfd8376fc14a36655af1/pydantic_core-2.27.2-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:7a66efda2387de898c8f38c0cf7f14fca0b51a8ef0b24bfea5849f1b3c95af27", size = 1999404 },
|
||||
{ url = "https://files.pythonhosted.org/packages/ca/2d/c365cfa930ed23bc58c41463bae347d1005537dc8db79e998af8ba28d35e/pydantic_core-2.27.2-cp313-cp313-musllinux_1_1_armv7l.whl", hash = "sha256:18a101c168e4e092ab40dbc2503bdc0f62010e95d292b27827871dc85450d7ee", size = 2130130 },
|
||||
{ url = "https://files.pythonhosted.org/packages/f4/d7/eb64d015c350b7cdb371145b54d96c919d4db516817f31cd1c650cae3b21/pydantic_core-2.27.2-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:ba5dd002f88b78a4215ed2f8ddbdf85e8513382820ba15ad5ad8955ce0ca19a1", size = 2157946 },
|
||||
{ url = "https://files.pythonhosted.org/packages/a4/99/bddde3ddde76c03b65dfd5a66ab436c4e58ffc42927d4ff1198ffbf96f5f/pydantic_core-2.27.2-cp313-cp313-win32.whl", hash = "sha256:1ebaf1d0481914d004a573394f4be3a7616334be70261007e47c2a6fe7e50130", size = 1834387 },
|
||||
{ url = "https://files.pythonhosted.org/packages/71/47/82b5e846e01b26ac6f1893d3c5f9f3a2eb6ba79be26eef0b759b4fe72946/pydantic_core-2.27.2-cp313-cp313-win_amd64.whl", hash = "sha256:953101387ecf2f5652883208769a79e48db18c6df442568a0b5ccd8c2723abee", size = 1990453 },
|
||||
{ url = "https://files.pythonhosted.org/packages/51/b2/b2b50d5ecf21acf870190ae5d093602d95f66c9c31f9d5de6062eb329ad1/pydantic_core-2.27.2-cp313-cp313-win_arm64.whl", hash = "sha256:ac4dbfd1691affb8f48c2c13241a2e3b60ff23247cbcf981759c768b6633cf8b", size = 1885186 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pymysql"
|
||||
version = "1.1.1"
|
||||
@@ -536,6 +598,19 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/b8/49/21633706dd6feb14cd3f7935fc00b60870ea057686035e1a99ae6d9d9d53/SQLAlchemy-2.0.36-py3-none-any.whl", hash = "sha256:fddbe92b4760c6f5d48162aef14824add991aeda8ddadb3c31d56eb15ca69f8e", size = 1883787 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sqlmodel"
|
||||
version = "0.0.22"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "pydantic" },
|
||||
{ name = "sqlalchemy" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/b5/39/8641040ab0d5e1d8a1c2325ae89a01ae659fc96c61a43d158fb71c9a0bf0/sqlmodel-0.0.22.tar.gz", hash = "sha256:7d37c882a30c43464d143e35e9ecaf945d88035e20117bf5ec2834a23cbe505e", size = 116392 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/dd/b1/3af5104b716c420e40a6ea1b09886cae3a1b9f4538343875f637755cae5b/sqlmodel-0.0.22-py3-none-any.whl", hash = "sha256:a1ed13e28a1f4057cbf4ff6cdb4fc09e85702621d3259ba17b3c230bfb2f941b", size = 28276 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typing-extensions"
|
||||
version = "4.12.2"
|
||||
|
||||
Reference in New Issue
Block a user