Compare commits
82
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02e7a6df3a | ||
|
|
7be869b2b6 | ||
|
|
15c4776918 | ||
|
|
d3102b57cc | ||
|
|
9bef20de5b | ||
|
|
9231c04c6a | ||
|
|
36ba4d35e0 | ||
|
|
b80959866a | ||
|
|
de1eba025a | ||
|
|
28e575f364 | ||
|
|
d8368b4b92 | ||
|
|
cc10bb518c | ||
|
|
90131f6395 | ||
|
|
1814867c09 | ||
|
|
390bf8a489 | ||
|
|
74aa78c748 | ||
|
|
379f280c11 | ||
|
|
7d1e69c007 | ||
|
|
b905ce7216 | ||
|
|
4bb7db3f71 | ||
|
|
b3f48d4603 | ||
|
|
90763c73a7 | ||
|
|
635419dc7c | ||
|
|
2356d5edbf | ||
|
|
9eed0a1f4e | ||
|
|
a9a6ab4520 | ||
|
|
e08a764591 | ||
|
|
8b43f766b3 | ||
|
|
cb9cad9783 | ||
|
|
216becff6e | ||
|
|
836673198a | ||
|
|
e34739a0b1 | ||
|
|
7c592e6acc | ||
|
|
0f8637be23 | ||
|
|
3b597aeac7 | ||
|
|
c43b2297a4 | ||
|
|
1b337a291d | ||
|
|
16b662875f | ||
|
|
307f61934e | ||
|
|
00265f2f58 | ||
|
|
93d558edbc | ||
|
|
0f2b1aa2e6 | ||
|
|
3f6bac99ab | ||
|
|
46e2955642 | ||
|
|
ac9bf6b35f | ||
|
|
869b2ccb82 | ||
|
|
3ddfdfe9b0 | ||
|
|
3860e74579 | ||
|
|
3b49a6ec2a | ||
|
|
2f89588358 | ||
|
|
0513df944f | ||
|
|
ddf319b9d5 | ||
|
|
13f5bc0aab | ||
|
|
e6f3fcb604 | ||
|
|
eaa342d479 | ||
|
|
ac11f3e462 | ||
|
|
106b394c44 | ||
|
|
6c1505685b | ||
|
|
2e681be690 | ||
|
|
5448f2a426 | ||
|
|
7647c355af | ||
|
|
a95fca40f9 | ||
|
|
148ba253cf | ||
|
|
640d481018 | ||
|
|
4c18513661 | ||
|
|
37b4d2d62e | ||
|
|
9c762fb346 | ||
|
|
2c9e9e246a | ||
|
|
ab721c1625 | ||
|
|
2864f342cc | ||
|
|
92511db446 | ||
|
|
44c2720f80 | ||
|
|
35cebdebce | ||
|
|
e4437cc654 | ||
|
|
fe2c400a2a | ||
|
|
39875585ef | ||
|
|
7796ead644 | ||
|
|
531d2f3a0e | ||
|
|
8595a12f7f | ||
|
|
f76171ac84 | ||
|
|
1605c8ad50 | ||
|
|
63e77958fb |
@@ -0,0 +1,26 @@
|
|||||||
|
name: build_develop
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Install Docker
|
||||||
|
uses: https://github.com/papodaca/install-docker-action@v1
|
||||||
|
- name: Log into container registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: gitea.cheezers.org
|
||||||
|
username: imcompiling
|
||||||
|
password: ${{ secrets.PASSWORD }}
|
||||||
|
- name: Build Docker Image
|
||||||
|
run: docker build -t gitea.cheezers.org/imcompiling/agon:develop .
|
||||||
|
- name: Push Docker Image
|
||||||
|
run: docker push gitea.cheezers.org/imcompiling/agon:develop
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
name: build_release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: ["v[0-9].[0-9].[0-9]"]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Install Docker
|
||||||
|
uses: https://github.com/papodaca/install-docker-action@v1
|
||||||
|
- name: Log into container registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: gitea.cheezers.org
|
||||||
|
username: imcompiling
|
||||||
|
password: ${{ secrets.PASSWORD }}
|
||||||
|
- name: Set env
|
||||||
|
run: echo "GIT_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||||
|
- name: Build Docker Images
|
||||||
|
run: docker build -t gitea.cheezers.org/imcompiling/agon:latest -t gitea.cheezers.org/imcompiling/agon:${{env.GIT_TAG}} .
|
||||||
|
- name: Push Latest Image
|
||||||
|
run: docker push gitea.cheezers.org/imcompiling/agon:latest
|
||||||
|
- name: Push Tagged Image
|
||||||
|
run: docker push gitea.cheezers.org/imcompiling/agon:${{env.GIT_TAG}}
|
||||||
@@ -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:
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ from nextcord.ext import commands
|
|||||||
|
|
||||||
from .create import CreateCog
|
from .create import CreateCog
|
||||||
from .delete import DeleteCog
|
from .delete import DeleteCog
|
||||||
|
from .help import HelpCog
|
||||||
from .refresh import RefreshCog
|
from .refresh import RefreshCog
|
||||||
from .set import SetCog
|
from .set import SetCog
|
||||||
from .update import UpdateCog
|
from .update import UpdateCog
|
||||||
|
from .view import ViewCog
|
||||||
|
|
||||||
|
|
||||||
# This function will be called when this extension is loaded.
|
# This function will be called when this extension is loaded.
|
||||||
@@ -19,6 +21,8 @@ def setup(bot: commands.Bot):
|
|||||||
"""
|
"""
|
||||||
bot.add_cog(CreateCog(bot))
|
bot.add_cog(CreateCog(bot))
|
||||||
bot.add_cog(DeleteCog())
|
bot.add_cog(DeleteCog())
|
||||||
|
bot.add_cog(HelpCog())
|
||||||
bot.add_cog(RefreshCog(bot))
|
bot.add_cog(RefreshCog(bot))
|
||||||
bot.add_cog(SetCog())
|
bot.add_cog(SetCog())
|
||||||
bot.add_cog(UpdateCog(bot))
|
bot.add_cog(UpdateCog(bot))
|
||||||
|
bot.add_cog(ViewCog())
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
"""
|
||||||
|
Commands for helping a user.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import nextcord
|
||||||
|
from nextcord.ext import commands
|
||||||
|
|
||||||
|
|
||||||
|
class HelpCog(commands.Cog, name="Help commands."):
|
||||||
|
"""
|
||||||
|
Class holds commands for getting help.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
"""
|
||||||
|
Default constructor for HelpCog class. Does nothing.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@nextcord.slash_command()
|
||||||
|
async def help(self, interaction: nextcord.Interaction):
|
||||||
|
"""
|
||||||
|
Parent slash command for help. Never called.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@help.subcommand(description="Describes how to get started with Agon.")
|
||||||
|
async def setup(self, interaction: nextcord.Interaction):
|
||||||
|
"""
|
||||||
|
Sends a message describing how to get started with Agon.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# I hate this but don't want indents in the string.
|
||||||
|
# pylint: disable=line-too-long
|
||||||
|
help_str: str = """Welcome to Agon! Three simple steps are needed to get started.
|
||||||
|
1.) Set a channel to recieve submission verifications with "/set verify_channel."
|
||||||
|
This channel is used to allow moderators to check if a submission is real/valid.
|
||||||
|
|
||||||
|
2.) Set a channel for submissions to be posted in with "/set submission_channel."
|
||||||
|
This channel will be where all user submission messages are sent.
|
||||||
|
|
||||||
|
3.) Set up your highscore tables! Use "/create group" to first create a group message in the channel you would like and then use "/create category" to create a category in that group message!"""
|
||||||
|
# pylint: enable=line-too-long
|
||||||
|
print(help_str)
|
||||||
|
|
||||||
|
await interaction.response.send_message(content=help_str)
|
||||||
@@ -48,7 +48,7 @@ class SetCog(commands.Cog, name="Set command."):
|
|||||||
Command function to register a CategoryGroup's output channel.
|
Command function to register a CategoryGroup's output channel.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction that invoked the command
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
group_id (str): String representation of Group id to register channel to. Is SlashOption.
|
||||||
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.
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
"""
|
||||||
|
View command heirarchy.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import nextcord
|
||||||
|
import pandas as pd
|
||||||
|
from nextcord.ext import commands
|
||||||
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
# pylint: disable=import-error
|
||||||
|
from utilities.sql_data_classes import Category, CategoryGroup, Score, engine
|
||||||
|
from utilities.utils import MAX_LINE_LENGTH, autofill_categories, autofill_groups, format_score_string
|
||||||
|
|
||||||
|
|
||||||
|
class ViewCog(commands.Cog, name="View Command"):
|
||||||
|
"""
|
||||||
|
Class holds commands for viewing data.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
"""
|
||||||
|
Default constructor for ViewCog class. Does nothing.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@nextcord.slash_command()
|
||||||
|
async def view(self, interaction: nextcord.Interaction):
|
||||||
|
"""
|
||||||
|
Parent slash command for view. Never called.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@view.subcommand(description="Lists all scores for a given category.")
|
||||||
|
async def leaderboard(
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
group_id: str = nextcord.SlashOption(
|
||||||
|
name="group", description="Group to show leaderboard from.", required=True
|
||||||
|
),
|
||||||
|
category_id: str = nextcord.SlashOption(
|
||||||
|
name="category", description="Category to show leaderboard.", required=True
|
||||||
|
),
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Gathers all users that have a submission in the group/category combo and returns a message with them
|
||||||
|
in ranked order.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
str_list: "list[str]" = []
|
||||||
|
|
||||||
|
# get group, category, and all scores sorted correctly.
|
||||||
|
with Session(engine) as session:
|
||||||
|
stmt = select(CategoryGroup).where(CategoryGroup.GroupId == int(group_id))
|
||||||
|
group = session.scalar(stmt)
|
||||||
|
|
||||||
|
stmt = select(Category).where(Category.CategoryId == int(category_id))
|
||||||
|
category = session.scalar(stmt)
|
||||||
|
|
||||||
|
d_f = pd.read_sql_query(
|
||||||
|
sql=session.query(Score).where(Score.CategoryId == category_id).statement, con=engine
|
||||||
|
)
|
||||||
|
|
||||||
|
scores = d_f.sort_values("Score", ascending=category.IsAscending).reset_index()
|
||||||
|
|
||||||
|
# get the longest string
|
||||||
|
longest_str: int = scores.UserName.map(len).max()
|
||||||
|
|
||||||
|
for i, row in scores.iterrows():
|
||||||
|
str_list.append(
|
||||||
|
format_score_string(
|
||||||
|
row["UserName"], row["Score"], longest_str, category.IsTimeRecord, i + 1, MAX_LINE_LENGTH
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
message_str: str = f"**{group.GroupName} {category.CategoryName} Leaderboard!**\n```"
|
||||||
|
if len(str_list) == 0:
|
||||||
|
message_str += "No Submissions!"
|
||||||
|
else:
|
||||||
|
for line in str_list:
|
||||||
|
message_str += f"{line}\n"
|
||||||
|
|
||||||
|
message_str += "```"
|
||||||
|
|
||||||
|
await interaction.response.send_message(content=message_str)
|
||||||
|
|
||||||
|
@leaderboard.on_autocomplete("group_id")
|
||||||
|
async def group_autocomplete(self, interaction: nextcord.Interaction, group_id: str):
|
||||||
|
"""
|
||||||
|
Autocomplete function for table names.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
|
group_id (str): String to be autocompleted with Group name.
|
||||||
|
"""
|
||||||
|
await interaction.response.send_autocomplete(autofill_groups(interaction.guild_id, group_id))
|
||||||
|
|
||||||
|
@leaderboard.on_autocomplete("category_id")
|
||||||
|
async def category_autocomplete(self, interaction: nextcord.Interaction, category_id: str, group_id: str):
|
||||||
|
"""
|
||||||
|
Autocomplete function for category names.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
|
category_id (str): String to be autocompleted with Category name.
|
||||||
|
group_id (str): Group to find Category from.
|
||||||
|
"""
|
||||||
|
await interaction.response.send_autocomplete(
|
||||||
|
autofill_categories(interaction.guild_id, int(group_id), category_id)
|
||||||
|
)
|
||||||
@@ -4,11 +4,11 @@ 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
|
||||||
from utilities.sql_data_classes import Guild, engine
|
from utilities.sql_data_classes import Guild, engine
|
||||||
from utilities.utils import add_preset_configuration
|
|
||||||
|
|
||||||
|
|
||||||
class GuildListener(commands.Cog, name="Guild Listener"):
|
class GuildListener(commands.Cog, name="Guild Listener"):
|
||||||
@@ -19,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)
|
Args:
|
||||||
|
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)
|
||||||
|
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)
|
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.
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
"""
|
||||||
|
Initializing code for all loops.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from nextcord.ext import commands
|
||||||
|
|
||||||
|
from .bot_presence import BotPresence
|
||||||
|
from .guild_data import GuildData
|
||||||
|
|
||||||
|
|
||||||
|
# This function will be called when this extension is loaded.
|
||||||
|
# It is necessary to add these functions to the bot.
|
||||||
|
def setup(bot: commands.Bot):
|
||||||
|
"""Adds function to bot"""
|
||||||
|
bot.add_cog(BotPresence(bot))
|
||||||
|
bot.add_cog(GuildData(bot))
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Functions for controlling the bot's presence.
|
Functions for controlling the bot's presence. Also contains the loop.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import random
|
import random
|
||||||
@@ -46,10 +46,3 @@ class BotPresence(commands.Cog, name="Bot Presence"):
|
|||||||
status += f" | {len(self.bot.guilds)} servers"
|
status += f" | {len(self.bot.guilds)} servers"
|
||||||
|
|
||||||
await self.bot.change_presence(activity=nextcord.Game(status))
|
await self.bot.change_presence(activity=nextcord.Game(status))
|
||||||
|
|
||||||
|
|
||||||
# This function will be called when this extension is loaded.
|
|
||||||
# It is necessary to add these functions to the bot.
|
|
||||||
def setup(bot: commands.Bot):
|
|
||||||
"""Adds function to bot"""
|
|
||||||
bot.add_cog(BotPresence(bot))
|
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
"""
|
||||||
|
Contains a loop that updates guild data in the database periodically.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from nextcord.ext import commands, tasks
|
||||||
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
# pylint: disable=import-error
|
||||||
|
from utilities.sql_data_classes import Guild, engine
|
||||||
|
|
||||||
|
|
||||||
|
class GuildData(commands.Cog, name="Guild Data"):
|
||||||
|
"""Class to contain loop."""
|
||||||
|
|
||||||
|
def __init__(self, bot: commands.bot) -> None:
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_ready(self):
|
||||||
|
"""Starts the loop when bot is ready."""
|
||||||
|
await self.bot.wait_until_ready()
|
||||||
|
# pylint doesn't recognize that periodic_update_guild_data is subclassed from tasks.loop.
|
||||||
|
await self.periodic_update_guild_data.start() # pylint: disable=no-member
|
||||||
|
|
||||||
|
@tasks.loop(hours=24)
|
||||||
|
async def periodic_update_guild_data(self):
|
||||||
|
"""Loops every day, calls update_guild_data."""
|
||||||
|
self.update_guild_data()
|
||||||
|
|
||||||
|
def update_guild_data(self):
|
||||||
|
"""
|
||||||
|
Updates all known guild's data in the database.
|
||||||
|
"""
|
||||||
|
with Session(engine) as session:
|
||||||
|
for guild in self.bot.guilds:
|
||||||
|
# update given guild name for guild id
|
||||||
|
stmt = select(Guild).where(Guild.GuildId == guild.id)
|
||||||
|
guild_data = session.scalar(stmt)
|
||||||
|
|
||||||
|
# just in case checking if the guild doesn't exist.
|
||||||
|
if guild_data is None:
|
||||||
|
new_guild = Guild(GuildId=guild.id, GuildName=guild.name)
|
||||||
|
session.add(new_guild)
|
||||||
|
else:
|
||||||
|
guild_data.GuildName = guild.name
|
||||||
|
|
||||||
|
session.commit()
|
||||||
@@ -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
|
||||||
@@ -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("🎂")
|
||||||
|
|||||||
@@ -231,6 +231,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,27 +0,0 @@
|
|||||||
version: "3"
|
|
||||||
services:
|
|
||||||
sqldb:
|
|
||||||
restart: unless-stopped
|
|
||||||
image: mysql:latest
|
|
||||||
container_name: "Highscores-DataBase"
|
|
||||||
volumes:
|
|
||||||
- highscores_data:/var/lib/mysql
|
|
||||||
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:
|
|
||||||
@@ -3,8 +3,10 @@ use highscores;
|
|||||||
|
|
||||||
CREATE TABLE Guilds(
|
CREATE TABLE Guilds(
|
||||||
GuildId bigint unsigned not null unique,
|
GuildId bigint unsigned not null unique,
|
||||||
|
GuildName varchar(95) not null,
|
||||||
SubmissionChannel bigint unsigned,
|
SubmissionChannel bigint unsigned,
|
||||||
VerificationChannel bigint unsigned,
|
VerificationChannel bigint unsigned,
|
||||||
|
Active boolean DEFAULT true,
|
||||||
PRIMARY KEY (GuildId)
|
PRIMARY KEY (GuildId)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -17,7 +19,7 @@ CREATE TABLE CategoryGroups(
|
|||||||
PadLength smallint not null DEFAULT 26,
|
PadLength smallint not null DEFAULT 26,
|
||||||
UsernameLength smallint DEFAULT 12,
|
UsernameLength smallint DEFAULT 12,
|
||||||
CONSTRAINT UniqueGuildCategoryGroup UNIQUE (GuildId, GroupName),
|
CONSTRAINT UniqueGuildCategoryGroup UNIQUE (GuildId, GroupName),
|
||||||
FOREIGN KEY (GuildId) REFERENCES Guilds(GuildId),
|
FOREIGN KEY (GuildId) REFERENCES Guilds(GuildId) ON DELETE CASCADE,
|
||||||
PRIMARY KEY (GroupId)
|
PRIMARY KEY (GroupId)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -30,7 +32,7 @@ CREATE TABLE Categories(
|
|||||||
IsTimeRecord boolean not null DEFAULT false,
|
IsTimeRecord boolean not null DEFAULT false,
|
||||||
IsValidated boolean not null DEFAULT true,
|
IsValidated boolean not null DEFAULT true,
|
||||||
CONSTRAINT UniqueCategoryInGroup UNIQUE (GroupId, CategoryName),
|
CONSTRAINT UniqueCategoryInGroup UNIQUE (GroupId, CategoryName),
|
||||||
FOREIGN KEY (GroupId) REFERENCES CategoryGroups(GroupId),
|
FOREIGN KEY (GroupId) REFERENCES CategoryGroups(GroupId) ON DELETE CASCADE,
|
||||||
PRIMARY Key (CategoryId)
|
PRIMARY Key (CategoryId)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -38,6 +40,6 @@ CREATE TABLE Scores(
|
|||||||
UserName varchar(30) not null,
|
UserName varchar(30) not null,
|
||||||
Score float not null, -- Maybe should have time and int scores?? timestamp type?
|
Score float not null, -- Maybe should have time and int scores?? timestamp type?
|
||||||
CategoryId int unsigned not null,
|
CategoryId int unsigned not null,
|
||||||
FOREIGN KEY (CategoryId) REFERENCES Categories(CategoryId),
|
FOREIGN KEY (CategoryId) REFERENCES Categories(CategoryId) ON DELETE CASCADE,
|
||||||
PRIMARY KEY (CategoryId, UserName)
|
PRIMARY KEY (CategoryId, UserName)
|
||||||
);
|
);
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
nextcord>=2.3.2
|
nextcord>=2.3.2
|
||||||
python-dotenv>=0.20.0
|
python-dotenv>=0.20.0
|
||||||
pandas>=1.5.2
|
pandas>=1.5.2
|
||||||
sqlalchemy>=1.4.44
|
sqlalchemy<2.0
|
||||||
pymysql>=1.0.2
|
pymysql>=1.0.2
|
||||||
cryptography>=2.8
|
cryptography>=2.8
|
||||||
+51
-28
@@ -40,18 +40,18 @@ 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(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 = {
|
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,18 +71,18 @@ 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]":
|
||||||
@@ -130,12 +130,12 @@ def autofill_users_in_group_category(guild_id: int, group_id: int, category_id:
|
|||||||
|
|
||||||
# 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]":
|
||||||
@@ -158,12 +158,12 @@ def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]":
|
|||||||
|
|
||||||
# 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:
|
||||||
@@ -231,20 +231,12 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
|||||||
# 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:
|
||||||
user_length = group.UsernameLength
|
username = processed_group["UserName"][ind]
|
||||||
username = processed_group["UserName"][ind][:user_length].ljust(user_length, " ")
|
score = processed_group["Score"][ind]
|
||||||
|
|
||||||
# get score, pad to correct length
|
str_list[ind + 1] += format_score_string(
|
||||||
if category.IsTimeRecord:
|
username, score, group.UsernameLength, category.IsTimeRecord, ind + 1, pad_length
|
||||||
# MM:SS.ms is 7 characters long
|
)
|
||||||
# if there are single digit minutes, add a space for formatting.
|
|
||||||
score = get_time_str(processed_group["Score"][ind])
|
|
||||||
if score.find(":") and len(score.split(":", maxsplit=1)[0]) < 2:
|
|
||||||
score = " " + score
|
|
||||||
else:
|
|
||||||
score = str(int(processed_group["Score"][ind])).rjust(7, " ")
|
|
||||||
|
|
||||||
str_list[ind + 1] += f"{ind + 1}: {username} - {score}".ljust(pad_length, " ")
|
|
||||||
else:
|
else:
|
||||||
# if not enough entries, pad out
|
# if not enough entries, pad out
|
||||||
if ind + 1 <= category.Size:
|
if ind + 1 <= category.Size:
|
||||||
@@ -262,7 +254,6 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
|||||||
# need to use index to allow for modifying the list
|
# need to use index to allow for modifying the list
|
||||||
for ind, line in enumerate(str_list):
|
for ind, line in enumerate(str_list):
|
||||||
if len(line) > MAX_LINE_LENGTH:
|
if len(line) > MAX_LINE_LENGTH:
|
||||||
|
|
||||||
split_loc = int(MAX_LINE_LENGTH / pad_length) * pad_length
|
split_loc = int(MAX_LINE_LENGTH / pad_length) * pad_length
|
||||||
new_line = line[split_loc:]
|
new_line = line[split_loc:]
|
||||||
str_list[ind] = line[:split_loc]
|
str_list[ind] = line[:split_loc]
|
||||||
@@ -283,6 +274,38 @@ def format_highscore_message(session: Session, group: CategoryGroup) -> str:
|
|||||||
return ret_string + "```"
|
return ret_string + "```"
|
||||||
|
|
||||||
|
|
||||||
|
def format_score_string(
|
||||||
|
username: str, score: float, username_length: int, is_time_record: bool, rank: int, pad_length: int
|
||||||
|
) -> str:
|
||||||
|
"""
|
||||||
|
Builds the string to show a user's score.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
username (str): username.
|
||||||
|
score (int): score in int form.
|
||||||
|
username_length (float): limit to how long username is allowed to be.
|
||||||
|
is_time_record (bool): if the score represents an number or a time record.
|
||||||
|
rank (int): the user's rank.
|
||||||
|
pad_length (int): limit to how long the string can be.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: string to show user's score.
|
||||||
|
"""
|
||||||
|
username = username[:username_length].ljust(username_length, " ")
|
||||||
|
|
||||||
|
# get score, pad to correct length
|
||||||
|
if is_time_record:
|
||||||
|
# MM:SS.ms is 7 characters long
|
||||||
|
# if there are single digit minutes, add a space for formatting.
|
||||||
|
score = get_time_str(score)
|
||||||
|
if score.find(":") and len(score.split(":", maxsplit=1)[0]) < 2:
|
||||||
|
score = " " + score
|
||||||
|
else:
|
||||||
|
score = str(int(score)).rjust(7, " ")
|
||||||
|
|
||||||
|
return f"{rank}: {username} - {score}".ljust(pad_length, " ")
|
||||||
|
|
||||||
|
|
||||||
def get_time_str(time_in: float) -> str:
|
def get_time_str(time_in: float) -> str:
|
||||||
"""
|
"""
|
||||||
Formats a float value into the desired string format for a timestamp.
|
Formats a float value into the desired string format for a timestamp.
|
||||||
|
|||||||
Reference in New Issue
Block a user