예제 #1
0
from bot import bot
from telebot import types
from models import Homework, Group, CompletedHomework, User
from db import session
from telebot.types import ReplyKeyboardMarkup, KeyboardButton
from filters import callback
from scenarios.main_menu import send_main_menu


@bot.message_handler(func=callback("Сдать домашнее задание"))
def push_homework(message):
    chat_id = message.chat.id
    markup = ReplyKeyboardMarkup(one_time_keyboard=True)

    for hw in message.current_group.homeworks:
        markup.add(KeyboardButton(hw.id))

    bot.send_message(chat_id, "Выберите ДЗ:", reply_markup=markup)

    bot.register_next_step_handler(message, push_next)


states = dict()


def push_next(message):
    states[message.chat.id] = message.text

    bot.send_message(message.chat.id, "Отправьте файл с домашкой")
    bot.register_next_step_handler(message, push_next2)
예제 #2
0
from bot import bot
from telebot import types
from models import Homework, CompletedHomework, User
from db import session
from telebot.types import ReplyKeyboardMarkup, KeyboardButton
from filters import callback
from scenarios.main_menu import send_main_menu


@bot.message_handler(func=callback("Проверить дз"))
def check_homework(message):
    chat_id = message.chat.id
    markup = ReplyKeyboardMarkup(one_time_keyboard=True)

    for hw in message.current_group.homeworks:
        markup.add(KeyboardButton(hw.id))

    bot.send_message(chat_id, "Выберите дз для проверки", reply_markup=markup)

    bot.register_next_step_handler(message, check_next)


states = dict()


def check_next(message):
    chat_id = message.chat.id
    homework = session.query(Homework).get(message.text)

    states[chat_id] = homework
예제 #3
0
from bot import bot
from models import Role
from filters import callback

from excel import excel_db, converter


@bot.message_handler(func=callback("Экспорт в Excel"))
def excel_export(message):
    excel_db.clear_table()

    group = message.current_group

    students = group.users
    hws = group.homeworks

    for hw in hws:
        excel_db.add_column(str(hw.id))

    for student in students:
        if not student.is_student(group):
            continue

        excel_db.add_student(student.name)

        for hw in hws:
            completed = hw.get_completed_from_student(student)
            mark = completed.marks
            comment = completed.comment

            data = str(mark)
예제 #4
0
from bot import bot
from telebot import types
from models import Homework, Group, CompletedHomework, User
from db import session
from telebot.types import ReplyKeyboardMarkup, KeyboardButton
from filters import callback
from scenarios.main_menu import send_main_menu


@bot.message_handler(func=callback("Посмотреть баллы"))
def get_marks(message):
    chat_id = message.chat.id
    user = User.from_telegram_id(chat_id)
    completed_homeworks = user.completed_homeworks

    s = ''
    for hw in completed_homeworks:
        if hw.is_checked():
            s += f'Дз {hw.id}, оценка: {hw.marks}'

            if hw.has_comment():
                s += f', комментарий: {hw.comment}'

            s += '\n'
        else:
            s += f'Дз {hw.id}, не проверено\n'
    bot.send_message(chat_id, s)
    send_main_menu(message)
예제 #5
0
from bot import bot
from telebot import types
from models import Homework
from db import session
from filters import callback

# TODO    deadline


@bot.message_handler(func=callback("Добавить дз"))
def add_homework(message):
    chat_id = message.chat.id
    msg = bot.send_message(chat_id, 'Загрузите файл с ДЗ')
    bot.register_next_step_handler(msg, upload_homework)


def upload_homework(message):
    chat_id = message.chat.id
    homework_id = message.document.file_id
    homework = Homework(file_telegram_id=homework_id,
                        deadline="",
                        group=message.current_group)
    session.add(homework)
    session.commit()
    bot.send_message(chat_id, "Файл загружен!")
