mirror of
https://github.com/Xevion/contest-assistant.git
synced 2025-12-13 14:11:16 -06:00
submission channel config command, basic submission filtering
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from discord.ext.commands import Context
|
||||||
|
|
||||||
from contest import checks
|
from contest import checks
|
||||||
from contest.bot import ContestBot
|
from contest.bot import ContestBot
|
||||||
@@ -17,20 +18,43 @@ class ContestCog(commands.Cog):
|
|||||||
cur_prefix = await self.bot.db.get_prefix(ctx.guild.id)
|
cur_prefix = await self.bot.db.get_prefix(ctx.guild.id)
|
||||||
if 1 <= len(new_prefix) <= 2:
|
if 1 <= len(new_prefix) <= 2:
|
||||||
if cur_prefix == new_prefix:
|
if cur_prefix == new_prefix:
|
||||||
return await ctx.send(f'The prefix is already `{new_prefix}`')
|
return await ctx.send(f':no_entry_sign: The prefix is already `{new_prefix}`.')
|
||||||
else:
|
else:
|
||||||
await self.bot.db.set_prefix(ctx.guild.id, new_prefix)
|
await self.bot.db.set_prefix(ctx.guild.id, new_prefix)
|
||||||
return await ctx.send(f':white_check_mark: Prefix changed to `{new_prefix}`')
|
return await ctx.send(f':white_check_mark: Prefix changed to `{new_prefix}`.')
|
||||||
else:
|
else:
|
||||||
return await ctx.send(':no_entry_sign: Invalid argument. Prefix must be 1 or 2 characters long.')
|
return await ctx.send(':no_entry_sign: Invalid argument. Prefix must be 1 or 2 characters long.')
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@checks.privileged()
|
@checks.privileged()
|
||||||
async def submission(self, ctx, new_submission: discord.TextChannel):
|
async def submission(self, ctx: Context, new_submission: discord.TextChannel):
|
||||||
"""Changes the bot's saved submission channel."""
|
"""Changes the bot's saved submission channel."""
|
||||||
pass
|
cur_submission = await self.bot.db.get_submission_channel(ctx.guild.id)
|
||||||
|
if cur_submission == new_submission.id:
|
||||||
|
return await ctx.send(
|
||||||
|
f':no_entry_sign: The submission channel is already set to {new_submission.mention}.')
|
||||||
|
else:
|
||||||
|
await self.bot.db.set_submission_channel(ctx.guild.id, new_submission.id)
|
||||||
|
return await ctx.send(f':white_check_mark: Submission channel changed to {new_submission.mention}.')
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_message(self, message: discord.Message):
|
||||||
|
if message.author == self.bot.user or message.author.bot or not message.guild: return
|
||||||
|
cur_submission = await self.bot.db.get_submission_channel(message.guild.id)
|
||||||
|
|
||||||
|
if message.channel.id == cur_submission:
|
||||||
|
attachments = message.attachments
|
||||||
|
if len(attachments) == 0:
|
||||||
|
await message.delete(delay=1)
|
||||||
|
warning = await message.channel.send(
|
||||||
|
f':no_entry_sign: {message.author.mention} Each submission must contain exactly one image.')
|
||||||
|
await warning.delete(delay=5)
|
||||||
|
elif len(attachments) > 1:
|
||||||
|
await message.delete(delay=1)
|
||||||
|
warning = await message.channel.send(
|
||||||
|
f':no_entry_sign: {message.author.mention} Each submission must contain exactly one image.')
|
||||||
|
await warning.delete(delay=5)
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None:
|
async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None:
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class ContestDatabase(object):
|
|||||||
finally:
|
finally:
|
||||||
await cur.close()
|
await cur.close()
|
||||||
|
|
||||||
async def get_submission(self, guild_id: int) -> int:
|
async def get_submission_channel(self, guild_id: int) -> int:
|
||||||
cur = await self.conn.cursor()
|
cur = await self.conn.cursor()
|
||||||
try:
|
try:
|
||||||
await cur.execute('''SELECT submission FROM guild WHERE id = ?''', [guild_id])
|
await cur.execute('''SELECT submission FROM guild WHERE id = ?''', [guild_id])
|
||||||
@@ -84,7 +84,7 @@ class ContestDatabase(object):
|
|||||||
finally:
|
finally:
|
||||||
await cur.close()
|
await cur.close()
|
||||||
|
|
||||||
async def set_submission(self, guild_id: int, new_submission: int) -> None:
|
async def set_submission_channel(self, guild_id: int, new_submission: int) -> None:
|
||||||
"""Updates the submission channel for a specific guild in the database"""
|
"""Updates the submission channel for a specific guild in the database"""
|
||||||
await self.conn.execute('''UPDATE guild SET submission = ? WHERE id = ?''', [new_submission, guild_id])
|
await self.conn.execute('''UPDATE guild SET submission = ? WHERE id = ?''', [new_submission, guild_id])
|
||||||
await self.conn.commit()
|
await self.conn.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user