Example #1
0
async def set_guild(guild_name: str):
    guild = get_object(data.bot.guilds, guild_name)
    if guild:
        data.data["selected_guild"] = guild
        print(f"set selected guild to {guild}")
    else:
        print("could not find guild {}".format(guild_name))
Example #2
0
async def get_role_position(role):
    guild = data.data["selected_guild"]
    if not guild:
        print("no guild selected")
        return

    role = get_object(guild.roles, role)
    if not role:
        print(f"could not find role {role}")
        return

    print(role.position)
Example #3
0
async def set_role_name(role, new_name):
    guild = data.data["selected_guild"]
    if not guild:
        print("no guild selected")
        return

    role = get_object(guild.roles, role)
    if not role:
        print(f"cannot find role {role}")
        return

    old_role_name = role.name
    await role.edit(name = new_name)
    print(f"set role {old_role_name}'s name to {new_name}")
Example #4
0
async def set_role_position(role, value):
    guild = data.data["selected_guild"]
    if not guild:
        print("no guild selected")
        return

    role = get_object(guild.roles, role)
    if not role:
        print(f"could not find role {role}")
        return

    value = int(value)
    await role.edit(position = value)
    print(f"set role {role}'s position to {value}")
Example #5
0
async def set_role_color(role, color: int):
    guild = data.data["selected_guild"]
    if not guild:
        print("no guild selected")
        return

    role = get_object(guild.roles, role)
    if not role:
        print(f"could not find role {role}")
        return

    color = int(color, 16)
    await role.edit(color = discord.Color(color))
    print(f"set role {role}'s color to {color}")
Example #6
0
async def set_afk_channel(vc_name):
    guild = data.data["selected_guild"]
    if not guild:
        print(f"no guild selected")
        return

    if vc_name == "none":
        await guild.edit(afk_channel = None)
        print("removed afk channel")
    else:
        channel = get_object(guild.voice_channels, vc_name)
        if channel:
            await guild.edit(afk_channel = channel)
            print(f"changed afk channel to {vc_name}")
        else:
            print(f"cannot find voice channel {vc_name}")
Example #7
0
async def get_role_permissions(role):
    guild = data.data["selected_guild"]
    if not guild:
        print("no guild selected")
        return

    role = get_object(guild.roles, role)
    if not role:
        print(f"could not find role {role}")
        return

    permissions = {}
    for permission in role.permissions:
        permissions[permission[0]] = permission[1]

    print(permissions)
Example #8
0
async def set_role_mentionable(role, value):
    guild = data.data["selected_guild"]
    if not guild:
        print("no guild selected")
        return

    role = get_object(guild.roles, role)
    if not role:
        print(f"could not find role {role}")
        return

    if value == "true":
        value = True
    elif value == "false":
        value = False
    else:
        print(f"{value} is not a valid value")
        return

    await role.edit(mentionable = value)
    print(f"set role {role}'s mentionable value to {value}")
Example #9
0
async def set_role_permission(role, permission, value):
    guild = data.data["selected_guild"]
    if not guild:
        print("no guild selected")
        return

    role = get_object(guild.roles, role)
    if not role:
        print(f"could not find role {role}")
        return

    if value == "true":
        value = True
    elif value == "false":
        value = False
    else:
        print(f"{value} is not a valid value")
        return

    permissions = discord.Permissions()
    permissions.update(**{permission: value})

    await role.edit(permissions = permissions)
    print(f"set permission {permission} to {value} for role {role}")
Example #10
0
    async def set(self, context, name, *, value):
        response = await context.send(
            embed=create_embed({
                'title': f'Changing {name} to {value}...',
                'color': discord.Color.gold()
            }))

        try:
            guild_data = get_guild_data(context.guild.id)
            if name in ['join_channel']:
                if value == 'none':
                    guild_data[name] = None
                    save_guild_data(guild_data)
                    await response.edit(
                        embed=create_embed({
                            'title': f'Removed {name}',
                        }))
                else:
                    channel = get_object(context.guild.text_channels, value)
                    if channel:
                        guild_data[name] = channel.id
                        save_guild_data(guild_data)
                        await response.edit(embed=create_embed({
                            'title':
                            f'Changed {name} to {channel.name}',
                        }))
                    else:
                        await response.edit(
                            embed=create_embed({
                                'title': f'Could not find channel {value}',
                                'color': discord.Color.red()
                            }))
                        print(f'Could not find channel {value}')
            elif name in ['meme_channels']:
                channel = get_object(context.guild.text_channels, value)
                if not channel:
                    await response.edit(
                        embed=create_embed({
                            'title': f'Could not find channel {value}',
                            'color': discord.Color.red()
                        }))
                    print(f'Could not find channel {value}')
                    return

                if channel.id in guild_data[name]:
                    guild_data[name].remove(channel.id)
                    save_guild_data(guild_data)
                    await response.edit(
                        embed=create_embed({
                            'title': f'Removed channel #{channel.name}',
                            'color': discord.Color.green()
                        }))
                else:
                    guild_data[name].append(channel.id)
                    save_guild_data(guild_data)
                    await response.edit(
                        embed=create_embed({
                            'title': f'Added channel #{channel.name}',
                            'color': discord.Color.green()
                        }))
            else:
                await response.edit(
                    embed=create_embed({
                        'title': f'{name} is an invalid setting',
                        'color': discord.Color.red()
                    }))
                print(f'{name} is an invalid setting')
        except Exception as error_message:
            await response.edit(embed=create_embed(
                {
                    'title': f'Could not change {name} to {value}',
                    'color': discord.Color.red()
                }, {'Error Message': error_message}))

            print(f'Could not change {name} to {value}')
            print(error_message)