예제 #6
0
    for group in user.groups:
        markup.add(KeyboardButton(group.name))

    markup.add(KeyboardButton("Создать группу"))
    bot.send_message(chat_id,
                     "Пожалуйста, выбери свою группу\nИли создай новую.",
                     reply_markup=markup)
    bot.register_next_step_handler(message, got_group)


def got_group(message):
    if message.text == "Создать группу":
        return create.create_group(message)

    user = User.from_telegram_id(message.chat.id)
    groups = {group.name: group for group in user.groups}

    if message.text in groups.keys():
        current_groups[message.chat.id] = groups[message.text]
        message.current_group = groups[message.text]
        send_main_menu(message)
    else:
        return select_group(message)


@bot.message_handler(func=callback("Выйти из группы"))
def exit_from_group(message):
    del current_groups[message.chat.id]
    return select_group(message)
예제 #7
0
from bot import bot
from filters import callback
from models import User
from telebot.types import ReplyKeyboardMarkup, KeyboardButton
from scenarios.main_menu import send_main_menu


@bot.message_handler(func=callback("Удалить человека"))
def remove(message):
    chat_id = message.chat.id
    markup = ReplyKeyboardMarkup(one_time_keyboard=True)

    for user in message.current_group.users:
        markup.add(KeyboardButton(user.telegram_nickname))

    bot.send_message(chat_id, "Выберите человека:", reply_markup=markup)
    bot.register_next_step_handler(message, remove_success)


def remove_success(message):
    chat_id = message.chat.id
    group_name = message.current_group.name
    user = User.from_telegram_nickname(message.text)

    message.current_group.delete_user(user)
    bot.send_message(chat_id, "Пользователь удалён")

    send_main_menu(message)
예제 #8
0
from bot import bot
from telebot import types
from models import Homework, CompletedHomework, User
from db import session
from telebot.types import ReplyKeyboardMarkup, KeyboardButton
from filters import callback
from scenarios.main_menu import send_main_menu


@bot.message_handler(func=callback("Сообщение всем ученикам"))
def broadcast(message):
    bot.send_message(message.chat.id, "Введите сообщение")
    bot.register_next_step_handler(message, send)


def send(message):
    msg_text = message.text
    for student in message.current_group.users:
        if not student.is_student(message.current_group):
            continue
        bot.send_message(student.telegram_id, msg_text)

    bot.send_message(message.chat.id, "Сообщение отправлено!")
예제 #9
0
from bot import bot
from telebot.types import ReplyKeyboardMarkup, KeyboardButton
from telebot import types
from models import User, Role
from db import session
from filters import callback
from scenarios.main_menu import send_main_menu


@bot.message_handler(func=callback("Написать преподавателю"))
def choose_teacher(message):
    chat_id = message.chat.id

    markup = ReplyKeyboardMarkup(one_time_keyboard=True)

    for user in message.current_group.users:
        if user.is_teacher(message.current_group):
            markup.add(KeyboardButton(user.name))

    bot.send_message(chat_id, "Кому Вы хотите написать?", reply_markup=markup)
    bot.register_next_step_handler(message, ask_teacher)


usernames = dict()


def ask_teacher(message):
    chat_id = message.chat.id
    answer = message.text

    if answer == 'Отмена':
예제 #10
0
from bot import bot
from db import session
from filters import callback
from models import Role, User
from telebot.types import ReplyKeyboardMarkup, KeyboardButton
from scenarios.main_menu import send_main_menu


@bot.message_handler(func=callback("Изменить роль"))
def user_select(message):
    chat_id = message.chat.id
    markup = ReplyKeyboardMarkup(one_time_keyboard=True)

    for user in message.current_group.users:
        markup.add(KeyboardButton(user.name))

    bot.send_message(chat_id, "Выберите человека:", reply_markup=markup)
    bot.register_next_step_handler(message, change_roles)


username = ''
is_checked = False


def change_roles(message):
    chat_id = message.chat.id

    global username
    username = message.text

    markup = ReplyKeyboardMarkup(one_time_keyboard=True)