Esempio n. 1
0
    def get_date(message):
        if message.text == '/exit':
            return_to_menu()
        elif re.fullmatch(r'\d{1,2}\s\d{1,2}\s\d{1,2}', message.text):
            in_date = message.text.split()
            cw_ = Course.Classwork(call.data['c_id'], call.data['cw_id'])

            try:
                date = datetime.date(2000 + int(in_date[0]), int(in_date[1]),
                                     int(in_date[2])).strftime('%d %b %Y')
            except ValueError:
                botHelper.send_mes(
                    msgs[get_lang(call.message.chat.id)]['teacher']
                    ['management']['wrong_input'], message.messasge_id)
                bot.register_next_step_handler(message, get_date)
            else:
                cw_.date = date
                cw_.name = date

                return_to_menu()
        else:
            botHelper.send_mes(
                msgs[get_lang(call.message.chat.id)]['teacher']['management']
                ['wrong_input'], message.messasge_id)
            bot.register_next_step_handler(message, get_date)
Esempio n. 2
0
def menu_command(message):
    lang = get_lang(message.chat.id)

    if User.User(message.chat.id).type_u == 'unlogined':
        botHelper.send_mes(msgs[lang]['common']['new_user'], message.chat.id)
    else:
        if User.User(message.chat.id).type_u == 'student':
            markup = mkp.create(lang, [
                cbt.course_list_of('all', lang),
                cbt.course_list_of('my', lang)
            ],
                                include_back=False)

            botHelper.send_mes(msgs[get_lang(
                message.chat.id)]['common']['menu'],
                               message.chat.id,
                               markup=markup)
        else:
            markup = mkp.create(lang, [
                cbt.course_list_of('all', lang),
                cbt.course_list_of('my', lang)
            ], [tbt.manage_list(lang)], [tbt.new_course(lang)],
                                include_back=False)

            botHelper.send_mes(msgs[get_lang(
                message.chat.id)]['common']['menu'],
                               message.chat.id,
                               markup=markup)
Esempio n. 3
0
def announce(call):
    def return_to_menu():
        new_mes = botHelper.send_mes('empty', call.message.chat.id)
        botHelper.renew_menu(call, new_mes)
        back(call, True)

    def cancel():
        botHelper.send_mes(msgs[lang]['teacher']['announce']['cancel'])
        return_to_menu()

    def send():
        course_ = Course.Course(call.data['c_id'])

        for part in course_.participants:
            try:
                botHelper.send_mes(
                    msgs[lang]['teacher']['announce']['got_announce'].format(
                        course_.name), part.id)
                botHelper.send_mes(announce_info['text'], part.id)
                for file, caption in zip(announce_info['file'],
                                         announce_info['file_caption']):
                    bot.send_document(part.id, file, caption=caption)
            except TBotApiException:
                continue

        botHelper.send_mes(msgs[lang]['teacher']['announce']['sent'],
                           call.message.chat.id)

        return_to_menu()

    def get_file(message):
        if message.text == '/exit':
            cancel()
        elif message.text == '/send':
            send()
        else:
            if message.document:
                announce_info['file'].append(message.document.file_id)
                announce_info['file_caption'].append(message.caption)
                bot.register_next_step_handler(message, get_file)

    def get_text(message):
        if message.text == '/exit':
            cancel()
        else:
            announce_info['text'] = message.text

            botHelper.send_mes(msgs[lang]['teacher']['announce']['files'],
                               call.message.chat.id)
            bot.register_next_step_handler(message, get_file)

    call.data = json.loads(call.data)
    lang = get_lang(call.message.chat.id)
    announce_info = {'text': '', 'file': [], 'file_caption': []}

    botHelper.edit_mes(msgs[lang]['teacher']['announce']['begin'], call)
    botHelper.send_mes(msgs[lang]['teacher']['announce']['input_text'],
                       call.message.chat.id)
    bot.register_next_step_handler(call.message, get_text)
Esempio n. 4
0
    def get_mark(message):
        if message.text == '/exit':
            return_to_menu()
        elif message.text == '-1':
            mark.value = None
        elif re.fullmatch(r'\d+', message.text):
            if int(message.text) <= task_.highest_mark:
                mark.value = int(message.text)

                return_to_menu()
            else:
                botHelper.send_mes(msgs[get_lang(call.message.chat.id)]
                                   ['teacher']['management']['error_mark'])
                bot.register_next_step_handler(message, get_mark)
        else:
            botHelper.send_mes(msgs[get_lang(
                call.message.chat.id)]['teacher']['management']['wrong_input'])
            bot.register_next_step_handler(message, get_mark)
Esempio n. 5
0
def confirm(call):
    call.data = json.loads(call.data)

    text = botHelper.get_from_disc(get_confirm_message, call=call)
    if text:
        botHelper.edit_mes(text,
                           call,
                           markup=mkp.create_confirm(
                               get_lang(call.message.chat.id), call.data))
