예제 #1
0
파일: bot.py 프로젝트: rtix/course_bot
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)
예제 #2
0
파일: bot.py 프로젝트: rtix/course_bot
def course_owner(call, lang):
    course_ = Course.Course(call.data['c_id'])

    text = msgs[lang]['teacher']['course_owner_full'].format(
        name=course_.name,
        num=len(course_.participants),
        lock=UI.to_dtime(course_.entry_restriction),
        desc=course_.description)
    c_text = msgs[lang]['confirm']['delete_course'].format(course_.name)
    markup = mkp.create(
        lang, [tbt.user_list(call.data['c_id'], lang)],
        [tbt.task_list(call.data['c_id'], lang)],
        [tbt.classwork_list(call.data['c_id'], lang)],
        [tbt.announce(call.data['c_id'], lang)], [
            tbt.switch_lock(call.data['c_id'],
                            True if course_.is_open else False, lang)
        ], [
            cbt.confirm_action(
                'delete_course',
                msgs[lang]['buttons']['confirm']['delete_course'],
                c_text,
                call.message.chat.id,
                call.message.message_id,
                c_id=course_.id)
        ])

    botHelper.edit_mes(text, call, markup=markup)
예제 #3
0
파일: bot.py 프로젝트: rtix/course_bot
def st_tsk(call, lang):
    task_ = Course.Task(call.data['c_id'], call.data['t_id'])
    text = msgs[lang]['student']['student_task'].format(
        name=task_.name,
        desc=task_.description,
        mark=task_.mark(call.message.chat.id).value,
        hmark=int(task_.highest_mark))

    botHelper.edit_mes(text, call, markup=mkp.create(lang))
예제 #4
0
파일: bot.py 프로젝트: rtix/course_bot
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)
예제 #5
0
파일: bot.py 프로젝트: rtix/course_bot
def usr_mng(call, lang):
    course_ = Course.Course(call.data['c_id'])
    tasks = course_.tasks
    user = User.User(call.data['u_id'])
    cws = course_.classworks

    if tasks:
        total_mark = sum(
            filter(None, map(lambda x: x.mark(call.data['u_id']).value,
                             tasks)))
        mean_mark = total_mark / len(tasks)
    else:
        total_mark = None
        mean_mark = None

    if cws:
        overall = len(cws)
        att = sum(map(lambda cw_: cw_.attendance(call.data['u_id']).value,
                      cws))
    else:
        overall = None
        att = None

    text = msgs[lang]['teacher']['management']['user'].format(
        course=course_.name,
        name=user.name,
        email='',
        mean=mean_mark,
        total=total_mark,
        attend=att,
        attend_tot=overall)

    c_text = msgs[lang]['confirm']['kick'].format(user.name)

    markup = mkp.create(lang, [
        cbt.confirm_action('kick',
                           msgs[lang]['buttons']['confirm']['kick'],
                           c_text,
                           call.message.chat.id,
                           call.message.message_id,
                           c_id=call.data['c_id'],
                           u_id=call.data['u_id'])
    ])

    botHelper.edit_mes(text, call, markup=markup)
예제 #6
0
파일: bot.py 프로젝트: rtix/course_bot
def course(call, lang):
    course_ = Course.Course(call.data['c_id'])
    num_par = len(course_.participants)
    owner = course_.owner

    if owner.id == call.message.chat.id:  # owner
        if course_.is_open:
            lock = msgs[lang]['teacher']['lock_open']
        else:
            lock = msgs[lang]['teacher']['lock_close']
        desc = course_.description
        if len(desc) > UI.constants.COURSE_INFO_DESC_LENGTH:
            desc = botHelper.remove_danger(
                desc[:UI.constants.COURSE_INFO_DESC_LENGTH]) + '...'

        botHelper.edit_mes(
            msgs[lang]['teacher']['course_owner_min'].format(name=course_.name,
                                                             num=num_par,
                                                             lock=lock,
                                                             desc=desc),
            call,
            markup=mkp.create(lang, [tbt.manage(call.data['c_id'], lang)]))
    elif course_.id in (c.id
                        for c in User.User(call.message.chat.id).participation
                        ):  # enrolled
        cws = course_.classworks
        attend_text = ''
        overall = len(cws)
        if overall:
            att = sum(
                map(lambda cw_: cw_.attendance(call.message.chat.id).value,
                    cws))
            attend_text = msgs[lang]['student']['attendance'].format(
                count=att, overall=overall, ratio=int(att / overall * 100))

        tasks = course_.tasks
        if tasks:
            total_mark = sum(
                map(lambda task_: task_.mark(call.message.chat.id).value,
                    tasks))
            mean_mark = total_mark / len(tasks)
            mark_text = msgs[lang]['student']['marks'].format(
                total_mark, round(mean_mark, 2))
        else:
            mark_text = ''

        text = msgs[lang]['student']['course'].format(name=course_.name,
                                                      fio=owner.name,
                                                      num=num_par,
                                                      mail='',
                                                      marks=mark_text,
                                                      attend=attend_text)

        c_text = msgs[lang]['confirm']['leave_course'].format(course_.name)
        if not course_.is_open:
            c_text += msgs[lang]['confirm']['leave_course_append']

        markup = mkp.create(lang, [cbt.task_list(call.data['c_id'], lang)], [
            cbt.confirm_action('leave',
                               msgs[lang]['buttons']['confirm']['leave'],
                               c_text,
                               call.message.chat.id,
                               call.message.message_id,
                               c_id=course_.id)
        ])

        botHelper.edit_mes(text, call, markup=markup)
    else:  # not enrolled
        locked = '' if course_.is_open else msgs[lang]['student'][
            'course_closed']
        end_entry = course_.entry_restriction
        lock = UI.to_dtime(
            end_entry) if end_entry else msgs[lang]['student']['lock_absent']

        text = msgs[lang]['student']['course_not_enroll'].format(
            name=course_.name,
            fio=owner.name,
            desc=course_.description,
            num=num_par,
            lock=lock,
            mail='',
            locked=locked)  # TODO mail

        c_text = msgs[lang]['confirm']['enroll_course'].format(course_.name)

        if locked:
            markup = mkp.create(lang)
        else:
            markup = mkp.create(lang, [
                cbt.confirm_action('enroll',
                                   msgs[lang]['buttons']['confirm']['enroll'],
                                   c_text,
                                   call.message.chat.id,
                                   call.message.message_id,
                                   c_id=course_.id)
            ])

        botHelper.edit_mes(text, call, markup=markup)