async def end_game(self, message: Message): loading_message = await message.channel.send(f'Ending game...') config = {} guild: Guild = message.guild State.save_config(guild.id, config) State.save_plugins(guild.id, []) await self.bot.save_guild_config(guild, config) player_role = State.get_player_role(guild.id) observer_role = State.get_observer_role(guild.id) for player in player_role.members: await player.remove_roles(player_role) await player.add_roles(observer_role) await message.channel.send(f'The game ends.') await loading_message.delete() await message.delete() await self.bot.refresh_from_config(guild, config)
async def refresh_from_config( self, guild: Guild, config: Dict[str, Any], force_reset=False ): logging.info(f'Refreshing server state from config for {guild.name}') State.save_config(guild.id, config) if 'rp' not in config or not config['rp']: return modified_config = False roleplay = self.roleplays[config['rp']] if 'connections' not in config: config['connections'] = {} modified_config = True for connection in roleplay.connections: if connection.name not in config['connections']: config['connections'][connection.name] = { 'h': connection.hidden, 'l': connection.locked, 'k': [] } modified_config = True if modified_config: State.save_config(guild.id, config) await self.save_guild_config(guild, config) # Pick all the plugins required by the roleplay plugins = [] plugin_configs = roleplay.plugins if plugin_configs: for plugin_id, plugin_config \ in plugin_configs.items(): # noinspection PyArgumentList plugins.append( self.plugins[plugin_id]( self, roleplay, **plugin_config ) ) State.save_plugins(guild.id, plugins) # Ensure the server state matches gm_role = await self.create_or_update_role(guild, roleplay.roles['gm']) player_role = await self.create_or_update_role( guild, roleplay.roles['player'] ) observer_role = await self.create_or_update_role( guild, roleplay.roles['observer'] ) State.save_roles(guild.id, gm_role, player_role, observer_role) sections: Dict[str, CategoryChannel] = { c.name: c for c in guild.categories } for channel_id, room in roleplay.rooms.items(): source = guild if room.section: if room.section not in sections: sections[room.section] = await guild.create_category( room.section, ) section = sections[room.section] source = section channel: TextChannel = next( (c for c in source.text_channels if c.name == channel_id), None ) overwrites = { guild.default_role: PermissionOverwrite( read_messages=False ), self.user: PermissionOverwrite(read_messages=True), gm_role: PermissionOverwrite( read_messages=True, send_messages=True ), observer_role: PermissionOverwrite( read_messages=True, send_messages=False ) } if channel: if not force_reset: continue await channel.edit(topic=room.description) for target, overwrite in overwrites.items(): await channel.set_permissions(target, overwrite=overwrite) else: await source.create_text_channel( channel_id, topic=room.description, overwrites=overwrites )