コード例 #1
0
ファイル: source.py プロジェクト: Eng-MFQ/InnoCalendar
 def weekday_select_handler(message):
     """
     Handler for schedule request of specific weekday
     """
     log(permanent.MODULE_NAME, message)
     # check user is configured
     if not controller.get_user(message.chat.id).is_configured:
         bot.send_message(message.chat.id,
                          permanent.MESSAGE_USER_NOT_CONFIGURED,
                          reply_markup=main_markup)
         return
     # remove star symbol if needed
     weekday = message.text[:2]
     # force check message is weekday due to some bug
     if weekday not in permanent.TEXT_DAYS_OF_WEEK:
         return
     # get list of lessons for specified user and day
     schedule = controller.get_day_lessons(
         message.from_user.id,
         day=permanent.TEXT_DAYS_OF_WEEK.index(weekday))
     elective_shedule = get_day_elective_lessons(
         message.from_user.id,
         day=permanent.TEXT_DAYS_OF_WEEK.index(weekday))
     # convert lessons to understandable string output
     reply = "Core Courses:\n"
     reply += permanent.MESSAGE_FREE_DAY if not schedule else \
         permanent.HEADER_SEPARATOR.join(str(lesson) for lesson in schedule)
     reply += '\nElectives:\n'
     reply += (MESSAGE_FREE_DAY_ELECTIVE
               if not elective_shedule else permanent.HEADER_SEPARATOR.join(
                   str(lesson) for lesson in elective_shedule))
     bot.send_message(message.chat.id, reply, reply_markup=main_markup)
コード例 #2
0
ファイル: source.py プロジェクト: Eng-MFQ/InnoCalendar
    def process_course_step(message):
        """
        Get user's course and request course group
        """
        log(permanent.MODULE_NAME, message)
        if not message.text:
            bot.send_message(message.chat.id,
                             permanent.MESSAGE_ERROR,
                             reply_markup=main_markup)
            return
        course = message.text
        # check course is in registered courses
        if course not in permanent.REGISTERED_COURSES.keys():
            bot.send_message(message.chat.id,
                             permanent.MESSAGE_ERROR,
                             reply_markup=main_markup)
            return
        controller.append_user_group(message.from_user.id, course)

        options = telebot.types.ReplyKeyboardMarkup(True, False)
        # add buttons of groups in selected course
        options.add(*list(permanent.REGISTERED_COURSES[course]))
        msg = bot.send_message(message.chat.id,
                               permanent.REQUEST_GROUP,
                               reply_markup=options)
        bot.register_next_step_handler(msg, process_group_step)
コード例 #3
0
ファイル: source.py プロジェクト: Eng-MFQ/InnoCalendar
    def schedule_command_handler(message):
        """
        Register module's commands
        """
        log(permanent.MODULE_NAME, message)
        if '/friend' in message.text:
            # both '/friend' and '/friend @alias' are supported
            if message.text == "/friend":
                msg = bot.send_message(message.chat.id,
                                       permanent.REQUEST_ALIAS)
                bot.register_next_step_handler(msg,
                                               process_friend_request_step)
            elif len(message.text) > 8:
                alias = message.text[8:].strip()
                send_friend_schedule(message, alias)
        elif message.text == '/configure_schedule':
            # Register user if he is not registered
            if not controller.get_user(message.from_user.id):
                controller.register_user(message.from_user.id,
                                         message.from_user.username)

            # set configured to false and remove his groups
            controller.set_user_configured(message.from_user.id, False)
            options = telebot.types.ReplyKeyboardMarkup(True, False)

            # add buttons to choose course
            options.add(*list(permanent.REGISTERED_COURSES.keys()))
            msg = bot.send_message(message.chat.id,
                                   permanent.REQUEST_COURSE,
                                   reply_markup=options)
            bot.register_next_step_handler(msg, process_course_step)
コード例 #4
0
ファイル: source.py プロジェクト: Eng-MFQ/InnoCalendar
 def process_request_string(message):
     """
     Get and save new user's favorite string
     """
     # log message
     log(permanent.MODULE_NAME, message)
     # save new string to db
     controller.set_string(message.from_user.id, message.text)
     # notify user of changes
     bot.send_message(message.chat.id, permanent.MESSAGE_STRING_SAVED)
