예제 #1
0
파일: test.py 프로젝트: igalaxy-git/chatbot
def go_test(update, context):
    id = update.message.from_user.id

    if id not in test_dict.keys():
        path = 'all_comands/tests/' + update.message.text + '.json'
        test_dict[id] = Test(read_json(path))
    else:
        test_dict[id].check_it(update.message.text)

    current = test_dict[id]
    text = current.ask_next()

    if text['count'] == 10:
        count = current.get_result()

        user = session.query(User).filter(User.id == id).first()
        res = TEXT[user.mode]['test']

        update.message.reply_text(f'{res[1]} {count}/10\n{res[2]}',
                                  reply_markup=ReplyKeyboardRemove())
        del test_dict[id]

        return ConversationHandler.END
    elif text['markup'] is not None:
        markup = ReplyKeyboardMarkup([text['markup'] + ['❌']],
                                     one_time_keyboard=True)
        update.message.reply_text(text['text'], reply_markup=markup)
    else:
        markup = ReplyKeyboardMarkup([['❌']], one_time_keyboard=True)
        update.message.reply_text(text['text'], reply_markup=markup)

    return 1
예제 #2
0
def start(update, context):
    print('go')
    print(session)
    users = list(map(lambda x: x.id, session.query(User).all()))
    id = update.message.from_user.id
    print('go 1')

    if id not in users:
        new = User(id=id, mode='en')
        session.add(new)
        session.commit()
    else:
        new = session.query(User).filter(User.id == id).first()

    text = TEXT[new.mode]['start']

    update.message.reply_text(text)
예제 #3
0
def send_lesson(update, context):
    id = update.message.from_user.id
    user = session.query(User).filter(User.id == id).first()

    update.message.reply_photo(photo=open(f'all_comands/lessons/{LESSONS[update.message.text]}', 'rb'))
    update.message.reply_text(TEXT[user.mode]['lessons'][1])

    return 1
예제 #4
0
def ru(update, context):
    id = update.message.from_user.id

    user = session.query(User).filter(User.id == id).first()
    user.mode = 'ru'
    session.commit()

    update.message.reply_text('Готово!')
예제 #5
0
def en(update, context):
    id = update.message.from_user.id

    user = session.query(User).filter(User.id == id).first()
    user.mode = 'en'
    session.commit()

    update.message.reply_text('Done!')
예제 #6
0
def lesson(update, context):
    id = update.message.from_user.id
    user = session.query(User).filter(User.id == id).first()

    commands = ReplyKeyboardMarkup([COMMANDS[user.mode]['lessons'] + ['❌']], one_time_keyboard=True)

    text = TEXT[user.mode]['lessons'][0]

    update.message.reply_text(text, reply_markup=commands)

    return 1
예제 #7
0
def choose_tr_lang(update, context):
    id = update.message.from_user.id
    user = session.query(User).filter(User.id == id).first()

    markup = ReplyKeyboardMarkup([COMMANDS[user.mode]['translate'] + ['❌']],
                                 one_time_keyboard=True)

    update.message.reply_text(TEXT[user.mode]['translate'][0],
                              reply_markup=markup)

    return 1
예제 #8
0
파일: test.py 프로젝트: igalaxy-git/chatbot
def test(update, context):
    id = update.message.from_user.id
    user = session.query(User).filter(User.id == id).first()

    text = TEXT[user.mode]['test'][0]
    commands = COMMANDS[user.mode]['test'] + ['❌']
    markup = ReplyKeyboardMarkup([commands], one_time_keyboard=True)

    update.message.reply_text(text, reply_markup=markup)

    return 1
예제 #9
0
def get_tr_lang(update, context):
    id = update.message.from_user.id
    user = session.query(User).filter(User.id == id).first()

    translate_dict[id] = update.message.text

    text = TEXT[user.mode]['translate'][1]
    markup = ReplyKeyboardMarkup([['❌']], one_time_keyboard=True)

    update.message.reply_text(text, reply_markup=markup)

    return 2
예제 #10
0
def recommend(update, context):
    id = update.message.from_user.id
    user = session.query(User).filter(User.id == id).first()

    markup = ReplyKeyboardMarkup([COMMANDS[user.mode]['rec']],
                                 one_time_keyboard=True)

    text = TEXT[user.mode]['rec'][0]

    update.message.reply_text(text, reply_markup=markup)

    return 1
예제 #11
0
def get_rec(update, context):
    id = update.message.from_user.id
    user = session.query(User).filter(User.id == id).first()

    kind = update.message.text

    if kind == 'фильм' or kind == 'film':
        length = session.query(Film).count()
        rand = randint(1, length)

        rec = user.rec_films
        res = session.query(Film).filter(Film.id == rand).first()

        if rec is None:
            rec = ''

        while str(rand) in rec.split() or res is None:
            rand = randint(1, length)
            res = session.query(Film).filter(Film.id == rand).first()

        user.rec_films = rec + f' {str(rand)}'

        res = f'🟠{res.name}\n\n🔸{res.plot_ru}' \
            if user.mode == 'ru' else f'🟠{res.name}\n\n🔸{res.plot_en}'

    elif kind == 'книга' or kind == 'book':

        length = session.query(Book).count()
        rand = randint(1, length)

        rec = user.rec_books

        res = session.query(Book).filter(Book.id == rand).first()

        if rec is None:
            rec = ''

        while str(rand) in rec.split() or res is None:
            rand = randint(1, length)
            res = session.query(Book).filter(Book.id == rand).first()

        user.rec_books = rec + f' {str(rand)}'

        res = f'🟠{res.author} - {res.name}\n\n🔸{res.plot_ru}' \
            if user.mode == 'ru' else \
            f'🟠{res.author} - {res.name}\n\n🔸{res.plot_en}'

    text = TEXT[user.mode]['rec'][1]
    session.commit()

    update.message.reply_text(text + res, reply_markup=ReplyKeyboardRemove())

    return ConversationHandler.END
예제 #12
0
파일: talk.py 프로젝트: igalaxy-git/chatbot
def talk(update, context):
    id = update.message.from_user.id
    user = session.query(User).filter(User.id == id).first()
    markup = ReplyKeyboardMarkup([['❌']])

    if id not in talking_now.keys():
        talking_now[id] = TALKING[update.message.text]

        update.message.reply_text(TEXT[user.mode][talking_now[id]],
                                  reply_markup=markup)
        return 1

    response = which_response(update.message.text, talking_now[id])
    update.message.reply_text(response, reply_markup=markup)

    return 1
예제 #13
0
파일: help.py 프로젝트: igalaxy-git/chatbot
def help(update, context):
    id = update.message.from_user.id
    user = session.query(User).filter(User.id == id).first()

    text = TEXT[user.mode]['help']
    update.message.reply_text(text)
예제 #14
0
def send_meme(update, context):
    id = update.message.from_user.id
    user = session.query(User).filter(User.id == id).first()

    update.message.reply_photo(photo=memes.get_url())
    update.message.reply_text(TEXT[user.mode]['memes'])