Example #1
0
def city_game(bot, update, user_data):
    text = update.message.text.title().strip()
    user_text_first_letter = text[0]
    user_text_without_bad_ending = check_last_letter(text)

    if not user_data:
        user_data['cities'] = cities
        user_data['all_city'] = all_city
        user_data['check'] = 'stub'

    get_city = user_data['all_city'].get(user_text_first_letter)
    if get_city is None:
        text = f'Не знаю городов на букву {user_text_first_letter}'
        update.message.reply_text(text, reply_markup=get_keyboard())
    elif text not in get_city:
        update.message.reply_text('Я про такой город не слышал.',
                                  reply_markup=get_keyboard())
    elif text not in user_data['cities'][user_text_first_letter]:
        update.message.reply_text('Такой город уже был назван',
                                  reply_markup=get_keyboard())
    elif (user_text_without_bad_ending[0] != user_data['check']
          and user_data['check'] != 'stub'):
        update.message.reply_text('Не дури меня старина:)',
                                  reply_markup=get_keyboard())
    else:
        text_last_letter = user_text_without_bad_ending[-1].upper()
        bot_word = random.sample(user_data['cities'][text_last_letter], 1)[0]
        update.message.reply_text(f'{bot_word}, твой ход старина:)',
                                  reply_markup=get_keyboard())
        bot_word_without_bad_ending = check_last_letter(bot_word)
        user_data['cities'][user_text_without_bad_ending[0]].discard(text)
        user_data['cities'][bot_word_without_bad_ending[0]].discard(bot_word)
        user_data['check'] = bot_word_without_bad_ending[-1].upper()

    return game
Example #2
0
def word_count(bot, update, user_data):
    command, *text = update.message.text.split()
    if not text:
        update.message.reply_text('You were enter anything',
                                  reply_markup=get_keyboard())
    else:
        len_correct_text = len([
            1 for word in text
            if word not in string.punctuation and not word.isdigit()
        ])
        update.message.reply_text(f'{len_correct_text} word(s)',
                                  reply_markup=get_keyboard())
Example #3
0
def planet_talk(bot, update, user_data):
    planet_name = "зельдобаран"
    user_text = update.message.text.split(' ')
    user_planet = user_text[1]
    if user_planet == 'Меркурий':
        planet_name = 'Меркурий'
        planet = ephem.Mercury(datetime.now())
        update.message.reply_text(planet_answer(planet, planet_name), reply_markup=get_keyboard())
    if user_planet == 'Венера':
        planet_name = 'Венера'
        planet = ephem.Venus(datetime.now())
        update.message.reply_text(planet_answer(planet, planet_name), reply_markup=get_keyboard())
    if user_planet == 'Марс':
        planet_name = 'Марс'
        planet = ephem.Mars(datetime.now())
        update.message.reply_text(planet_answer(planet, planet_name), reply_markup=get_keyboard())
    if user_planet == 'Юпитер':
        planet_name = 'Юпитер'
        planet = ephem.Jupiter(datetime.now())
        update.message.reply_text(planet_answer(planet, planet_name), reply_markup=get_keyboard())
    if user_planet == 'Сатурн':
        planet_name = 'Сатурн'
        planet = ephem.Saturn(datetime.now())
        update.message.reply_text(planet_answer(planet, planet_name), reply_markup=get_keyboard())
    if user_planet == 'Уран':
        planet_name = 'Уран'
        planet = ephem.Uranus(datetime.now())
        update.message.reply_text(planet_answer(planet, planet_name), reply_markup=get_keyboard())
    if user_planet == 'Нептун':
        planet_name = 'Нептун'
        planet = ephem.Neptune(datetime.now())
        update.message.reply_text(planet_answer(planet, planet_name), reply_markup=get_keyboard())
    if user_planet == 'Плутон':
        update.message.reply_text("Плутон не Планета!!!!", reply_markup=get_keyboard())