コード例 #5
0
ファイル: source.py プロジェクト: Eng-MFQ/InnoCalendar
 def process_friend_request_step(message):
     """
     Get friend's alias after /friend command to show his current schedule
     """
     log(permanent.MODULE_NAME, message)
     if not message.text:
         bot.send_message(message.chat.id,
                          permanent.MESSAGE_ERROR,
                          reply_markup=main_markup)
         return
     send_friend_schedule(message, message.text)
コード例 #6
0
 def admin(message):
     """
     Register module's commands
     """
     log(permanent.MODULE_NAME, message)
     # only admins from list are allowed to call admin commands
     if message.from_user.id not in permanent.ADMIN_LIST:
         bot.send_message(message.chat.id, permanent.MESSAGE_UNAUTHORIZED)
         return
     elif message.text == '/helpa':
         # send admin commands help
         bot.send_message(message.chat.id, ' '.join(admin_commands))
コード例 #7
0
ファイル: source.py プロジェクト: Eng-MFQ/InnoCalendar
 def remind_command_handler(message):
     """
     Register commands to change module settings
     """
     log(permanent.MODULE_NAME, message)
     if message.text == '/configure_remind':
         markup = telebot.types.ReplyKeyboardMarkup(True, False)
         markup.add(permanent.MESSAGE_YES, permanent.MESSAGE_NO)
         msg = bot.send_message(message.chat.id,
                                permanent.REQUEST_REMINDERS,
                                reply_markup=markup)
         bot.register_next_step_handler(msg, process_reminders_step)
コード例 #8
0
ファイル: source.py プロジェクト: Eng-MFQ/InnoCalendar
    def add_course_handler(message):
        """
        Register module's commands
        """
        log(permanent.MODULE_NAME, message)
        if message.text == '/add_course':
            lessons = controller.get_electives_course()
            options = telebot.types.ReplyKeyboardMarkup(True, False)

            for lesson in lessons:
                line_list = telebot.types.KeyboardButton(lesson.subject)
                options.row(line_list)

            reply = str("What course you want to add?")
            msg = bot.send_message(message.chat.id, reply, reply_markup=options)
            bot.register_next_step_handler(msg, process_electives)
コード例 #9
0
ファイル: source.py プロジェクト: Eng-MFQ/InnoCalendar
 def process_english_step(message):
     """
     Save user`s english group to database
     """
     log(permanent.MODULE_NAME, message)
     if not message.text or len(
             message.text
     ) != 8 or message.text[:6] not in permanent.REGISTERED_COURSES["B19"]:
         bot.send_message(message.chat.id,
                          permanent.MESSAGE_ERROR,
                          reply_markup=main_markup)
         return
     controller.append_user_group(message.from_user.id, message.text)
     controller.set_user_configured(message.from_user.id, True)
     bot.send_message(message.chat.id,
                      permanent.MESSAGE_SETTINGS_SAVED,
                      reply_markup=main_markup)
コード例 #10
0
ファイル: source.py プロジェクト: Eng-MFQ/InnoCalendar
    def process_group_step(message):
        """
        Save user`s group choice to database
        """
        log(permanent.MODULE_NAME, message)
        # check msg has text
        if not message.text:
            bot.send_message(message.chat.id,
                             permanent.MESSAGE_ERROR,
                             reply_markup=main_markup)
            return
        if message.text[:3] in permanent.REGISTERED_COURSES.keys():
            user_course = message.text[:3]
        elif message.text[:4] in permanent.REGISTERED_COURSES.keys():
            user_course = message.text[:4]
        else:
            bot.send_message(message.chat.id,
                             permanent.MESSAGE_ERROR,
                             reply_markup=main_markup)
            return
        if message.text not in permanent.REGISTERED_COURSES[user_course]:
            bot.send_message(message.chat.id,
                             permanent.MESSAGE_ERROR,
                             reply_markup=main_markup)
            return

        course_BS = message.text
        if user_course == 'B19':
            # B19 need special configuration for english group
            options = telebot.types.ReplyKeyboardMarkup(True, False)
            # add buttons for english group select
            options.add(*[
                f"{course_BS}-{group}"
                for group in permanent.B19_ENGLISH_GROUPS
            ])
            msg = bot.send_message(message.chat.id,
                                   permanent.REQUEST_ENGLISH,
                                   reply_markup=options)
            bot.register_next_step_handler(msg, process_english_step)
        else:
            controller.append_user_group(message.from_user.id, message.text)
            controller.set_user_configured(message.from_user.id, True)
            bot.send_message(message.chat.id,
                             permanent.MESSAGE_SETTINGS_SAVED,
                             reply_markup=main_markup)
