Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ec84fa5687 | ||
|
|
5b078c4a56 | ||
|
|
226d7c77d7 | ||
|
|
4bb7a925e5 | ||
|
|
7ef8768634 |
@@ -14,13 +14,7 @@ jobs:
|
|||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Install Docker
|
- name: Install Docker
|
||||||
uses: https://github.com/papodaca/install-docker-action@v1
|
uses: https://github.com/papodaca/install-docker-action@v1
|
||||||
- name: Log into container registry
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
registry: gitea.cheezers.org
|
|
||||||
username: imcompiling
|
|
||||||
password: ${{ secrets.PASSWORD }}
|
|
||||||
- name: Build Docker Image
|
- name: Build Docker Image
|
||||||
run: docker build -t gitea.cheezers.org/imcompiling/agon:develop .
|
run: docker build -t viker.cheezers.net:5000/agon:develop .
|
||||||
- name: Push Docker Image
|
- name: Push Docker Image
|
||||||
run: docker push gitea.cheezers.org/imcompiling/agon:develop
|
run: docker push viker.cheezers.net:5000/agon:develop
|
||||||
|
|||||||
@@ -14,17 +14,11 @@ jobs:
|
|||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Install Docker
|
- name: Install Docker
|
||||||
uses: https://github.com/papodaca/install-docker-action@v1
|
uses: https://github.com/papodaca/install-docker-action@v1
|
||||||
- name: Log into container registry
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
registry: gitea.cheezers.org
|
|
||||||
username: imcompiling
|
|
||||||
password: ${{ secrets.PASSWORD }}
|
|
||||||
- name: Set env
|
- name: Set env
|
||||||
run: echo "GIT_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
run: echo "GIT_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||||
- name: Build Docker Images
|
- name: Build Docker Images
|
||||||
run: docker build -t gitea.cheezers.org/imcompiling/agon:latest -t gitea.cheezers.org/imcompiling/agon:${{env.GIT_TAG}} .
|
run: docker build -t viker.cheezers.net:5000/agon:latest -t viker.cheezers.net:5000/agon:${{env.GIT_TAG}} .
|
||||||
- name: Push Latest Image
|
- name: Push Latest Image
|
||||||
run: docker push gitea.cheezers.org/imcompiling/agon:latest
|
run: docker push viker.cheezers.net:5000/agon:latest
|
||||||
- name: Push Tagged Image
|
- name: Push Tagged Image
|
||||||
run: docker push gitea.cheezers.org/imcompiling/agon:${{env.GIT_TAG}}
|
run: docker push viker.cheezers.net:5000/agon:${{env.GIT_TAG}}
|
||||||
|
|||||||
@@ -105,7 +105,6 @@ venv/
|
|||||||
ENV/
|
ENV/
|
||||||
env.bak/
|
env.bak/
|
||||||
venv.bak/
|
venv.bak/
|
||||||
poetry.lock
|
|
||||||
|
|
||||||
# Spyder project settings
|
# Spyder project settings
|
||||||
.spyderproject
|
.spyderproject
|
||||||
|
|||||||
+12
-9
@@ -1,18 +1,21 @@
|
|||||||
FROM python:3.12.3-slim
|
FROM python:3.8.10-slim
|
||||||
|
|
||||||
RUN apt-get update && apt-get -y upgrade && apt-get -y install sqlite3
|
# install dependencies for mysqlclient
|
||||||
|
# RUN apt-get update && apt-get -y upgrade && apt-get -y install python3-dev default-libmysqlclient-dev build-essential
|
||||||
|
|
||||||
|
RUN pip install --upgrade pip
|
||||||
|
|
||||||
WORKDIR /home
|
WORKDIR /home
|
||||||
|
|
||||||
|
|
||||||
COPY main.py main.py
|
|
||||||
COPY pyproject.toml pyproject.toml
|
|
||||||
|
|
||||||
COPY classes classes/
|
COPY classes classes/
|
||||||
COPY cogs cogs/
|
COPY cogs cogs/
|
||||||
COPY database_setup database_setup/
|
|
||||||
COPY utilities utilities/
|
COPY utilities utilities/
|
||||||
|
COPY highscores.py highscores.py
|
||||||
|
COPY requirements.txt requirements.txt
|
||||||
|
|
||||||
RUN pip install --upgrade pip && pip install poetry && poetry export -f requirements.txt --output requirements.txt && pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
CMD ["python3", "./main.py"]
|
# remove build deps that aren't needed to run
|
||||||
|
# RUN apt-get -y remove python3-dev build-essential && apt-get -y autoremove
|
||||||
|
|
||||||
|
CMD ["python3", "./highscores.py"]
|
||||||
+19
-160
@@ -2,6 +2,7 @@
|
|||||||
Contains classes and enum for tracking data on submissions.
|
Contains classes and enum for tracking data on submissions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from dataclasses import dataclass, field
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from nextcord import Embed
|
from nextcord import Embed
|
||||||
@@ -9,9 +10,11 @@ from sqlalchemy import select
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from database_setup.sql_data_classes import Category, CategoryGroup, engine
|
from utilities.sql_data_classes import Category, CategoryGroup, engine
|
||||||
|
from utilities.utils import score_float_to_str
|
||||||
|
|
||||||
|
|
||||||
|
# TODO use the fancy enums
|
||||||
class SubmissionState(Enum):
|
class SubmissionState(Enum):
|
||||||
"""
|
"""
|
||||||
Enum for which state a submission is in
|
Enum for which state a submission is in
|
||||||
@@ -25,171 +28,34 @@ class SubmissionState(Enum):
|
|||||||
VERIFY = 6
|
VERIFY = 6
|
||||||
|
|
||||||
|
|
||||||
# TODO remake into a data class
|
@dataclass
|
||||||
class Submission:
|
class Submission:
|
||||||
"""
|
"""
|
||||||
Class for an individual submission. Contains submission information such as
|
Class for an individual submission. Contains submission information such as
|
||||||
guild id, message id, table, category, username, score and submission state.
|
guild id, message id, table, category, username, score and submission state.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, guild_id: int, group_id: int, username: str) -> None:
|
category_id: int = field(init=False, default=0)
|
||||||
"""
|
group_id: int
|
||||||
Default constructor for Submission. Just need to know guild_id, table, and username.
|
guild_id: int
|
||||||
Score and category are defaulted at empty, message id is 0, and submission state
|
is_time_record: bool = field(init=False, default=False)
|
||||||
is SubmissionState.CATEGORY.
|
message_id: int = field(init=False, default=0)
|
||||||
"""
|
score: float = field(init=False, default=0.0)
|
||||||
self._category_id: int = 0
|
submission_state: SubmissionState = field(init=False, default=SubmissionState.CATEGORY)
|
||||||
self._guild_id: int = guild_id
|
username: str
|
||||||
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 get_embed(self) -> Embed:
|
||||||
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."""
|
"""Creates an embed based off of the submission state and fields filled out."""
|
||||||
state: SubmissionState = self.submission_state
|
state: SubmissionState = self.submission_state
|
||||||
|
|
||||||
if state is SubmissionState.CATEGORY:
|
if state is SubmissionState.CATEGORY:
|
||||||
description = "Step 1: Choose your category!"
|
description = "Step 1: Choose your category!"
|
||||||
elif state is SubmissionState.SCORE:
|
elif state is SubmissionState.SCORE:
|
||||||
description = "Step 2: Send a message to input your score!"
|
description = "Step 2: Input your score!"
|
||||||
elif state is SubmissionState.PROOF:
|
elif state is SubmissionState.PROOF:
|
||||||
description = "Step 3: Send a message with a picture attached to submit your proof!"
|
description = "Step 3: Submit your proof!"
|
||||||
elif state is SubmissionState.NAME:
|
elif state is SubmissionState.NAME:
|
||||||
description = (
|
description = "Step 4 (Optional): Change name on submission! (proceed to next if skipping)"
|
||||||
"Step 4 (Optional): Send a message to change name on submission! (proceed to next if skipping)"
|
|
||||||
)
|
|
||||||
elif state is SubmissionState.SUBMIT:
|
elif state is SubmissionState.SUBMIT:
|
||||||
description = "Step 5: Submit if everything looks correct!"
|
description = "Step 5: Submit if everything looks correct!"
|
||||||
elif state is SubmissionState.VERIFY:
|
elif state is SubmissionState.VERIFY:
|
||||||
@@ -212,16 +78,9 @@ class Submission:
|
|||||||
)
|
)
|
||||||
embed.add_field(name="Category", value=session.scalar(stmt), inline=False)
|
embed.add_field(name="Category", value=session.scalar(stmt), inline=False)
|
||||||
if self.score:
|
if self.score:
|
||||||
embed.add_field(name="Score", value=self.score, inline=False)
|
embed.add_field(name="Score", value=score_float_to_str(self.score, self.is_time_record), inline=False)
|
||||||
|
|
||||||
embeds = [embed]
|
return 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:
|
class SubmissionMap:
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
Commands for creating items in bot.
|
Commands for creating items in bot.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
from sqlalchemy import exc, select
|
from sqlalchemy import exc, select
|
||||||
@@ -9,7 +11,7 @@ from sqlalchemy.orm import Session
|
|||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from cogs.submission.submission_views import SubmissionCreateButton
|
from cogs.submission.submission_views import SubmissionCreateButton
|
||||||
from database_setup.sql_data_classes import Category, CategoryGroup, engine
|
from utilities.sql_data_classes import Category, CategoryGroup, engine
|
||||||
from utilities.utils import MAX_LINE_LENGTH, autofill_groups, send_highscore_message
|
from utilities.utils import MAX_LINE_LENGTH, autofill_groups, send_highscore_message
|
||||||
|
|
||||||
|
|
||||||
@@ -38,7 +40,7 @@ class CreateCog(commands.Cog, name="Create Cog"):
|
|||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
group_id: str = nextcord.SlashOption(name="group", description="Group to add Category to.", required=True),
|
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),
|
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_ascending: bool = nextcord.SlashOption(description="If higher value is better score.", required=True),
|
||||||
is_time_record: bool = nextcord.SlashOption(
|
is_time_record: bool = nextcord.SlashOption(
|
||||||
description="If the score should be shown in time format. Cannot be changed.", required=True
|
description="If the score should be shown in time format. Cannot be changed.", required=True
|
||||||
),
|
),
|
||||||
@@ -62,6 +64,7 @@ class CreateCog(commands.Cog, name="Create Cog"):
|
|||||||
is_validated (bool): If the scores should be validated or not. Is SlashOption.
|
is_validated (bool): If the scores should be validated or not. Is SlashOption.
|
||||||
size (int): How many sores to show in the category message. Is SlashOption.
|
size (int): How many sores to show in the category message. Is SlashOption.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
new_category = Category(
|
new_category = Category(
|
||||||
CategoryName=category_name,
|
CategoryName=category_name,
|
||||||
GroupId=int(group_id),
|
GroupId=int(group_id),
|
||||||
@@ -110,7 +113,7 @@ class CreateCog(commands.Cog, name="Create Cog"):
|
|||||||
min_value=1,
|
min_value=1,
|
||||||
max_value=30,
|
max_value=30,
|
||||||
),
|
),
|
||||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption(
|
||||||
description="Channel to post Group in. If left empty, defaults to current channel.",
|
description="Channel to post Group in. If left empty, defaults to current channel.",
|
||||||
required=False,
|
required=False,
|
||||||
channel_types=[nextcord.ChannelType.text],
|
channel_types=[nextcord.ChannelType.text],
|
||||||
@@ -129,6 +132,7 @@ class CreateCog(commands.Cog, name="Create Cog"):
|
|||||||
channel (Optional[nextcord.abc.GuildChannel]): Channel to post group in. If None, defaults to current
|
channel (Optional[nextcord.abc.GuildChannel]): Channel to post group in. If None, defaults to current
|
||||||
channel. Is SlashOption.
|
channel. Is SlashOption.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# if no channel provided, use current channel.
|
# if no channel provided, use current channel.
|
||||||
if channel is None:
|
if channel is None:
|
||||||
channel = interaction.channel
|
channel = interaction.channel
|
||||||
@@ -164,4 +168,5 @@ class CreateCog(commands.Cog, name="Create Cog"):
|
|||||||
interaction (nextcord.Interaction): Interaction with command.
|
interaction (nextcord.Interaction): Interaction with command.
|
||||||
group_id (str): String to run autocomplete compared to.
|
group_id (str): String to run autocomplete compared to.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
||||||
|
|||||||
+11
-4
@@ -2,13 +2,15 @@
|
|||||||
Commands for deleting groups/categories/scores in database and messages in discord..
|
Commands for deleting groups/categories/scores in database and messages in discord..
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
from sqlalchemy import distinct, select
|
from sqlalchemy import distinct, select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from database_setup.sql_data_classes import Category, CategoryGroup, Score, engine
|
from utilities.sql_data_classes import Category, CategoryGroup, Score, engine
|
||||||
from utilities.utils import (
|
from utilities.utils import (
|
||||||
autofill_categories,
|
autofill_categories,
|
||||||
autofill_groups,
|
autofill_groups,
|
||||||
@@ -46,7 +48,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
|||||||
async def channel_messages(
|
async def channel_messages(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption(
|
||||||
description="Channel to clear of messages.",
|
description="Channel to clear of messages.",
|
||||||
required=False,
|
required=False,
|
||||||
channel_types=[nextcord.ChannelType.text],
|
channel_types=[nextcord.ChannelType.text],
|
||||||
@@ -62,6 +64,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
|||||||
channel (Optional[nextcord.abc.GuildChannel]): Channel to clear of messages.
|
channel (Optional[nextcord.abc.GuildChannel]): Channel to clear of messages.
|
||||||
Is a SlashOption. Limited to text channels. Defaults to None.
|
Is a SlashOption. Limited to text channels. Defaults to None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not channel:
|
if not channel:
|
||||||
channel = interaction.channel
|
channel = interaction.channel
|
||||||
|
|
||||||
@@ -104,9 +107,10 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
|||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
user_name (str): User to remove from highscores
|
user_name (str): User to remove from highscores
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(distinct(Score.CategoryId)).where(Score.UserName == user_name)
|
stmt = select(distinct(Score.CategoryId)).where(Score.UserName == user_name)
|
||||||
category_ids: list[int] = list(session.scalars(stmt))
|
category_ids: "list[int]" = list(session.scalars(stmt))
|
||||||
|
|
||||||
stmt = select(Score).where(Score.UserName == user_name)
|
stmt = select(Score).where(Score.UserName == user_name)
|
||||||
for score in session.scalars(stmt):
|
for score in session.scalars(stmt):
|
||||||
@@ -181,6 +185,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
|||||||
category_id (str): String representation of Category id to remove user from. Is SlashOption.
|
category_id (str): String representation of Category id to remove user from. Is SlashOption.
|
||||||
user_name (str): The user to remove. Is SlashOption.
|
user_name (str): The user to remove. Is SlashOption.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == int(group_id))
|
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == int(group_id))
|
||||||
group = session.scalar(stmt)
|
group = session.scalar(stmt)
|
||||||
@@ -214,6 +219,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
|||||||
group_id (str): String representation of Group id to remove user from. Is SlashOption.
|
group_id (str): String representation of Group id to remove user from. Is SlashOption.
|
||||||
user_name (str): The user to remove. Is SlashOption.
|
user_name (str): The user to remove. Is SlashOption.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == int(group_id))
|
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == int(group_id))
|
||||||
group = session.scalar(stmt)
|
group = session.scalar(stmt)
|
||||||
@@ -261,7 +267,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
|||||||
@from_category.on_autocomplete("user_name")
|
@from_category.on_autocomplete("user_name")
|
||||||
@from_group.on_autocomplete("user_name")
|
@from_group.on_autocomplete("user_name")
|
||||||
async def user_autocomplete(
|
async def user_autocomplete(
|
||||||
self, interaction: nextcord.Interaction, user_name: str, group_id: str, category_id: str | None = None
|
self, interaction: nextcord.Interaction, user_name: str, group_id: str, category_id: Optional[str] = None
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Autocomplete functions for user names.
|
Autocomplete functions for user names.
|
||||||
@@ -272,6 +278,7 @@ class DeleteCog(commands.Cog, name="Table Management"):
|
|||||||
group_id (str): String representation of Group id to find category from.
|
group_id (str): String representation of Group id to find category from.
|
||||||
category_id (Optional[str]): String representation of Category id to find User from, can be None.
|
category_id (Optional[str]): String representation of Category id to find User from, can be None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
await interaction.response.send_autocomplete(
|
await interaction.response.send_autocomplete(
|
||||||
autofill_users_in_group_category(
|
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), category_id if category_id else 0, user_name
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class HelpCog(commands.Cog, name="Help commands."):
|
|||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# I hate this but don't want indents in the string.
|
# I hate this but don't want indents in the string.
|
||||||
# pylint: disable=line-too-long
|
# pylint: disable=line-too-long
|
||||||
help_str: str = """Welcome to Agon! Three simple steps are needed to get started.
|
help_str: str = """Welcome to Agon! Three simple steps are needed to get started.
|
||||||
@@ -41,5 +42,6 @@ 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!"""
|
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
|
# pylint: enable=line-too-long
|
||||||
|
print(help_str)
|
||||||
|
|
||||||
await interaction.response.send_message(content=help_str)
|
await interaction.response.send_message(content=help_str)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from sqlalchemy.orm import Session
|
|||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from cogs.submission.submission_views import SubmissionCreateButton
|
from cogs.submission.submission_views import SubmissionCreateButton
|
||||||
from database_setup.sql_data_classes import CategoryGroup, engine
|
from utilities.sql_data_classes import CategoryGroup, engine
|
||||||
from utilities.utils import autofill_groups, send_highscore_message
|
from utilities.utils import autofill_groups, send_highscore_message
|
||||||
|
|
||||||
|
|
||||||
@@ -46,6 +46,7 @@ class RefreshCog(commands.Cog, name="Refresh Cog"):
|
|||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
group_id (str): Str representation of Group id to refresh. Is SlashOption.
|
group_id (str): Str representation of Group id to refresh. Is SlashOption.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CategoryGroup)
|
select(CategoryGroup)
|
||||||
@@ -77,6 +78,7 @@ class RefreshCog(commands.Cog, name="Refresh Cog"):
|
|||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(CategoryGroup).where(CategoryGroup.GuildId == interaction.guild_id)
|
stmt = select(CategoryGroup).where(CategoryGroup.GuildId == interaction.guild_id)
|
||||||
|
|
||||||
@@ -98,4 +100,5 @@ class RefreshCog(commands.Cog, name="Refresh Cog"):
|
|||||||
interaction (nextcord.Interaction): Interaction with command.
|
interaction (nextcord.Interaction): Interaction with command.
|
||||||
group_id (str): String to run autocomplete compared to.
|
group_id (str): String to run autocomplete compared to.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
||||||
|
|||||||
+11
-4
@@ -2,13 +2,15 @@
|
|||||||
Set command heirarchy.
|
Set command heirarchy.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from database_setup.sql_data_classes import CategoryGroup, Guild, engine
|
from utilities.sql_data_classes import CategoryGroup, Guild, engine
|
||||||
from utilities.utils import MAX_LINE_LENGTH, autofill_groups
|
from utilities.utils import MAX_LINE_LENGTH, autofill_groups
|
||||||
|
|
||||||
|
|
||||||
@@ -35,7 +37,7 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
group_id: str = nextcord.SlashOption(
|
group_id: str = nextcord.SlashOption(
|
||||||
name="group", description="Category Group to assign to channel.", required=True
|
name="group", description="Category Group to assign to channel.", required=True
|
||||||
),
|
),
|
||||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption(
|
||||||
description="Channel to register",
|
description="Channel to register",
|
||||||
required=False,
|
required=False,
|
||||||
channel_types=[nextcord.ChannelType.text],
|
channel_types=[nextcord.ChannelType.text],
|
||||||
@@ -51,6 +53,7 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
channel (nextcord.abc.GuildChannel, optional): Channel to register
|
channel (nextcord.abc.GuildChannel, optional): Channel to register
|
||||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not channel:
|
if not channel:
|
||||||
channel = interaction.channel
|
channel = interaction.channel
|
||||||
channel_id = channel.id
|
channel_id = channel.id
|
||||||
@@ -90,6 +93,7 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
group_id (str): String representation of Group id to set pad length in. Is SlashOption.
|
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.
|
length (int): Number of characters. Is SlashOption. Defaults to 26.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CategoryGroup)
|
select(CategoryGroup)
|
||||||
@@ -107,7 +111,7 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
async def submission_channel(
|
async def submission_channel(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption(
|
||||||
description="Channel to register",
|
description="Channel to register",
|
||||||
required=False,
|
required=False,
|
||||||
channel_types=[nextcord.ChannelType.text],
|
channel_types=[nextcord.ChannelType.text],
|
||||||
@@ -122,6 +126,7 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
channel Optional[nextcord.abc.GuildChannel], optional): Channel to register
|
channel Optional[nextcord.abc.GuildChannel], optional): Channel to register
|
||||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not channel:
|
if not channel:
|
||||||
channel = interaction.channel
|
channel = interaction.channel
|
||||||
|
|
||||||
@@ -151,6 +156,7 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
interaction (nextcord.Interaction): Interaction that invoked the command
|
interaction (nextcord.Interaction): Interaction that invoked the command
|
||||||
length (int): Number of characters. Is SlashOption. Defaults to 12.
|
length (int): Number of characters. Is SlashOption. Defaults to 12.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CategoryGroup)
|
select(CategoryGroup)
|
||||||
@@ -166,7 +172,7 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
async def verify_channel(
|
async def verify_channel(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
channel: nextcord.abc.GuildChannel | None = nextcord.SlashOption(
|
channel: Optional[nextcord.abc.GuildChannel] = nextcord.SlashOption(
|
||||||
description="Channel to register",
|
description="Channel to register",
|
||||||
required=False,
|
required=False,
|
||||||
channel_types=[nextcord.ChannelType.text],
|
channel_types=[nextcord.ChannelType.text],
|
||||||
@@ -181,6 +187,7 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
channel (Optional[nextcord.abc.GuildChannel]): Channel to register
|
channel (Optional[nextcord.abc.GuildChannel]): Channel to register
|
||||||
Is a SlashOption. Limited to text channels, Defaults to None.
|
Is a SlashOption. Limited to text channels, Defaults to None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not channel:
|
if not channel:
|
||||||
channel = interaction.channel
|
channel = interaction.channel
|
||||||
channel_id = channel.id
|
channel_id = channel.id
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from sqlalchemy import select
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from database_setup.sql_data_classes import Guild, engine
|
from utilities.sql_data_classes import Guild, engine
|
||||||
from utilities.utils import autofill_users_in_guild
|
from utilities.utils import autofill_users_in_guild
|
||||||
|
|
||||||
from .views.update_username_verify import UpdateUsernameVerifyView
|
from .views.update_username_verify import UpdateUsernameVerifyView
|
||||||
@@ -57,6 +57,7 @@ class UpdateCog(commands.Cog, name="Update commands."):
|
|||||||
old_username (str): Username to replace.
|
old_username (str): Username to replace.
|
||||||
new_username (str): Username to replace old with.
|
new_username (str): Username to replace old with.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(Guild.VerificationChannel).where(Guild.GuildId == interaction.guild_id)
|
stmt = select(Guild.VerificationChannel).where(Guild.GuildId == interaction.guild_id)
|
||||||
verify_channel = interaction.guild.get_channel(session.scalar(stmt))
|
verify_channel = interaction.guild.get_channel(session.scalar(stmt))
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from sqlalchemy import select
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from database_setup.sql_data_classes import Category, CategoryGroup, Score, engine
|
from utilities.sql_data_classes import Category, CategoryGroup, Score, engine
|
||||||
from utilities.utils import MAX_LINE_LENGTH, autofill_categories, autofill_groups, format_score_string
|
from utilities.utils import MAX_LINE_LENGTH, autofill_categories, autofill_groups, format_score_string
|
||||||
|
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ class ViewCog(commands.Cog, name="View Command"):
|
|||||||
group_id (str): String representation of Group id to search from. Is SlashOption.
|
group_id (str): String representation of Group id to search from. Is SlashOption.
|
||||||
category_id (str): String representation of Category id to show leaderboard. Is SlashOption.
|
category_id (str): String representation of Category id to show leaderboard. Is SlashOption.
|
||||||
"""
|
"""
|
||||||
str_list: list[str] = []
|
str_list: "list[str]" = []
|
||||||
|
|
||||||
# get group, category, and all scores sorted correctly.
|
# get group, category, and all scores sorted correctly.
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
|
|||||||
@@ -2,12 +2,14 @@
|
|||||||
Contains view and helper functions for confirming and processing deletes.
|
Contains view and helper functions for confirming and processing deletes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from sqlalchemy import delete, select
|
from sqlalchemy import delete, select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from database_setup.sql_data_classes import Category, CategoryGroup, engine
|
from utilities.sql_data_classes import Category, CategoryGroup, engine
|
||||||
from utilities.utils import send_highscore_message
|
from utilities.utils import send_highscore_message
|
||||||
|
|
||||||
|
|
||||||
@@ -59,7 +61,7 @@ class DeleteConfirmView(nextcord.ui.Modal):
|
|||||||
await interaction.response.send_message("Deletion complete.", ephemeral=True)
|
await interaction.response.send_message("Deletion complete.", ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
def create_delete_id(group_id: int, category_id: int | None = None) -> str:
|
def create_delete_id(group_id: int, category_id: Optional[int] = None) -> str:
|
||||||
"""
|
"""
|
||||||
Creates a delete id string to tell the view what to delete.
|
Creates a delete id string to tell the view what to delete.
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from sqlalchemy import distinct, exc, select
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from database_setup.sql_data_classes import Category, CategoryGroup, Score, engine
|
from utilities.sql_data_classes import Category, CategoryGroup, Score, engine
|
||||||
from utilities.utils import send_highscore_message
|
from utilities.utils import send_highscore_message
|
||||||
|
|
||||||
|
|
||||||
@@ -19,7 +19,9 @@ class UpdateUsernameVerifyView(nextcord.ui.View):
|
|||||||
super().__init__(timeout=None)
|
super().__init__(timeout=None)
|
||||||
|
|
||||||
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-username-update")
|
@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
|
||||||
|
): # pylint: disable=unused-argument
|
||||||
"""
|
"""
|
||||||
Button for denying username update. Deletes message.
|
Button for denying username update. Deletes message.
|
||||||
|
|
||||||
@@ -30,7 +32,9 @@ class UpdateUsernameVerifyView(nextcord.ui.View):
|
|||||||
await interaction.message.delete()
|
await interaction.message.delete()
|
||||||
|
|
||||||
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-username-update")
|
@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
|
||||||
|
): # pylint: disable=unused-argument
|
||||||
"""
|
"""
|
||||||
Button for approving username update. Tells guild data to update username, then updates
|
Button for approving username update. Tells guild data to update username, then updates
|
||||||
message to show it is complete.
|
message to show it is complete.
|
||||||
@@ -39,6 +43,7 @@ class UpdateUsernameVerifyView(nextcord.ui.View):
|
|||||||
button (nextcord.ui.Button): unused
|
button (nextcord.ui.Button): unused
|
||||||
interaction (nextcord.Interaction): Interaction with the button
|
interaction (nextcord.Interaction): Interaction with the button
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
try:
|
try:
|
||||||
embed_content = interaction.message.embeds[0].to_dict()
|
embed_content = interaction.message.embeds[0].to_dict()
|
||||||
@@ -46,7 +51,7 @@ class UpdateUsernameVerifyView(nextcord.ui.View):
|
|||||||
new_username: str = embed_content["fields"][1]["value"]
|
new_username: str = embed_content["fields"][1]["value"]
|
||||||
|
|
||||||
stmt = select(distinct(Score.CategoryId)).where(Score.UserName == old_username)
|
stmt = select(distinct(Score.CategoryId)).where(Score.UserName == old_username)
|
||||||
category_ids: list[int] = list(session.scalars(stmt))
|
category_ids: "list[int]" = list(session.scalars(stmt))
|
||||||
|
|
||||||
stmt = select(Score).where(Score.UserName == old_username)
|
stmt = select(Score).where(Score.UserName == old_username)
|
||||||
for score in session.scalars(stmt):
|
for score in session.scalars(stmt):
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from sqlalchemy import select
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from database_setup.sql_data_classes import Guild, engine
|
from utilities.sql_data_classes import Guild, engine
|
||||||
|
|
||||||
|
|
||||||
class GuildListener(commands.Cog, name="Guild Listener"):
|
class GuildListener(commands.Cog, name="Guild Listener"):
|
||||||
@@ -25,6 +25,7 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
|||||||
Args:
|
Args:
|
||||||
guild (nextcord.Guild): Guild that was joined.
|
guild (nextcord.Guild): Guild that was joined.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(Guild).where(Guild.GuildId == guild.id)
|
stmt = select(Guild).where(Guild.GuildId == guild.id)
|
||||||
guild_data = session.scalar(stmt)
|
guild_data = session.scalar(stmt)
|
||||||
@@ -52,6 +53,7 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
|||||||
Args:
|
Args:
|
||||||
guild (nextcord.Guild): Guild that was left.
|
guild (nextcord.Guild): Guild that was left.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(Guild).where(Guild.GuildId == guild.id)
|
stmt = select(Guild).where(Guild.GuildId == guild.id)
|
||||||
guild_data = session.scalar(stmt)
|
guild_data = session.scalar(stmt)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from sqlalchemy import select
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from database_setup.sql_data_classes import Guild, engine
|
from utilities.sql_data_classes import Guild, engine
|
||||||
|
|
||||||
|
|
||||||
class GuildData(commands.Cog, name="Guild Data"):
|
class GuildData(commands.Cog, name="Guild Data"):
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ Defines cog for on message listener.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
@@ -12,8 +11,9 @@ from sqlalchemy.orm import Session
|
|||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from classes.submission import SubmissionState
|
from classes.submission import SubmissionState
|
||||||
from main import submission_objects
|
from highscores import submission_objects
|
||||||
from database_setup.sql_data_classes import Category, Guild, engine
|
from utilities.sql_data_classes import Guild, engine
|
||||||
|
from utilities.utils import score_str_to_float
|
||||||
|
|
||||||
|
|
||||||
class SubmissionListener(commands.Cog, name="Message Listener"):
|
class SubmissionListener(commands.Cog, name="Message Listener"):
|
||||||
@@ -29,8 +29,6 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
|
|||||||
if message.author.id == self.bot.user.id:
|
if message.author.id == self.bot.user.id:
|
||||||
return
|
return
|
||||||
|
|
||||||
await birthday_action(message)
|
|
||||||
|
|
||||||
guild_id = message.guild.id
|
guild_id = message.guild.id
|
||||||
|
|
||||||
if submission_objects.has_user(message.author.id):
|
if submission_objects.has_user(message.author.id):
|
||||||
@@ -44,59 +42,42 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
|
|||||||
await self.bot.get_guild(guild_id).get_channel(submission_channel_id).fetch_message(message_id)
|
await self.bot.get_guild(guild_id).get_channel(submission_channel_id).fetch_message(message_id)
|
||||||
)
|
)
|
||||||
|
|
||||||
# need check if correct user and correct channel
|
# need check if correct user and correct channel
|
||||||
if message.channel.id == submission_channel_id:
|
if message.channel.id == submission_channel_id:
|
||||||
state = submission.submission_state
|
state = submission.submission_state
|
||||||
if state == SubmissionState.SCORE and message.content:
|
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 = submission.is_time_record
|
||||||
|
|
||||||
# check with regex if score matches correctly
|
time_regex = re.search("^([0-9]{1,2}:[0-9]|[0-9])?[0-9](\\.[0-9])?$", message.content)
|
||||||
is_time_record = session.scalar(stmt)
|
int_regex = re.search("^[0-9]+$", message.content)
|
||||||
|
if time_regex is None and is_time_record:
|
||||||
|
embed = submission_message.embeds[0]
|
||||||
|
embed.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:
|
||||||
|
embed = submission_message.embeds[0]
|
||||||
|
embed.add_field(name="Error", value="Number record must only be number.")
|
||||||
|
else:
|
||||||
|
submission.score = score_str_to_float(message.content, is_time_record)
|
||||||
|
embed = submission.get_embed()
|
||||||
|
await submission_message.edit(
|
||||||
|
embed=embed,
|
||||||
|
)
|
||||||
|
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
|
||||||
|
embed = submission.get_embed()
|
||||||
|
await submission_message.edit(
|
||||||
|
embed=embed,
|
||||||
|
)
|
||||||
|
|
||||||
time_regex = re.search("^([0-9]{1,2}:[0-9]|[0-9])?[0-9](\\.[0-9])?$", message.content)
|
await message.delete()
|
||||||
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.
|
# This function will be called when this extension is loaded.
|
||||||
@@ -104,18 +85,3 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
|
|||||||
def setup(bot: commands.Bot):
|
def setup(bot: commands.Bot):
|
||||||
"""Adds function to bot"""
|
"""Adds function to bot"""
|
||||||
bot.add_cog(SubmissionListener(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,5 +1,7 @@
|
|||||||
"""Views used for submission process."""
|
"""Views used for submission process."""
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
@@ -7,15 +9,15 @@ from sqlalchemy.orm import Session, aliased
|
|||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from classes.submission import Submission, SubmissionState
|
from classes.submission import Submission, SubmissionState
|
||||||
from main import submission_objects
|
from highscores import submission_objects
|
||||||
from database_setup.sql_data_classes import Category, CategoryGroup, Guild, engine
|
from utilities.sql_data_classes import Category, CategoryGroup, Guild, Submissions, engine
|
||||||
|
|
||||||
from .verification_view import VerificationView
|
from .verification_view import VerificationView
|
||||||
|
|
||||||
|
|
||||||
def category_select_options(group_id: int) -> "list[nextcord.SelectOption]":
|
def category_select_options(group_id: int) -> "list[nextcord.SelectOption]":
|
||||||
"""Returns list of categories for a given boss."""
|
"""Returns list of categories for a given boss."""
|
||||||
options: list[nextcord.SelectOption] = []
|
options: "list[nextcord.SelectOption]" = []
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
subq = select(CategoryGroup).where(CategoryGroup.GroupId == group_id).subquery()
|
subq = select(CategoryGroup).where(CategoryGroup.GroupId == group_id).subquery()
|
||||||
@@ -28,7 +30,7 @@ def category_select_options(group_id: int) -> "list[nextcord.SelectOption]":
|
|||||||
return options
|
return options
|
||||||
|
|
||||||
|
|
||||||
############ Items used in submission process ############
|
# Items used in submission process ########################
|
||||||
|
|
||||||
|
|
||||||
class SubmissionDropdown(nextcord.ui.Select):
|
class SubmissionDropdown(nextcord.ui.Select):
|
||||||
@@ -45,9 +47,14 @@ class SubmissionDropdown(nextcord.ui.Select):
|
|||||||
async def callback(self, interaction: nextcord.Interaction):
|
async def callback(self, interaction: nextcord.Interaction):
|
||||||
submission = submission_objects.get_user_submission(interaction.user.id)
|
submission = submission_objects.get_user_submission(interaction.user.id)
|
||||||
submission.category_id = self.values[0]
|
submission.category_id = self.values[0]
|
||||||
embeds = submission.get_embeds()
|
|
||||||
|
with Session(engine) as session:
|
||||||
|
stmt = select(Category.IsTimeRecord).where(Category.CategoryId == submission.category_id)
|
||||||
|
submission.is_time_record = session.scalar(stmt)
|
||||||
|
|
||||||
|
embed = submission.get_embed()
|
||||||
await interaction.message.edit(
|
await interaction.message.edit(
|
||||||
embeds=embeds,
|
embed=embed,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -98,8 +105,8 @@ class NextButton(nextcord.ui.Button):
|
|||||||
else:
|
else:
|
||||||
state = SubmissionState(state.value + 1)
|
state = SubmissionState(state.value + 1)
|
||||||
submission.submission_state = state
|
submission.submission_state = state
|
||||||
embeds = submission.get_embeds()
|
embed = submission.get_embed()
|
||||||
await interaction.edit(embeds=embeds, view=SubmissionView(self._bot, interaction.user.id))
|
await interaction.edit(embed=embed, view=SubmissionView(self._bot, interaction.user.id))
|
||||||
|
|
||||||
|
|
||||||
class SubmitButton(nextcord.ui.Button):
|
class SubmitButton(nextcord.ui.Button):
|
||||||
@@ -114,27 +121,40 @@ class SubmitButton(nextcord.ui.Button):
|
|||||||
stmt = select(Guild.VerificationChannel).where(Guild.GuildId == interaction.guild_id)
|
stmt = select(Guild.VerificationChannel).where(Guild.GuildId == interaction.guild_id)
|
||||||
verification_channel_id = session.scalar(stmt)
|
verification_channel_id = session.scalar(stmt)
|
||||||
channel = interaction.guild.get_channel(verification_channel_id)
|
channel = interaction.guild.get_channel(verification_channel_id)
|
||||||
submission = submission_objects.get_user_submission(interaction.user.id)
|
active_submission = submission_objects.get_user_submission(interaction.user.id)
|
||||||
|
|
||||||
error_response = "Registered Verification channel does not exist or was never registered. \
|
error_response = "Registered Verification channel does not exist or was never registered. \
|
||||||
Contact server admins."
|
Contact server admins."
|
||||||
assert channel is not None, await channel.send(error_response)
|
assert channel is not None, await channel.send(error_response)
|
||||||
|
|
||||||
submission.submission_state = SubmissionState.VERIFY
|
active_submission.submission_state = SubmissionState.VERIFY
|
||||||
|
|
||||||
embeds = submission.get_embeds()
|
embed = active_submission.get_embed()
|
||||||
|
|
||||||
await channel.send(
|
verification_message = await channel.send(
|
||||||
files=[await attch.to_file() for attch in interaction.message.attachments],
|
files=[await attch.to_file() for attch in interaction.message.attachments],
|
||||||
view=VerificationView(),
|
view=VerificationView(),
|
||||||
embeds=embeds,
|
embed=embed,
|
||||||
content=f"Submission from <@{interaction.user.id}>.",
|
content=f"Submission from <@{interaction.user.id}>.",
|
||||||
)
|
)
|
||||||
await interaction.message.edit(content=f"<@{interaction.user.id}> Submitted!", view=None)
|
await interaction.message.edit(content=f"<@{interaction.user.id}> Submitted!", view=None)
|
||||||
|
|
||||||
|
new_submission = Submissions(
|
||||||
|
CategoryId=active_submission.category_id,
|
||||||
|
GroupId=active_submission.group_id,
|
||||||
|
IsTimeRecord=active_submission.is_time_record,
|
||||||
|
Score=active_submission.score,
|
||||||
|
SubmissionMessageId=interaction.message.id,
|
||||||
|
UserName=active_submission.username,
|
||||||
|
VerificationMessageId=verification_message.id,
|
||||||
|
)
|
||||||
submission_objects.remove_user_submission(interaction.user.id)
|
submission_objects.remove_user_submission(interaction.user.id)
|
||||||
|
with Session(engine) as session:
|
||||||
|
session.add(new_submission)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
############ Submission Views ############
|
# Submission Views ########################
|
||||||
|
|
||||||
|
|
||||||
class SubmissionCreateButton(nextcord.ui.View):
|
class SubmissionCreateButton(nextcord.ui.View):
|
||||||
@@ -145,8 +165,11 @@ class SubmissionCreateButton(nextcord.ui.View):
|
|||||||
self._bot = bot
|
self._bot = bot
|
||||||
|
|
||||||
@nextcord.ui.button(label="Submit", style=nextcord.ButtonStyle.primary, custom_id="submitcreate")
|
@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
|
async def submitcreate_button(
|
||||||
|
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||||
|
): # pylint: disable=unused-argument
|
||||||
"""Button for score submission."""
|
"""Button for score submission."""
|
||||||
|
|
||||||
# Don't allow a user to start a new submission if one already exists
|
# Don't allow a user to start a new submission if one already exists
|
||||||
if submission_objects.has_user(interaction.user.id):
|
if submission_objects.has_user(interaction.user.id):
|
||||||
await interaction.send("Please finish in progress submission first.", ephemeral=True)
|
await interaction.send("Please finish in progress submission first.", ephemeral=True)
|
||||||
@@ -166,11 +189,11 @@ class SubmissionCreateButton(nextcord.ui.View):
|
|||||||
# a user should only have 1 submission active at once.
|
# a user should only have 1 submission active at once.
|
||||||
# split username on pipe. Decided to store whole username...
|
# split username on pipe. Decided to store whole username...
|
||||||
username: str = interaction.user.display_name.split("|")[0]
|
username: str = interaction.user.display_name.split("|")[0]
|
||||||
submission: Submission = Submission(interaction.guild_id, group_id, username)
|
submission: Submission = Submission(group_id, interaction.guild_id, username)
|
||||||
|
|
||||||
submission_objects.add_submission(interaction.user.id, submission)
|
submission_objects.add_submission(interaction.user.id, submission)
|
||||||
|
|
||||||
embeds = submission.get_embeds()
|
embed = submission.get_embed()
|
||||||
|
|
||||||
submission_message = await channel.send(
|
submission_message = await channel.send(
|
||||||
f"<@{interaction.user.id}>",
|
f"<@{interaction.user.id}>",
|
||||||
@@ -178,7 +201,7 @@ class SubmissionCreateButton(nextcord.ui.View):
|
|||||||
self._bot,
|
self._bot,
|
||||||
interaction.user.id,
|
interaction.user.id,
|
||||||
),
|
),
|
||||||
embeds=embeds,
|
embed=embed,
|
||||||
)
|
)
|
||||||
|
|
||||||
# update the message_id once its created
|
# update the message_id once its created
|
||||||
@@ -193,7 +216,7 @@ class SubmissionView(nextcord.ui.View):
|
|||||||
bot: commands.Bot,
|
bot: commands.Bot,
|
||||||
submission_user: int,
|
submission_user: int,
|
||||||
*,
|
*,
|
||||||
timeout: float | None = 300,
|
timeout: Optional[float] = 300,
|
||||||
):
|
):
|
||||||
super().__init__(timeout=timeout)
|
super().__init__(timeout=timeout)
|
||||||
self._submission_user = submission_user
|
self._submission_user = submission_user
|
||||||
@@ -226,6 +249,6 @@ class SubmissionView(nextcord.ui.View):
|
|||||||
|
|
||||||
return check
|
return check
|
||||||
|
|
||||||
# async def on_timeout(self) -> None:
|
async def on_timeout(self) -> None:
|
||||||
# # remove user from submission objects after time out. Allows user to start new submission.
|
# remove user from submission objects after time out. Allows user to start new submission.
|
||||||
# submission_objects.remove_user_submission(self._submission_user)
|
submission_objects.remove_user_submission(self._submission_user)
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
"""View for verification buttons"""
|
"""View for verification buttons"""
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from utilities.sql_data_classes import Submissions, engine
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from utilities.utils import submit_score
|
from utilities.utils import submit_score
|
||||||
@@ -13,32 +17,38 @@ class VerificationView(nextcord.ui.View):
|
|||||||
super().__init__(timeout=None)
|
super().__init__(timeout=None)
|
||||||
|
|
||||||
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-button-submission")
|
@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
|
async def deny_button(
|
||||||
|
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||||
|
): # pylint: disable=unused-argument
|
||||||
"""Button for denying score submission."""
|
"""Button for denying score submission."""
|
||||||
|
with Session(engine) as session:
|
||||||
|
stmt = select(Submissions).where(Submissions.VerificationMessageId == interaction.message.id)
|
||||||
|
submission = session.scalar(stmt)
|
||||||
|
# let user know submission was denied
|
||||||
|
|
||||||
|
# TODO need to access bot here
|
||||||
|
|
||||||
|
# delete the submission
|
||||||
|
session.delete(stmt)
|
||||||
|
session.commit()
|
||||||
await interaction.message.delete()
|
await interaction.message.delete()
|
||||||
|
|
||||||
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-button-submission")
|
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-button-submission")
|
||||||
async def approve_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): # pylint: disable=unused-argument
|
async def approve_button(
|
||||||
"""Button for approving score submission."""
|
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||||
for embed in interaction.message.embeds:
|
): # pylint: disable=unused-argument
|
||||||
content = embed.to_dict()
|
with Session(engine) as session:
|
||||||
|
stmt = select(Submissions).where(Submissions.VerificationMessageId == interaction.message.id)
|
||||||
for field in content["fields"]:
|
submission = session.scalar(stmt)
|
||||||
if field["name"] == "GroupId":
|
|
||||||
group_id = int(field["value"])
|
|
||||||
elif field["name"] == "CategoryId":
|
|
||||||
category_id = int(field["value"])
|
|
||||||
elif field["name"] == "Score":
|
|
||||||
score = field["value"]
|
|
||||||
elif field["name"] == "User Name":
|
|
||||||
user = field["value"]
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await submit_score(interaction, group_id, category_id, user, score)
|
await submit_score(
|
||||||
|
interaction, submission.GroupId, submission.CategoryId, submission.UserName, submission.Score
|
||||||
|
)
|
||||||
content = interaction.message.content
|
content = interaction.message.content
|
||||||
content += f"\nApproved by <@{interaction.user.id}>."
|
content += f"\nApproved by <@{interaction.user.id}>."
|
||||||
# remove the bot information embed. it should always be the first one.
|
await interaction.message.edit(content=content, view=None)
|
||||||
await interaction.message.edit(content=content, view=None, embed=interaction.message.embeds[0])
|
# TODO send message to let user know submission was accepted. Need access to bot here.
|
||||||
except UnboundLocalError:
|
except UnboundLocalError:
|
||||||
await interaction.send("Instruct user to submit with all fields.")
|
await interaction.send("Instruct user to submit with all fields.")
|
||||||
await interaction.message.edit(view=None)
|
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"]
|
|
||||||
@@ -9,10 +9,9 @@ import sys
|
|||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
from classes.submission import SubmissionMap
|
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from utilities import config
|
from utilities import config
|
||||||
|
from classes.submission import SubmissionMap
|
||||||
|
|
||||||
logger = logging.getLogger("nextcord")
|
logger = logging.getLogger("nextcord")
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
@@ -30,7 +29,7 @@ def main():
|
|||||||
print("ERROR: Python version must be >= 3.8")
|
print("ERROR: Python version must be >= 3.8")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# Allows privileged intents for monitoring members joining, roles editing, and role assignments
|
# Allows privledged intents for monitoring members joining, roles editing, and role assignments
|
||||||
# These need to be enabled in the developer portal as well
|
# These need to be enabled in the developer portal as well
|
||||||
intents = nextcord.Intents.default()
|
intents = nextcord.Intents.default()
|
||||||
|
|
||||||
@@ -42,4 +42,15 @@ CREATE TABLE Scores(
|
|||||||
CategoryId int unsigned not null,
|
CategoryId int unsigned not null,
|
||||||
FOREIGN KEY (CategoryId) REFERENCES Categories(CategoryId) ON DELETE CASCADE,
|
FOREIGN KEY (CategoryId) REFERENCES Categories(CategoryId) ON DELETE CASCADE,
|
||||||
PRIMARY KEY (CategoryId, UserName)
|
PRIMARY KEY (CategoryId, UserName)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Submissions(
|
||||||
|
CategoryId int unsigned not null,
|
||||||
|
GroupId int unsigned not null,
|
||||||
|
IsTimeRecord boolean not null,
|
||||||
|
Score float not null,
|
||||||
|
SubmissionMessageId bigint unsigned not null,
|
||||||
|
UserName varchar(30) not null,
|
||||||
|
VerificationMessageId bigint unsigned not null,
|
||||||
|
PRIMARY KEY (CategoryId, GroupId, UserName)
|
||||||
);
|
);
|
||||||
-131
@@ -1,131 +0,0 @@
|
|||||||
[tool.poetry]
|
|
||||||
name = "agon"
|
|
||||||
version = "0.1.0"
|
|
||||||
description = "A highscores discord bot"
|
|
||||||
authors = ["imcompiling <[email protected]>"]
|
|
||||||
readme = "README.md"
|
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
|
||||||
python = "^3.12"
|
|
||||||
nextcord = "^2.6.0"
|
|
||||||
python-dotenv = "^1.0.1"
|
|
||||||
pandas = "^2.2.3"
|
|
||||||
sqlalchemy = "^2.0.35"
|
|
||||||
pymysql = "^1.1.1"
|
|
||||||
cryptography = "^43.0.1"
|
|
||||||
setuptools = "^75.1.0"
|
|
||||||
|
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
|
||||||
ruff = "^0.6.9"
|
|
||||||
|
|
||||||
[build-system]
|
|
||||||
requires = ["poetry-core"]
|
|
||||||
build-backend = "poetry.core.masonry.api"
|
|
||||||
|
|
||||||
[tool.ruff]
|
|
||||||
# Exclude a variety of commonly ignored directories.
|
|
||||||
exclude = [
|
|
||||||
".bzr",
|
|
||||||
".direnv",
|
|
||||||
".eggs",
|
|
||||||
".git",
|
|
||||||
".git-rewrite",
|
|
||||||
".hg",
|
|
||||||
".ipynb_checkpoints",
|
|
||||||
".mypy_cache",
|
|
||||||
".nox",
|
|
||||||
".pants.d",
|
|
||||||
".pyenv",
|
|
||||||
".pytest_cache",
|
|
||||||
".pytype",
|
|
||||||
".ruff_cache",
|
|
||||||
".svn",
|
|
||||||
".tox",
|
|
||||||
".venv",
|
|
||||||
".vscode",
|
|
||||||
"__pypackages__",
|
|
||||||
"_build",
|
|
||||||
"buck-out",
|
|
||||||
"build",
|
|
||||||
"dist",
|
|
||||||
"node_modules",
|
|
||||||
"site-packages",
|
|
||||||
"venv",
|
|
||||||
"dakiny-messages", # Don't need to lint this git repo.
|
|
||||||
]
|
|
||||||
|
|
||||||
# Same as Black.
|
|
||||||
line-length = 120
|
|
||||||
indent-width = 4
|
|
||||||
|
|
||||||
# Assume Python 3.8
|
|
||||||
target-version = "py312"
|
|
||||||
|
|
||||||
[tool.ruff.lint]
|
|
||||||
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
|
|
||||||
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
|
|
||||||
# McCabe complexity (`C901`) by default.
|
|
||||||
select = ["ALL"]
|
|
||||||
ignore = [
|
|
||||||
"ANN101",
|
|
||||||
"B008", # I build SlashOptions as arguments.
|
|
||||||
"COM812",
|
|
||||||
"COM819",
|
|
||||||
"D107", # don't want docstrings on init functions
|
|
||||||
"D203",
|
|
||||||
"D206",
|
|
||||||
"D212",
|
|
||||||
"D300",
|
|
||||||
"E111",
|
|
||||||
"E114",
|
|
||||||
"E117",
|
|
||||||
"ISC001",
|
|
||||||
"ISC002",
|
|
||||||
"PD011", # doesn't like me using '.values' on embeds....
|
|
||||||
"Q000",
|
|
||||||
"Q001",
|
|
||||||
"Q002",
|
|
||||||
"Q003",
|
|
||||||
"W191",
|
|
||||||
]
|
|
||||||
|
|
||||||
# Allow fix for all enabled rules (when `--fix`) is provided.
|
|
||||||
fixable = ["ALL"]
|
|
||||||
unfixable = []
|
|
||||||
|
|
||||||
# Allow unused variables when underscore-prefixed.
|
|
||||||
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
|
||||||
|
|
||||||
[tool.ruff.lint.pydocstyle]
|
|
||||||
convention = "google"
|
|
||||||
|
|
||||||
[tool.ruff.lint.flake8-annotations]
|
|
||||||
mypy-init-return = true
|
|
||||||
|
|
||||||
[tool.ruff.format]
|
|
||||||
# Like Black, use double quotes for strings.
|
|
||||||
quote-style = "double"
|
|
||||||
|
|
||||||
# Like Black, indent with spaces, rather than tabs.
|
|
||||||
indent-style = "space"
|
|
||||||
|
|
||||||
# Like Black, respect magic trailing commas.
|
|
||||||
skip-magic-trailing-comma = false
|
|
||||||
|
|
||||||
# Like Black, automatically detect the appropriate line ending.
|
|
||||||
line-ending = "auto"
|
|
||||||
|
|
||||||
# Enable auto-formatting of code examples in docstrings. Markdown,
|
|
||||||
# reStructuredText code/literal blocks and doctests are all supported.
|
|
||||||
#
|
|
||||||
# This is currently disabled by default, but it is planned for this
|
|
||||||
# to be opt-out in the future.
|
|
||||||
docstring-code-format = true
|
|
||||||
|
|
||||||
# Set the line length limit used when formatting code snippets in
|
|
||||||
# docstrings.
|
|
||||||
#
|
|
||||||
# This only has an effect when the `docstring-code-format` setting is
|
|
||||||
# enabled.
|
|
||||||
docstring-code-line-length = "dynamic"
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
nextcord>=2.3.2
|
||||||
|
python-dotenv>=0.20.0
|
||||||
|
pandas>=1.5.2
|
||||||
|
sqlalchemy<2.0
|
||||||
|
pymysql>=1.0.2
|
||||||
|
cryptography>=2.8
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
"""Simple file to set up the sqlalchemy connection to database."""
|
"""
|
||||||
|
Simple file to set up the sqlalchemy connection to database.
|
||||||
|
"""
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.ext.automap import automap_base
|
from sqlalchemy.ext.automap import automap_base
|
||||||
|
|
||||||
|
# pylint: disable=import-error
|
||||||
from utilities import config
|
from utilities import config
|
||||||
|
|
||||||
# connect with sql alchemy and autoload schema
|
# connect with sql alchemy and autoload schema
|
||||||
@@ -11,7 +14,8 @@ Base = automap_base()
|
|||||||
Base.prepare(autoload_with=engine)
|
Base.prepare(autoload_with=engine)
|
||||||
|
|
||||||
# define the classes
|
# define the classes
|
||||||
Guild = Base.classes.Guilds
|
|
||||||
CategoryGroup = Base.classes.CategoryGroups
|
|
||||||
Category = Base.classes.Categories
|
Category = Base.classes.Categories
|
||||||
|
CategoryGroup = Base.classes.CategoryGroups
|
||||||
|
Guild = Base.classes.Guilds
|
||||||
Score = Base.classes.Scores
|
Score = Base.classes.Scores
|
||||||
|
Submissions = Base.classes.Submissions
|
||||||
+69
-48
@@ -11,7 +11,7 @@ from sqlalchemy import distinct, select
|
|||||||
from sqlalchemy.orm import Session, aliased
|
from sqlalchemy.orm import Session, aliased
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from database_setup.sql_data_classes import Category, CategoryGroup, Guild, Score, engine
|
from utilities.sql_data_classes import Category, CategoryGroup, Guild, Score, engine
|
||||||
|
|
||||||
MAX_LINE_LENGTH = 142
|
MAX_LINE_LENGTH = 142
|
||||||
|
|
||||||
@@ -29,6 +29,7 @@ def autofill_categories(guild_id: int, group_id: int, category_begin: str) -> "d
|
|||||||
Returns:
|
Returns:
|
||||||
dict[str, str]: List of all category names that start with category_begin.
|
dict[str, str]: List of all category names that start with category_begin.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
# search database for all category names
|
# search database for all category names
|
||||||
subq = (
|
subq = (
|
||||||
@@ -39,15 +40,15 @@ def autofill_categories(guild_id: int, group_id: int, category_begin: str) -> "d
|
|||||||
)
|
)
|
||||||
cat_group_alias = aliased(CategoryGroup, subq)
|
cat_group_alias = aliased(CategoryGroup, subq)
|
||||||
stmt = select(Category).where(Category.GroupId == cat_group_alias.GroupId)
|
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)}
|
categories_dict: "dict[str, str]" = {cat.CategoryName: str(cat.CategoryId) for cat in session.scalars(stmt)}
|
||||||
|
|
||||||
# if string empty, return all category names
|
# if string empty, return all category names
|
||||||
if not category_begin:
|
if not category_begin:
|
||||||
return dict(list(categories_dict.items())[:25])
|
return dict(list(category_begin.items())[:25])
|
||||||
|
|
||||||
# else find all categories that start with category_begin
|
# else find all categories that start with category_begin
|
||||||
# TODO is it better to have sql handle the starts with or python?
|
# TODO is it better to have sql handle the starts with or python?
|
||||||
categories: dict[str, str] = {
|
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()
|
cat_name: cat_id for cat_name, cat_id in categories_dict.items() if category_begin.lower() in cat_name.lower()
|
||||||
}
|
}
|
||||||
return dict(list(categories.items())[:25])
|
return dict(list(categories.items())[:25])
|
||||||
@@ -64,19 +65,20 @@ def autofill_groups(guild_id: int, group_begin: str) -> "dict[str, str]":
|
|||||||
Returns:
|
Returns:
|
||||||
dict[str, str]: Dict of group names and ids where group name start with group_begin. Key is name, value is id.
|
dict[str, str]: Dict of group names and ids where group name start with group_begin. Key is name, value is id.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
# Select all groups in guild.
|
# Select all groups in guild.
|
||||||
stmt = select(CategoryGroup).where(CategoryGroup.GuildId == guild_id)
|
stmt = select(CategoryGroup).where(CategoryGroup.GuildId == guild_id)
|
||||||
|
|
||||||
# dict has to have key values of same type for discord.
|
# 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.GroupName: str(group.GroupId) for group in session.scalars(stmt)}
|
||||||
|
|
||||||
# if string empty, return all group names
|
# if string empty, return all group names
|
||||||
if not group_begin:
|
if not group_begin:
|
||||||
return dict(list(group_dict.items())[:25])
|
return dict(list(group_dict.items())[:25])
|
||||||
|
|
||||||
# else find all groups that start with group_begin
|
# else find all groups that start with group_begin
|
||||||
groups: dict[str, str] = {
|
groups: "dict[str, str]" = {
|
||||||
group_name: group_id for group_name, group_id in group_dict.items() if group_begin.lower() in group_name.lower()
|
group_name: group_id for group_name, group_id in group_dict.items() if group_begin.lower() in group_name.lower()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +99,7 @@ def autofill_users_in_group_category(guild_id: int, group_id: int, category_id:
|
|||||||
Returns:
|
Returns:
|
||||||
list[str]: List of users that start with user_begin.
|
list[str]: List of users that start with user_begin.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
# get all categories in the group
|
# get all categories in the group
|
||||||
subq = (
|
subq = (
|
||||||
@@ -123,14 +126,14 @@ def autofill_users_in_group_category(guild_id: int, group_id: int, category_id:
|
|||||||
category = aliased(Category, subq)
|
category = aliased(Category, subq)
|
||||||
stmt = select(distinct(Score.UserName)).where(Score.CategoryId == category.CategoryId)
|
stmt = select(distinct(Score.UserName)).where(Score.CategoryId == category.CategoryId)
|
||||||
|
|
||||||
users_list: list[str] = list(session.scalars(stmt))
|
users_list: "list[str]" = list(session.scalars(stmt))
|
||||||
|
|
||||||
# if string empty, return all users
|
# if string empty, return all users
|
||||||
if not user_begin:
|
if not user_begin:
|
||||||
return users_list[:25]
|
return users_list[:25]
|
||||||
|
|
||||||
# else find all users that start with user_begin
|
# else find all users that start with user_begin
|
||||||
users: list[str] = [user for user in users_list if user_begin.lower() in user.lower()]
|
users: "list[str]" = [user for user in users_list if user_begin.lower() in user.lower()]
|
||||||
|
|
||||||
return users[:25]
|
return users[:25]
|
||||||
|
|
||||||
@@ -146,18 +149,19 @@ def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]":
|
|||||||
Returns:
|
Returns:
|
||||||
list[str]: All users with submissions in the guild.
|
list[str]: All users with submissions in the guild.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
group_ids = select(CategoryGroup.GroupId).where(CategoryGroup.GuildId == guild_id)
|
group_ids = select(CategoryGroup.GroupId).where(CategoryGroup.GuildId == guild_id)
|
||||||
category_ids = select(Category.CategoryId).where(Category.GroupId.in_(group_ids))
|
category_ids = select(Category.CategoryId).where(Category.GroupId.in_(group_ids))
|
||||||
stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(category_ids))
|
stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(category_ids))
|
||||||
users_list: list[str] = list(session.scalars(stmt))
|
users_list: "list[str]" = list(session.scalars(stmt))
|
||||||
|
|
||||||
# if string empty, return all users
|
# if string empty, return all users
|
||||||
if not user_begin:
|
if not user_begin:
|
||||||
return users_list[:25]
|
return users_list[:25]
|
||||||
|
|
||||||
# else find all users that start with user_begin
|
# else find all users that start with user_begin
|
||||||
users: list[str] = [user for user in users_list if user_begin.lower() in user.lower()]
|
users: "list[str]" = [user for user in users_list if user_begin.lower() in user.lower()]
|
||||||
|
|
||||||
return users[:25]
|
return users[:25]
|
||||||
|
|
||||||
@@ -175,6 +179,7 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
|||||||
Returns:
|
Returns:
|
||||||
str: Formatted string for discord message
|
str: Formatted string for discord message
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ret_string = f"**{group.GroupName}**\n```"
|
ret_string = f"**{group.GroupName}**\n```"
|
||||||
|
|
||||||
stmt = select(Guild).where(Guild.GuildId == group.GuildId)
|
stmt = select(Guild).where(Guild.GuildId == group.GuildId)
|
||||||
@@ -196,19 +201,17 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
|||||||
max_cat_size: int = 0
|
max_cat_size: int = 0
|
||||||
pad_length = group.PadLength
|
pad_length = group.PadLength
|
||||||
for cat in session.scalars(stmt):
|
for cat in session.scalars(stmt):
|
||||||
max_cat_size = max(cat.Size, max_cat_size)
|
if cat.Size > max_cat_size:
|
||||||
|
max_cat_size = cat.Size
|
||||||
categories.append(cat)
|
categories.append(cat)
|
||||||
category_ids.append(cat.CategoryId)
|
category_ids.append(cat.CategoryId)
|
||||||
|
|
||||||
# get all scores in category group, load into data frame.
|
# get all scores in category group, load into data frame.
|
||||||
d_f = pd.read_sql_query(
|
d_f = pd.read_sql_query(sql=session.query(Score).where(Score.CategoryId.in_(category_ids)).statement, con=engine)
|
||||||
sql=session.query(Score).where(Score.CategoryId.in_(category_ids)).statement,
|
|
||||||
con=engine,
|
|
||||||
)
|
|
||||||
|
|
||||||
# this list is what will be printed in the discord message
|
# this list is what will be printed in the discord message
|
||||||
# first string will be category list, others will be score printouts
|
# first string will be category list, others will be score printouts
|
||||||
str_list: list[str] = ["" for i in range(max_cat_size + 1)]
|
str_list: "list[str]" = ["" for i in range(max_cat_size + 1)]
|
||||||
groups_df = d_f.groupby("CategoryId")
|
groups_df = d_f.groupby("CategoryId")
|
||||||
|
|
||||||
# TODO figure out how to have less nests.
|
# TODO figure out how to have less nests.
|
||||||
@@ -232,18 +235,14 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
|||||||
score = processed_group["Score"][ind]
|
score = processed_group["Score"][ind]
|
||||||
|
|
||||||
str_list[ind + 1] += format_score_string(
|
str_list[ind + 1] += format_score_string(
|
||||||
username,
|
username, score, group.UsernameLength, category.IsTimeRecord, ind + 1, pad_length
|
||||||
score,
|
|
||||||
group.UsernameLength,
|
|
||||||
category.IsTimeRecord,
|
|
||||||
ind + 1,
|
|
||||||
pad_length,
|
|
||||||
)
|
)
|
||||||
# if not enough entries, pad out
|
|
||||||
elif ind + 1 <= category.Size:
|
|
||||||
str_list[ind + 1] += f"{ind + 1}: ".ljust(pad_length, " ")
|
|
||||||
else:
|
else:
|
||||||
str_list[ind + 1] += "".ljust(pad_length, " ")
|
# if not enough entries, pad out
|
||||||
|
if ind + 1 <= category.Size:
|
||||||
|
str_list[ind + 1] += f"{ind + 1}: ".ljust(pad_length, " ")
|
||||||
|
else:
|
||||||
|
str_list[ind + 1] += "".ljust(pad_length, " ")
|
||||||
else:
|
else:
|
||||||
for ind in range(max_cat_size):
|
for ind in range(max_cat_size):
|
||||||
if ind + 1 <= category.Size:
|
if ind + 1 <= category.Size:
|
||||||
@@ -276,12 +275,7 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def format_score_string(
|
def format_score_string(
|
||||||
username: str,
|
username: str, score: float, username_length: int, is_time_record: bool, rank: int, pad_length: int
|
||||||
score: float,
|
|
||||||
username_length: int,
|
|
||||||
is_time_record: bool,
|
|
||||||
rank: int,
|
|
||||||
pad_length: int,
|
|
||||||
) -> str:
|
) -> str:
|
||||||
"""
|
"""
|
||||||
Builds the string to show a user's score.
|
Builds the string to show a user's score.
|
||||||
@@ -327,6 +321,44 @@ def get_time_str(time_in: float) -> str:
|
|||||||
return time.strftime(f"%-M:%S.{milliseconds}", time.gmtime(time_in))
|
return time.strftime(f"%-M:%S.{milliseconds}", time.gmtime(time_in))
|
||||||
|
|
||||||
|
|
||||||
|
def score_float_to_str(score: float, is_time_record: bool) -> str:
|
||||||
|
"""
|
||||||
|
Converts a float representation of a score into a string. Easier to transport the score as one data type.
|
||||||
|
Calls get_time_str if the score is a time record, otherwise just converts the string.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
score (float): float representation of the score.
|
||||||
|
is_time_record (bool): true if the score is a time record.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: string representation of the score.
|
||||||
|
"""
|
||||||
|
if is_time_record:
|
||||||
|
return get_time_str(score)
|
||||||
|
else:
|
||||||
|
return str(score)
|
||||||
|
|
||||||
|
|
||||||
|
def score_str_to_float(score: str, is_time_record: bool) -> float:
|
||||||
|
"""
|
||||||
|
Converts a string representation of score into a float. Easier to transport the score as one data type.
|
||||||
|
Operates differently depending on if the score is a time record or an int.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
score (str): string representation of the score.
|
||||||
|
is_time_record (bool): true if the score is a time record.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
float: float representation of the score.
|
||||||
|
"""
|
||||||
|
if is_time_record:
|
||||||
|
minutes = float(score.split(":", maxsplit=1)[0])
|
||||||
|
seconds = float(score.split(":", maxsplit=1)[1])
|
||||||
|
return (minutes * 60) + seconds
|
||||||
|
else:
|
||||||
|
return float(score)
|
||||||
|
|
||||||
|
|
||||||
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) -> nextcord.Message:
|
||||||
"""
|
"""
|
||||||
Function takes care of checking if a message exists for a group.
|
Function takes care of checking if a message exists for a group.
|
||||||
@@ -340,6 +372,7 @@ async def send_highscore_message(session: Session, guild: nextcord.Guild, group:
|
|||||||
Returns:
|
Returns:
|
||||||
nextcord.Message: Message object that was posted with group contents.
|
nextcord.Message: Message object that was posted with group contents.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
highscore_string = format_highscore_message(session, group)
|
highscore_string = format_highscore_message(session, group)
|
||||||
channel = guild.get_channel(group.ChannelId)
|
channel = guild.get_channel(group.ChannelId)
|
||||||
|
|
||||||
@@ -356,11 +389,7 @@ async def send_highscore_message(session: Session, guild: nextcord.Guild, group:
|
|||||||
|
|
||||||
|
|
||||||
async def submit_score(
|
async def submit_score(
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction, group_id: int, category_id: int, username: str, score: float
|
||||||
group_id: int,
|
|
||||||
category_id: int,
|
|
||||||
username: str,
|
|
||||||
score: str,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Adds passed score to group. Then updates group message by calling send_highscore_message.
|
Adds passed score to group. Then updates group message by calling send_highscore_message.
|
||||||
@@ -373,17 +402,8 @@ async def submit_score(
|
|||||||
username (str): The user who submitted the score.
|
username (str): The user who submitted the score.
|
||||||
score (str): Score to submit. Need to convert to correct type.
|
score (str): Score to submit. Need to convert to correct type.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(Category.IsTimeRecord).where(Category.CategoryId == 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
|
|
||||||
else:
|
|
||||||
score = float(score)
|
|
||||||
|
|
||||||
stmt = select(Score).where(Score.UserName == username).where(Score.CategoryId == category_id)
|
stmt = select(Score).where(Score.UserName == username).where(Score.CategoryId == category_id)
|
||||||
existing_score = session.scalar(stmt)
|
existing_score = session.scalar(stmt)
|
||||||
|
|
||||||
@@ -409,8 +429,9 @@ def add_preset_configuration(guild_id: int, config_str: str) -> None:
|
|||||||
guild_id (int): Guild id to add config to
|
guild_id (int): Guild id to add config to
|
||||||
config_str (str): Config name to add
|
config_str (str): Config name to add
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
with open(f"example_config/{config_str}.json", encoding="utf-8") as file:
|
with open(f"example_config/{config_str}.json", encoding="utf-8", mode="r") as file:
|
||||||
config = json.load(file)
|
config = json.load(file)
|
||||||
|
|
||||||
for group_name, categorys in config["tables"].items():
|
for group_name, categorys in config["tables"].items():
|
||||||
|
|||||||
Reference in New Issue
Block a user