Example #1
0
    def _unset_indirect(
            date: datetime.date,
            sender: models.Person,
            recipient_listnum: int
            ):
        recipient = database.people.get_student_by_listnum(recipient_listnum)
        if not recipient:
            message = (
                f'InputError: при использовании конструкции "as STUDENT" '
                f'STUDENT должен быть целым числом и находиться в промежутке '
                f'[1, 25].'
            )
            bot.error(sender.id, message)
            return
        database.foodbot.set_eating(recipient, date, None)

        sender_listnum = sender.fields["list_number"]
        sender_message = (
            f'Ученик №{recipient_listnum} удален из списоков "Едят" и '
            f'"Не едят".'
        )
        bot.message(sender.id, sender_message)
        recipient_message = (
            f'Ученик №{sender_listnum} удалил вас из списоков "Едят" и '
            f'"Не едят".'
        )
        bot.message(recipient.id, recipient_message)
Example #2
0
    def _unset_direct(self, date: datetime.date, person: models.Person):
        if not self.has_required_tags(person):
            bot.error(person.id, 'TagError: вы не являетесь учеником.')
            return
        database.foodbot.set_eating(person, date, None)

        message = 'Вы удалены из списков "Едят" и "Не едят".'
        bot.message(person.id, message)
Example #3
0
def run_command(super_command: str, command: str, date: datetime.date,
                person: models.Person, args: list):
    cmd = get_command(super_command, command)
    if not cmd:
        message = f'InputError: введенной вами команды не существует.'
        bot.error(person.id, message)
        return
    cmd.run(date, person, args)
Example #4
0
    def _set_eating_direct(self, date: datetime.date, person: models.Person):
        if not self.has_required_tags(person):
            bot.error(person.id, 'TagError: вы не являетесь учеником.')
            return
        database.foodbot.set_eating(person, date, True)

        message = 'Вы добавлены в список "Едят".'
        bot.message(person.id, message)
Example #5
0
 def run(self, date: datetime.date, person: models.Person, args: List[str]):
     if not args:
         self._set_not_eating_direct(date, person)
     elif 'as' == args[0].lower() and len(args) == 2:
         recipient_listnum = int(args[1])
         if recipient_listnum is None:
             message = (
                 f'InputError: Команда "{self.keyword}" не может принимать '
                 f'аргументы отличные от "as STUDENT", где STUDENT является '
                 f'целым числом.')
             bot.error(person.id, message)
         else:
             self._set_not_eating_indirect(date, person, recipient_listnum)
     else:
         message = (
             f'InputError: Команда "{self.keyword}" не может принимать '
             f'аргументы отличные от "as STUDENT".')
         bot.error(person.id, message)
Example #6
0
def _message_handler(sender_id: str, message: str):
    sender = database.people.get_person_by_id(sender_id)
    elements = message.split()

    if len(elements) == 0:
        msg = ('InputError: пустое сообщение.')
        bot.error(sender_id, msg)
        return
    super_command = elements[0]

    if len(elements) == 1:
        command = ''
        args = list()
    else:
        command = elements[1]
        args = elements[2:]

    today = datetime.date.today()

    commands.run_command(super_command, command, today, sender, args)
Example #7
0
    def run(self, date: datetime.date, person: models.Person, args: List[str]):
        if args:
            message = (
                f'InputError: Команда "{self.keyword}" не может принимать '
                f'никакие аргументы.')
            bot.error(person.id, message)
            return

        eatings = database.foodbot.get_eatings(date)

        eating_list = list()
        not_eating_list = list()
        unset_list = list()

        for student, eating in eatings.items():
            if eating is None:
                unset_list.append(_repr_student(student))
            elif eating:
                eating_list.append(_repr_student(student))
            else:
                not_eating_list.append(_repr_student(student))

        message = (f'Дата: {_repr_date(date)}\n'
                   f'===-===-===-===-===\n'
                   f'\n'
                   f'Едят:\n'
                   f'{_repr_list(eating_list)}\n'
                   f'\n'
                   f'Не едят:\n'
                   f'{_repr_list(not_eating_list)}\n'
                   f'\n'
                   f'Не отметились:\n'
                   f'{_repr_list(unset_list)}\n'
                   f'\n'
                   f'===-===-===-===-===\n'
                   f'# Едят: {len(eating_list)}\n'
                   f'# Не едят: {len(not_eating_list)}\n'
                   f'# Не отметились: {len(unset_list)}\n')
        bot.message(person.id, message)
Example #8
0
    def run(self, date: datetime.date, person: models.Person, args: List[str]):
        if args:
            message = (
                f'InputError: Команда "{self.keyword}" не может принимать '
                f'никакие аргументы.')
            bot.error(person.id, message)
            return

        message = (
            f'Введите\n'
            f'- "{foodbot.SUPER_COMMAND} {foodbot.SetEatingCommand.keyword}", '
            f'чтобы попасть в список "Едят";\n'
            f'- "{foodbot.SUPER_COMMAND} {foodbot.SetNotEatingCommand.keyword}", '
            f'чтобы попасть в список "Не едят";\n'
            f'- "{foodbot.SUPER_COMMAND} {foodbot.UnsetCommand.keyword}", '
            f'чтобы удалить себя из обоих списков;\n'
            f'- "{foodbot.SUPER_COMMAND} {foodbot.ShowListCommand.keyword}", '
            f'чтобы получить списки "Едят" и "Не едят".\n'
            f'- "{foodbot.SUPER_COMMAND} {foodbot.ShowHelpCommand.keyword}", '
            f'чтобы вывести это сообщение."\n'
            f'\n'
            f'Добавьте "as STUDENT" к концу команды, чтобы выполнить ее от лица '
            f'другого ученика. STUDENT - это целое число в диапазоне [1, 25].')
        bot.message(person.id, message)