def edit_card(self, message): id = message['data']['id'] text = xhtml_unescape(message['data']['value'].strip()) clean_data = {'value': text, 'id': id} message_out = self.generate_message('editCard', clean_data) self.broadcast_to_all_room_user(self, message_out) room_id = self.rooms.get_room_id(self) self.cards.update_text(room_id, card_id=id, text=xhtml_escape(text)) sentence_generator = SentenceGenerator() res = sentence_generator.generate_sentence(text) for sent in res: message_out = self.generate_message('advice', {'sent': sent}) self.send_message(message_out) yield gen.sleep(2.5)
def create_card(self, message): user_id = self.get_current_user_id() message['data']['user_id'] = user_id message_out = self.generate_message('createCard', message['data']) self.broadcast(message_out) room_id = self.rooms.get_room_id(self) self.cards.add(room_id, message['data']) idea = Idea(card_id=message['data']['id']) idea.save() if message['data']['ai_switch']: sentence_generator = SentenceGenerator() res = yield from sentence_generator.generate_sentence( message['data']['text']) for sent in res: message_out = self.generate_message('advice', {'sent': sent}) self.send_message(message_out) yield from asyncio.sleep(2.5)