async def input_registration_data(external_id, massage): text = massage["text"].split() first_name = text[0] last_name = text[1] date = text[2] # try: # date = datetime.strptime('%d.%m.%Y', text[2]).strftime('%d.%m.%Y') # except: # send_message(external_id, "Напиши дату нормально") # return permission = 'user' response = await requests.post(app.config['USERS_DB_URL'] + 'signup', json={ 'first_name': first_name, 'last_name': last_name, 'external_id': external_id, 'date': date, 'permission': permission }) response = response.json() if not response['ok']: send_message(external_id, "Что-то пошло не так") await register() else: if (await login(external_id))['ok']: send_message(external_id, "Ок", get_start_markup(True))
async def notify(external_id, massage): response = await login(external_id) if response['ok'] and response['user'].permission == 'admin': massage = send_message(external_id, "Что отправим этим плебеям?") else: massage = send_message(external_id, "Эта команда для вас недоступна") return {"ok": True, "massage": massage}
async def register(external_id, massage): response = await login(external_id) if not response['ok']: app.logger.debug('register') updater.intercept_routing(external_id, process_register_dialog) process_register_dialog(external_id, massage) else: send_message(external_id, "Братик, да ты уже зарегистрирован", get_start_markup(True)) return {"ok": True}
def send_concerts_representation_message(chat_id, text, concerts, markup=None): if chat_id in concert_pagination.massage_id: delete_message(chat_id, concert_pagination.massage_id[chat_id]) resp = send_message(chat_id, text, markup) resp = resp.json() concert_pagination.set(concerts, chat_id, resp['result']['message_id'])
async def represent_profile(external_id, massage): await login(external_id) response = await requests.get(app.config['TICKETS_DB_URL'] + 'sold_tickets/' + str(external_id)) response = response.json() user_db_response = await login(external_id) if user_db_response['ok']: user = user_db_response['user'] text = f'{user.last_name} {user.first_name}\n\nБилеты:\n' if response['ok']: sold_tickets = response['sold_tickets'] for ticket in sold_tickets: text += f'{ticket["concert"]}\t{ticket["type"]} {ticket["count"]}шт\n' send_message(external_id, text) return {"ok": True} send_message(external_id, "Зарегистрируйтесь", get_start_markup(False)) return {"ok": False}
def handle_message(self, chat_id, input_text, restart=False): if restart: self.handlers.pop(chat_id, None) if chat_id in self.handlers: try: answer = self.handlers[chat_id].send(input_text) except StopIteration as e: del self.handlers[chat_id] if e.value: send_message(chat_id=chat_id, text=e.value[0], reply_markup=e.value[1]) return True else: answer = next(self.handlers[chat_id]) reply_markup = None text = answer if not isinstance(answer, str): text = answer[0] reply_markup = answer[1] send_message(chat_id=chat_id, text=text, reply_markup=reply_markup) return False
def input_notification(external_id, massage): text = massage["text"] response = requests.get(app.config['USERS_DB_URL'] + 'user') response = response.json() indices = [] if response['ok']: for user in response['users']: indices.append(user['external_id']) else: return {"ok": False} massages = [] for i in indices: ret = send_message(i, text) massages.append(ret) return {"ok": True, "massages": massages}
async def see_details(external_id, massage): send_message(external_id, concert_pagination.current(external_id), concert_markup)
async def request_city_to_find_concert(external_id, massage): send_message(external_id, "В каком городе будем искать?") return {"ok": True}
async def not_handled(external_id, massage): text = not_handled_answers[randint(0, len(not_handled_answers) - 1)] send_message(external_id, text, get_start_markup(True))
async def process_help_command(external_id, massage): send_message(external_id, "Привет") send_message(external_id, "Здесь ты можешь купить билеты", get_start_markup((await login(external_id))['ok'])) return {"ok": True}