예제 #1
0
def schedule_helper(msg):
    db = DBManager(DB_PATH)
    db.connect()
    schedule = db.get_schedule_by_uid(msg.chat.id)
    if not schedule:
        resp = "You haven't schedule any questions yet"
    else:
        resp = "\n".join(schedule)
    bot.send_message(msg.chat.id, resp)
예제 #2
0
def _initialize_variables():
    db = DBManager(DB_PATH)
    db.connect()
    uids = db.get_uids()

    for uid in uids:
        permitted_for_answer[uid] = True
        permitted_for_update[uid] = False
    registered_users_buffer.update(uids)
    db.disconnect()
예제 #3
0
def show_words_helper(msg):
    db = DBManager(DB_PATH)
    db.connect()
    resp_data = db.get_all_words_by_uid(msg.chat.id)
    if not resp_data:
        resp = "No words uploaded yet"
    else:
        resp = " ".join(map(lambda s: " - ".join(s) + '\n', resp_data)) + ' '
    bot.send_message(msg.chat.id, resp)
    db.disconnect()
예제 #4
0
def start_handler(msg):
    """
    /start command handler

    :param msg: message
    :return: None
    """
    db = DBManager(DB_PATH)
    db.connect()
    if not db.is_registered(msg.chat.id):
        db.register(msg.chat.id)
        bot.send_message(msg.chat.id, GREETING_MSG)
        permitted_for_answer[msg.chat.id] = True
        permitted_for_update[msg.chat.id] = False
        registered_users_buffer.update([msg.chat.id])
    else:
        bot.send_message(msg.chat.id, "I know you.")
    db.disconnect()
예제 #5
0
def upload_handler(msg):
    permitted_for_update[msg.chat.id] = False
    permitted_for_answer[msg.chat.id] = True
    plain_text = msg.text
    if plain_text.strip().lower() == 'break':
        bot.send_message(msg.chat.id, "Upload abandoned")
        return
    processed, unprocessed = parse(plain_text)
    db = DBManager(DB_PATH)
    db.connect()
    db.add_words(msg.chat.id, processed)
    resp1 = "Processed words:" + \
            " ".join(map(lambda s: " ".join(s) + '\n', processed)) + "\n"
    resp2 = "Unprocessed words:" + \
            " ".join(map(lambda s: " ".join(s) + '\n', unprocessed))
    bot.send_message(msg.chat.id, resp1 + resp2)
예제 #6
0
def add_time_handler(msg):
    """
    "Send me message ALSO at this time"

    :param msg: message
    :return: None
    """
    raw_data = msg.text.split(' ')
    if len(raw_data) != 2 or not is_valid_time_string(raw_data[1]):
        bot.send_message(
            msg.chat.id,
            "Inconsistent time format, try to stick with hh:mm:ss")
    else:
        time_string = raw_data[1]
        db = DBManager(DB_PATH)
        db.connect()
        db.add_scheduled_time_by_uid(msg.chat.id, time_string)
        bot.send_message(msg.chat.id, f"Time {time_string} added in schedule")
예제 #7
0
def next_word_handler(msg):
    """
    "I dont want wait, or I can not answer given word - give me a new one"
    (Implicitly modifies global words buffer)

    :param msg: message
    :return: None
    """
    global words_buffer
    db = DBManager(DB_PATH)
    db.connect()
    new_pair = build_random_words_by_uids(db, [msg.chat.id])
    db.disconnect()
    if not new_pair:
        bot.send_message(msg.chat.id, "You haven't added any words yet")
        return
    if msg.chat.id in words_buffer:
        words_buffer.pop(msg.chat.id)  # ensure absence of previous word
    callback([msg.chat.id], new_pair)
    permitted_for_answer[msg.chat.id] = True
    permitted_for_update[msg.chat.id] = False