async def toggle_key( self, message: Message, room1: str, room2: str, user: str ): connection = self.roleplay.get_connection(room1, room2) if not connection: await message.channel.send( f'No connection from {room1} to {room2}.' ) return config = State.get_config(message.guild.id) keys = config['connections'][connection.name]['k'] for member in message.mentions: if member.id not in keys: keys.append(member.id) await message.channel.send( f'{member.mention} can now lock and unlock the connection ' f'from {room1} to {room2}.' ) else: keys.remove(member.id) await message.channel.send( f'{member.mention} can no longer lock and unlock the ' f'connection from {room1} to {room2}.' ) State.save_config(message.guild.id, config) await self.bot.save_guild_config(message.guild, config) await message.delete()
async def hide(self, message: Message, location: str): config = State.get_config(message.guild.id) channel: TextChannel = message.channel connection = self.roleplay.get_connection(channel.name, location) if not connection: await channel.send( f'No connection from {channel.name} to {location}.', delete_after=60*60 ) return is_hidden = config['connections'][connection.name].get('h', False) if is_hidden: await channel.send( f'Connection from {channel.name} to {location} is already ' 'hidden.', delete_after=60*60 ) else: config['connections'][connection.name]['h'] = True State.save_config(message.guild.id, config) await self.bot.save_guild_config(message.guild, config) text = f'A connection between {channel.name} and {location} has ' \ f'been hidden.' await channel.send(text) await message.delete() await self.bot.get_chronicle(message.guild).log_announcement( channel, text )
async def _lock_or_unlock( self, message: Message, location: str, lock: bool = True ): config = State.get_config(message.guild.id) channel: TextChannel = message.channel connection = self.roleplay.get_connection(channel.name, location) if not connection: await channel.send( f'No connection from {channel.name} to {location}.', delete_after=60*60 ) return connection_config = config['connections'][connection.name] if not State.is_admin(message.author) \ and message.author.id not in connection_config['k']: await channel.send( f'{message.author.mention} does not have the key to ' f'{location}.', delete_after=60*60 ) return locked = connection_config['l'] if locked and lock or not locked and not lock: await channel.send( f'Access to {location} is already ' f'{"locked" if lock else "unlocked"}.', delete_after=60*60 ) return self._update_connection( config["connections"], channel.name, location, locked=lock ) State.save_config(message.guild.id, config) await self.bot.save_guild_config(message.guild, config) await channel.send( f'{"Locked" if lock else "Unlocked"} access to {location}.' ) await message.delete() name = 'the GM' \ if State.is_admin(message.author) else message.author.display_name await self.bot.get_chronicle(message.guild).log_announcement( channel, f'Access from **{message.channel.name}** to **{location}** ' f'{"" if lock else "un"}locked by **{name}**' )
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 )