diff options
Diffstat (limited to 'commands.py')
-rw-r--r-- | commands.py | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/commands.py b/commands.py index 62046f6..a422e26 100644 --- a/commands.py +++ b/commands.py @@ -4,6 +4,7 @@ import random import config +import discord from discord.ext import commands @@ -15,8 +16,8 @@ async def await_n(it) -> List[Any]: return [task.result() for task in done] -async def answer(ctx: commands.Context, msg: str): - await ctx.send(f'{ctx.author.mention} {msg}') +async def answer(ctx: commands.Context, msg: str, *args, **kwargs): + await ctx.send(f'{ctx.author.mention} {msg}', *args, **kwargs) @commands.command(help='display this help message', aliases=('hepl', 'h', '?')) @@ -48,22 +49,6 @@ async def destroy(ctx: commands.Context): ctx.bot.pair_channels = [] -def fac(n): - i = 1 - for z in range(2, n+1): - i *= z - return i - - -def n_th_permutation(n, lst): - nlst = [None for _ in lst] - indexes = list(range(len(lst))) - for i in lst: - n, index = divmod(n, len(indexes)) - nlst[indexes.pop(index)] = i - return nlst - - def round_up_div(a, b): a, b = divmod(a, b) return a+1 if b else a @@ -107,7 +92,7 @@ async def shuffle(ctx: commands.Context, channel_size=2): group.append(tutors.pop()) for _ in range(count - tutor_count): for i, member in enumerate(normals): - if any(frozenset((member.id, other.id)) in ctx.bot.oldgroups for other in group): + if any((frozenset((member.id, other.id)) in ctx.bot.oldgroups) for other in group): continue group.append(normals.pop(i)) break @@ -123,7 +108,7 @@ async def shuffle(ctx: commands.Context, channel_size=2): for member1 in group: for member2 in group: if member1 != member2: - ctx.bot.oldgroups.add(frozenset((member1, member2))) + ctx.bot.oldgroups.add(frozenset((member1.id, member2.id))) random.shuffle(futures) for group in groups: @@ -151,7 +136,7 @@ async def stop(ctx: commands.Context, cancel_loop=True): async def loop_cycle(ctx, t): - if not await shuffle(ctx): + if not await shuffle(ctx, 3): return False await asyncio.sleep(t) await ctx.bot.update_scores(ctx.guild) @@ -227,5 +212,19 @@ async def list(ctx: commands.Context): else: await answer(ctx, 'there is no tutor :/') +@commands.command( + help='get the scoreboard', + aliases=('scores', 'score', 'points') +) +async def scoreboard(ctx: commands.Context): + text = config.SCOREBOARD_TEXT + scores = [i for i in ctx.bot.score_map.items()] + scores = sorted(scores, reverse=True, key=lambda i: i[1]) + for n, (member, score) in enumerate(scores): + if score > 0: + text += f'\n {n+1}. {ctx.bot.get_username(member)} hat {score} Punkt{"" if score == 1 else "e"}' + embed = discord.Embed(title=config.SCOREBOARD_TITLE, type="rich", description=text, colour=discord.Colour.purple()) + await ctx.send(embed=embed) + bot_commands = [cmd for cmd in locals().values() if isinstance(cmd, commands.Command)] |