Skip to content

Commit d8d6f33

Browse files
author
ishtar
committed
2022-05-16: added option to join unsolved challenges
1 parent 907f13e commit d8d6f33

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

ovisbot/extensions/ctf/ctf.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,12 @@ async def leave(self, ctx):
488488
ctfrole = discord.utils.get(ctx.guild.roles, name="Team-" + ctf_name)
489489
await ctx.message.author.remove_roles(ctfrole)
490490

491+
def is_joinable(challenge):
492+
return not (ctx.message.author.name in challenge.attempted_by)
493+
494+
def is_unsolved(challenge):
495+
return challenge.solved_at is None
496+
491497
@ctf.command()
492498
async def attempt(self, ctx, challname):
493499
"""
@@ -518,6 +524,16 @@ async def attempt(self, ctx, challname):
518524

519525
ctf.save()
520526
await ctx.channel.send(f"Άμα είσαι κουνόσσιηλλος...")
527+
528+
elif chall_name in ['--unsolved', '--rem']:
529+
unsolved = filter(lambda x: is_unsolved(x) and is_joinable(x), ctf.challenges)
530+
for challenge in unsolved:
531+
challenge.attempted_by = challenge.attempted_by + [ctx.message.author.name] # why not .append()?
532+
chall_channel = discord.utils.get(ctx.channel.category.channels, name=challenge.name)
533+
await chall_channel.set_permissions(ctx.message.author, read_messages=True)
534+
ctf.save()
535+
await ctx.channel.send(f"Δώστους βιτσιά {ctx.message.author.name} μου!!")
536+
521537
else:
522538
challenge = next(
523539
(c for c in ctf.challenges if c.name == ctf_name + "-" + chall_name),

0 commit comments

Comments
 (0)