Skip to content

Commit

Permalink
2022-05-16: added option to join unsolved challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
ishtar committed May 16, 2022
1 parent 907f13e commit d8d6f33
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ovisbot/extensions/ctf/ctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,12 @@ async def leave(self, ctx):
ctfrole = discord.utils.get(ctx.guild.roles, name="Team-" + ctf_name)
await ctx.message.author.remove_roles(ctfrole)

def is_joinable(challenge):
return not (ctx.message.author.name in challenge.attempted_by)

def is_unsolved(challenge):
return challenge.solved_at is None

@ctf.command()
async def attempt(self, ctx, challname):
"""
Expand Down Expand Up @@ -518,6 +524,16 @@ async def attempt(self, ctx, challname):

ctf.save()
await ctx.channel.send(f"Άμα είσαι κουνόσσιηλλος...")

elif chall_name in ['--unsolved', '--rem']:
unsolved = filter(lambda x: is_unsolved(x) and is_joinable(x), ctf.challenges)
for challenge in unsolved:
challenge.attempted_by = challenge.attempted_by + [ctx.message.author.name] # why not .append()?
chall_channel = discord.utils.get(ctx.channel.category.channels, name=challenge.name)
await chall_channel.set_permissions(ctx.message.author, read_messages=True)
ctf.save()
await ctx.channel.send(f"Δώστους βιτσιά {ctx.message.author.name} μου!!")

else:
challenge = next(
(c for c in ctf.challenges if c.name == ctf_name + "-" + chall_name),
Expand Down

0 comments on commit d8d6f33

Please sign in to comment.