Beispiel #1
0
def start(bot, message):
    if message.message.chat_id not in locals:
        addlocal(message.message.chat_id)
    admin = next((x for x in admins if x.ID == message.message.chat_id), None)
    if admin is not None:

        reply_markup = replykeyboardmarkup.ReplyKeyboardMarkup(
            [[
                get_text("Present", admin.ID),
                get_text("Not present", admin.ID),
                get_text("Time", admin.ID)
            ], [get_text("look_requests", admin.ID)]],
            resize_keyboard=True)
        bot.send_message(message.message.chat_id,
                         get_text("set_status", admin.ID) %
                         (message.message.chat.first_name),
                         reply_markup=reply_markup)
    else:
        reply_markup = replykeyboardmarkup.ReplyKeyboardMarkup(
            [["\U0001F4A4", "\U0001F4A7"],
             [get_text("change_campus", message.message.chat_id)],
             [get_text("leave_request", message.message.chat_id)]],
            resize_keyboard=True)
        bot.send_message(message.message.chat_id,
                         get_text("user_start", message.message.chat_id) %
                         (message.message.chat.first_name),
                         reply_markup=reply_markup)
        check_campus(bot, message.message.chat_id)
Beispiel #2
0
def handle_cb(bot, update):

    logging.info("Entering handle_cb()")

    session = update.callback_query.from_user.id
    matched_obj = re.match(re.compile(snooze_cb_regex),
                           update.callback_query["data"])

    if matched_obj != None:
        logging.info("This is a snooze callback.")
        snoozing_memo[session] = matched_obj.group(1)

        markup = replykeyboardmarkup.ReplyKeyboardMarkup(
            keyboard=keyboard_snooze)
        bot.sendMessage(chat_id=session,
                        text=msg_snooze_till_when,
                        reply_markup=markup)

        return SNOOZE

    else:
        logging.info("This is a recur callback.")
        matched_obj = re.match(re.compile(recur_cb_regex),
                               update.callback_query["data"])
        recur_memo[session] = matched_obj.group(1)

        logging.info("target memo id : {}".format(recur_memo[session]))

        markup = replykeyboardmarkup.ReplyKeyboardMarkup(
            keyboard=keyboard_recur_remind_date)
        bot.sendMessage(chat_id=session,
                        text=msg_remind_date,
                        reply_markup=markup)

        return RECUR
Beispiel #3
0
def snooze_options(bot, update):
    logging.info("Entering snooze_options()")

    session = update.message.chat_id
    snooze_by_id(snoozing_memo[session])

    reference_date = date.today()
    if update.message.text == button_snooze_1D:
        obj_date = reference_date + timedelta(days=1)
    elif update.message.text == button_snooze_2D:
        obj_date = reference_date + timedelta(days=2)
    elif update.message.text == button_snooze_3D:
        obj_date = reference_date + timedelta(days=3)
    elif update.message.text == button_snooze_1W:
        obj_date = reference_date + timedelta(days=7)
    else:
        if update.message.text != button_next_schedule:
            bot.sendMessage(chat_id=session,
                            text=msg_cannot_process_date_input)
            return None

    if update.message.text != button_next_schedule:
        update_remind_date_by_id(snoozing_memo[session], obj_date)

    bot.sendMessage(chat_id=session, text=msg_done_add)

    markup = replykeyboardmarkup.ReplyKeyboardMarkup(keyboard=keyboard_start)
    bot.sendMessage(chat_id=session, text=msg_greeting, reply_markup=markup)

    del snoozing_memo[session]
    return -1
Beispiel #4
0
def recur_options(bot, update):
    logging.info("Entering recur_options()")
    session = update.message.chat_id

    target_memo = get_memo_by_id(recur_memo[session])
    memo_end_date = target_memo["endDate"]

    new_end_date_yyyy = memo_end_date.year + 1 if memo_end_date.month == 12 else memo_end_date.year
    new_end_date_mm = 1 if memo_end_date.month == 12 else memo_end_date.month + 1

    new_end_date = date(new_end_date_yyyy, new_end_date_mm, memo_end_date.day)

    if update.message.text == button_remind_1D:
        new_remind_date = new_end_date + timedelta(days=-1)
    elif update.message.text == button_remind_2D:
        new_remind_date = new_end_date + timedelta(days=-2)
    elif update.message.text == button_remind_3D:
        new_remind_date = new_end_date + timedelta(days=-3)
    elif update.message.text == button_remind_1W:
        new_remind_date = new_end_date + timedelta(days=-7)
    elif update.message.text == button_remind_10D:
        new_remind_date = new_end_date + timedelta(days=-10)
    elif update.message.text == button_remind_2W:
        new_remind_date = new_end_date + timedelta(days=-14)

    update_end_and_remind_by_id(recur_memo[session], new_end_date,
                                new_remind_date)

    bot.sendMessage(chat_id=session, text=msg_done_add)
    markup = replykeyboardmarkup.ReplyKeyboardMarkup(keyboard=keyboard_start)
    bot.sendMessage(chat_id=session, text=msg_greeting, reply_markup=markup)

    del recur_memo[session]
    return -1
