Exemplo n.º 1
0
def status_message(message):
    with DBInterface(config.database_name) as db:
        courses = db.get_chat_courses(message.chat.id)
    if not courses:
        bot.send_message(message.chat.id,**config.md_mes(config.no_courses_message))
        return
    bot.send_message(message.chat.id,**config.md_mes(format_status(courses)))
Exemplo n.º 2
0
def check_handler(message):
    if len(message.text.split())>=1:
        answers = []
        for mes in message.text.split()[1:]:
            try:
                ans = parser.get_course_info(mes)
            except (parser.WebExeption, parser.URLExeption):
                bot.send_message(message.chat.id,**config.md_mes(
                    config.parser_error_message))
                return
            answers.append(config.check_message % ans[1:])
        answer = '\n'.join(answers)
        bot.send_message(message.chat.id,**config.md_mes(answer))
    else:
        bot.send_message(message.chat.id,**config.md_mes(config.no_link_error))
Exemplo n.º 3
0
 def notification(self, old_full, busy, places, course_followers):
     if old_full and (busy < places):
         for course_name, chat_id, add_time, in course_followers:
             self.bot.send_message(
                 chat_id,
                 config.md_mes(config.course_not_full_message %
                               (course_name, busy, places)))
Exemplo n.º 4
0
def follow_handler(message):
    try:
        if len(message.text.split())>=1:
            for mes in message.text.split()[1:]:
                course_info = parser.get_course_info(mes)
                t = time.time() 
                with DBInterface(config.database_name) as db:
                    db = DBInterface(config.database_name)
                    db.add_course(*course_info,add_time=t)
                    db.follow(message.chat.id,course_info[0],t)
                bot.send_message(message.chat.id,
                    **config.md_mes(config.successful_follow_message % course_info[1:]))
        else:
            bot.send_message(message.chat.id,**config.md_mes(config.no_link_error))
    except DatabaseError as e:
        bot.send_message(message.chat.id, **config.md_mes(config.database_error_message))
        print(str(e))
Exemplo n.º 5
0
def unfollow_handler(message):
    try:
        if len(message.text.split())>=1:
            for mes in message.text.split()[1:]:
                course_info = parser.get_course_info(mes)
                with DBInterface(config.database_name) as db:
                    res = db.unfollow(course_info[0], message.chat.id)
                    if res:
                        bot.send_message(message.chat.id, **config.md_mes(
                            config.successful_unfollow_message % course_info[1]))
                    else:
                        bot.send_message(message.chat.id, **config.md_mes(
                            config.not_following_message % course_info[1]))
        else:
            bot.send_message(message.chat.id,**config.md_mes(config.no_link_error))

    except DatabaseError as e:
        bot.send_message(message.chat.id, **config.md_mes(config.database_error_message))
        print(str(e))
Exemplo n.º 6
0
def my_id_handler(message):
    bot.send_message(message.chat.id,**config.md_mes(str(message.chat.id)))
Exemplo n.º 7
0
def help_handler(message):
    bot.send_message(message.chat.id,**config.md_mes( config.help_message))
Exemplo n.º 8
0
def start_handler(message):
    answer = '\n'.join([config.hello_message, config.help_message])
    with DBInterface(config.database_name) as db:
        db.add_chat(message.chat.id)
    bot.send_message(message.chat.id,**config.md_mes(answer))