示例#1
0
def cmd_video(message):
    db.del_state(str(message.chat.id), config.DB_cols.STATE.value)
    markup = mark_up(['random'])

    bot.send_message(message.chat.id,
                     "Send me a TED Talks video link "
                     "or press " + "*" + "random" + "*" +
                     " and let me find one for you!",
                     reply_markup=markup,
                     parse_mode='Markdown')
    db.set_property(str(message.chat.id), config.DB_cols.STATE.value,
                    config.States.SEND_LINK.value)
示例#2
0
def dict_enter_word(message):
    db.del_state(str(message.chat.id), config.DB_cols.LOOKUP.value)
    # get available POS-tags from the dictionary and give user the choice
    pos = dict_func_get_pos(message.text.lower().strip())
    if pos:
        # make everything a list as for only POS you get strings
        pos = list(pos)
        markup = mark_up(pos)
        bot.send_message(message.chat.id,
                         "Please select the part of speech:\n",
                         reply_markup=markup)
        db.set_property(str(message.chat.id), config.DB_cols.WORD.value,
                        message.text.lower().strip())
        db.set_property(str(message.chat.id), config.DB_cols.POS.value,
                        ", ".join(pos))
        db.set_property(str(message.chat.id), config.DB_cols.LOOKUP.value,
                        config.LookUp.ENTER_WORD.value)
    else:
        bot.send_message(
            message.chat.id,
            "Sorry, I am afraid your word is not in Merriam-Wesbter's Dictionary"
        )
        bot.send_message(
            message.chat.id, "Type /look_up to search for another word.\n"
            "Type /info or /commands to revise what I can do and see my commands.\n"
            "Type /reset to start anew.")
        db.set_property(str(message.chat.id), config.DB_cols.LOOKUP.value,
                        config.LookUp.START.value)
示例#3
0
def cmd_start(message):
    db.set_id(str(message.chat.id))
    db.del_state(str(message.chat.id), config.DB_cols.LOOKUP.value)
    db.del_state(str(message.chat.id), config.DB_cols.STATE.value)
    bot.send_message(
        message.chat.id,
        "Hi, I'm Linguini and I can help you learn new vocabulary.\n"
        "I can send videos, exercises and dictionary definitions.\n"
        "Let's have some fun watching TEDTalks videos and doing vocabulary exercises!\n"
        "Send /video to get a video.\n"
        "Type /look_up to look up a word in the dictionary.\n"
        "Send /info to know me better.\n"
        "Send /commands to list the available commands.\n")
    bot.send_photo(message.chat.id, config.pasta_img[randint(0, 4)])
    db.set_property(str(message.chat.id), config.DB_cols.STATE.value,
                    config.States.START.value)
    db.set_property(str(message.chat.id), config.DB_cols.LOOKUP.value,
                    config.LookUp.START.value)
示例#4
0
def dict_pos(message):
    pos = db.get_current_state(str(message.chat.id), config.DB_cols.POS.value)
    pos_input = message.text.lower().strip()
    # check if input is a correct POS-tag
    if pos_input in pos:
        db.del_state(str(message.chat.id), config.DB_cols.LOOKUP.value)
        word = db.get_current_state(str(message.chat.id),
                                    config.DB_cols.WORD.value).strip()
        # get the definition and audio
        my_def, audio = dict_func_get_definition(word, pos_input)
        if my_def:
            bot.send_audio(message.chat.id,
                           audio,
                           '*' + word + '*',
                           parse_mode='Markdown')
            bot.send_message(message.chat.id, my_def)
            db.set_property(str(message.chat.id), config.DB_cols.LOOKUP.value,
                            config.LookUp.START.value)
            bot.send_message(
                message.chat.id, "Type /look_up to search for another word.\n"
                "Type /info or /commands to revise what I can do and see my commands.\n"
                "Type /reset to start anew.")
        else:
            bot.send_message(
                message.chat.id,
                "Sorry, I am afraid your word is not in Merriam-Webster's Dictionary"
            )
            bot.send_message(
                message.chat.id, "Type /look_up to search for another word.\n"
                "Type /info or /commands to revise what I can do and see my commands.\n"
                "Type /reset to start anew.")
            db.set_property(str(message.chat.id), config.DB_cols.LOOKUP.value,
                            config.LookUp.START.value)
    else:
        markup = mark_up(pos.split(','))
        bot.send_message(
            message.chat.id, "Seems like there was a typo in your input.\n"
            "Please, select a part of speech and press the corresponding button.",
            reply_markup=markup)
