From 9b472f1af089439e0a8cac67635392214213cea1 Mon Sep 17 00:00:00 2001 From: NatrixAeria Date: Mon, 19 Oct 2020 23:45:44 +0200 Subject: Disallow actions to plebs --- commands.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'commands.py') diff --git a/commands.py b/commands.py index a422e26..a804469 100644 --- a/commands.py +++ b/commands.py @@ -20,6 +20,11 @@ async def answer(ctx: commands.Context, msg: str, *args, **kwargs): await ctx.send(f'{ctx.author.mention} {msg}', *args, **kwargs) +def is_admin_channel(ctx: commands.Context): + print(ctx.message.channel,ctx.bot.admin_channel, ctx.message.channel == ctx.bot.admin_channel) + return ctx.message.channel.id == ctx.bot.admin_channel + + @commands.command(help='display this help message', aliases=('hepl', 'h', '?')) async def help(ctx: commands.Context): command_doc = '\n'.join( @@ -31,12 +36,14 @@ async def help(ctx: commands.Context): @commands.command(help='create a new lobby', aliases=('create', 'inti', 'craete', 'cretae', 'c', 'i', '+')) async def init(ctx: commands.Context): + if not is_admin_channel(ctx): return ctx.bot.meta_channel = ctx.bot.get_meta_channel(ctx) or await ctx.bot.create_category(ctx) ctx.bot.lobby_channel = ctx.bot.get_lobby_channel(ctx, ctx.bot.meta_channel) or await ctx.bot.create_lobby(ctx) @commands.command(help=f'destruct all {config.NAME} channels', aliases=('kill', 'desctruction', 'genocide', '-')) async def destroy(ctx: commands.Context): + if not is_admin_channel(ctx): return await stop(ctx) futures = [] meta_channel = ctx.bot.get_meta_channel(ctx) @@ -56,6 +63,7 @@ def round_up_div(a, b): @commands.command(help='start shuffling', aliases=('start', 'run', 'strat', 'rnu')) async def shuffle(ctx: commands.Context, channel_size=2): + if not is_admin_channel(ctx): return if channel_size < 1: await answer(ctx, 'error: channel size must be at least 1 (you jerk)') return False @@ -120,6 +128,7 @@ async def shuffle(ctx: commands.Context, channel_size=2): @commands.command(help='move everyone back to lobby', aliases=('quit', 'exit', 'abort', 'back', 'return')) async def stop(ctx: commands.Context, cancel_loop=True): + if not is_admin_channel(ctx): return channels = await ctx.bot.get_channels(ctx) if not channels: return @@ -149,6 +158,7 @@ async def loop_cycle(ctx, t): f' (default: {config.DEFAULT_LOOP_TIME}) seconds', aliases=('repeat', 'shuffleloop')) async def loop(ctx: commands.Context, n=config.DEFAULT_LOOP_COUNT, t=config.DEFAULT_LOOP_TIME): + if not is_admin_channel(ctx): return try: n, t = int(n), int(t) except ValueError: @@ -171,6 +181,7 @@ async def loop(ctx: commands.Context, n=config.DEFAULT_LOOP_COUNT, t=config.DEFA aliases=('tutor', 'hello') ) async def add(ctx: commands.Context, id=None): + if not is_admin_channel(ctx): return if id is None: return await answer(ctx, 'error: expecting user id') try: @@ -185,6 +196,7 @@ async def add(ctx: commands.Context, id=None): aliases=('rm', 'del', 'delete', 'byebye', 'bb') ) async def remove(ctx: commands.Context, id=None): + if not is_admin_channel(ctx): return if id is None: return await answer(ctx, 'error: expecting user id') try: @@ -200,6 +212,7 @@ async def remove(ctx: commands.Context, id=None): aliases=('tutors',) ) async def list(ctx: commands.Context): + if not is_admin_channel(ctx): return if ctx.bot.tutors: users = [] for tutor in ctx.bot.tutors: -- cgit v1.2.3-54-g00ecf