Compare commits
60
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
2864f342cc |
@@ -0,0 +1,20 @@
|
||||
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: Build Docker Image
|
||||
run: docker build -t viker.cheezers.net:5000/agon:develop .
|
||||
- name: Push Docker Image
|
||||
run: docker push viker.cheezers.net:5000/agon:develop
|
||||
@@ -0,0 +1,24 @@
|
||||
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: Set env
|
||||
run: echo "GIT_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
- name: Build Docker Images
|
||||
run: docker build -t viker.cheezers.net:5000/agon:latest -t viker.cheezers.net:5000/agon:${{env.GIT_TAG}} .
|
||||
- name: Push Latest Image
|
||||
run: docker push viker.cheezers.net:5000/agon:latest
|
||||
- name: Push Tagged Image
|
||||
run: docker push viker.cheezers.net:5000/agon:${{env.GIT_TAG}}
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/bin/bash -x
|
||||
|
||||
# this file is intended to build the docker image and push to the correct repository. Intended to be run by my buildbot instance.
|
||||
|
||||
# build, tag, and push develop
|
||||
docker build -t viker.cheezers.net:5000/agon:develop .
|
||||
docker push viker.cheezers.net:5000/agon:develop
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/bin/bash -x
|
||||
|
||||
# this file is intended to build the docker image and push to the correct repository. Intended to be run by my buildbot instance.
|
||||
|
||||
# check if there is a git tag. if so, tag with that tag and release
|
||||
# expecting tag to be 6 characters long. otherwise isn't not the right tag
|
||||
GITTAG=$(git describe --tags)
|
||||
length=${#GITTAG}
|
||||
|
||||
if [ $length -eq 6 ]; then
|
||||
docker build -t viker.cheezers.net:5000/agon:release -t viker.cheezers.net:5000/agon:$GITTAG .
|
||||
docker push viker.cheezers.net:5000/agon:release iker.cheezers.net:5000/agon:$GITTAG
|
||||
else
|
||||
docker build -t viker.cheezers.net:5000/agon:release .
|
||||
docker push viker.cheezers.net:5000/agon:release
|
||||
fi
|
||||
@@ -4,11 +4,11 @@ Defines cog for guild listeners. Contains functions for various guild events.
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
# pylint: disable=import-error
|
||||
from utilities.sql_data_classes import Guild, engine
|
||||
from utilities.utils import add_preset_configuration
|
||||
|
||||
|
||||
class GuildListener(commands.Cog, name="Guild Listener"):
|
||||
@@ -19,14 +19,52 @@ class GuildListener(commands.Cog, name="Guild Listener"):
|
||||
|
||||
@commands.Cog.listener()
|
||||
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:
|
||||
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()
|
||||
|
||||
# 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.
|
||||
# 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
|
||||
@@ -46,10 +46,3 @@ class BotPresence(commands.Cog, name="Bot Presence"):
|
||||
status += f" | {len(self.bot.guilds)} servers"
|
||||
|
||||
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()
|
||||
@@ -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:
|
||||
@@ -3,8 +3,10 @@ use highscores;
|
||||
|
||||
CREATE TABLE Guilds(
|
||||
GuildId bigint unsigned not null unique,
|
||||
GuildName varchar(95) not null,
|
||||
SubmissionChannel bigint unsigned,
|
||||
VerificationChannel bigint unsigned,
|
||||
Active boolean DEFAULT true,
|
||||
PRIMARY KEY (GuildId)
|
||||
);
|
||||
|
||||
|
||||
+14
-14
@@ -40,18 +40,18 @@ def autofill_categories(guild_id: int, group_id: int, category_begin: str) -> "d
|
||||
)
|
||||
cat_group_alias = aliased(CategoryGroup, subq)
|
||||
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 not category_begin:
|
||||
return categories_dict
|
||||
return dict(list(category_begin.items())[:25])
|
||||
|
||||
# else find all categories that start with category_begin
|
||||
# TODO is it better to have sql handle the starts with or python?
|
||||
categories: dict = {
|
||||
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()
|
||||
}
|
||||
return categories
|
||||
return dict(list(categories.items())[:25])
|
||||
|
||||
|
||||
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)
|
||||
|
||||
# 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 not group_begin:
|
||||
return group_dict
|
||||
return dict(list(group_dict.items())[:25])
|
||||
|
||||
# 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()
|
||||
}
|
||||
|
||||
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]":
|
||||
@@ -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 not user_begin:
|
||||
return users_list
|
||||
return users_list[:25]
|
||||
|
||||
# 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]":
|
||||
@@ -158,12 +158,12 @@ def autofill_users_in_guild(guild_id: int, user_begin: str) -> "list[str]":
|
||||
|
||||
# if string empty, return all users
|
||||
if not user_begin:
|
||||
return users_list
|
||||
return users_list[:25]
|
||||
|
||||
# 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:
|
||||
|
||||
Reference in New Issue
Block a user