示例#5
0
def vid_transcript_or_exercise(message):
    mg = message.text.strip().lower()
    if mg in ['transcript', 'exercise']:
        db.del_state(str(message.chat.id), config.DB_cols.STATE.value)
        url = db.get_current_state(str(message.chat.id),
                                   config.DB_cols.URL.value)
        transcript = vid_func_get_transcript(url)
        if transcript:
            if mg == 'transcript':
                bot.send_message(message.chat.id, 'OK, transcript\'s coming.')
                # in case transcript is longer than message max length
                # a user can send a link to a very long video
                if len(transcript) > 2000:
                    sents = nltk.sent_tokenize(transcript)
                    print(sents)
                    part = ''
                    parts = []
                    for sent in sents:
                        part = part + ' ' + sent.strip()
                        if len(part) < 2000:
                            pass
                        else:
                            parts.append(part)
                            part = ''

                    for p in parts:
                        bot.send_message(message.chat.id, p)

                    bot.send_message(
                        message.chat.id,
                        'Kind reminder: you can always /look_up a new word.\n'
                        'Would you like to /reset?')
                    db.set_property(str(message.chat.id),
                                    config.DB_cols.STATE.value,
                                    config.States.START.value)
                else:
                    bot.send_message(message.chat.id, transcript)
                    bot.send_message(
                        message.chat.id,
                        'Kind reminder: you can always /look_up a new word.\n'
                        'Would you like to /reset?')
                    db.set_property(str(message.chat.id),
                                    config.DB_cols.STATE.value,
                                    config.States.START.value)

            elif mg == 'exercise':
                bot.send_message(
                    message.chat.id, 'OK, exercises are on the way.\n'
                    'If you don\'t know a word or two -\n'
                    ' just  /look_up :-)\n')
                exercises = vid_func_get_exercise(transcript)
                if exercises:
                    exercises = json.dumps(exercises)
                    db.set_property(str(message.chat.id),
                                    config.DB_cols.EXERCISES.value, exercises)
                    db.set_property(str(message.chat.id),
                                    config.DB_cols.STATE.value,
                                    config.States.EXERCISE_CHECKED.value)
                    db.set_property(str(message.chat.id),
                                    config.DB_cols.COUNTER.value, "0")
                    vid_send_exercise(message)
                else:
                    bot.send_message(
                        message.chat.id, "I beg your pardon!\n"
                        "For some reason no exercises were found.\n"
                        "Maybe it's the tricks of Don Rigatoni, he is such a mobster.\n"
                        "Anyway, we can always start anew with /reset!")
                    bot.send_photo(message.chat.id, config.rigatoni_img)
                    db.set_property(str(message.chat.id),
                                    config.DB_cols.STATE.value,
                                    config.States.START.value)

        else:
            bot.send_message(
                message.chat.id, "I beg your pardon!\n"
                "For some reason no transcript was found.\n"
                "Maybe it's the tricks of Don Rigatoni, he is such a mobster.\n"
                "But we can always start anew with /reset!")
            bot.send_photo(message.chat.id, config.rigatoni_img)
            db.set_property(str(message.chat.id), config.DB_cols.STATE.value,
                            config.States.START.value)
    else:
        markup = mark_up(['exercise', 'transcript'])
        bot.send_message(message.chat.id,
                         "Seems like there was a typo in your input.\n"
                         "Please, press \"exercise\" to train your vocabulary"
                         "or \"transcript\" to get the transcript.",
                         reply_markup=markup)
示例#6
0
def vid_send_video(message):
    mg = message.text.lower().strip()
    markup = mark_up(['exercise', 'transcript'])
    if mg == 'random':
        bot.send_message(message.chat.id,
                         "Great! Give me a moment to find a video.")
        # use our pre-compiled list of urls
        with open('urls.txt', 'r') as file:
            random_urls = [file.readline().strip() for line in file]
        my_random = random_urls[randint(0, len(random_urls))]
        print('my random', my_random)
        url = vid_func_get_url(my_random)
        print('got', url)
        if url:
            bot.send_video(message.chat.id, url)
            bot.send_message(message.chat.id,
                             "After you watch the video press " + "*" +
                             "exercise" + "*" + " to train your vocabulary!"
                             "You can also just see the full " + "*" +
                             "transcript" + "*",
                             reply_markup=markup,
                             parse_mode='Markdown')
            db.set_property(str(message.chat.id), config.DB_cols.URL.value,
                            my_random)
            db.set_property(str(message.chat.id), config.DB_cols.STATE.value,
                            config.States.SEND_EXERCISE.value)

        else:
            mk = mark_up(['random'])
            bot.send_message(message.chat.id,
                             "Sorry, I am afraid I can't access videos now.\n"
                             "Please send " + "*" + "random" + "*" +
                             " to try again.\n"
                             "To start anew send /reset",
                             reply_markup=mk,
                             parse_mode='Markdown')
    else:
        url = vid_func_get_url(mg)
        print(url)
        if url:
            bot.send_message(message.chat.id,
                             "Great! Give me a moment to find a video.")
            bot.send_video(message.chat.id, url)
            bot.send_message(message.chat.id,
                             "After you watch the video press " + "*" +
                             "exercise" + "*" + " to train your vocabulary!"
                             "You can also just see the full " + "*" +
                             "transcript" + "*",
                             reply_markup=markup,
                             parse_mode='Markdown')
            db.set_property(str(message.chat.id), config.DB_cols.URL.value, mg)
            db.set_property(str(message.chat.id), config.DB_cols.STATE.value,
                            config.States.SEND_EXERCISE.value)
        else:
            mk = mark_up(['random'])
            bot.send_message(message.chat.id,
                             "Sorry, seems like you entered an invalid link\n"
                             "Please send me a valid link or type " + "*" +
                             "random" + "*" + " and I will pick one for you!",
                             reply_markup=mk,
                             parse_mode='Markdown')
示例#7
0
def cmd_lookup(message):
    db.del_state(str(message.chat.id), config.DB_cols.LOOKUP.value)
    bot.send_message(message.chat.id, "Please enter a word")
    db.set_property(str(message.chat.id), config.DB_cols.LOOKUP.value,
                    config.LookUp.LOOK_UP.value)