Example #1
0
File: bot.py Project: mmdaz/Bot
def get_debt_date_day(bot, update):
    user_peer = update.get_effective_user()
    debt_day = update.get_effective_message()
    dispatcher.set_conversation_data(update, "debt_day", debt_day.text)
    if not ((0 < int(debt_day.text) < 32 and 0 < int(
            dispatcher.get_conversation_data(update, "debt_month")) < 7) or
            (0 < int(debt_day.text) < 31 and 6 < int(
                dispatcher.get_conversation_data(update, "debt_month")) < 13)):
        bot.send_message(TemplateMessage(Message.INVALID_INPUT, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_debt_date_day),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
    else:
        dispatcher.get_conversation_data(
            update, "debt").date = "{}:{}:{}".format(
                dispatcher.get_conversation_data(update, "debt_year"),
                dispatcher.get_conversation_data(update, "debt_month"),
                dispatcher.get_conversation_data(update, "debt_day"))
        print(dispatcher.get_conversation_data(update, "debt").user_id)
        bot.send_message(TemplateMessage(Message.GET_DEBT_PHOTO, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(PhotoFilter(), get_debt_photo),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
Example #2
0
File: bot.py Project: mmdaz/Bot
def get_date_minute(bot, update):
    minute = update.get_effective_message().text
    dispatcher.set_conversation_data(update, "minute", minute)
    user_peer = update.get_effective_user()
    if not 0 <= int(minute) < 60:
        bot.send_message(TemplateMessage(Message.INVALID_INPUT, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_date_minute),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
    else:
        # print(create_time(year, month, day, hour, minute))
        dispatcher.get_conversation_data(
            update, "alarm").start_time = create_time(
                dispatcher.get_conversation_data(update, "year"),
                dispatcher.get_conversation_data(update, "month"),
                dispatcher.get_conversation_data(update, "day"),
                dispatcher.get_conversation_data(update, "hour"),
                dispatcher.get_conversation_data(update, "minute"))
        bot.send_message(TemplateMessage(Message.GET_ALARM_REPETITION_PERIOD,
                                         button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), finish_creating_alarm),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
Example #3
0
File: bot.py Project: mmdaz/Bot
def get_date_day(bot, update):
    day = update.get_effective_message().text
    dispatcher.set_conversation_data(update, "day", day)
    user_peer = update.get_effective_user()
    if not (
        (0 < int(day) < 32
         and 0 < int(dispatcher.get_conversation_data(update, "month")) < 7) or
        (0 < int(day) < 31
         and 6 < int(dispatcher.get_conversation_data(update, "month")) < 13)):
        bot.send_message(TemplateMessage(Message.INVALID_INPUT, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_date_day),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
    else:
        bot.send_message(TemplateMessage(Message.GET_ALARM_HOUR, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_date_hour),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
def request_money_changer(bot, update):
    user_peer = update.get_effective_user()
    sender_name = update.get_effective_message().text
    dispatcher.set_conversation_data(update,
                                     key="sender_name",
                                     value=sender_name)
    money_changers = select_ready_money_changers()
    buttons_list, keywords = get_buttons_from_money_changers(money_changers)
    if buttons_list:
        buttons_list += [BotButtons.back_to_main_menu]
        template_message = TemplateMessage(
            TextMessage(BotTexts.choose_one_money_changer), buttons_list)
        send_message(message=template_message,
                     peer=user_peer,
                     step=Step.request_money_changer)
        dispatcher.register_conversation_next_step_handler(
            update,
            handlers=common_handlers + [
                MessageHandler(TemplateResponseFilter(keywords=keywords),
                               request_province)
            ])
    else:
        buttons_list += [BotButtons.back_to_main_menu]
        template_message = TemplateMessage(
            TextMessage(BotTexts.no_money_changer_found), buttons_list)
        send_message(message=template_message,
                     peer=user_peer,
                     step=Step.request_money_changer)
        dispatcher.finish_conversation(update)
Example #5
0
File: bot.py Project: mmdaz/Bot
def get_date_hour(bot, update):
    hour = update.get_effective_message().text
    dispatcher.set_conversation_data(update, "hour", hour)
    user_peer = update.get_effective_user()
    if not 0 <= int(hour) < 24:
        bot.send_message(TemplateMessage(Message.INVALID_INPUT, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_date_hour),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
    else:
        bot.send_message(TemplateMessage(Message.GET_ALARM_MINUTE,
                                         button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_date_minute),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
Example #6
0
File: bot.py Project: mmdaz/Bot
def get_alarm_stop_message(bot, update):
    user_peer = update.get_effective_user()
    alarm_stop_message = update.get_effective_message()
    if check_stop_message_repetition(user_peer.get_json_str(),
                                     alarm_stop_message.text):
        bot.send_message(TemplateMessage(Message.STOP_MESSAGE_REPETIOTION,
                                         button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_alarm_stop_message),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
    else:
        dispatcher.get_conversation_data(
            update, "alarm").stop_message = alarm_stop_message.text
        bot.send_message(TemplateMessage(Message.GET_ALARM_PHOTO, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(PhotoFilter(), get_alarm_photo),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
Example #7
0
File: bot.py Project: mmdaz/Bot
def get_date_year(bot, update):
    user_peer = update.get_effective_user()
    year = update.get_effective_message().text
    dispatcher.set_conversation_data(update, "year", year)
    if int(year) < 1397:
        bot.send_message(TemplateMessage(Message.INVALID_INPUT, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_date_year),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
        print("salammmmmmmmmmmmmmmmmmmmmmmmmm")

    else:
        bot.send_message(TemplateMessage(Message.GET_ALARM_MONTH, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_date_month),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
Example #8
0
File: bot.py Project: mmdaz/Bot
def get_debt_date_month(bot, update):
    user_peer = update.get_effective_user()
    debt_month = update.get_effective_message()
    dispatcher.set_conversation_data(update, "debt_month", debt_month.text)
    if not (0 < int(debt_month.text) < 13):
        bot.send_message(TemplateMessage(Message.INVALID_INPUT, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_debt_date_month),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
    else:
        bot.send_message(TemplateMessage(Message.GET_DEBT_DAY, button_list),
                         user_peer,
                         success_callback=success,
                         failure_callback=failure)
        dispatcher.register_conversation_next_step_handler(
            update, [
                MessageHandler(TextFilter(), get_debt_date_day),
                MessageHandler(TemplateResponseFilter(keywords="/start"),
                               start_bot)
            ])
def show_current_money_branches(bot, update):
    user_peer = update.get_effective_user()
    money_changer = select_money_changer_by_peer_id(user_peer.peer_id)
    branches = select_branches_by_money_changer_id(
        money_changer_id=money_changer.id)
    dispatcher.set_conversation_data(update, "branches", branches)
    if branches:
        branches_buttons, keywords = get_template_buttons_from_branches(
            branches)
        template_message = TemplateMessage(
            TextMessage(BotTexts.choose_branch_for_remove), branches_buttons)
        send_message(message=template_message,
                     peer=user_peer,
                     step=Step.request_province_name)
        dispatcher.register_conversation_next_step_handler(
            update,
            handlers=common_handlers + [
                MessageHandler(TemplateResponseFilter(keywords=keywords),
                               remove_money_branch)
            ])
    else:
        buttons_list = [BotButtons.back_to_main_menu]
        template_message = TemplateMessage(
            TextMessage(BotTexts.no_branches_found), buttons_list)
        send_message(message=template_message,
                     peer=user_peer,
                     step=Step.request_province_name)
        dispatcher.finish_conversation(update)
def update_money_changer(bot, update):
    user_peer = update.get_effective_user()
    text_entered = arabic_to_eng_number(update.get_effective_message().text)
    previous_state = dispatcher.get_conversation_data(update, "previous_state")
    money_changer = select_money_changer_by_peer_id(user_peer.peer_id)
    res = None
    text_message = None
    if previous_state == request_remittance_fee_percent:
        percent = float(text_entered)
        res = update_money_changer_remittance_fee_percent(
            money_changer=money_changer, percent=percent)
        text_message = TextMessage(
            BotTexts.remittance_fee_percent_updated_successfully.format(
                percent))
    elif previous_state == request_dollar_rial:
        dollar_rial = float(text_entered)
        res = update_money_changer_dollar_rial(money_changer=money_changer,
                                               dollar_rial=dollar_rial)
        text_message = TextMessage(
            BotTexts.dollar_rial_updated_successfully.format(dollar_rial))
    elif previous_state == request_dollar_afghani:
        dollar_afghani = float(text_entered)
        res = update_money_changer_dollar_afghani(
            money_changer=money_changer, dollar_afghani=dollar_afghani)
        text_message = TextMessage(
            BotTexts.dollar_afghani_updated_successfully.format(
                dollar_afghani))
    elif previous_state == request_card_number:
        card_number = text_entered
        res = update_money_changer_card_number(money_changer=money_changer,
                                               card_number=card_number)
        text_message = TextMessage(
            BotTexts.card_number_updated_successfully.format(card_number))
    if res:
        buttons_list = [BotButtons.back_to_main_menu]
        template_message = TemplateMessage(text_message, buttons_list)
        send_message(message=template_message,
                     peer=user_peer,
                     step=Step.update_money_changer)
        dispatcher.register_conversation_next_step_handler(
            update,
            handlers=common_handlers + [
                MessageHandler(TextFilter(Patterns.float_numbers),
                               request_sender_name)
            ])
    else:
        buttons_list = [BotButtons.back_to_main_menu]
        template_message = TemplateMessage(TextMessage(BotTexts.error),
                                           buttons_list)
        send_message(message=template_message,
                     peer=user_peer,
                     step=Step.update_money_changer)
        dispatcher.finish_conversation(update)
Example #11
0
def send_tweet(bot, update):
    user_peer = update.get_effective_user()
    user_id = user_peer.peer_id
    tweet_text = update.get_effective_message().text
    user = get_user(user_id=user_id)
    if send_tweet_api(final_oauth_token=user.final_oauth_token,
                      final_oauth_token_secret=user.final_oauth_token_secret,
                      tweet_text=tweet_text):
        general_message = TextMessage(ReadyMessage.success_tweet)
    else:
        general_message = TextMessage(ReadyMessage.fail_tweet)
    btn_list = [
        TemplateMessageButton(text=TMessage.back,
                              value=TMessage.back,
                              action=0)
    ]
    template_message = TemplateMessage(general_message=general_message,
                                       btn_list=btn_list)
    kwargs = {
        "message": template_message,
        "user_peer": user_peer,
        "try_times": 1
    }
    bot.send_message(template_message,
                     user_peer,
                     success_callback=success,
                     failure_callback=failure,
                     kwargs=kwargs)
    dispatcher.finish_conversation(update)
Example #12
0
def search_tweets(bot, update):
    query = update.get_effective_message().text
    user = dispatcher.get_conversation_data(update, "user")
    statuses = search_api(user=user, query=query)

    statuses = statuses.get("statuses")
    if statuses:
        loop = asyncio.get_event_loop()
        loop.call_soon(send_status_message, 0, loop, statuses, bot, update)
        dispatcher.finish_conversation(update)
    else:
        btn_list = [
            TemplateMessageButton(text=ButtonText.back,
                                  value=ButtonText.back,
                                  action=0)
        ]
        general_message = TextMessage(ReadyText.no_search_result)
        template_message = TemplateMessage(general_message=general_message,
                                           btn_list=btn_list)
        kwargs = {
            "message": template_message,
            "update": update,
            "bot": bot,
            "try_times": 1
        }
        bot.respond(update,
                    template_message,
                    success_callback=success_send_message,
                    failure_callback=failure_send_message,
                    kwargs=kwargs)
        dispatcher.finish_conversation(update)
Example #13
0
File: bot.py Project: mmdaz/Bot
def start_bot(bot, update):
    user_peer = update.get_effective_user()
    input = update.get_effective_message()
    print(input.text)
    btn_list = [
        TemplateMessageButton("ساختن هشدار جدید ", "/create_alarm", 0),
        TemplateMessageButton("اضافه کردن بدهی ", "/add_debt", 0),
        TemplateMessageButton("گرفتن فایل اکسل صورتحساب ها  ", "/get_excel", 0)
    ]
    temlate_message = TemplateMessage(
        general_message=Message.START_BOT_MESSAGE, btn_list=btn_list)
    bot.send_message(temlate_message,
                     user_peer,
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(update, [
        MessageHandler(TemplateResponseFilter(keywords=["/create_alarm"]),
                       start_creating_alarm),
        MessageHandler(TemplateResponseFilter(keywords=["/add_debt"]),
                       start_get_debt_conversation),
        MessageHandler(TemplateResponseFilter(keywords=["/get_excel"]),
                       send_excel_report),
        MessageHandler(TextFilter(keywords=["/start"]), start_bot),
        MessageHandler(TemplateResponseFilter(keywords=["/start"]), start_bot)
    ])
Example #14
0
def send_tweet(bot, update):
    user_peer = update.get_effective_user()
    tweet_text = update.get_effective_message().text
    user = dispatcher.get_conversation_data(update, "user")
    if send_tweet_api(user=user, tweet_text=tweet_text):
        general_message = TextMessage(ReadyText.success_tweet)
    else:
        general_message = TextMessage(ReadyText.fail_tweet)
    btn_list = [
        TemplateMessageButton(text=ButtonText.back,
                              value=ButtonText.back,
                              action=0)
    ]
    template_message = TemplateMessage(general_message=general_message,
                                       btn_list=btn_list)
    kwargs = {
        "message": template_message,
        "update": update,
        "bot": bot,
        "try_times": 1
    }
    bot.send_message(template_message,
                     user_peer,
                     success_callback=success_send_message,
                     failure_callback=failure_send_message,
                     kwargs=kwargs)
    dispatcher.finish_conversation(update)
Example #15
0
def get_tweet_text(bot, update):
    user_peer = update.get_effective_user()
    user = get_registered_user(bot, update)
    if user:
        dispatcher.set_conversation_data(update, "user", user)
        general_message = TextMessage(ReadyText.send_text_twitter)
        btn_list = [
            TemplateMessageButton(text=ButtonText.cancel,
                                  value=ButtonText.cancel,
                                  action=0)
        ]
        template_message = TemplateMessage(general_message=general_message,
                                           btn_list=btn_list)
        kwargs = {
            "message": template_message,
            "update": update,
            "bot": bot,
            "try_times": 1
        }
        bot.send_message(template_message,
                         user_peer,
                         success_callback=success_send_message,
                         failure_callback=failure_send_message,
                         kwargs=kwargs)
        dispatcher.register_conversation_next_step_handler(
            update, common_handlers + [
                MessageHandler(TextFilter(), send_tweet),
                MessageHandler(DefaultFilter(), start_conversation)
            ])
Example #16
0
def verify(bot, update):
    user_peer = update.get_effective_user()
    auth = dispatcher.get_conversation_data(update, "auth")
    oauth_verifier = update.get_effective_message().text
    final_dict = final_verify(oauth_verifier=oauth_verifier, auth=auth)
    new_user = User(peer_id=int(user_peer.peer_id),
                    access_hash=user_peer.access_hash,
                    twitter_user_id=final_dict.get('user_id'),
                    screen_name=final_dict.get('screen_name'),
                    oauth_token=final_dict.get('oauth_token'),
                    oauth_token_secret=final_dict.get('oauth_token_secret'))
    result = User.add_new_user(new_user)
    if result and result == ReadyText.register_before:
        general_message = TextMessage(ReadyText.register_before)
    elif result:
        general_message = TextMessage(ReadyText.success_insert_user)
    else:
        general_message = TextMessage(ReadyText.failure_insert_user)
    message = TemplateMessage(general_message=general_message,
                              btn_list=main_menu)
    kwargs = {"message": message, "update": update, "bot": bot, "try_times": 1}
    bot.send_message(message,
                     user_peer,
                     success_callback=success_send_message,
                     failure_callback=failure_send_message,
                     kwargs=kwargs)
    dispatcher.finish_conversation(update)
Example #17
0
    def initiate_search_officers(self, bot, update):
        self.handlers.extend(self.dispatcher.message_handlers)
        user = update.get_effective_user()
        message = TemplateMessage(
            TextMessage(ConstantMessage.officer_search_criterion), [
                TemplateMessageButton(ButtonMessage.all_officers),
                TemplateMessageButton(ButtonMessage.main_menu_message)
            ])
        self.send_message(bot, update, message, user,
                          sys._getframe().f_code.co_name)
        self.handlers.extend([
            MessageHandler(
                TemplateResponseFilter(keywords=[ButtonMessage.all_officers]),
                self.handle_customer_criterion_input),
            MessageHandler(
                TemplateResponseFilter(
                    keywords=[ButtonMessage.main_menu_message]),
                self.show_menu),
        ])

        # TODO: This seems odd to me to add two lists, find a better way if possible
        self.dispatcher.register_conversation_next_step_handler(
            update, self.handlers + [
                MessageHandler(TextFilter(),
                               self.handle_customer_criterion_input)
            ])
Example #18
0
def start_conversation(bot, update):
    user_peer = update.get_effective_user()
    general_message = TextMessage(ReadyMessage.start_conversation)
    btn_list = [
        TemplateMessageButton(text=TMessage.send_tweet,
                              value=TMessage.send_tweet,
                              action=0),
        TemplateMessageButton(text=TMessage.get_home_time_line,
                              value=TMessage.get_home_time_line,
                              action=0),
        TemplateMessageButton(text=TMessage.search,
                              value=TMessage.search,
                              action=0),
        TemplateMessageButton(text=TMessage.info,
                              value=TMessage.info,
                              action=0)
    ]
    template_message = TemplateMessage(general_message=general_message,
                                       btn_list=btn_list)
    kwargs = {
        "message": template_message,
        "user_peer": user_peer,
        "try_times": 1
    }
    bot.send_message(template_message,
                     user_peer,
                     success_callback=success,
                     failure_callback=failure,
                     kwargs=kwargs)
    dispatcher.finish_conversation(update)
Example #19
0
def get_tweet_text(bot, update):
    user_peer = update.get_effective_user()
    user_id = user_peer.peer_id
    user = get_user(user_id=user_id)
    if not check_user_registration(update, user_peer, user):
        return 0
    general_message = TextMessage(ReadyMessage.send_text_twitter)
    btn_list = [
        TemplateMessageButton(text=TMessage.cancel,
                              value=TMessage.cancel,
                              action=0)
    ]
    template_message = TemplateMessage(general_message=general_message,
                                       btn_list=btn_list)
    kwargs = {
        "message": template_message,
        "user_peer": user_peer,
        "try_times": 1
    }
    bot.send_message(template_message,
                     user_peer,
                     success_callback=success,
                     failure_callback=failure,
                     kwargs=kwargs)
    dispatcher.register_conversation_next_step_handler(update, [
        CommandHandler("info", info),
        MessageHandler(TextFilter(), send_tweet),
        MessageHandler(DefaultFilter(), start_conversation)
    ])
Example #20
0
    def show_menu(self, bot, update, response=None, user_data=None):
        self.dispatcher.clear_conversation_data(update=update)

        user_peer = update.get_effective_user()
        if not User.exists(user_peer.peer_id):
            session.add(
                User(peer_id=user_peer.peer_id,
                     access_hash=user_peer.access_hash))
            session.commit()

        categories = session.query(Category).all()
        category_list = [
            TemplateMessageButton(category.description)
            for category in categories
        ]
        message = TemplateMessage(TextMessage(ConstantMessage.menu_message),
                                  category_list)
        kwargs = {
            'update': update,
            'user_id': user_peer.peer_id,
            'step': sys._getframe().f_code.co_name
        }
        bot.send_message(message,
                         user_peer,
                         success_callback=self.success_sending_message,
                         failure_callback=self.failure_send_message,
                         **kwargs)
def money_changer_panel(bot, update):
    user_peer = update.get_effective_user()

    money_changer = select_money_changer_by_peer_id(user_peer.peer_id)
    buttons_list = [
        BotButtons.register_branch, BotButtons.update_card_number,
        BotButtons.update_dollar_rial, BotButtons.update_dollar_afghani,
        BotButtons.update_remittance_fee_percent, BotButtons.remove_branch,
        BotButtons.help
    ]
    dollar_rial = money_changer.dollar_rial
    remittance_fee_percent = money_changer.remittance_fee_percent
    dollar_afghani = money_changer.dollar_afghani
    if not money_changer.dollar_rial:
        dollar_rial = BotTexts.undefined
    if not money_changer.dollar_afghani:
        dollar_afghani = BotTexts.undefined
    if not money_changer.remittance_fee_percent:
        remittance_fee_percent = BotTexts.undefined
    text = BotTexts.money_changer_info.format(money_changer.name,
                                              money_changer.card_number,
                                              dollar_rial, dollar_afghani,
                                              remittance_fee_percent)
    text = eng_to_arabic_number(text)
    text += BotTexts.choose_one_option
    template_message = TemplateMessage(TextMessage(text), buttons_list)
    send_message(message=template_message,
                 peer=user_peer,
                 step=Step.start_bot_for_logged_in_users)
    dispatcher.finish_conversation(update)
Example #22
0
File: bot.py Project: mmdaz/Bot
async def send_alarm(bot=dispatcher.bot):
    while (True):
        current_time = jdatetime.datetime.now()
        if current_time.hour == 21:
            for debt in search_debt_for_send(current_time):
                user_peer = Peer.load_from_json(debt.user_id)
                target_photo = get_photo_by_id(debt.photo_id)
                photo_message = PhotoMessage(
                    target_photo.file_id, target_photo.access_hash,
                    target_photo.name, target_photo.file_size,
                    target_photo.mime_type, target_photo.thumb,
                    target_photo.width, target_photo.height,
                    target_photo.ext_width, target_photo.ext_height,
                    target_photo.file_storage_version,
                    TextMessage(target_photo.caption_text),
                    target_photo.checksum, target_photo.algorithm)
                photo_message.caption_text = TextMessage(debt.creditor_name)
                purchase_message = PurchaseMessage(photo_message,
                                                   debt.card_number,
                                                   debt.amount,
                                                   MoneyRequestType.normal)
                bot.send_message(purchase_message,
                                 user_peer,
                                 success_callback=success,
                                 failure_callback=failure)
                bot.send_message(TemplateMessage(
                    TextMessage("بازگشت به منوی اصلی "), btn_list=button_list),
                                 user_peer,
                                 success_callback=success,
                                 failure_callback=failure)

        for alarm in search_alarm_for_send(current_time):
            user_peer = Peer.load_from_json(alarm.user_id)
            update_alarm_time(alarm)
            photo = PhotoMessage.load_from_json(alarm.photo_json)
            photo.caption_text = TextMessage(alarm.message)
            bot.send_message(photo,
                             user_peer,
                             success_callback=success,
                             failure_callback=failure)
            bot.send_message(TemplateMessage(
                TextMessage("بازگشت به منوی اصلی "), btn_list=button_list),
                             user_peer,
                             success_callback=success,
                             failure_callback=failure)

        await asyncio.sleep(30)
def help_me(bot, update):
    user_peer = update.get_effective_user()
    buttons_list = [BotButtons.back_to_main_menu]
    template_message = TemplateMessage(general_message=TextMessage(
        BotTexts.help_message),
                                       btn_list=buttons_list)
    send_message(message=template_message, peer=user_peer, step=Step.help)
    dispatcher.register_conversation_next_step_handler(
        update, handlers=common_handlers)
    def handle_report_begin_date(self, bot, update):
        user = update.get_effective_user()
        message = arabic_to_eng_number(update.get_effective_message().text)
        if re.match(RegexPattern.interval_pattern, message):
            split_message = message.split('-')
            self.dispatcher.set_conversation_data(
                update=update,
                key='start_time_delta',
                value=split_message[0]
            )
            self.dispatcher.set_conversation_data(
                update=update,
                key='end_time_delta',
                value=split_message[1]
            )
            self.create_and_send_final_report(update, bot)

        else:
            row_date = re.match(RegexPattern.jalali_input_pattern, message)
            if row_date:
                message = TemplateMessage(
                    TextMessage(ConstantMessage.service_report_end_date),
                    [TemplateMessageButton(ButtonMessage.main_menu_message)]
                )
                self.dispatcher.set_conversation_data(
                    update=update,
                    key='begin_date',
                    value=row_date
                )
                self.send_message(
                    bot,
                    update,
                    message,
                    user,
                    sys._getframe().f_code.co_name
                )
                self.dispatcher.register_conversation_next_step_handler(
                    update,
                    self.handlers +
                    [
                        MessageHandler(
                            TextFilter(),
                            self.handle_report_end_date
                        ),
                    ]
                )

            else:
                message = TextMessage(ConstantMessage.bad_format)
                self.send_message(
                    bot,
                    update,
                    message,
                    user,
                    sys._getframe().f_code.co_name
                )
Example #25
0
File: bot.py Project: mmdaz/Bot
def start_get_debt_conversation(bot, update):
    user_peer = update.get_effective_user()
    debt = Debt("", "", "", "", "", "", "")
    dispatcher.set_conversation_data(update, "debt", debt)
    debt.user_id = user_peer.get_json_str()
    bot.send_message(TemplateMessage(Message.GET_DEBT_AMOUNT, button_list),
                     user_peer,
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(update, [
        MessageHandler(TextFilter(), get_amount),
        MessageHandler(TemplateResponseFilter(keywords="/start"), start_bot)
    ])
Example #26
0
File: bot.py Project: mmdaz/Bot
def get_amount(bot, update):
    user_peer = update.get_effective_user()
    amount = update.get_effective_message()
    dispatcher.get_conversation_data(update, "debt").amount = amount.text
    bot.send_message(TemplateMessage(Message.GET_DEBT_CARD_NUMBER,
                                     button_list),
                     user_peer,
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(update, [
        MessageHandler(TextFilter(), get_card_number),
        MessageHandler(TemplateResponseFilter(keywords="/start"), start_bot)
    ])
Example #27
0
File: bot.py Project: mmdaz/Bot
def get_name_creditor(bot, update):
    user_peer = update.get_effective_user()
    creditor_name = update.get_effective_message()
    dispatcher.get_conversation_data(update,
                                     "debt").creditor_name = creditor_name.text
    bot.send_message(TemplateMessage(Message.GET_DEBT_YEAR, button_list),
                     user_peer,
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(update, [
        MessageHandler(TextFilter(), get_debt_date_year),
        MessageHandler(TemplateResponseFilter(keywords="/start"), start_bot)
    ])
Example #28
0
File: bot.py Project: mmdaz/Bot
def start_creating_alarm(bot, update):
    alarm = Alarm("", "", "", "", "", "", 5, "true")
    dispatcher.set_conversation_data(update, "alarm", alarm)
    user_peer = update.get_effective_user()
    alarm.user_id = user_peer.get_json_str()
    command = update.get_effective_message()
    bot.send_message(TemplateMessage(Message.GET_ALARM_NAME, button_list),
                     user_peer,
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(update, [
        MessageHandler(TextFilter(), get_alarm_name),
        MessageHandler(TemplateResponseFilter(keywords="/start"), start_bot)
    ])
Example #29
0
File: bot.py Project: mmdaz/Bot
def get_alarm_message(bot, update):
    user_peer = update.get_effective_user()
    alarm_message = update.get_effective_message()
    dispatcher.get_conversation_data(update,
                                     "alarm").message = alarm_message.text
    bot.send_message(TemplateMessage(Message.GET_ALARM_STOP_MESSAGE,
                                     button_list),
                     user_peer,
                     success_callback=success,
                     failure_callback=failure)
    dispatcher.register_conversation_next_step_handler(update, [
        MessageHandler(TextFilter(), get_alarm_stop_message),
        MessageHandler(TemplateResponseFilter(keywords="/start"), start_bot)
    ])
def request_receiver_name(bot, update):
    user_peer = update.get_effective_user()
    branch_id = update.get_effective_message().text
    dispatcher.set_conversation_data(update, key="branch_id", value=branch_id)
    buttons_list = [BotButtons.back_to_main_menu]
    general_message = TextMessage(BotTexts.enter_receiver_name)
    template_message = TemplateMessage(general_message, buttons_list)
    send_message(message=template_message,
                 peer=user_peer,
                 step=Step.request_receiver_name)
    dispatcher.register_conversation_next_step_handler(
        update,
        handlers=common_handlers +
        [MessageHandler(TextFilter(), request_receiver_father_name)])