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

fix indexing and cleanup #186

Open
wants to merge 7 commits 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
15 changes: 9 additions & 6 deletions ovisbot/extensions/ctf/ctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@

logger = logging.getLogger(__name__)

UNSOLVED_PREFIX_LEN = len('--unsolved-') - 1

CHALLENGE_CATEGORIES = [
"crypto",
"web",
Expand Down Expand Up @@ -77,6 +79,7 @@
"hard": (":icecream:", "παωτόν"),
}


class Ctf(commands.Cog):
def __init__(self, bot):
self.bot = bot
Expand Down Expand Up @@ -367,7 +370,7 @@ async def finish_error(self, ctx, error):
@ctf.command()
async def solve(self, ctx):
"""
Marks the current challenge as solved by you.
Marks the current challenge as solved by you.
Addition of team mates that helped to solve is optional
"""
chall_name = ctx.channel.name
Expand Down Expand Up @@ -459,7 +462,7 @@ async def unsolve_error(self, ctx, error):
"Ρε πελλοβρεμένε! For this command you have to be in a ctf challenge channel created by `!ctf addchallenge`."
)
elif isinstance(error.original, ChallengeNotSolvedException):
await ctx.channel.send(f"Ρε κουμπάρε.. αφού ένεν λυμένη η ασκηση.")
await ctx.channel.send("Ρε κουμπάρε.. αφού ένεν λυμένη η ασκηση.")

@ctf.command()
async def join(self, ctx, *params):
Expand Down Expand Up @@ -517,7 +520,7 @@ async def attempt(self, ctx, challname):
)

ctf.save()
await ctx.channel.send(f"Άμα είσαι κουνόσσιηλλος...")
await ctx.channel.send("Άμα είσαι κουνόσσιηλλος...")
elif chall_name == '--unsolved':
author = ctx.message.author.name
# fetch all challenges that have an empty "solved_at" attribute
Expand All @@ -529,10 +532,10 @@ async def attempt(self, ctx, challname):
await chall_channel.set_permissions(author, read_messages=True)
ctf.save()
await ctx.channel.send("Άτε ρε παιχτουρα μου δωκε μεσα...")
elif chall_name.startswith("--unsolved-") and chall_name[11:] in ['web', 'pwn', 'misc', 'crypto', 'forensics', 'hardware']:
elif chall_name.startswith("--unsolved-") and chall_name[UNSOLVED_PREFIX_LEN:] in CHALLENGE_CATEGORIES:
author = ctx.message.author.name
# fetch unsolved challenges which are in the mentioned category
for challenge in filter(lambda x: not x.solved_at and x.tags.count(chall_name[11:]), ctf.challenges):
for challenge in filter(lambda x: not x.solved_at and x.tags.count(chall_name[UNSOLVED_PREFIX_LEN:]), ctf.challenges):
if author in challenge.attempted_by:
continue
challenge.attempted_by.append(author)
Expand Down Expand Up @@ -753,7 +756,7 @@ async def showcreds(self, ctx):
raise CTFSharedCredentialsNotSet
emb = discord.Embed(description=ctf.credentials(), colour=4387968)
await ctx.channel.send(embed=emb)

@showcreds.error
async def showcreds_error(self, ctx, error):
if isinstance(error, CTF.DoesNotExist):
Expand Down