Пример #1
0
    async def _set(self, ctx, member, username: str):
        """Manually link two accounts together"""
        query = Query()
        member = await query.parseUser(ctx, member)

        if username != "+remove":
            user = await query.get_user(username)

            if user is None:
                await ctx.send(f'{username} does not exist on dmoj')
                return

            username = user.username

        handle = query.get_handle(member.id, ctx.guild.id)
        if handle == username:
            return await ctx.send(
                f'{member.display_name} is already linked with {handle}')

        if handle:
            handle = session.query(Handle_DB)\
                .filter(Handle_DB.id == member.id)\
                .filter(Handle_DB.guild_id == ctx.guild.id).first()
            session.delete(handle)
            session.commit()
            await ctx.send(
                f'Unlinked {member.display_name} with handle {handle.handle}')

        if username == "+remove":
            return

        if query.get_handle_user(username, ctx.guild.id):
            await ctx.send('This handle is already linked with another user')
            return

        handle = Handle_DB()
        handle.id = member.id
        handle.handle = username
        handle.user_id = user.id
        handle.guild_id = ctx.guild.id
        session.add(handle)
        session.commit()
        await ctx.send(f"Linked {member.name} with {username}.")

        rank_to_role = {
            role.name: role
            for role in ctx.guild.roles if role.name in RANKS
        }
        rank = self.rating_to_rank(user.rating)
        if rank in rank_to_role:
            await self._update_rank(ctx.author, rank_to_role[rank],
                                    'Dmoj account linked')
        else:
            await ctx.send("You are missing the " + rank.name + " role")
Пример #2
0
 async def unlink(self, ctx):
     """Unlink your discord account with your dmoj account"""
     query = Query()
     if not query.get_handle(ctx.author.id, ctx.guild.id):
         await ctx.send('You are not linked with any user')
         return
     handle = session.query(Handle_DB)\
         .filter(Handle_DB.id == ctx.author.id)\
         .filter(Handle_DB.guild_id == ctx.guild.id).first()
     session.delete(handle)
     session.commit()
     await ctx.send(f'Unlinked you with handle {handle.handle}')
Пример #3
0
async def unlink(ctx: lightbulb.Context) -> None:
    # TODO: Add admin ability to manually unlink
    query = Query()
    if not query.get_handle(ctx.author.id, ctx.get_guild().id):
        await ctx.respond("You are not linked with any user")
        return
    handle = (
        session.query(Handle_DB)
        .filter(Handle_DB.id == ctx.author.id)
        .filter(Handle_DB.guild_id == ctx.get_guild().id)
        .first()
    )
    session.query(User_DB).filter(User_DB.id == handle.user_id).delete()
    session.query(Submission_DB).filter(Submission_DB._user == handle.handle).delete()
    session.delete(handle)
    session.commit()
    await ctx.respond(escape_markdown(f"Unlinked you with handle {handle.handle}"))
Пример #4
0
async def _set(ctx):
    """Manually link two accounts together"""
    # TODO: I don't like the bot spamming replies to itself, figure out a way to lessen that
    member = ctx.options.member
    username = ctx.options.handle
    query = Query()

    if username != "+remove":
        try:
            user = await query.get_user(username)

            if user is None:
                raise ObjectNotFound()
        except ObjectNotFound:
            await ctx.respond(escape_markdown(f"{username} does not exist on dmoj"))
            return

        username = user.username

    handle = query.get_handle(member.id, ctx.get_guild().id)
    if handle == username:
        return await ctx.respond(escape_markdown(f"{member.display_name} is already linked with {handle}"))

    if handle:
        handle = (
            session.query(Handle_DB)
            .filter(Handle_DB.id == member.id)
            .filter(Handle_DB.guild_id == ctx.get_guild().id)
            .first()
        )
        session.delete(handle)
        session.commit()
        await ctx.respond(escape_markdown(f"Unlinked {member.display_name} with handle {handle.handle}"))

    if username == "+remove":
        return

    if query.get_handle_user(username, ctx.get_guild().id):
        await ctx.respond("This handle is already linked with another user")
        return

    handle = Handle_DB()
    handle.id = member.id
    handle.handle = username
    handle.user_id = user.id
    handle.guild_id = ctx.get_guild().id
    session.add(handle)
    session.commit()
    await ctx.respond(escape_markdown(f"Linked {member.display_name} with {username}"))

    rank_to_role = {}
    rc = lightbulb.RoleConverter(ctx)
    for role_id in ctx.get_guild().get_roles():
        role = await rc.convert(str(role_id))
        if role.name in RANKS:
            rank_to_role[role.name] = role

    rank = rating_to_rank(user.rating)
    if rank in rank_to_role:
        await _update_rank(member, rank_to_role[rank], "Dmoj account linked")
    else:
        await ctx.respond("You are missing the `" + rank.name + "` role")