Esempio n. 6
0
def menu(call):
    lang = get_lang(call.message.chat.id)

    if User.User(call.message.chat.id).type_u == 'student':
        markup = mkp.create(
            lang,
            [cbt.course_list_of('all', lang),
             cbt.course_list_of('my', lang)],
            include_back=False)

        botHelper.edit_mes(msgs[lang]['common']['menu'], call, markup=markup)
    else:
        markup = mkp.create(
            lang,
            [cbt.course_list_of('all', lang),
             cbt.course_list_of('my', lang)], [tbt.manage_list(lang)],
            [tbt.new_course(lang)],
            include_back=False)

        botHelper.edit_mes(msgs[lang]['common']['menu'], call, markup=markup)
Esempio n. 7
0
    def idle():
        if course_info['lock'] is None:
            t = None
        else:
            t = UI.to_dtime(course_info['lock'])

        if course_info['name'] and course_info['desc']:
            c = creating['valid']
        elif course_info['name'] and not course_info['desc']:
            c = creating['desc']
        elif not course_info['name'] and course_info['desc']:
            c = creating['name']
        else:
            c = creating['both']

        text = msgs[get_lang(
            chat_id)]['teacher']['course_create']['new_course'].format(
                name=course_info['name'],
                desc=course_info['desc'],
                lock=t,
                create=c)

        msg = botHelper.send_mes(text, chat_id)
        bot.register_next_step_handler(msg, get_user_command)
Esempio n. 8
0
def registration(message):
    def name(msg):
        if re.fullmatch(r"[a-zA-Zа-яА-Я]+ [a-zA-Zа-яА-Я ]+", msg.text):
            user.name = msg.text

            menu_command(msg)
        else:
            botHelper.send_mes(
                msgs[lang]['common']['registration']['wrong_name'],
                message.chat.id)
            bot.register_next_step_handler(message, name)

    lang = get_lang(message.chat.id)

    if User.User(message.chat.id).type_u == 'unlogined':
        try:
            user = User.User(id=message.chat.id,
                             username=message.from_user.username,
                             name='noname')
            botHelper.send_mes(msgs[lang]['common']['registration']['teacher'],
                               message.chat.id)
        except User.TeacherAccessDeniedError:
            user = User.User(id=message.chat.id,
                             name='noname',
                             group='1',
                             email='*****@*****.**')
            botHelper.send_mes(
                msgs[lang]['common']['registration']['mere_human'],
                message.chat.id)

        botHelper.send_mes(msgs[lang]['common']['registration']['input'],
                           message.chat.id)
        bot.register_next_step_handler(message, name)
    else:
        botHelper.send_mes(msgs[lang]['common']['registration']['already'],
                           message.chat.id)
Esempio n. 9
0
def new_task(call):
    def return_to_menu():
        new_mes = botHelper.send_mes('empty', call.message.chat.id)
        botHelper.renew_menu(call, new_mes)
        back(call, True)

    def cancel():
        botHelper.send_mes(msgs[lang]['teacher']['task_create']['canceled'],
                           call.message.chat.id)
        return_to_menu()

    def create():
        name = task_info['name']
        if not name:
            name = msgs[lang]['teacher']['task_create']['name'] + str(
                len(Course.Course(call.data['c_id']).tasks) + 1)

        Course.Task(course_id=call.data['c_id'],
                    name=name,
                    description=task_info['desc'].format(task_info['hmark']),
                    highest_mark=task_info['hmark'])

        botHelper.send_mes(msgs[lang]['teacher']['task_create']['created'],
                           call.message.chat.id)
        return_to_menu()

    def get_hmark(message):
        if message.text == '/exit':
            cancel()
        else:
            if message.text != '0' and re.fullmatch(r'\d+', message.text):
                task_info['hmark'] = int(message.text)

                create()
            else:
                botHelper.send_mes(
                    msgs[lang]['teacher']['task_create']['error_max_mark'],
                    call.message.chat.id)
                bot.register_next_step_handler(message, get_hmark)

    def get_desc(message):
        if message.text == '/exit':
            cancel()
        else:
            if len(message.text) <= UI.constants.TASK_DESC_MAX_LENGTH:
                if message.text != '/no':
                    task_info['desc'] += message.text

                botHelper.send_mes(
                    msgs[lang]['teacher']['task_create']['input_max_mark'],
                    call.message.chat.id)
                bot.register_next_step_handler(message, get_hmark)
            else:
                botHelper.send_mes(
                    msgs[lang]['teacher']['task_create']
                    ['error_length'].format(UI.constants.TASK_DESC_MAX_LENGTH),
                    call.message.chat.id)
                bot.register_next_step_handler(message, get_desc)

    def get_name(message):
        if message.text == '/exit':
            cancel()
            return_to_menu()
        else:
            if len(message.text) <= UI.constants.TASK_NAME_MAX_LENGTH:
                if message.text != '/no':
                    task_info['name'] = message.text

                botHelper.send_mes(
                    msgs[lang]['teacher']['task_create']['input_desc'],
                    call.message.chat.id)
                bot.register_next_step_handler(message, get_desc)
            else:
                botHelper.send_mes(
                    msgs[lang]['teacher']['task_create']
                    ['error_length'].format(UI.constants.TASK_NAME_MAX_LENGTH),
                    call.message.chat.id)
                bot.register_next_step_handler(message, get_name)

    call.data = json.loads(call.data)
    lang = get_lang(call.message.chat.id)
    task_info = {
        'name': '',
        'desc': msgs[lang]['teacher']['task_create']['max_mark'],
        'hmark': 0
    }

    botHelper.edit_mes(msgs[lang]['teacher']['task_create']['begin'], call)
    botHelper.send_mes(msgs[lang]['teacher']['task_create']['input_name'],
                       call.message.chat.id)
    bot.register_next_step_handler(call.message, get_name)
