def _check_guild(guild: Guild):
    """Check that the guild has a correct configuration. Some properties may not be tested."""
    logger.info("Checking game guild !")
    errors_bot_role = _check_bot_privileges(guild)
    if errors_bot_role:
        return errors_bot_role
    guild_channels = guild.channels
    errors = []
    for ch_descr in CategoryChannelCollection.to_list():
        check_channel_description(
            ch_descr,
            guild,
            guild_channels,
            errors,
            allowed_role_descriptions=RoleCollection.to_list())

    for ch_descr in ChannelCollection.to_list():
        check_channel_description(
            ch_descr,
            guild,
            guild_channels,
            errors,
            allowed_role_descriptions=RoleCollection.to_list())

    for r_descr in RoleCollection.to_list():
        check_role_description(r_descr, guild, errors)
    return errors
예제 #2
0
async def init_guild(guild_wrapper) -> bool:
    """Coroutine to initialize a new a guild or to reset it when the version has changed."""
    # Print information on the guild
    logger.info(get_guild_info(BOT, guild_wrapper))
    logger.info(get_members_info(guild_wrapper))
    logger.info(get_roles_info(guild_wrapper))
    logger.info(get_channels_info(guild_wrapper))

    # Get existing channels and roles, but do not set/create/update anything
    await fetch_roles(guild_wrapper, RoleCollection.to_list())
    await fetch_channels(guild_wrapper, CategoryChannelCollection.to_list())
    await fetch_channels(guild_wrapper, ChannelCollection.to_list())

    # Add guild listeners and show the control panel
    await guild_wrapper.add_listeners(UtilsList(guild_wrapper))  # add utils
    await guild_wrapper.add_listeners(
        MinigameCollection.get_guild_instances(guild_wrapper))  # add minigames
    if VERBOSE >= 10:
        await guild_wrapper.listener_manager.show_control_panel(
            guild_wrapper.guild)  # show control panel

    # Send a success message
    try:
        channel = await get_safe_text_channel(guild_wrapper.guild,
                                              "BOARD",
                                              create=False)
        if VERBOSE >= 10:
            await channel.send("Bot redémarré !")
    except discord.DiscordException as err:
        logger.error(f"Failed to send reboot message: {err}")
        return False
    else:
        logger.info("Guild initialized successfully")
        return True
예제 #3
0
async def update_guild_roles(guild: Guild,
                             delete_old=False,
                             clear_references=True) -> bool:
    logger.info("Doing: update server roles")
    upd_ok = await update_roles(guild,
                                RoleCollection.to_list(),
                                delete_old=delete_old,
                                clear_references=clear_references)
    logger.info(f"Done{'' if upd_ok else ' with errors'}: update server roles")
    return upd_ok
def _check_bot_privileges(guild: Guild):
    highest_game_role_description = max(
        r.object_reference or guild.default_role
        for r in RoleCollection.to_list())
    highest_bot_role = guild.me.top_role
    if highest_bot_role >= highest_game_role_description:
        return []
    err = f"Highest bot role ({highest_bot_role}) must be higher than other game roles in hierarchy! " \
          f"At least one role with a higher position ({highest_game_role_description}) was found."
    logger.error(err)
    return [err]
예제 #5
0
async def fetch(guild):
    await fetch_roles(guild, RoleCollection.to_list())
    await fetch_channels(guild, CategoryChannelCollection.to_list())
    await fetch_channels(guild, ChannelCollection.to_list())
    logger.debug("Channels fetched")