Beispiel #5
0
def memo_name(bot, update):
    memos[update.message.chat_id].memo_text = update.message.text

    markup = replykeyboardmarkup.ReplyKeyboardMarkup(
        keyboard=keyboard_end_date)
    bot.sendMessage(chat_id=update.message.chat_id,
                    text=msg_end_date,
                    reply_markup=markup)
    return END_DATE
Beispiel #6
0
def remind_date_calendar(bot, update):
    markup = replykeyboardmarkup.ReplyKeyboardMarkup(
        keyboard=gen_calendar_keyboard(
            memos[update.message.chat_id].moving_year, memos[
                update.message.chat_id].moving_mth))

    bot.sendMessage(chat_id=update.message.chat_id,
                    text=msg_pls_choose_date,
                    reply_markup=markup)

    return REMIND_DATE_CALENDAR
Beispiel #7
0
def add_new_expense(bot, update):
    logging.info("Entered add_new_expense()")
    # bot.sendMessage(chat_id=update.message.chat_id)
    session = update.message.chat_id
    captioned_expense[session] = expense()

    markup = replykeyboardmarkup.ReplyKeyboardMarkup(keyboard=keyboard_date)
    bot.sendMessage(chat_id=update.message.chat_id, text=msg_input_date,
                    reply_markup=markup)
    logging.info("Quiting add_new_expense()")
    return NEW_EXPENSE_DATE
Beispiel #8
0
def set_end_date(bot, update, yyyy, mm, dd):
    obj_date = date(yyyy, mm, dd)
    memos[update.message.chat_id].memo_end_date = obj_date
    bot.sendMessage(chat_id=update.message.chat_id,
                    text=msg_input_date.format(
                        memos[update.message.chat_id].memo_end_date.__str__()))

    markup = replykeyboardmarkup.ReplyKeyboardMarkup(
        keyboard=keyboard_remind_date)
    bot.sendMessage(chat_id=update.message.chat_id,
                    text=msg_remind_date,
                    reply_markup=markup)
Beispiel #9
0
def end_date_calendar(bot, update):
    calendar_date = date.today()
    markup = replykeyboardmarkup.ReplyKeyboardMarkup(
        keyboard=gen_calendar_keyboard(calendar_date.year,
                                       calendar_date.month))

    logging.info("before send calendar")
    # logging.info(markup_pkg)
    bot.sendMessage(chat_id=update.message.chat_id,
                    text=msg_pls_choose_date,
                    reply_markup=markup)
    logging.info("after send calendar")
    return END_DATE_CALENDAR
Beispiel #10
0
def del_memo(bot, update):
    matched_obj = re.match(re.compile(regex_del_item_prefix),
                           update.message.text)
    del_idx = matched_obj.group(1)
    send_memo_detail(bot, update, del_idx)

    captioned_memo[update.message.chat_id] = int(del_idx)

    markup = replykeyboardmarkup.ReplyKeyboardMarkup(
        keyboard=keyboard_confirm_del)
    bot.sendMessage(chat_id=update.message.chat_id,
                    text=msg_confirm_to_del,
                    reply_markup=markup)

    return DEL_ITEM
Beispiel #11
0
def choose_from_cats(bot, update):
    logging.info("Entered choose_from_cats()")

    # cat_list = get_expense_cat()
    logging.debug("Extracted catagory list : {}".format(cat_list))

    keyboard_cat = []

    for idx, each_cat in enumerate(cat_list):
        if idx % 3 == 0:
            keyboard_cat.append([])

        keyboard_cat[len(keyboard_cat) - 1].append(each_cat)

    markup = replykeyboardmarkup.ReplyKeyboardMarkup(keyboard=keyboard_cat)
    bot.sendMessage(chat_id=update.message.chat_id, text=msg_which_cat, reply_markup=markup)

    logging.info("Quiting choose_from_cats()")
