~robin_jadoul/organizers-bot

87053d4ee393172d9aac67f6b4fa62b377f6aeac — LucidBrot 2 years ago fbe9772
untested: a command to register more easily to ctfnote - no more preshared secret required for people with the CTFPlayer role
2 files changed, 41 insertions(+), 4 deletions(-)

M organizers_bot/bot.py
M organizers_bot/ctfnote.py
M organizers_bot/bot.py => organizers_bot/bot.py +13 -0
@@ 252,6 252,19 @@ def setup():
    async def ctfnote_update_assigned_player(ctx: discord_slash.SlashContext, playername: discord.member.Member):
        await ctfnote.assign_player(ctx, playername)

    @slash.slash(name="ctfnote_register_myself",
                 description="Register yourself a ctfnote account",
                 guild_ids=[config.bot.guild],
                 options=[
                     create_option(name="password",
                                   description="Autogenerated if unspecified",
                                   option_type=SlashCommandOptionType.STRING,
                                   required=False),
                 ])
    @require_role(config.mgmt.player_role)
    async def ctfnote_register_myself(ctx: discord_slash.SlashContext, password: str):
        await ctfnote.register_themselves(ctx, password or None)

    @slash.slash(name="ctfnote_who_leads",
                 description="Ping who's the current leader of this challenge",
                 guild_ids=[config.bot.guild])

M organizers_bot/ctfnote.py => organizers_bot/ctfnote.py +28 -4
@@ 395,9 395,10 @@ class CTFNote:
        ctf = CTF(self.client, result["ctf"])
        return ctf
    
    async def createMemberAccount(self, user):
    async def createMemberAccount(self, user, password=None):
        """
        Creates a guest account invitation link
        Creates a guest account invitation link.
        Password is autogenerated unless specified as optional argument.
        """
        query = gql.gql(queries.create_account)
        result = await self.client.execute_async(query, variable_values={


@@ 406,7 407,7 @@ class CTFNote:
        token = result["createInvitationLink"]["invitationLinkResponse"]["token"]

        # password = "".join([choice(ascii_letters+digits) for _ in range(16)])
        password = "organizerssostrong" + str(randrange(1000, 9999))
        password = password or ("organizerssostrong" + str(randrange(1000, 9999)))
        tmp = CTFNote(self.url)
        await tmp.login(user, password, token)
        new_acc = await tmp.getMe()


@@ 606,6 607,29 @@ async def add_task(ctx: discord_slash.SlashContext, created, name: str,
        msg = await created.send(ctfnote_url + hackmd_url + bot_data_store)
        await msg.pin()

async def register_themselves(ctx: discord_slash.SlashContext, password: str = None):
    """
        Intended mainly for interactive use (User command to sign themselves up).
    """
    if not enabled:
        await ctx.send("CTFNote integration is currently not in use. Ignoring your request.", hidden=True)
        return

    current_ctf = await refresh_ctf(ctx) 
    if current_ctf is None: return

    all_users = await ctfnote.getUsers()
    sender = ctx.message.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)
    await ctx.send(f"Account {uid} was created with password {password}", hidden=True)
    

async def assign_player(ctx: discord_slash.SlashContext, playername):
    if not enabled:
        await ctx.send("CTFNote integration is currently not in use. Ignoring your request.", hidden=True)


@@ 637,7 661,7 @@ async def assign_player(ctx: discord_slash.SlashContext, playername):
        await task.unassignUser(pid)
    #print(task.people)
    await task.assignUser(user_id)
    await ctx.send(f"Player {playername.mention} was assigned to challenge {task.title}")
    await ctx.send(f"Player {playername.mention} was assigned to challenge {task.title}", hidden=False)


async def fixup_task(ctx: discord_slash.SlashContext,