def handle(self, content): Module.handle(self, content) if content == self._content["exit"]["text"]: session.clear() self._enqueue_response(self._content["exit"]["response"]) self._send()
def handle(self, content): Module.handle(self, content) sended = json.loads(session.get(self._sended_news_key, "[]")) to_send = None attempts = 0 while not to_send: try: new = self._get_new() except Exception: pass if new: to_send_hash = hashlib.md5(new["link"].encode()).hexdigest() if to_send_hash not in sended: to_send = new sended.append(to_send_hash) attempts = attempts + 1 if attempts >= self._max_attempts: break if to_send: session[self._sended_news_key] = json.dumps(sended) self._enqueue_response(to_send["title"]) self._enqueue_response(to_send["link"]) else: self._enqueue_response(self._content["not_found"]) self._enqueue_response(self._content["exit"]) self._send()
def handle(self, content): Module.handle(self, content) if not content: self._enqueue_response(self._content["introduction"]) self._enqueue_response_media( self._get_static_file(self._content["image"], self.NAME)) for content in self._content["contents"]: self._enqueue_response(content) self._enqueue_response(self._content["exit"]) self._send()
def handle(self, content): Module.handle(self, content) current_module = session.get(self._current_module_key, None) if not current_module: if content is None: self._welcome() elif content not in ["1", "2"]: self._enqueue_generic(self._content["menu"]) else: self._run_module(content, current_module) else: self._run_module(content, current_module) self._send()
def handle(self, content): Module.handle(self, content) index = session.get(self._last_message_key, 0) index = index + 1 messages = self._content["messages"] m = messages[index % len(messages)] self._enqueue_response(m["text"]) self._enqueue_response_media( self._get_static_file(m["image"], self.NAME)) self._enqueue_response(self._content["source"]) session[self._last_message_key] = index self._enqueue_response(self._content["exit"]) self._send()
def handle(self, content, menu): Module.handle(self, content) if self._cookie_key in session: for item in menu: if item["option"] == content: return True self._enqueue_response(self._content["ask_again"]) else: self._enqueue_response(self._content["welcome_message"]) session[self._cookie_key] = True menu_text = "\n".join( [f'{item["option"]} - {item["text"]}' for item in menu]) self._enqueue_response(menu_text) self._enqueue_response(self._content["how_to_response"]) self._send() return False
def handle(self, content): Module.handle(self, content) if not content: for content in self._content["contents"]: self._enqueue_response(content) index = session.get(self._last_image_index_key, 0) index = index + 1 images = self._content["images"] self._enqueue_response_media( self._get_static_file(images[index % len(images)], self.NAME) ) session[self._last_image_index_key] = index self._enqueue_response(self._content["exit"]) self._send()