Update message listener to new database.
This commit is contained in:
@@ -2,15 +2,16 @@
|
||||
Defines cog for on message listener.
|
||||
"""
|
||||
|
||||
from datetime import date
|
||||
import random
|
||||
import re
|
||||
|
||||
from nextcord.ext import commands
|
||||
import nextcord
|
||||
from nextcord.ext import commands
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import aliased
|
||||
|
||||
from classes.submission import SubmissionState # pylint: disable=import-error
|
||||
from highscores import highscores_data, submission_objects # pylint: disable=import-error
|
||||
# pylint: disable=import-error
|
||||
from classes.submission import SubmissionState
|
||||
from highscores import Category, CategoryGroup, Guild, session, submission_objects
|
||||
|
||||
|
||||
class SubmissionListener(commands.Cog, name="Message Listener"):
|
||||
@@ -28,21 +29,13 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
|
||||
|
||||
guild_id = message.guild.id
|
||||
|
||||
# troll addition for friends birthday
|
||||
if guild_id == 239758371358638080 and date.today() == date(2022, 7, 31):
|
||||
# 5% chance to send the message
|
||||
chance = random.randint(1, 20)
|
||||
if chance == 1:
|
||||
await message.channel.send("Happy Birthday Chris <@642330132958281750>")
|
||||
|
||||
if submission_objects.has_user(message.author.id):
|
||||
submission = submission_objects.get_user_submission(message.author.id)
|
||||
message_id = submission.message_id
|
||||
submission_channel_id = highscores_data.get_guild(guild_id).submission_channel
|
||||
stmt = select(Guild.SubmissionChannel).where(Guild.GuildId == guild_id)
|
||||
submission_channel_id = session.scalar(stmt)
|
||||
submission_message: nextcord.Message = (
|
||||
await self.bot.get_guild(guild_id)
|
||||
.get_channel(submission_channel_id)
|
||||
.fetch_message(message_id)
|
||||
await self.bot.get_guild(guild_id).get_channel(submission_channel_id).fetch_message(message_id)
|
||||
)
|
||||
|
||||
# need check if correct user and correct channel
|
||||
@@ -50,17 +43,23 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
|
||||
state = submission.submission_state
|
||||
if state == SubmissionState.SCORE and message.content:
|
||||
|
||||
# check with regex if score matches correctly
|
||||
is_time_record = (
|
||||
highscores_data.get_guild(guild_id)
|
||||
.get_table(submission.table)
|
||||
.get_category(submission.category)
|
||||
.time_record
|
||||
subq = (
|
||||
select(CategoryGroup)
|
||||
.where(CategoryGroup.GuildId == guild_id)
|
||||
.where(CategoryGroup.GroupName == submission.table)
|
||||
.subquery()
|
||||
)
|
||||
aliased_category_group = aliased(CategoryGroup, subq)
|
||||
stmt = (
|
||||
select(Category.IsTimeRecord)
|
||||
.where(Category.GroupId == aliased_category_group.GroupId)
|
||||
.where(Category.CategoryName == submission.category)
|
||||
)
|
||||
|
||||
time_regex = re.search(
|
||||
"^([0-9]{1,2}:[0-9]|[0-9])?[0-9](\\.[0-9])?$", message.content
|
||||
)
|
||||
# check with regex if score matches correctly
|
||||
is_time_record = session.scalar(stmt)
|
||||
|
||||
time_regex = re.search("^([0-9]{1,2}:[0-9]|[0-9])?[0-9](\\.[0-9])?$", message.content)
|
||||
int_regex = re.search("^[0-9]+$", message.content)
|
||||
if time_regex is None and is_time_record:
|
||||
embed = submission_message.embeds[0]
|
||||
@@ -97,9 +96,7 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
|
||||
files=[await attch.to_file() for attch in message.attachments],
|
||||
)
|
||||
elif state == SubmissionState.NAME and message.content:
|
||||
submission.username = message.content[
|
||||
: highscores_data.get_guild(guild_id).username_length
|
||||
]
|
||||
submission.username = message.content
|
||||
embed = submission.get_embed()
|
||||
await submission_message.edit(
|
||||
embed=embed,
|
||||
|
||||
@@ -4,9 +4,8 @@ Functions for controlling the bot's presence.
|
||||
|
||||
import random
|
||||
|
||||
from nextcord.ext import commands
|
||||
from nextcord.ext import tasks
|
||||
import nextcord
|
||||
from nextcord.ext import commands, tasks
|
||||
|
||||
|
||||
class BotPresence(commands.Cog, name="Bot Presence"):
|
||||
|
||||
Reference in New Issue
Block a user