From 329ef7561eb70e9aa57474e4bf8d1c3bfb3b88b4 Mon Sep 17 00:00:00 2001 From: NatrixAeria Date: Sun, 18 Oct 2020 21:39:42 +0200 Subject: Add a tutor list --- commands.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'commands.py') diff --git a/commands.py b/commands.py index 8e673c2..0a10b7f 100644 --- a/commands.py +++ b/commands.py @@ -136,5 +136,51 @@ async def loop(ctx: commands.Context, n=config.DEFAULT_LOOP_COUNT, t=config.DEFA if not result: break +@commands.command( + help='add a tutor', + aliases=('tutor', 'hello') +) +async def add(ctx: commands.Context, id=None): + if id is None: + return await answer(ctx, 'error: expecting user id') + try: + id = int(id) + except ValueError: + return await answer(ctx, 'error: invalid user id') + ctx.bot.add_tutor(id) + await answer(ctx, f'added user id {id} to the tutor list') + +@commands.command( + help='remove a tutor', + aliases=('rm', 'del', 'delete', 'byebye', 'bb') +) +async def remove(ctx: commands.Context, id=None): + if id is None: + return await answer(ctx, 'error: expecting user id') + try: + id = int(id) + except ValueError: + return await answer(ctx, 'error: invalid user id') + ctx.bot.remove_tutor(id) + await answer(ctx, f'romved user id {id} from the tutor list') + + +@commands.command( + help='list all tutors', + aliases=('tutors',) +) +async def list(ctx: commands.Context): + if ctx.bot.tutors: + futures = [] + for tutor in ctx.bot.tutors: + try: + user = ctx.bot.get_user(tutor) or await ctx.bot.fetch_user(tutor) + futures.append(answer(ctx, f' • {user} ({tutor})')) + except Exception as e: + futures.append(await answer(ctx, f' • *unknown* ({tutor})')) + await await_n(futures) + else: + await answer(ctx, 'there is no tutor :/') + bot_commands = [cmd for cmd in locals().values() if isinstance(cmd, commands.Command)] -- cgit v1.2.3-54-g00ecf