def test_answer_handler(call): user = Botuser(uid=call.message.chat.id, bot=bot) try: starting_helper.first_post_handler(call=call, user=user, bot=bot) except: logging.exception(str(call)) logging.exception('Got exception on main handler') user.send_message(message_index="ERROR_MESSAGE")
def simpletextmessage(m): user = Botuser(uid=m.chat.id, bot=bot) try: starting_helper.text_message_handler(user=user, message=m, bot=bot, input_value=m.text) except: logging.exception(str(m)) logging.exception('Got exception on main handler') user.send_message(message_index="ERROR_MESSAGE")
def sendpostbyindex(m): user = Botuser(uid=m.chat.id, bot=bot) try: enter_custom_post_index(user) except: logging.exception(str(m)) logging.exception('Got exception on main handler') user.send_message(message_index="ERROR_MESSAGE")
def handlestart(m): user = Botuser(uid=m.chat.id, bot=bot) try: starting_helper.stating_handler(user=user, message=m) except: logging.exception(str(m)) logging.exception('Got exception on main handler') user.send_message(message_index="ERROR_MESSAGE")
def handlestart(m): try: user = Botuser(uid=m.chat.id, bot=bot) last_name = m.from_user.last_name first_name = m.from_user.first_name username = m.from_user.username user.join_aggrbot(last_name=last_name, first_name=first_name, username=username, ref_key='Notset', lang='rus' ) bot.send_message(chat_id=m.chat.id, text='Привет. Чат бот находится в разработке, скоро все будет готово') except: logging.exception(str(m)) logging.exception('Got exception on main handler')
def get_active_notifications(self): while True: Dbconnetor.execute_insert_query("SET TIME ZONE 'Europe/Moscow';") notifications = Dbconnetor.execute_select_many_query( """SELECT request_id, sender_user_id, message_text FROM toparents_bot.user_requests WHERE request_status = 'NEW'""") for notification in notifications: admin_list = Botuser.get_admins() request_text = notification[2] sender_id = notification[1] request_id = notification[0] sender_username = Botuser.get_username(sender_id) send_text = ('#request\nОТ: {}\n\n{}'.format( sender_username, request_text)) for admin in admin_list: user = Botuser(uid=admin, bot=self.bot) keyboard = KeyboardHelper.reply_to_user_request_keyboard( user=user, sender_id=sender_id, request_id=request_id) sent_message = user.send_message(chat_id=user.uid, text=send_text, keyboard=keyboard) user.save_request_message( request_id=request_id, admin_id=user.uid, message_id=sent_message.message_id) time.sleep(1) Dbconnetor.execute_insert_query( "UPDATE toparents_bot.user_requests SET request_status = 'SENT' WHERE request_id = '{}' " .format(request_id)) time.sleep(5)
def handlestart(m): user = Botuser(uid=m.chat.id, bot=bot) try: user.send_select_lang_message() except: logging.exception(str(m)) logging.exception('Got exception on main handler') user.send_message(message_index="ERROR_MESSAGE")
def handlestart(m): user = Botuser(uid=m.chat.id, bot=bot) try: user.reset_results() if user.isauth(): question_to_send = user.select_question_number_to_send() user.send_question(question_num=question_to_send) else: user.send_select_lang_message() except: logging.exception(str(m)) logging.exception('Got exception on main handler') user.send_message(message_index="ERROR_MESSAGE")
def handlestart(m): user = Botuser(uid=m.chat.id, bot=bot) try: if user.isauth(): max_count_questions = dbconnector.count_questions() max_count_additional_questions = dbconnector.count_additional_questions( ) question_to_send = user.select_question_number_to_send() additional_question_to_send = user.select_addtional_question_number_to_send( ) if question_to_send <= max_count_questions: user.send_question(question_num=question_to_send) elif additional_question_to_send <= max_count_additional_questions: user.send_additional_question( question_num=additional_question_to_send, test_type='ADD_TEST') else: user.send_message('GO_TO_AGGR') else: ref_key = m.text.replace('/start ', '') if ref_key == ('/start'): ref_key = None last_name = m.from_user.last_name first_name = m.from_user.first_name username = m.from_user.username starting_helper.check_status(user=user, ref_key=ref_key, last_name=last_name, first_name=first_name, username=username) except: logging.exception(str(m)) logging.exception('Got exception on main handler') user.send_message(message_index="ERROR_MESSAGE")
def test_answer_handler(call): try: data = call.data.split('_') answer = data[1] next_question_num = int(data[2]) user = Botuser(uid=call.message.chat.id, bot=bot) user.save_answer(question_num=next_question_num - 1, answer=answer, test_type='MAIN_TEST') max_count_questions = dbconnector.count_questions() edit_text = user.select_question(question_num=next_question_num - 1, test_type='MAIN_TEST') bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=edit_text) if next_question_num <= max_count_questions: user.send_question(question_num=next_question_num) else: user.send_main_test_results() time.sleep(5) user.send_message('ADD_TEST_START') user.send_additional_question(question_num=1, test_type='ADD_TEST') except: logging.exception(str(call)) logging.exception('Got exception on main handler') user.send_message(message_index="ERROR_MESSAGE")
def test_answer_handler(call): try: lang = call.data[5:] user = Botuser(uid=call.message.chat.id, bot=bot) first_name = call.from_user.first_name username = call.from_user.username last_name = call.from_user.last_name user.join_to_bot_users(lang=lang, last_name=last_name, first_name=first_name, username=username) if not user.isauth(): send_message = user.select_message('JOIN_MESSAGE') else: send_message = ('ok') bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=send_message) max_count_questions = dbconnector.count_questions() max_count_additional_questions = dbconnector.count_additional_questions( ) question_to_send = user.select_question_number_to_send() additional_question_to_send = user.select_question_number_to_send() if question_to_send <= max_count_questions: user.send_question(question_num=question_to_send) elif additional_question_to_send <= max_count_additional_questions: user.send_additional_question(question_num=question_to_send, test_type='ADD_TEST') else: user.send_message('GO_TO_AGGR') except: logging.exception(str(call)) logging.exception('Got exception on main handler') user.send_message(message_index="ERROR_MESSAGE")