Compare commits
22
Commits
v3.0.6
...
00212ea09d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00212ea09d | ||
|
|
96c902fcc3 | ||
|
|
c177ae67d6 | ||
|
|
b73cddab53 | ||
|
|
8f88c76e2e | ||
|
|
c977a4e958 | ||
|
|
e2e8d8de30 | ||
|
|
7f007ffa1f | ||
|
|
913f915bf0 | ||
|
|
02e7a6df3a | ||
|
|
7be869b2b6 | ||
|
|
15c4776918 | ||
|
|
d3102b57cc | ||
|
|
9bef20de5b | ||
|
|
9231c04c6a | ||
|
|
36ba4d35e0 | ||
|
|
b80959866a | ||
|
|
de1eba025a | ||
|
|
28e575f364 | ||
|
|
d8368b4b92 | ||
|
|
cc10bb518c | ||
|
|
90131f6395 |
@@ -14,7 +14,13 @@ 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 viker.cheezers.net:5000/agon:develop .
|
run: docker build -t gitea.cheezers.org/imcompiling/agon:develop .
|
||||||
- name: Push Docker Image
|
- name: Push Docker Image
|
||||||
run: docker push viker.cheezers.net:5000/agon:develop
|
run: docker push gitea.cheezers.org/imcompiling/agon:develop
|
||||||
|
|||||||
@@ -14,11 +14,17 @@ 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 viker.cheezers.net:5000/agon:latest -t viker.cheezers.net:5000/agon:${{env.GIT_TAG}} .
|
run: docker build -t gitea.cheezers.org/imcompiling/agon:latest -t gitea.cheezers.org/imcompiling/agon:${{env.GIT_TAG}} .
|
||||||
- name: Push Latest Image
|
- name: Push Latest Image
|
||||||
run: docker push viker.cheezers.net:5000/agon:latest
|
run: docker push gitea.cheezers.org/imcompiling/agon:latest
|
||||||
- name: Push Tagged Image
|
- name: Push Tagged Image
|
||||||
run: docker push viker.cheezers.net:5000/agon:${{env.GIT_TAG}}
|
run: docker push gitea.cheezers.org/imcompiling/agon:${{env.GIT_TAG}}
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ venv/
|
|||||||
ENV/
|
ENV/
|
||||||
env.bak/
|
env.bak/
|
||||||
venv.bak/
|
venv.bak/
|
||||||
|
poetry.lock
|
||||||
|
|
||||||
# Spyder project settings
|
# Spyder project settings
|
||||||
.spyderproject
|
.spyderproject
|
||||||
|
|||||||
+5
-7
@@ -1,21 +1,19 @@
|
|||||||
FROM python:3.8.10-slim
|
FROM python:3.12.3-slim
|
||||||
|
|
||||||
# install dependencies for mysqlclient
|
# install dependencies for mysqlclient
|
||||||
# RUN apt-get update && apt-get -y upgrade && apt-get -y install python3-dev default-libmysqlclient-dev build-essential
|
# 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 classes classes/
|
COPY classes classes/
|
||||||
COPY cogs cogs/
|
COPY cogs cogs/
|
||||||
COPY utilities utilities/
|
COPY utilities utilities/
|
||||||
COPY highscores.py highscores.py
|
COPY main.py main.py
|
||||||
COPY requirements.txt requirements.txt
|
COPY pyproject.toml pyproject.toml
|
||||||
|
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install --upgrade pip && pip install poetry && poetry export -f requirements.txt --output requirements.txt && pip install -r requirements.txt
|
||||||
|
|
||||||
# remove build deps that aren't needed to run
|
# remove build deps that aren't needed to run
|
||||||
# RUN apt-get -y remove python3-dev build-essential && apt-get -y autoremove
|
# RUN apt-get -y remove python3-dev build-essential && apt-get -y autoremove
|
||||||
|
|
||||||
CMD ["python3", "./highscores.py"]
|
CMD ["python3", "./main.py"]
|
||||||
@@ -183,11 +183,13 @@ class Submission:
|
|||||||
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: Input your score!"
|
description = "Step 2: Send a message to input your score!"
|
||||||
elif state is SubmissionState.PROOF:
|
elif state is SubmissionState.PROOF:
|
||||||
description = "Step 3: Submit your proof!"
|
description = "Step 3: Send a message with a picture attached to submit your proof!"
|
||||||
elif state is SubmissionState.NAME:
|
elif state is SubmissionState.NAME:
|
||||||
description = "Step 4 (Optional): Change name on submission! (proceed to next if skipping)"
|
description = (
|
||||||
|
"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:
|
||||||
|
|||||||
@@ -40,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 higher value is better score.", required=True),
|
is_ascending: bool = nextcord.SlashOption(description="If lower value is a 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
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -42,6 +42,5 @@ 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)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ Defines cog for guild listeners. Contains functions for various guild events.
|
|||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
@@ -18,14 +19,52 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
|||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_guild_join(self, guild: nextcord.Guild):
|
async def on_guild_join(self, guild: nextcord.Guild):
|
||||||
"""Listener for Guild Join. Adds guild to database."""
|
"""
|
||||||
|
Listener for Guild Join. Adds guild to database.
|
||||||
|
|
||||||
new_guild = Guild(GuildId=guild.id, GuildName=guild.name)
|
Args:
|
||||||
|
guild (nextcord.Guild): Guild that was joined.
|
||||||
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
session.add(new_guild)
|
stmt = select(Guild).where(Guild.GuildId == guild.id)
|
||||||
|
guild_data = session.scalar(stmt)
|
||||||
|
|
||||||
|
# just in case check if the guild already exists
|
||||||
|
if guild_data is None:
|
||||||
|
new_guild = Guild(GuildId=guild.id, GuildName=guild.name)
|
||||||
|
session.add(new_guild)
|
||||||
|
else:
|
||||||
|
guild_data.GuildName = guild.name
|
||||||
|
guild_data.Active = True
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
# let imcompiling#2272 know about a new server joining!
|
||||||
|
# staying with fetch due to intents not being set up correctly. Maybe change to get eventually.
|
||||||
|
imcompiling: nextcord.User = await self.bot.fetch_user(206602713511886849)
|
||||||
|
await imcompiling.send(f'Agon has joined server "{guild.name}"!')
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_guild_remove(self, guild: nextcord.Guild):
|
||||||
|
"""
|
||||||
|
Listens to when the bot has been removed from a guild. Update's the database to record the active flag as false.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
guild (nextcord.Guild): Guild that was left.
|
||||||
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
|
stmt = select(Guild).where(Guild.GuildId == guild.id)
|
||||||
|
guild_data = session.scalar(stmt)
|
||||||
|
guild_data.Active = False
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
# let imcompiling#2272 know about leaving a server.
|
||||||
|
# staying with fetch due to intents not being set up correctly. Maybe change to get eventually.
|
||||||
|
imcompiling: nextcord.User = await self.bot.fetch_user(206602713511886849)
|
||||||
|
await imcompiling.send(f'Agon has been removed from "{guild.name}".')
|
||||||
|
|
||||||
|
|
||||||
# This function will be called when this extension is loaded.
|
# This function will be called when this extension is loaded.
|
||||||
# It is necessary to add these functions to the bot.
|
# It is necessary to add these functions to the bot.
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ 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
|
||||||
@@ -11,7 +12,7 @@ from sqlalchemy.orm import Session
|
|||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from classes.submission import SubmissionState
|
from classes.submission import SubmissionState
|
||||||
from highscores import submission_objects
|
from main import submission_objects
|
||||||
from utilities.sql_data_classes import Category, Guild, engine
|
from utilities.sql_data_classes import Category, Guild, engine
|
||||||
|
|
||||||
|
|
||||||
@@ -28,6 +29,8 @@ 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):
|
||||||
@@ -45,7 +48,6 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
|
|||||||
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)
|
stmt = select(Category.IsTimeRecord).where(Category.CategoryId == submission.category_id)
|
||||||
|
|
||||||
# check with regex if score matches correctly
|
# check with regex if score matches correctly
|
||||||
@@ -102,3 +104,19 @@ 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("🎂")
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ 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 highscores import submission_objects
|
from main import submission_objects
|
||||||
from utilities.sql_data_classes import Category, CategoryGroup, Guild, engine
|
from utilities.sql_data_classes import Category, CategoryGroup, Guild, engine
|
||||||
|
|
||||||
from .verification_view import VerificationView
|
from .verification_view import VerificationView
|
||||||
@@ -147,9 +147,7 @@ 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(
|
async def submitcreate_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): # pylint: disable=unused-argument
|
||||||
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
|
||||||
@@ -231,6 +229,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,29 +0,0 @@
|
|||||||
version: "3"
|
|
||||||
services:
|
|
||||||
sqldb:
|
|
||||||
restart: unless-stopped
|
|
||||||
image: mysql:latest
|
|
||||||
container_name: "Highscores-DataBase"
|
|
||||||
volumes:
|
|
||||||
- highscores_data:/var/lib/mysql
|
|
||||||
ports:
|
|
||||||
- 3306:3306
|
|
||||||
environment:
|
|
||||||
- MYSQL_ROOT_PASSWORD=${SQL_PASS}
|
|
||||||
- MYSQL_ROOT_USERNAME=${SQL_USER}
|
|
||||||
|
|
||||||
bot:
|
|
||||||
restart: unless-stopped
|
|
||||||
build: .
|
|
||||||
container_name: "Highscores-Bot"
|
|
||||||
depends_on:
|
|
||||||
- sqldb
|
|
||||||
environment:
|
|
||||||
- DISCORD_TOKEN=${DISCORD_TOKEN}
|
|
||||||
- SQL_DB=${SQL_DB}
|
|
||||||
- SQL_HOST=${SQL_HOST}
|
|
||||||
- SQL_PASS=${SQL_PASS}
|
|
||||||
- SQL_USER=${SQL_USER}
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
highscores_data:
|
|
||||||
@@ -6,6 +6,7 @@ CREATE TABLE Guilds(
|
|||||||
GuildName varchar(95) not null,
|
GuildName varchar(95) not null,
|
||||||
SubmissionChannel bigint unsigned,
|
SubmissionChannel bigint unsigned,
|
||||||
VerificationChannel bigint unsigned,
|
VerificationChannel bigint unsigned,
|
||||||
|
Active boolean DEFAULT true,
|
||||||
PRIMARY KEY (GuildId)
|
PRIMARY KEY (GuildId)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
+130
@@ -0,0 +1,130 @@
|
|||||||
|
[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.3.2"
|
||||||
|
python-dotenv = ">=0.20.0"
|
||||||
|
pandas = ">=1.5.2"
|
||||||
|
sqlalchemy = "<2.0"
|
||||||
|
pymysql = ">=1.0.2"
|
||||||
|
cryptography = ">=2.8"
|
||||||
|
|
||||||
|
|
||||||
|
[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"
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
nextcord>=2.3.2
|
|
||||||
python-dotenv>=0.20.0
|
|
||||||
pandas>=1.5.2
|
|
||||||
sqlalchemy<2.0
|
|
||||||
pymysql>=1.0.2
|
|
||||||
cryptography>=2.8
|
|
||||||
+87
-32
@@ -16,7 +16,9 @@ from utilities.sql_data_classes import Category, CategoryGroup, Guild, Score, en
|
|||||||
MAX_LINE_LENGTH = 142
|
MAX_LINE_LENGTH = 142
|
||||||
|
|
||||||
|
|
||||||
def autofill_categories(guild_id: int, group_id: int, category_begin: str) -> "dict[str, str]":
|
def autofill_categories(
|
||||||
|
guild_id: int, group_id: int, category_begin: str
|
||||||
|
) -> "dict[str, str]":
|
||||||
"""
|
"""
|
||||||
Returns all category names that start with category_begin.
|
Returns all category names that start with category_begin.
|
||||||
If category_begin is empty, returns list of all category names.
|
If category_begin is empty, returns list of all category names.
|
||||||
@@ -40,18 +42,22 @@ 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 = {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 categories_dict
|
return dict(list(categories_dict.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 = {
|
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 categories
|
return dict(list(categories.items())[:25])
|
||||||
|
|
||||||
|
|
||||||
def autofill_groups(guild_id: int, group_begin: str) -> "dict[str, str]":
|
def autofill_groups(guild_id: int, group_begin: str) -> "dict[str, str]":
|
||||||
@@ -71,21 +77,27 @@ def autofill_groups(guild_id: int, group_begin: str) -> "dict[str, str]":
|
|||||||
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 = {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 group_dict
|
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 = {
|
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
return groups
|
return dict(list(groups.items())[:25])
|
||||||
|
|
||||||
|
|
||||||
def autofill_users_in_group_category(guild_id: int, group_id: int, category_id: int, user_begin: str) -> "list[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
|
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.
|
not None. Might be expensive due to unioning all users in group.
|
||||||
@@ -112,7 +124,9 @@ def autofill_users_in_group_category(guild_id: int, group_id: int, category_id:
|
|||||||
|
|
||||||
# If no category id, get all users in group.
|
# If no category id, get all users in group.
|
||||||
if category_id == 0:
|
if category_id == 0:
|
||||||
subq = select(Category.CategoryId).where(Category.GroupId == category_group.GroupId)
|
subq = select(Category.CategoryId).where(
|
||||||
|
Category.GroupId == category_group.GroupId
|
||||||
|
)
|
||||||
stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(subq))
|
stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(subq))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -124,18 +138,22 @@ def autofill_users_in_group_category(guild_id: int, group_id: int, category_id:
|
|||||||
.subquery()
|
.subquery()
|
||||||
)
|
)
|
||||||
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
|
return users_list[:25]
|
||||||
|
|
||||||
# else find all users that start with user_begin
|
# else find all users that start with user_begin
|
||||||
users = [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
|
return users[:25]
|
||||||
|
|
||||||
|
|
||||||
def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]":
|
def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]":
|
||||||
@@ -151,19 +169,27 @@ def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]":
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
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(
|
||||||
category_ids = select(Category.CategoryId).where(Category.GroupId.in_(group_ids))
|
CategoryGroup.GuildId == guild_id
|
||||||
stmt = select(distinct(Score.UserName)).where(Score.CategoryId.in_(category_ids))
|
)
|
||||||
|
category_ids = select(Category.CategoryId).where(
|
||||||
|
Category.GroupId.in_(group_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
|
return users_list[:25]
|
||||||
|
|
||||||
# else find all users that start with user_begin
|
# else find all users that start with user_begin
|
||||||
users = [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
|
return users[:25]
|
||||||
|
|
||||||
|
|
||||||
def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
||||||
@@ -207,7 +233,10 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
|||||||
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(sql=session.query(Score).where(Score.CategoryId.in_(category_ids)).statement, con=engine)
|
d_f = pd.read_sql_query(
|
||||||
|
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
|
||||||
@@ -225,17 +254,26 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
|||||||
|
|
||||||
# process data. Want each group sorted correctly and only top X results
|
# process data. Want each group sorted correctly and only top X results
|
||||||
processed_group = (
|
processed_group = (
|
||||||
group_df.sort_values("Score", ascending=category.IsAscending).head(category.Size).reset_index()
|
group_df.sort_values("Score", ascending=category.IsAscending)
|
||||||
|
.head(category.Size)
|
||||||
|
.reset_index()
|
||||||
)
|
)
|
||||||
|
|
||||||
# add each score to list
|
# add each score to list
|
||||||
for ind in range(max_cat_size): # need to subtract to deal with category name string
|
for ind in range(
|
||||||
|
max_cat_size
|
||||||
|
): # need to subtract to deal with category name string
|
||||||
if ind in processed_group.index:
|
if ind in processed_group.index:
|
||||||
username = processed_group["UserName"][ind]
|
username = processed_group["UserName"][ind]
|
||||||
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, score, group.UsernameLength, category.IsTimeRecord, ind + 1, pad_length
|
username,
|
||||||
|
score,
|
||||||
|
group.UsernameLength,
|
||||||
|
category.IsTimeRecord,
|
||||||
|
ind + 1,
|
||||||
|
pad_length,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# if not enough entries, pad out
|
# if not enough entries, pad out
|
||||||
@@ -275,7 +313,12 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def format_score_string(
|
def format_score_string(
|
||||||
username: str, score: float, username_length: int, is_time_record: bool, rank: int, pad_length: int
|
username: str,
|
||||||
|
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.
|
||||||
@@ -321,7 +364,9 @@ 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))
|
||||||
|
|
||||||
|
|
||||||
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.
|
||||||
Creates and sends/edits the message.
|
Creates and sends/edits the message.
|
||||||
@@ -351,7 +396,11 @@ async def send_highscore_message(session: Session, guild: nextcord.Guild, group:
|
|||||||
|
|
||||||
|
|
||||||
async def submit_score(
|
async def submit_score(
|
||||||
interaction: nextcord.Interaction, group_id: int, category_id: int, username: str, score: str
|
interaction: nextcord.Interaction,
|
||||||
|
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.
|
||||||
@@ -376,7 +425,11 @@ async def submit_score(
|
|||||||
else:
|
else:
|
||||||
score = float(score)
|
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)
|
||||||
|
|
||||||
if existing_score:
|
if existing_score:
|
||||||
@@ -403,7 +456,9 @@ def add_preset_configuration(guild_id: int, config_str: str) -> None:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
with open(f"example_config/{config_str}.json", encoding="utf-8", mode="r") 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