Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2022-05-16: added option to join unsolved challenges #179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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