Beispiel #12
0
def next_mth(bot, update):
    curr_year = memos[update.message.chat_id].moving_year
    curr_mth = memos[update.message.chat_id].moving_mth

    if curr_mth == 12:
        curr_mth = 1
        curr_year = curr_year + 1
    else:
        curr_mth = curr_mth + 1

    memos[update.message.chat_id].moving_year = curr_year
    memos[update.message.chat_id].moving_mth = curr_mth

    markup = replykeyboardmarkup.ReplyKeyboardMarkup(
        keyboard=gen_calendar_keyboard(curr_year, curr_mth))
    bot.sendMessage(chat_id=update.message.chat_id,
                    text=msg_confirm_curr_mth.format(curr_year.__str__(),
                                                     curr_mth.__str__()),
                    reply_markup=markup)
    return None
Beispiel #13
0
def show_all(bot, update):
    keyboard_list = [[button_confirm]]

    if update.message.chat_id in jin_list_cache:
        del jin_list_cache[update.message.chat_id]

    jin_list_cache[update.message.chat_id] = []

    for idx, each_memo in enumerate(get_all_memos()):
        jin_list_cache[update.message.chat_id].append(each_memo)
        keyboard_list.append([
            button_each_item_prefix.format(idx.__str__(), each_memo["item"]),
            button_each_item_del.format(idx.__str__())
        ])

    markup = replykeyboardmarkup.ReplyKeyboardMarkup(keyboard=keyboard_list)

    bot.sendMessage(chat_id=update.message.chat_id,
                    text=msg_all_memos_as_show,
                    reply_markup=markup)

    return SHOW_ALL
Beispiel #14
0
def set_remind_date(bot, update, yyyy, mm, dd):
    obj_date = date(yyyy, mm, dd)
    memos[update.message.chat_id].remind_date = obj_date
    bot.sendMessage(chat_id=update.message.chat_id,
                    text=msg_input_date.format(
                        memos[update.message.chat_id].remind_date.__str__()))

    markup = replykeyboardmarkup.ReplyKeyboardMarkup(keyboard=keyboard_start)
    bot.sendMessage(chat_id=update.message.chat_id,
                    text=msg_done_add,
                    reply_markup=markup)

    memos[update.message.chat_id].save_data()

    for admin_id in LIST_OF_ADMINS:
        bot.sendMessage(chat_id=admin_id,
                        text=msg_add_memo_detail.format(
                            memos[update.message.chat_id].memo_text,
                            memos[update.message.chat_id].memo_end_date,
                            memos[update.message.chat_id].remind_date))

    del memos[update.message.chat_id]
Beispiel #15
0
from telegram import replykeyboardmarkup, replykeyboardremove
from telegram.ext import Updater
from telegram.ext import CommandHandler, MessageHandler, Filters

from credentials import TBToken, bd

from keyboards import reg_keyboard, reg_keyboard2, loc_keyboard, locations, date_keyboard, dates, time_keyboard, times
from parsers import email_validator, otp_validator, name_surname_validator, name_surname_extractor
from DBMS import add_user, check_user, update_user, check_user_OTP, add_event_request, update_event_request, find_a_match, my_matched_requests, my_waiting_requests

updater = Updater(token=TBToken)
# JQ = updater.job_queue #for future, in order to add possibility of notification in TG
dispatcher = updater.dispatcher

reg_markup = replykeyboardmarkup.ReplyKeyboardMarkup(reg_keyboard,
                                                     one_time_keyboard=True)
reg_markup2 = replykeyboardmarkup.ReplyKeyboardMarkup(reg_keyboard2,
                                                      one_time_keyboard=True)
loc_markup = replykeyboardmarkup.ReplyKeyboardMarkup(loc_keyboard,
                                                     one_time_keyboard=True)
date_markup = replykeyboardmarkup.ReplyKeyboardMarkup(date_keyboard,
                                                      one_time_keyboard=True)
time_markup = replykeyboardmarkup.ReplyKeyboardMarkup(time_keyboard,
                                                      one_time_keyboard=True)


def start(bot, update, args):
    print("start started")
    c_i = update.message.chat_id
    c_u = check_user(c_i)
    if c_u:
Beispiel #16
0
def start(bot, update):
    logging.info("Entered start()")
    markup = replykeyboardmarkup.ReplyKeyboardMarkup(keyboard=keyboard_start)
    bot.sendMessage(chat_id=update.message.chat_id, text=msg_greeting,
                    reply_markup=markup)
    logging.info("Quiting start()")
Beispiel #17
0
def start(bot, update):
    markup = replykeyboardmarkup.ReplyKeyboardMarkup(keyboard=keyboard_start)
    bot.sendMessage(chat_id=update.message.chat_id,
                    text=msg_greeting,
                    reply_markup=markup)
Beispiel #18
0
def show_all_confirmed(bot, update):
    markup = replykeyboardmarkup.ReplyKeyboardMarkup(keyboard=keyboard_start)
    bot.sendMessage(chat_id=update.message.chat_id,
                    text=msg_greeting,
                    reply_markup=markup)
    return -1