コード例 #11
0
ファイル: source.py プロジェクト: Eng-MFQ/InnoCalendar
 def schedule_command_handler(message):
     """
     Register module's commands
     """
     # log message
     log(permanent.MODULE_NAME, message)
     # get user's favorite string from database
     favorite_string = controller.get_string(message.from_user.id)
     # set default string if no such found
     if not favorite_string:
         favorite_string = permanent.TEXT_DEFAULT_STRING
         controller.register_user(message.from_user.id, favorite_string)
     if message.text == '/set_favorite_string':
         # send string request
         msg = bot.send_message(message.chat.id, permanent.REQUEST_FAVORITE_STRING)
         # register new single-use message handler
         bot.register_next_step_handler(msg, process_request_string)
     elif message.text == '/get_favorite_string':
         bot.send_message(message.chat.id, favorite_string)
コード例 #12
0
ファイル: source.py プロジェクト: Eng-MFQ/InnoCalendar
 def process_reminders_step(message):
     """
     Save user if he wants reminders or delete him from db otherwise
     """
     log(permanent.MODULE_NAME, message)
     if not message.text:
         bot.send_message(message.chat.id,
                          permanent.MESSAGE_ERROR,
                          reply_markup=main_markup)
         return
     user_id = message.from_user.id
     if message.text == permanent.MESSAGE_YES:
         controller.register_user(user_id)
     elif message.text == permanent.MESSAGE_NO:
         controller.delete_user(user_id)
     else:
         bot.send_message(message.chat.id,
                          permanent.MESSAGE_ERROR,
                          reply_markup=main_markup)
         return
     bot.send_message(message.chat.id,
                      permanent.MESSAGE_SETTINGS_SAVED,
                      reply_markup=main_markup)
コード例 #13
0
ファイル: source.py プロジェクト: Eng-MFQ/InnoCalendar
    def main_buttons_handler(message):
        """
        Handler for processing three main buttons requests
        """
        log(permanent.MODULE_NAME, message)
        # check user if configured
        user = controller.get_user(message.chat.id)
        if not user or not user.is_configured:
            bot.send_message(message.chat.id,
                             permanent.MESSAGE_USER_NOT_CONFIGURED,
                             reply_markup=main_markup)
            return

        # update alias if it was changed
        controller.set_user_alias(message.from_user.id,
                                  message.from_user.username)

        if message.text == permanent.TEXT_BUTTON_NOW:
            send_current_schedule(message.chat.id, message.from_user.id)
        elif message.text == permanent.TEXT_BUTTON_DAY:
            markup = telebot.types.ReplyKeyboardMarkup(True)
            buttons = list()
            day_of_week = datetime.today().weekday()
            # make list of weekdays and add star for today
            for i, day in enumerate(permanent.TEXT_DAYS_OF_WEEK):
                buttons.append(
                    telebot.types.KeyboardButton(
                        day if day_of_week != i else day + "⭐"))
            markup.add(*buttons)
            bot.send_message(message.chat.id,
                             permanent.REQUEST_WEEKDAY,
                             reply_markup=markup)
        elif message.text == permanent.TEXT_BUTTON_WEEK:
            bot.send_message(message.chat.id,
                             permanent.MESSAGE_FULL_WEEK,
                             reply_markup=main_markup)
コード例 #14
0
ファイル: source.py プロジェクト: Eng-MFQ/InnoCalendar
 def inline_friend_command_handler(message):
     """
     Show friend's schedule if his alias was sent without /friend command
     """
     log(permanent.MODULE_NAME, message)
     send_friend_schedule(message, message.text)