Ejemplo n.º 1
0
def del_task(call, lang):
    if call.message.chat.id == Course.Course(call.data['c_id']).owner.id:
        Course.Task(call.data['c_id'], call.data['t_id']).delete()
        bot.answer_callback_query(call.id,
                                  msgs[lang]['callback']['task_deleted'])
    else:
        bot.answer_callback_query(call.id,
                                  msgs[lang]['callback']['task_not_exists'],
                                  show_alert=True)

    back(call, True, 2)
Ejemplo n.º 2
0
def switch_lock(call, lang):
    if call.data['lock']:
        Course.Course(call.data['c_id']).entry_restriction = time.time()
        bot.answer_callback_query(call.id,
                                  msgs[lang]['callback']['course_closed'])
    else:
        Course.Course(call.data['c_id']).entry_restriction = None
        bot.answer_callback_query(call.id,
                                  msgs[lang]['callback']['course_opened'])

    back(call, True)
Ejemplo n.º 3
0
def delete_course(call, lang):
    course_ = Course.Course(call.data['c_id'])

    if call.message.chat.id == course_.owner.id:
        course_.delete()
        bot.answer_callback_query(call.id,
                                  msgs[lang]['callback']['course_deleted'])
    else:
        bot.answer_callback_query(call.id,
                                  msgs[lang]['callback']['not_owner'],
                                  show_alert=True)

    back(call, True, 2)
Ejemplo n.º 4
0
def leave(call, lang):
    if call.data['c_id'] in (
            c.id for c in User.User(call.message.chat.id).participation):
        c = Course.Course(call.data['c_id'])
        c.remove_student(call.message.chat.id)
        bot.answer_callback_query(
            call.id, msgs[lang]['callback']['course_leave'] + c.name)
    else:
        bot.answer_callback_query(
            call.id,
            msgs[lang]['callback']['course_not_enrolled'],
            show_alert=True)

    back(call, True)
Ejemplo n.º 5
0
def enroll(call, lang):
    if call.data['c_id'] not in (
            c.id for c in User.User(call.message.chat.id).participation):
        c = Course.Course(call.data['c_id'])
        c.append_student(call.message.chat.id)
        bot.answer_callback_query(
            call.id, msgs[lang]['callback']['course_enrolled'] + c.name)
    else:
        bot.answer_callback_query(
            call.id,
            msgs[lang]['callback']['course_enrolled_already'],
            show_alert=True)

    back(call, True)
Ejemplo n.º 6
0
def kick(call, lang):
    course_ = Course.Course(call.data['c_id'])

    if User.User(call.message.chat.id).type_u == 'teacher':
        if course_.id in (c.id
                          for c in User.User(call.data['u_id']).participation):
            course_.remove_student(call.data['u_id'])
            bot.answer_callback_query(
                call.id, msgs[lang]['callback']['student_kicked'].format(
                    name=User.User(call.data['u_id']).name))
        else:
            bot.answer_callback_query(
                call.id,
                msgs[lang]['callback']['student_not_enrolled'],
                show_alert=True)
    else:
        bot.answer_callback_query(call.id,
                                  msgs[lang]['callback']['not_teacher'],
                                  show_alert=True)

    back(call, True, 2)