async def move_reset(self, message, user: Optional[str]): move_timers = State.get_var(message.guild.id, 'move_timers') if not move_timers: move_timers = defaultdict(lambda: datetime.min) for player in message.mentions: move_timers[player.id] = datetime.min State.set_var(message.guild.id, 'move_timers', move_timers)
async def character(request: Request): try: guild_id = int(request.match_info['guild_id']) except (KeyError, ValueError): guild_id = None char = None if guild_id is not None: user_id = request.match_info['user_id'] character_id = request.match_info['character_id'] config = State.get_config(guild_id) characters_data = config.get('characters', {}) char = characters_data.get(user_id, {}).get('characters', {}).get(character_id) if char: move_timers = State.get_var(guild_id, 'move_timers') move_countdown_time = None if move_timers: move_countdown_time = move_timers.get(int(user_id)) char = { **char, "move_countdown_time": move_countdown_time.astimezone().isoformat() if move_countdown_time else "" } return {'character': char}
async def move(self, message: Message, room: Optional[str]): connections = State.get_config(message.guild.id)['connections'] channel: TextChannel = message.channel destinations = self._list_destinations(connections, channel.name) if not room: destination_list = '\n'.join( destination + (' *(locked)*' if locked else '') for destination, locked in destinations ) await channel.send( ( 'The following destinations are available from here:\n' + destination_list ) if destination_list else 'No destinations are currently available.', delete_after=60*60 ) await message.delete() return for destination, locked in destinations: if destination == room: if locked: await channel.send( f'{room} is currently locked off.', delete_after=60*60 ) await message.delete() return break else: await channel.send( f'Cannot reach {room} from here.', delete_after=60*60 ) return move_timers = State.get_var(message.guild.id, 'move_timers') if not move_timers: move_timers = defaultdict(lambda: datetime.min) time_remaining = ( move_timers[message.author.id] - datetime.now() ).total_seconds() if time_remaining > 0: minutes = time_remaining // 60 await channel.send( 'Must wait ' + ( f'{int(minutes)} minutes' if minutes else f'{int(time_remaining)} seconds' ) + ' before moving again.', delete_after=60*60 ) return connection = self.roleplay.get_connection(channel.name, room) new_channel = await self._move_player( message.author, room, message.channel ) move_timers[message.author.id] = datetime.now() + timedelta( minutes=connection.timer ) State.set_var(message.guild.id, 'move_timers', move_timers) await channel.send(f'{message.author.mention} moves to {room}') await new_channel.send( f'{message.author.mention} moves in from {channel.name}' ) await message.delete()