summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatrixAeria <upezu@student.kit.edu>2020-10-20 08:08:55 +0200
committerNatrixAeria <upezu@student.kit.edu>2020-10-20 08:08:55 +0200
commit74847b8417f64e6c69fe2338f0a1b5d513b20ace (patch)
tree8af6a7969a3b69f9f500813c9e12d57b4e072f09
parentc524513a9d7da39bd8a7684d34e1d6b7851dbf23 (diff)
Add score system switch
-rw-r--r--commands.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/commands.py b/commands.py
index ff0c894..c3ff09a 100644
--- a/commands.py
+++ b/commands.py
@@ -82,7 +82,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, frompairchannels=False):
+async def shuffle(ctx: commands.Context, channel_size=2, frompairchannels=False, do_score=True):
if not is_admin_channel(ctx): return
if channel_size < 1:
await answer(ctx, 'error: channel size must be at least 1 (you jerk)')
@@ -145,11 +145,12 @@ async def shuffle(ctx: commands.Context, channel_size=2, frompairchannels=False)
ctx.bot.oldgroups.add(frozenset((member1.id, member2.id)))
random.shuffle(futures)
await await_n(futures)
- futures = []
- for group in groups:
- for member in group:
- futures.append(ctx.bot.send_panel(ctx, member, group))
- await await_n(futures)
+ if do_score:
+ futures = []
+ for group in groups:
+ 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
@@ -173,18 +174,19 @@ async def stop(ctx: commands.Context, cancel_loop=True):
await ctx.bot.destroy_pair_channels(ctx, meta_channel)
-async def loop_cycle(ctx, t, nt, g, isfirst, islast):
- if not await shuffle(ctx, g, frompairchannels=not isfirst):
+async def loop_cycle(ctx, t, nt, g, isfirst, islast, do_score):
+ if not await shuffle(ctx, g, frompairchannels=not isfirst, do_score=do_score):
return False
if nt >= t:
await asyncio.sleep(t)
else:
await asyncio.sleep(nt)
notify_channel = ctx.bot.get_notify_channel(ctx, ctx.bot.get_meta_channel(ctx))
- embed = discord.Embed(title=f"Noch {nt} Sekunden", type="rich", description="", colour=discord.Colour.blue())
+ embed = discord.Embed(title=f"Noch {t-nt} Sekunden", type="rich", description="", colour=discord.Colour.blue())
await notify_channel.send(embed=embed)
await asyncio.sleep(t - nt)
- await ctx.bot.update_scores(ctx.guild)
+ if do_score:
+ await ctx.bot.update_scores(ctx.guild)
if islast:
await stop(ctx, cancel_loop=False)
return True
@@ -194,7 +196,7 @@ async def loop_cycle(ctx, t, nt, g, isfirst, islast):
help=f'repeat "shuffle" and "stop" <n> (default: {config.DEFAULT_LOOP_COUNT}) times and <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, nt=config.DEFAULT_NOTIFY_TIME, g=3):
+async def loop(ctx: commands.Context, n=config.DEFAULT_LOOP_COUNT, t=config.DEFAULT_LOOP_TIME, nt=config.DEFAULT_NOTIFY_TIME, g=3, do_score=True):
if not is_admin_channel(ctx): return
try:
n, t = int(n), int(t)
@@ -203,7 +205,7 @@ async def loop(ctx: commands.Context, n=config.DEFAULT_LOOP_COUNT, t=config.DEFA
return
await answer(ctx, f'repeat shuffling {n} times and each {t} seconds')
for i in range(n):
- result = await ctx.bot.await_coroutine(loop_cycle(ctx, t, nt, g, i == 0, i == n-1))
+ result = await ctx.bot.await_coroutine(loop_cycle(ctx, t, nt, g, i == 0, i == n-1, do_score))
message = {
'cancelled': 'cancelled loop command',
'already running': 'cannot start loop, another task is running...'