mirror of
https://github.com/Xevion/contest-assistant.git
synced 2025-12-17 06:11:31 -06:00
permissions check, more db helper functions
This commit is contained in:
15
contest/checks.py
Normal file
15
contest/checks.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from discord.ext import commands
|
||||
|
||||
|
||||
def check_permissions(ctx, perms, *, check=all):
|
||||
resolved = ctx.channel.permissions_for(ctx.author)
|
||||
return check(getattr(resolved, name, None) == value for name, value in perms.items())
|
||||
|
||||
|
||||
def privileged():
|
||||
def predicate(ctx):
|
||||
return (ctx.guild is not None and ctx.guild.owner_id == ctx.author.id) \
|
||||
or check_permissions(ctx, {'manage_guild': True}) \
|
||||
or check_permissions(ctx, {'administrator': True})
|
||||
|
||||
return commands.check(predicate)
|
||||
@@ -76,6 +76,19 @@ class ContestDatabase(object):
|
||||
finally:
|
||||
await cur.close()
|
||||
|
||||
async def get_submission(self, guild_id: int) -> int:
|
||||
cur = await self.conn.cursor()
|
||||
try:
|
||||
await cur.execute('''SELECT submission FROM guild WHERE id = ?''', [guild_id])
|
||||
return (await cur.fetchone())[0]
|
||||
finally:
|
||||
await cur.close()
|
||||
|
||||
async def set_submission(self, guild_id: int, new_submission: int) -> None:
|
||||
"""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.commit()
|
||||
|
||||
async def teardown_guild(self, guild_id: int) -> None:
|
||||
"""Removes a guild from the database while completing appropriate teardown actions."""
|
||||
await self.conn.execute('''DELETE FROM guild WHERE id = ?''', [guild_id])
|
||||
|
||||
Reference in New Issue
Block a user