Example #4
0
def wordcount(bot, update, args):
    words = ' '.join(args)
    words = re.sub('[«»"!@#$:;.,?]', '', words)
    words = words.split()

    while len(words) != 0:
        update.message.reply_text('Words in your phrase: {}'.format(
            len(words)),
                                  reply_markup=get_keyboard())
        logging.info()
        break
    else:
        update.message.reply_text('Enter some words, please!',
                                  reply_markup=get_keyboard())
Example #5
0
def anketa_skip_comment(bot, update, user_data):
    user = get_or_create_user(db, update.effective_user, update.message)
    text = """
<b>Ваше имя и фамилия: </b>{anketa_name}
<b>Ваша оценка: </b>{anketa_rating}""".format(**user_data)
    update.message.reply_text(text, reply_markup=get_keyboard(), parse_mode=ParseMode.HTML)
    return ConversationHandler.END
Example #6
0
def planet_name(bot, update, user_data):
    planet_name = update.message.text.split()[1]
    date = ephem.now()
    planet = getattr(ephem, planet_name)(date)
    const = ephem.constellation(planet)
    text = f'Сегодня планета {planet_name} находится в созвездии {const[1]}'
    update.message.reply_text(text, reply_markup=get_keyboard())
Example #7
0
def wordcount(bot, update, user_data):
    words = update.message.text.split()[1:]
    if words != []:
        answer = "{} слова".format(len(words))
    else:
        answer = 'Забыл ввести фразу!'
    update.message.reply_text(answer, reply_markup=get_keyboard())
Example #8
0
def change_avatar(bot, update, user_data):
    if 'emo' in user_data:
        del user_data['emo']
    emo = get_user_emo(user_data)
    update.message.reply_text("Готово! {}".format(emo), reply_markup=get_keyboard())
    logging.info("User: %s, Chat ID: %s, Message: Changed avatar", update.message.chat.username,
                update.message.chat.id)
Example #9
0
def greet_user(bot, update, user_data):
    print(update.message.chat_id)
    emo = get_user_emo(user_data)
    user_data['emo'] = emo
    text = 'Привет {}'.format(emo)
    print(text)
    update.message.reply_text(text, reply_markup=get_keyboard())
Example #10
0
def send_cat_img(bot, update, user_data):
    """ Посылает картинку с котом из папки img, при вводе команды /cat"""
    cat_list = glob('img/cat*.jpg')
    cat_img = choice(cat_list)
    bot.send_photo(chat_id=update.message.chat.id,
                   photo=open(cat_img, 'rb'),
                   reply_markup=get_keyboard())
def talk_to_me(bot, update, user_data):
    emo = get_user_emo(user_data)
    user_text = f"Привет {update.message.chat.first_name}{emo}! Ты написал: {update.message.text}"
    logging.info("User: %s, Chat id: %s, Message: %s", update.message.chat.username,
                 update.message.chat.id,
                 update.message.text)
    update.message.reply_text(user_text, reply_markup=get_keyboard())
Example #12
0
def handle_change_reinvest(call):
    chat = call.message.chat
    users_db = Users_db(project_variables.DB_NAME)
    is_eng = users_db.select_stats_field(chat.id, 'is_eng')
    balance = users_db.select_stats_field(chat.id, 'balance')
    balance_btc = users_db.select_stats_field(chat.id, 'balance_btc')

    if balance > 0:
        users_db.update_stats_nullify_balance(chat.id)
        utils.invested(users_db, chat.id, balance, make_lift=0)
    if balance_btc > 0:
        users_db.update_stats_nullify_balance_btc(chat.id)
        utils.invested(users_db, chat.id, balance_btc, is_btc=1, make_lift=0)
    if is_eng:
        text = "Successfully reinvested"
    else:
        text = "Реинвестирование прошло успешно"
    users_db.close()

    try:
        bot.send_message(chat.id,
                         text,
                         reply_markup=utils.get_keyboard(
                             "main_keyboard", is_eng),
                         parse_mode="Markdown")
    except telebot.apihelper.ApiException:
        pass
