mirror of
https://github.com/Xevion/contest-assistant.git
synced 2026-01-31 06:23:53 -06:00
minor typehint fixes, make optional arg into optional kwarg, add additional TODOs, add basic attachment filtering
This commit is contained in:
+4
-3
@@ -5,6 +5,7 @@ from typing import ContextManager, List, Optional
|
|||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
# noinspection PyProtectedMember
|
||||||
from sqlalchemy.engine import Engine
|
from sqlalchemy.engine import Engine
|
||||||
from sqlalchemy.orm import Session, sessionmaker
|
from sqlalchemy.orm import Session, sessionmaker
|
||||||
|
|
||||||
@@ -87,11 +88,11 @@ class ContestBot(commands.Bot):
|
|||||||
if period is not None and period.active:
|
if period is not None and period.active:
|
||||||
period.deactivate()
|
period.deactivate()
|
||||||
|
|
||||||
async def add_voting_reactions(self, channel: discord.TextChannel, submissions: Optional[List[Submission]]) -> None:
|
async def add_voting_reactions(self, channel: discord.TextChannel, submissions: Optional[List[Submission]] = None) -> None:
|
||||||
"""Adds reactions to all valid submissions in the given channel."""
|
"""Adds reactions to all valid submissions in the given channel."""
|
||||||
if submissions is None:
|
if submissions is None:
|
||||||
with self.get_session() as session:
|
with self.get_session() as session:
|
||||||
period: Guild = session.query(Guild).get(channel.guild.id).current_period
|
period: Period = session.query(Guild).get(channel.guild.id).current_period
|
||||||
if period is None:
|
if period is None:
|
||||||
logger.error('No valid submissions - current period is not set for the Guild this channel belongs to.')
|
logger.error('No valid submissions - current period is not set for the Guild this channel belongs to.')
|
||||||
return
|
return
|
||||||
@@ -99,7 +100,7 @@ class ContestBot(commands.Bot):
|
|||||||
submissions = period.submissions
|
submissions = period.submissions
|
||||||
|
|
||||||
if len(submissions) == 0:
|
if len(submissions) == 0:
|
||||||
logger.warning('Attempted to add voting reactions to submissions, but none were given.')
|
logger.warning('Attempted to add voting reactions to submissions, but none were given or could be found.')
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
for submission in submissions:
|
for submission in submissions:
|
||||||
|
|||||||
+12
-6
@@ -19,6 +19,9 @@ expected_react_deletions: List[Tuple[int, int]] = []
|
|||||||
# TODO: Add command error handling to all commands
|
# TODO: Add command error handling to all commands
|
||||||
# TODO: Use embeds in all bot responses
|
# TODO: Use embeds in all bot responses
|
||||||
# TODO: Look into migrating from literals to i18n-ish representation of all messages & formatting
|
# TODO: Look into migrating from literals to i18n-ish representation of all messages & formatting
|
||||||
|
# TODO: Contest names
|
||||||
|
# TODO: Refactor Period into Contest (major)
|
||||||
|
|
||||||
|
|
||||||
class ContestCog(commands.Cog):
|
class ContestCog(commands.Cog):
|
||||||
def __init__(self, bot: ContestBot):
|
def __init__(self, bot: ContestBot):
|
||||||
@@ -125,8 +128,7 @@ class ContestCog(commands.Cog):
|
|||||||
overwrite.send_messages = False
|
overwrite.send_messages = False
|
||||||
overwrite.add_reactions = False
|
overwrite.add_reactions = False
|
||||||
response = 'Period stopped. Reactions and submissions disabled. Advance again to start a new period.'
|
response = 'Period stopped. Reactions and submissions disabled. Advance again to start a new period.'
|
||||||
# TODO: Fetch all submissions related to this period
|
# TODO: Fetch all submissions related to this period and show a embed
|
||||||
# TODO: Create new period for Guild at
|
|
||||||
|
|
||||||
period.advance_state()
|
period.advance_state()
|
||||||
|
|
||||||
@@ -184,8 +186,6 @@ class ContestCog(commands.Cog):
|
|||||||
if channel.id == guild.submission_channel:
|
if channel.id == guild.submission_channel:
|
||||||
attachments = message.attachments
|
attachments = message.attachments
|
||||||
|
|
||||||
# TODO: Do attachment filtering between videos/files/audio etc.
|
|
||||||
|
|
||||||
# Ensure that the submission contains at least one attachment
|
# Ensure that the submission contains at least one attachment
|
||||||
if len(attachments) == 0:
|
if len(attachments) == 0:
|
||||||
await message.delete(delay=1)
|
await message.delete(delay=1)
|
||||||
@@ -198,6 +198,12 @@ class ContestCog(commands.Cog):
|
|||||||
warning = await channel.send(
|
warning = await channel.send(
|
||||||
f':no_entry_sign: {message.author.mention} Each submission must contain exactly one image.')
|
f':no_entry_sign: {message.author.mention} Each submission must contain exactly one image.')
|
||||||
await warning.delete(delay=5)
|
await warning.delete(delay=5)
|
||||||
|
else:
|
||||||
|
attachment = attachments[0]
|
||||||
|
if attachment.is_spoiler():
|
||||||
|
await channel.send('Attachment must not make use of a spoiler.')
|
||||||
|
elif attachment.width is None:
|
||||||
|
await channel.send('Attachment must be a image or video.')
|
||||||
else:
|
else:
|
||||||
last_submission: Submission = session.query(Submission).filter_by(period=guild.current_period,
|
last_submission: Submission = session.query(Submission).filter_by(period=guild.current_period,
|
||||||
user=message.author.id).first()
|
user=message.author.id).first()
|
||||||
@@ -215,8 +221,8 @@ class ContestCog(commands.Cog):
|
|||||||
session.delete(last_submission)
|
session.delete(last_submission)
|
||||||
|
|
||||||
# Add the new submission row
|
# Add the new submission row
|
||||||
session.add(Submission(id=message.id, user=message.author.id,
|
session.add(Submission(id=message.id, user=message.author.id, period=guild.current_period,
|
||||||
period=guild.current_period, timestamp=message.created_at))
|
timestamp=message.created_at))
|
||||||
logger.info(f'New submission created ({message.id}).')
|
logger.info(f'New submission created ({message.id}).')
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
|
|||||||
Reference in New Issue
Block a user