예제 #1
0
def curr_link(message):
    link = ''
    try:
        obj = ChatLink.get(chat_id=message.chat.id)
    except ChatLink.DoesNotExist:
        pass
    else:
        link = obj.link
    bot.reply_to(message, f'Ссылка: "{link}"')
예제 #2
0
def remove(message):
    link = ''
    try:
        obj = ChatLink.get(chat_id=message.chat.id)
    except ChatLink.DoesNotExist:
        pass
    else:
        link = obj.link
        obj.delete_instance()
    bot.reply_to(message, f'Ссылка "{link}" удалена')
예제 #3
0
def link_save(message):
    chat_id = message.chat.id
    if ChatLink.select().where(ChatLink.chat_id == chat_id).exists():
        ChatLink.delete().where(ChatLink.chat_id == chat_id).execute()
    try:
        ChatLink.create(chat_id=chat_id, link=message.text.strip())
    except:  # отлавливаем все подряд
        bot.reply_to(message, f'Ошибка, ссылка не сохранена')
    else:
        bot.reply_to(message, f'Ссылка "{message.text}" сохранена')
예제 #4
0
파일: bot.py 프로젝트: zshanabek/shaqyru
def send_welcome(message):
    try:
        chat_id = message.chat.id
        if (message.chat.type == "private"):
            bot.send_message(
                chat_id,
                'Здравствуйте, это телеграм бот потребительского кооператива "Елимай-2019". Выберите язык на котором хотите продолжить переписку',
                reply_markup=utils.gen_inline_markup(config.languages, 2))
        else:
            bot.send_message(chat_id, "Бот работает в личном чате")
    except Exception:
        bot.reply_to(message, 'oooops')
예제 #5
0
def safe_reply(message, reply, parse_mode=None):
    typing_action(message)

    if len(reply) <= TELEGRAM_API_MAX_CHARS:
        bot.reply_to(message, reply, parse_mode=parse_mode)
        return

    # FIXME: splitting text breaks HTML markup.
    # split by lines AND max chars instead
    for splitted_reply in util.split_string(reply, TELEGRAM_API_MAX_CHARS):
        bot.reply_to(message, splitted_reply, parse_mode=parse_mode)
    sleep(0.1)
예제 #6
0
파일: bot.py 프로젝트: zshanabek/shaqyru
def process_name_step(message):
    try:
        chat_id = message.chat.id
        name = message.text
        user = user_dict[chat_id]
        user.name = name
        lang = 2 if user.language == "kz" else 3
        city_name = conn.select_city(user.city)[0][lang]
        bot.send_message(
            chat_id,
            f'{config.l10n[user.language]["name_single"]}: {user.name}\n'
            f'{config.l10n[user.language]["number_single"]}: {user.phone_number}\n'
            f'{config.l10n[user.language]["city_single"]}: {city_name}')
        save_data(message)
    except Exception:
        bot.reply_to(message, 'oooops')
예제 #7
0
파일: bot.py 프로젝트: zshanabek/shaqyru
def save_data(message):
    try:
        chat_id = message.chat.id
        user = user_dict[chat_id]
        id = None
        if conn.exist_user(user.telegram_id) and not conn.select_user(
                user.telegram_id)[7]:
            tpl = [
                user.name, user.city, user.phone_number, user.language,
                user.decision, user.telegram_id
            ]
            id = conn.update_user(tpl)
        else:
            tpl = (user.name, user.city, user.phone_number, user.language,
                   user.telegram_id, user.username, user.decision)
            if not conn.exist_user(user.telegram_id):
                id = conn.add_user(tpl)
                city = conn.select_city(user.city)[0][3]
                now = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
                user_tpl = (id, user.name, city, user.phone_number,
                            user.language, user.telegram_id, user.username,
                            now)
                worksheet.append_row(user_tpl)
        if id is not None:
            lang = 3
            username = '' if user.username == None else f'@{user.username}'
            bot.send_message(os.getenv("GROUP_CHAT_ID"), f'ID: {id}\n'
                             f'Имя: {user.name}\n'
                             f'Имя пользователя: {username}\n'
                             f'Город: {conn.select_city(user.city)[0][lang]}\n'
                             f'Номер: {user.phone_number}\n'
                             f'Язык: {user.language}',
                             disable_notification=True)
            bot.send_message(
                chat_id, config.l10n[user.language]['success_registration'])
        del user
    except Exception:
        bot.reply_to(message, 'oooops')
