~robin_jadoul/organizers-bot

7ddfa0a84a3d3613e6278f229d440821bf54e3bd — LucidBrot 2 years ago 87053d4
Fix Typos. Tested:

assigning player to chall creates ctfnote account if not yet exists. If exists, no creation happens. The creation message is now hidden if the user assigned themselves - so only they see it.

Spaces, Dashes, Caps, in challenge names used to be a problem because discord channels don't have these. So the channel name does not map directly to the ctfnote name. Fixed by saving the ctfnote ctfid in the pinned message and using that as an identifier instead.

When there is exactly one current ctf, it is used (if there is no pinned message or optional argument overriding that choice). When there are multiple, none are used and the fixup command has to be used with the optional argument.

Users can now register themselves on ctfnote with a command and get a hidden response. The password can be specified or autogenerated. Both code paths tested.
2 files changed, 7 insertions(+), 7 deletions(-)

M organizers_bot/bot.py
M organizers_bot/ctfnote.py
M organizers_bot/bot.py => organizers_bot/bot.py +1 -1
@@ 262,7 262,7 @@ def setup():
                                   required=False),
                 ])
    @require_role(config.mgmt.player_role)
    async def ctfnote_register_myself(ctx: discord_slash.SlashContext, password: str):
    async def ctfnote_register_myself(ctx: discord_slash.SlashContext, password: str = None):
        await ctfnote.register_themselves(ctx, password or None)

    @slash.slash(name="ctfnote_who_leads",

M organizers_bot/ctfnote.py => organizers_bot/ctfnote.py +6 -6
@@ 514,7 514,7 @@ async def refresh_ctf(ctx: discord_slash.SlashContext, ctfid: int = None):
        # if no ctf id is stored in the pinned message, we assume the first in the list of 
        # currently running CTFs is the right one
        current_ctfs = await ctfnote.getActiveCtfs()
        if current_ctfs is None or len(current_ctfs == 0):
        if current_ctfs is None or len(current_ctfs) == 0:
            await ctx.send("No active ctf! Go on ctfnote and fix the dates!")
            return None
        if len(current_ctfs) > 1:


@@ 619,14 619,14 @@ async def register_themselves(ctx: discord_slash.SlashContext, password: str = N
    if current_ctf is None: return

    all_users = await ctfnote.getUsers()
    sender = ctx.message.author
    sender = ctx.author
    uid = f"{sender.name}#{sender.discriminator}"
    user =  list(filter(lambda x: x['login'] == uid, all_users))
    if len(user) > 0:
        await ctx.send(f"Account {uid} already exists.", hidden=True)
        return

    user_id, password = await ctfnote.createMemberAccount(uid)
    user_id, password = await ctfnote.createMemberAccount(uid, password = password)
    await ctx.send(f"Account {uid} was created with password {password}", hidden=True)
    



@@ 643,9 643,9 @@ async def assign_player(ctx: discord_slash.SlashContext, playername):
    user =  list(filter(lambda x: x['login'] == uid, all_users))
    if len(user) == 0:
        # We can make the response hidden to other players if the sender is the person who is being assigned.
        sender = ctx.message.author
        sender = ctx.author
        sender_fullname = f"{sender.name}#{sender.discriminator}"
        hidden = (sender_fullname != uid)
        hidden = (sender_fullname == uid)

        user_id, password = await ctfnote.createMemberAccount(uid)
        await ctx.send(f"Account {playername} was created with password {password}", hidden=hidden)


@@ 701,7 701,7 @@ async def whos_leader_of_this_shit(ctx: discord_slash.SlashContext):
        return

    hide = True # reply will only be visible to *this* user.
    await ctx.defer(hidden=hide, thinking=true)
    await ctx.defer(hidden=hide)
                           # We defer here just in case the refresh ctf could take a while.
                           # might not be needed.
    current_ctf = await refresh_ctf(ctx)