def __init__(self, **kwargs): description_names = kwargs.pop("channel_descriptions", None) self._channel_descriptions = ChannelCollection.to_list() if description_names is None \ else [ChannelCollection.get(name) for name in description_names] self._init_channel_description = ChannelCollection.get(kwargs.pop("init_channel_description", "WELCOME")) self._visitor_role_description = RoleCollection.get(kwargs.pop("visitor_role_description", "VISITOR")) super().__init__(**kwargs)
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
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
async def update_guild_channels(guild: Guild, delete_old=False, clear_references=True) -> bool: logger.info("Doing: update server channels") upd_ok = await update_channels(guild, CategoryChannelCollection.to_list() + ChannelCollection.to_list(), delete_old=delete_old, clear_references=clear_references) logger.info( f"Done{'' if upd_ok else ' with errors'}: update server channels") return upd_ok
async def clean_channels(channels, limit=None, ignore="default", force=None): if ignore == "default": ignore = [CategoryChannelCollection.MASTER.value, CategoryChannelCollection.DEV.value] ignore = ignore or [] force = force or [] filtered_channels = filter_channels(channels, ignore, force) logger.info(f"Cleaning channels {filtered_channels}") result = True for channel_enum in ChannelCollection.to_list(): channel = channel_enum.value.object_reference if channel is None or channel not in filtered_channels: continue if not await clean_channel(channel, limit): result = False logger.info("Channels cleared!") return result
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")