Exemplo n.º 1
0
async def whos(ctx, role_name):
    role_dict = roles_dict.get(role_name)
    if role_dict is None:
        return
    if str(ctx.message.channel) not in role_dict['allowed_channels']:
        message = "Please " + ctx.message.author.mention + ", use the appropriate channels for this command: "
        message += ' '.join(role_dict['allowed_channels'])
        await ctx.send(message)
        return
    role = role_dict["role"]

    users = [x for x in role.members if str(x.status) == "online"]
    if len(users) > 0:
        uids = [member.id for member in users]
        infos = requests.get(
            "https://dev.openstudyroom.org/league/discord-api/",
            params={
                'uids': uids
            }).json()
        message = ''
        for user in users:
            message += user_info_message(user, infos)
        title = "The following users are " + role_dict['verbose'] + ":"
        embed = discord.Embed(title=title, description=message)
        add_footer(embed, ctx.message.author)
        await ctx.send(embed=embed)

    else:
        await ctx.send(
            "Sorry {}. Unfortunately, nobody is {} right now. :(".format(
                ctx.message.author.mention, role_dict['verbose']))
Exemplo n.º 2
0
async def list(ctx, role_name):
    role_dict = roles_dict.get(role_name)
    if role_dict is None:
        return

    if str(ctx.message.channel) not in role_dict['allowed_channels']:
        message = "Please " + ctx.message.author.mention + ", use the appropriate channels for this command: "
        message += ' '.join(role_dict['allowed_channels'])
        await ctx.send(message)
        return
    role = role_dict["role"]

    online_users = [x for x in role.members if str(x.status) == "online"]
    idle_users = [y for y in role.members if str(y.status) == "idle"]
    users = online_users
    if len(users) > 0:
        if len(users) > 15:
            message = "Sorry, but there are too many users in the " + role_name + " group to list."
            await ctx.send(message)
            return

        uids = [member.id for member in users]
        infos = requests.get("https://openstudyroom.org/league/discord-api/",
                             params={
                                 'uids': uids
                             }).json()
        message = ''
        message2 = ''
        for user in users:
            new_user_message = user_info_message(user, infos)
            if len(message) + len(new_user_message) < 2048:
                message += new_user_message
            else:
                message2 += new_user_message
        if message2 == '':
            message += "*" + str(len(idle_users)) + " more users are idle.*"
        else:
            message2 += "*" + str(len(idle_users)) + " more users are idle.*"

        title = "The following users are " + role_dict['verbose'] + ":"
        embed = discord.Embed(title=title, description=message)
        add_footer(embed, ctx.message.author)
        await ctx.send(embed=embed)

        if message2 != '':
            embed = discord.Embed(description=message2)
            add_footer(embed, ctx.message.author)
            await ctx.send(embed=embed)

    else:
        await ctx.send(
            "Sorry {}. Unfortunately, nobody is {} right now. :(".format(
                ctx.message.author.mention, role_dict['verbose']))
Exemplo n.º 3
0
async def no(ctx, role_name):
    role_dict = roles_dict.get(role_name)
    if role_dict is None:
        return
    if str(ctx.message.channel) not in role_dict['allowed_channels']:
        message = "Please " + ctx.message.author.mention + ", use the appropriate channels for this command: "
        message += ', '.join(role_dict['allowed_channels'])
        await ctx.send(message)
        return
    role = role_dict["role"]

    await ctx.message.author.remove_roles(role)
    await ctx.send(ctx.message.author.mention + " is no longer " +
                   role_dict["verbose"] + ".")