Esempio n. 10
0
def create_course(chat_id):
    def idle():
        if course_info['lock'] is None:
            t = None
        else:
            t = UI.to_dtime(course_info['lock'])

        if course_info['name'] and course_info['desc']:
            c = creating['valid']
        elif course_info['name'] and not course_info['desc']:
            c = creating['desc']
        elif not course_info['name'] and course_info['desc']:
            c = creating['name']
        else:
            c = creating['both']

        text = msgs[get_lang(
            chat_id)]['teacher']['course_create']['new_course'].format(
                name=course_info['name'],
                desc=course_info['desc'],
                lock=t,
                create=c)

        msg = botHelper.send_mes(text, chat_id)
        bot.register_next_step_handler(msg, get_user_command)

    def name(message):
        length = len(message.text)
        if UI.constants.COURSE_NAME_LENGTH_MIN <= length <= UI.constants.COURSE_NAME_LENGTH_MAX:
            course_info['name'] = message.text
            idle()
        else:
            botHelper.send_mes(
                msgs[lang]['teacher']['course_create']['error_name_length'],
                chat_id)
            message.text = '/name'
            get_user_command(message)

    def desc(message):
        length = len(message.text)
        if UI.constants.COURSE_DESC_LENGTH_MIN <= length <= UI.constants.COURSE_DESC_LENGTH_MAX:
            course_info['desc'] = message.text
            idle()
        else:
            botHelper.send_mes(
                msgs[lang]['teacher']['course_create']['error_desc_length'],
                chat_id)
            message.text = '/desc'
            get_user_command(message)

    def lock(message):
        if message.text == '0':
            course_info['lock'] = None
            idle()
        elif re.fullmatch(r'\d+', message.text):
            course_info['lock'] = time.time() + (int(message.text) * 24 * 60 *
                                                 60)
            idle()
        else:
            botHelper.send_mes(msgs[lang]['common']['wrong_input'], chat_id)
            message.text = '/lock'
            get_user_command(message)

    def get_user_command(message):
        if message.text == '/name':
            text = msgs[lang]['teacher']['course_create']['name_input'].format(
                UI.constants.COURSE_NAME_LENGTH_MIN,
                UI.constants.COURSE_NAME_LENGTH_MAX)

            botHelper.send_mes(text, chat_id)
            bot.register_next_step_handler(message, name)
        elif message.text == '/desc':
            text = msgs[lang]['teacher']['course_create']['desc_input'].format(
                UI.constants.COURSE_DESC_LENGTH_MIN,
                UI.constants.COURSE_DESC_LENGTH_MAX)

            botHelper.send_mes(text, chat_id)
            bot.register_next_step_handler(message, desc)
        elif message.text == '/lock':
            text = msgs[lang]['teacher']['course_create']['lock_input']

            botHelper.send_mes(text, chat_id)
            bot.register_next_step_handler(message, lock)
        elif message.text == '/create':
            if not course_info['name'] or not course_info['desc']:
                botHelper.send_mes(
                    msgs[lang]['teacher']['course_create']['name_and_desc'],
                    chat_id)
                bot.register_next_step_handler(message, get_user_command)
            else:
                c = Course.Course(owner_id=chat_id, name=course_info['name'])
                c.description = course_info['desc']
                c.entry_restriction = course_info['lock']

                botHelper.send_mes(
                    msgs[lang]['teacher']['course_create']['created'], chat_id)
                menu_command(message)
        elif message.text == '/exit':
            botHelper.send_mes(
                msgs[lang]['teacher']['course_create']['canceled'], chat_id)
            menu_command(message)
        else:
            botHelper.send_mes(
                msgs[lang]['teacher']['course_create']['wrong_command'],
                chat_id)
            bot.register_next_step_handler(message, get_user_command)

    lang = get_lang(chat_id)
    creating = {
        'valid': msgs[lang]['teacher']['course_create']['creating_valid'],
        'name': msgs[lang]['teacher']['course_create']['creating_name'],
        'desc': msgs[lang]['teacher']['course_create']['creating_desc'],
        'both': msgs[lang]['teacher']['course_create']['creating_both']
    }
    course_info = dict(name=None, desc=None, lock=None)
    idle()
Esempio n. 11
0
def new_course(call):
    botHelper.edit_mes(
        msgs[get_lang(
            call.message.chat.id)]['teacher']['course_create']['begin'], call)
    create_course(call.message.chat.id)
Esempio n. 12
0
def start(message):
    botHelper.send_mes(msgs[get_lang(message.chat.id)]['common']['start'],
                       message.chat.id)