async def chat_join(self, event): if not (event["username"] == self.scope["user"].username): await self.send_json( { "msg_type": 'ENTER', "username": colorize('brightBlue', event["username"]), }, )
async def send_global(self, message): if not self.isOnline: raise Exception('Rejected') now = datetime.datetime.now() try: time_since_last_global = now - self.last_global time_left = 10 - time_since_last_global.seconds if time_left > 0: await self.send_message( f"Please wait {time_left} seconds to do that...") return else: self.last_global = now except AttributeError: self.last_global = now text = colorize('brightRed', self.scope["user"].username ) + " -> ALL: \"" + " ".join(message) + '"' await self.channel_layer.group_send( 'dungeon', { "type": "chat.message", "username": self.scope["user"].username, "message": text, })
async def send_welcome(self): await self.send_json( {'message': colorize('brightBlue', ART['BANNER'])}) await self.send_json({ 'message': f"Hello {colorize('brightMagenta', self.player.name)}" })
async def send_help(self): options = [ 'help', 'status', 'look', 'go <room/number>', 'say <message>', 'send <message>', 'global <message>', 'leave' ] await self.send_message("COMMANDS: \r\n " + colorize("brightGreen", "\n ".join(options)) )
async def chat_leave(self, event): """ Called when someone has left our chat. """ # Send a message down to the client if not (event["username"] == self.scope["user"].username): await self.send_json( { "msg_type": 'EXIT', "username": colorize('brightBlue', event["username"]), }, )
async def send_room(self, message): if not self.isOnline: raise Exception('Rejected') text = colorize('brightBlue', self.scope["user"].username ) + " says, \"" + " ".join(message) + '"' await self.channel_layer.group_send( await self.get_current_room_name(), { "type": "chat.message", "username": self.scope["user"].username, "message": text, })