Example #13
0
def handle_reply_requisite(message):
    chat = message.chat
    pay_method = message.reply_to_message.text.split()[1]
    requisite = ''.join(message.text.split())

    users_db = Users_db(project_variables.DB_NAME)
    is_eng = users_db.select_stats_field(chat.id, 'is_eng')
    if not utils.check_requisite(pay_method, requisite):
        if is_eng:
            text = "You provided invalid requisite"
        else:
            text = "Введен неправильный реквизит"
    else:
        users_db.update_requisite(chat.id, pay_method, requisite)
        if is_eng:
            text = "Requisite is saved: *{}*"
        else:
            text = "Реквизит сохранен: *{}*"
    users_db.close()

    try:
        bot.send_message(chat.id,
                         text.format(requisite),
                         reply_markup=utils.get_keyboard(
                             "main_keyboard", is_eng),
                         parse_mode="Markdown")
    except telebot.apihelper.ApiException:
        pass
Example #14
0
def handle_language(message):
    chat = message.chat
    users_db = Users_db(project_variables.DB_NAME)
    is_eng = message.text == '🇺🇸 English'

    if users_db.select_spam_cnt(chat.id)[0] > MAX_REQUESTS_PER_TIME:
        if is_eng:
            text = "You are sending messages too quickly. You can change language after {} minutes"
        else:
            text = "Вы посылаете сообщения слишком быстро. Вы сможете изменить язык после {} минут"
        text = text.format(NULLIFY_AFTER)
    else:
        users_db.update_spam_cnt(chat.id)
        if is_eng:
            text = "You chose english language"
        else:
            text = "Вы выбрали русский язык"
        users_db.update_stats_field(chat.id, 'is_eng', int(is_eng))
    users_db.close()

    try:
        bot.send_message(chat.id,
                         text,
                         reply_markup=utils.get_keyboard(
                             "main_keyboard", is_eng))
    except telebot.apihelper.ApiException:
        pass
Example #15
0
def handle_ref_program(message):
    chat = message.chat
    users_db = Users_db(project_variables.DB_NAME)
    is_eng = users_db.select_stats_field(chat.id, 'is_eng')
    ref_program_info = users_db.select_ref_all(chat.id)
    users_db.close()
    if is_eng:
        text = "Earned total: *{:.2f} USD*\nEarned total: *{:.8f} BTC*\n\nInvited in 1st line: *{}*\nInvited in 2nd " \
               "line: *{}*\nInvited in 3rd line: *{}*\n\nEarned from 1st line: *{:.2f} USD*\nEarned from 1st line: *{" \
               ":.8f} BTC*\n\nEarned from 2nd line: *{:.2f} USD*\nEarned from 2nd line: *{:.8f} BTC*\n\nEarned from " \
               "3rd line: *{:.2f} USD*\nEarned from 3rd line: *{:.8f} BTC*\n\nYour id in Telegram: *{}* "
    else:
        text = "Прибыль вообщем: *{:.2f} USD*\nПрибыль вообщем: *{:.8f} BTC*\n\nПриглашенных в 1-ой линии: *{" \
               "}*\nПриглашенных во 2-ой линии: *{}*\nПриглашенных в 3-ей линии: *{}*\n\nПрибыль с 1-ой линии: *{" \
               ":.2f} USD*\nПрибыль с 1-ой линии: *{:.8f} BTC*\n\nПрибыль со 2-ой линии: *{:.2f} " \
               "USD*\nПрибыль со 2-ой линии: *{:.8f} BTC*\n\nПрибыль с 3-ей линии: *{:.2f} USD*\nПрибыль с " \
               "3-ей линии: *{:.8f} BTC*\n\nВаш id в Telegram: *{}*"
    ref_program_info = tuple(
        map(lambda line: 0 if line is None else line, ref_program_info))
    try:
        bot.send_message(
            chat.id,
            text.format(
                ref_program_info[2] + ref_program_info[4] +
                ref_program_info[6],
                utils.to_bitcoin(ref_program_info[3] + ref_program_info[5] +
                                 ref_program_info[7]), ref_program_info[8],
                ref_program_info[9], ref_program_info[10], ref_program_info[2],
                utils.to_bitcoin(ref_program_info[3]), ref_program_info[4],
                utils.to_bitcoin(ref_program_info[5]), ref_program_info[6],
                utils.to_bitcoin(ref_program_info[7]), chat.id),
            reply_markup=utils.get_keyboard("ref_program_keyboard", is_eng),
            parse_mode="Markdown")
    except telebot.apihelper.ApiException:
        pass
