diff options
author | NatrixAeria <upezu@student.kit.edu> | 2020-10-20 05:54:39 +0200 |
---|---|---|
committer | NatrixAeria <upezu@student.kit.edu> | 2020-10-20 05:54:39 +0200 |
commit | 3e96d80ddc3a4250a28c287d37247d67623de345 (patch) | |
tree | b261afd22c906c5848e807507b9ce6abef95174d | |
parent | 0e1af96e7506cca54395ab0c4b85e5bc376ff279 (diff) |
Do not send people back to Lobby
-rw-r--r-- | commands.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/commands.py b/commands.py index 989411d..92a1dd9 100644 --- a/commands.py +++ b/commands.py @@ -73,7 +73,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): +async def shuffle(ctx: commands.Context, channel_size=2, frompairchannels=False): if not is_admin_channel(ctx): return if channel_size < 1: await answer(ctx, 'error: channel size must be at least 1 (you jerk)') @@ -82,7 +82,13 @@ async def shuffle(ctx: commands.Context, channel_size=2): if not channels: return False meta_channel, lobby_channel = channels - members = await get_members(ctx.guild, lobby_channel) + if frompairchannels: + await await_n(pc.edit(name=pc.name+" Old") for pc in ctx.bot.pair_channels) + members = sum(await await_n(get_members(ctx.guild, pc) for pc in ctx.bot.pair_channels), start=[]) + oldpairs = ctx.bot.pair_channels + ctx.bot.pair_channels = [] + else: + members = await get_members(ctx.guild, lobby_channel) if not members: await answer(ctx, 'error: nobody wants to get shuffeled :(') return False @@ -135,6 +141,8 @@ async def shuffle(ctx: commands.Context, channel_size=2): for member in group: futures.append(ctx.bot.send_panel(ctx, member, group)) await await_n(futures) + if frompairchannels: + await await_n(ctx.bot.try_delete_channel(c) for c in oldpairs) return True @@ -156,12 +164,13 @@ async def stop(ctx: commands.Context, cancel_loop=True): await ctx.bot.destroy_pair_channels(ctx, meta_channel) -async def loop_cycle(ctx, t, g): - if not await shuffle(ctx, g): +async def loop_cycle(ctx, t, g, isfirst, islast): + if not await shuffle(ctx, g, frompairchannels=not isfirst): return False await asyncio.sleep(t) await ctx.bot.update_scores(ctx.guild) - await stop(ctx, cancel_loop=False) + if islast: + await stop(ctx, cancel_loop=False) return True @@ -177,8 +186,8 @@ async def loop(ctx: commands.Context, n=config.DEFAULT_LOOP_COUNT, t=config.DEFA await answer(ctx, 'error: expecting positive integer arguments for <n> and <t> (e.g. "loop 5 60" to repeat 5 times)') return await answer(ctx, f'repeat shuffling {n} times and each {t} seconds') - for _ in range(n): - result = await ctx.bot.await_coroutine(loop_cycle(ctx, t, g)) + for i in range(n): + result = await ctx.bot.await_coroutine(loop_cycle(ctx, t, g, i == 0, i == n-1)) message = { 'cancelled': 'cancelled loop command', 'already running': 'cannot start loop, another task is running...' |