예제 #8
0
파일: bot.py 프로젝트: ritcher/SCPCDividas
def message_handler(message):

    try:
        json_response = api.consultaDivida(message.text)
        if 'error' in json_response.keys():
            bot.reply_to(message, dialogs['sem_dividas'])
    except:
        bot.reply_to(message, dialogs['erro'], parse_mode='markdown')
    else:
        try:
            resultados = dialogs['resumo'].format(
                json_response['id'], json_response['cpf'],
                json_response['nomeConsumidor'], json_response['codigoCredor'],
                json_response['nomeCredor'], json_response['valorTotal'],
                json_response['dataCalculo'])
            for divida in json_response['carteiras']:
                resultados += dialogs['divida'].format(
                    divida['id'], divida['nome'], divida['numero'],
                    divida['valorSaldoDevedor'], divida['valorJuros'],
                    divida['valorMulta'], divida['valorDesconto'],
                    divida['valorTotal'])
                for fatura in divida['contratos']:
                    resultados += dialogs['fatura'].format(
                        fatura['numero'], fatura['valorSaldoDevedor'],
                        fatura['valorJuros'], fatura['valorMulta'],
                        fatura['valorDesconto'], fatura['valorTotal'],
                        fatura['diasAtraso'],
                        fatura['descricaoDetalheContrato'], fatura['cedente'],
                        fatura['cedente'])
        except KeyError:
            file = bytes(json.dumps(json_response, indent=4), 'utf-8')
            bot.send_document(message.chat.id, file)
        else:
            bot.reply_to(message, resultados, parse_mode='markdown')

            file = bytes(json.dumps(json_response, indent=4), 'utf-8')

            bot.send_document(message.chat.id, file)
예제 #9
0
def send_welcome(message):
    bot.reply_to(message, 'Hello! This bot helps you to store your trades.')
예제 #10
0
파일: bot.py 프로젝트: ritcher/SCPCDividas
def send_welcome(message):
    bot.reply_to(message, dialogs['welcome'])
예제 #11
0
파일: bot.py 프로젝트: zshanabek/shaqyru
def callback_query(call):
    chat_id = call.message.chat.id
    if call.data in ("cb_ru", "cb_kz"):
        language = 'kz' if call.data == 'cb_kz' else 'ru'
        user = User(language)
        user_dict[chat_id] = user
        bot.answer_callback_query(call.id,
                                  config.l10n[user.language]['language'])
        # video = open(
        #     '/home/sam/Documents/Projects/elimaiga/promo_kz.mp4', 'rb')
        # bot.send_video(chat_id, video)
        video = 'VIDEO_ID_KZ' if language == 'kz' else 'VIDEO_ID_RU'
        bot.send_video(chat_id,
                       os.getenv(video),
                       caption=config.l10n[user.language]['video'])
        user.username = call.message.chat.username
        user.telegram_id = str(call.message.chat.id)
        if not DEV_MODE:
            time.sleep(7)
        choices = {
            'cb_yes': config.l10n[user.language]['yes'],
            'cb_no': config.l10n[user.language]['no'],
        }
        bot.send_message(chat_id,
                         config.l10n[user.language]['offer'],
                         reply_markup=utils.gen_inline_markup(choices, 2))
    elif call.data in ("cb_no", "cb_yes"):
        if call.data == "cb_no":
            try:
                user = user_dict[chat_id]
                bot.edit_message_text(config.l10n[user.language]['deny'],
                                      chat_id, call.message.message_id)
                bot.answer_callback_query(call.id,
                                          config.l10n[user.language]['no'])
                if not conn.exist_user(str(chat_id)):
                    tpl = (user.name, user.city, user.phone_number,
                           user.language, user.telegram_id, user.username,
                           user.decision)
                    res = conn.add_user(tpl)
            except Exception:
                bot.reply_to(call.message, 'oooops')
        else:
            try:
                user = user_dict[chat_id]
                user.decision = True
                bot.answer_callback_query(call.id,
                                          config.l10n[user.language]['yes'])
                lang = 2 if user.language == "kz" else 3
                if conn.exist_user(user.telegram_id) and conn.select_user(
                        user.telegram_id)[7]:
                    res = conn.select_user(user.telegram_id)
                    bot.send_message(
                        chat_id,
                        config.l10n[user.language]['already_registered'])
                else:
                    res = conn.select_cities()
                    cities = []
                    for i in range(len(res)):
                        cities.append(res[i][lang])
                    callbacks = []
                    for i in range(len(res)):
                        callbacks.append('cb_city_' + str(res[i][0]))
                    cities = dict(zip(callbacks, cities))
                    msg = bot.send_message(
                        chat_id,
                        f"{user.name}, {config.l10n[user.language]['city']}",
                        reply_markup=utils.gen_inline_markup(cities, 1))
            except Exception:
                bot.reply_to(call.message, 'oooops')
    else:
        city = int(call.data.split('_')[-1])
        user = user_dict[chat_id]
        user.city = city
        buttons = (config.l10n[user.language]['send_contact'], )
        msg = bot.send_message(chat_id,
                               config.l10n[user.language]['number'],
                               reply_markup=utils.gen_reply_markup(
                                   buttons, 1, False, True))
        bot.register_next_step_handler(msg, process_phone_step)
예제 #12
0
파일: bot.py 프로젝트: zshanabek/shaqyru
def send_contacts(message):
    try:
        chat_id = message.chat.id
        bot.send_message(chat_id, 'Наш сайт https://elimai2019.kz/')
    except Exception:
        bot.reply_to(message, 'oooops')
예제 #13
0
def all_text(message):
    bot.reply_to(message, message.text)
예제 #14
0
def start(message):
    bot.reply_to(message, "Введите ссылку")