Example #16
0
def sms(bot, update):
    """Функция вызывается при отправке команды /start"""
    user = search_or_save_user(mdb, bot.effective_user, bot.message)
    smile = emojize(choice(SMILE), use_aliases=True)
    bot.message.reply_text('Привет {} {}'.format(bot.message.chat.first_name,
                                                 smile),
                           reply_markup=get_keyboard())
Example #17
0
def change_avatar(update, context):
    user_data = context.user_data
    if 'emo' in user_data:
        del user_data['emo']
    emo = greet_user_emo(user_data)
    update.message.reply_text('Готово: {}'.format(emo),
                              reply_markup=get_keyboard())
Example #18
0
def send_cat_pictures(update, context):
    cat_list = glob('images/*.jpg')
    cat_pic = choice(cat_list)
    bot = context.bot
    bot.send_photo(chat_id=update.message.chat.id,
                   photo=open(cat_pic, 'rb'),
                   reply_markup=get_keyboard())
Example #19
0
def greet_user(bot, update, user_data):
    user = get_or_create_user(db, update.effective_user, update.message)
    emo = get_user_emo(db, user)
    text = 'Привет, {} {}'.format(update.message.chat.first_name, emo)
    update.message.reply_text(text, reply_markup=get_keyboard())
    logging.info('{}({}): /start'.format(update.message.chat.username,
                                         update.message.chat.first_name))
Example #20
0
def greet_user(bot, update, user_data):
    print(update.message.chat_id)
    smile = get_user_emo(user_data)
    user_data['emo'] = smile
    text = 'Привет {}! {} Я тестовый бот и пока очень тупой, я всего лиш умею пофторять за тобой сообщения. Знаю комманду /start, результат которой ты сейчас наблюдаешь, а так же знаю команду /planet которая подскажет тебе в каком созвездии находится планета(прим: /planet Марс), так же я могу прислать тебе случайного котики /cat'.format(update.message.chat.first_name, smile)

    update.message.reply_text(text, reply_markup=get_keyboard())
Example #21
0
def bye_user(bot, update, user_data):
    user = get_or_create_user(db, update.effective_user, update.message)
    text = 'Вызван STOP!'
    print(text)
    bot.send_message(chat_id=update.message.chat_id,
                     text='Stop',
                     reply_markup=get_keyboard())
Example #22
0
def change_avatar(bot, update, user_data):
    user = get_or_create_user(db, update.effective_user, update.message)
    if 'emo' in user:
        del user['emo']
    emo = get_user_emo(db, user)
    update.message.reply_text('Готово: {}'.format(emo),
                              reply_markup=get_keyboard())
Example #23
0
def talk_to_me(bot, update, user_data):
    emo = get_user_emo(user_data)
    user_text = 'Привет {} {}! Ты написал: {}'.format(user['first_name'], emo,
                                                      update.message.text)
    logging.info('User: %s, Chat id: %s, Message: %s', user['username'],
                 update.message.chat.id, update.message.text)
    update.message.reply_text(user_text, reply_markup=get_keyboard())
Example #24
0
def anketa_skip_comment(bot, update, user_data):
    user_text = """
<b>Имя Фамилия:</b> {anketa_name}
<b>Оценка:</b> {anketa_rating}""".format(**user_data)
    update.message.reply_text(user_text, reply_markup=get_keyboard(),
                                parse_mode=ParseMode.HTML)
    return ConversationHandler.END
Example #25
0
def handle_withdraw(call):
    chat = call.message.chat
    users_db = Users_db(project_variables.DB_NAME)
    is_eng = users_db.select_stats_field(chat.id, 'is_eng')
    balance = users_db.select_stats_field(chat.id, 'balance')
    balance_btc = users_db.select_stats_field(chat.id, 'balance_btc')
    users_db.close()

    keyboard = None
    if balance < project_variables.MIN_WITHDRAW_USD and balance_btc < project_variables.MIN_WITHDRAW_BTC:
        if is_eng:
            text = "You don't have enough money to withdraw\nMinimum is *{} USD* or *{:.8f} BTC*"
        else:
            text = "У вас нехватает средств для вывода\nМинимальная сумма: *{} USD* or *{:.8f} BTC*"
        text = text.format(
            project_variables.MIN_WITHDRAW_USD,
            utils.to_bitcoin(project_variables.MIN_WITHDRAW_BTC))
    else:
        if is_eng:
            text = "Choose currency:"
        else:
            text = "Выберете валюту:"
        keyboard = utils.get_keyboard("withdraw_currency")

    try:
        bot.send_message(chat.id,
                         text,
                         reply_markup=keyboard,
                         parse_mode="Markdown")
    except telebot.apihelper.ApiException:
        pass
Example #26
0
def greet_user(bot, update, user_data):
    user = get_or_create_user(db, update.effective_user, update.message)
    emo = get_user_emo(db, user)
    user_data['emo'] = emo
    text = 'Привет {}'.format(emo)
    logging.info(text)
    update.message.reply_text(text, reply_markup=get_keyboard())
Example #27
0
def send_cat_picture(bot, update, user_data):
    user = get_or_create_user(db, update.effective_user, update.message)
    cat_list = glob('images/cat*.jp*g')
    cat_pic = choice(cat_list)
    bot.send_photo(chat_id=update.message.chat.id,
                   photo=open(cat_pic, 'rb'),
                   reply_markup=get_keyboard())
Example #28
0
def planet(bot, update, args):
    date_today = d.datetime.today()
    planet_name = ' '.join(args)
    planet_name = planet_name.lower()
    try:
        if planet_name == 'mars':
            planet_name = ephem.Mars(date_today)
            update.message.reply_text(ephem.constellation(planet_name)[1])
        elif planet_name == 'neptune':
            planet_name = ephem.Neptune(date_today)
            update.message.reply_text(ephem.constellation(planet_name)[1])
        elif planet_name == 'pluto':
            planet_name = ephem.Pluto(date_today)
            update.message.reply_text(ephem.constellation(planet_name)[1])
        elif planet_name == 'saturn':
            planet_name = ephem.Saturn(date_today)
            update.message.reply_text(ephem.constellation(planet_name)[1])
        elif planet_name == 'uranus':
            planet_name = ephem.Uranus(date_today)
            update.message.reply_text(ephem.constellation(planet_name)[1])
        elif planet_name == 'venus':
            planet_name = ephem.Venus(date_today)
            update.message.reply_text(ephem.constellation(planet_name)[1])
        elif planet_name == 'jupiter':
            planet_name = ephem.Jupiter(date_today)
            update.message.reply_text(ephem.constellation(planet_name)[1])
        else:
            update.message.reply_text('No data')
    except IndexError:
        update.message.reply_text(
            'Enter planet name please! For example, /planet Mars',
            reply_markup=get_keyboard())
        logging.info('User did not enter a planet')
Example #29
0
def greet_user(bot, update, user_data):
    emo = get_user_emo(user_data)
    user_data['emo'] = emo
    text = 'Привет {}'.format(emo)
    logging.info(text)

    update.message.reply_text(text, reply_markup=get_keyboard())
Example #30
0
def chenge_avatar(update, context):
    user = get_or_create_user(db, update.effective_user, update.message)

    if 'emo' in user:
        del user['emo']
    emo = get_user_emo(user)
    update.message.reply_text(f'Готово {emo}', reply_markup=get_keyboard())