Пример #1
0
    def __send_info_to_removed_users(self):
        removed_orders = self.__pizza_calculator.users_removed_orders

        if not removed_orders:
            return

        users_orders = self.__pizza_calculator.users_orders

        for user_id, _ in removed_orders.items():
            if user_id in users_orders:
                self._client.send_direct_message(user_id, Messages.order_reduced(len(users_orders[user_id])))
            else:
                self._client.send_direct_message(user_id, Messages.order_removed())
Пример #2
0
 def __send_user_status(self):
     self._client.send_direct_response(
         Messages.stop_direct(stop_time=self._message.time,
                              pizzas=self.__pizza_calculator.pizzas_to_order,
                              orders=self.__orders_summaries,
                              lucky_order=self.__pizza_calculator.lucky_order)
     )
Пример #3
0
 def __send_chat_status(self):
     self._client.send_group_response(
         Messages.stop_group(organizer=self.__organizer,
                             pizzas=self.__pizza_calculator.pizzas_to_order,
                             orders=self.__orders_summaries,
                             lucky_order=self.__pizza_calculator.lucky_order)
     )
Пример #4
0
    def __ensure_started(self):
        self.__organizer = self._organizers.find_single(chat=self._chat)

        if not self.__organizer:
            raise Exception(Messages.error_not_started())

        logger.debug("Pizza started. OK.")
Пример #5
0
    def __send_chat_status(self):
        pizza_calculator = PizzaCalculator(
            orders=self._orders.find_all(chat=self._chat),
            optional_orders=self._optional_orders.find_all(chat=self._chat),
            forced_orders=self._forced_orders.find_all(chat=self._chat))

        pizza_calculator.calculate()

        self._client.send_group_response(
            Messages.slices_group(
                pizzas=pizza_calculator.pizzas_to_order,
                missing_slices=pizza_calculator.missing_slices_to_next_pizza))
Пример #6
0
    def handle(self):
        logger.debug("Handling for user '%s' at chat '%s'..." % (self._user.id, self._chat.id))

        self.__ensure_started()

        self.__pizza_calculator = PizzaCalculator(
            orders=self._orders.find_all(chat=self._chat),
            optional_orders=self._optional_orders.find_all(chat=self._chat),
            forced_orders=self._forced_orders.find_all(chat=self._chat)
        )

        self.__pizza_calculator.calculate()

        users_summaries = self.__pizza_calculator.summarize_users_orders()
        users_summaries_msgs = [Messages.status_user_summary(summary=summary) for summary in users_summaries]
        status_message = Messages.status(
            organizer=self.__organizer,
            pizzas=self.__pizza_calculator.pizzas_to_order,
            missing_slices=self.__pizza_calculator.missing_slices_to_next_pizza,
            summaries=users_summaries_msgs
        )

        self._client.send_group_response(status_message)
Пример #7
0
 def help_message(self):
     return Messages.help(self)
Пример #8
0
 def __prepare_messages_components(self):
     users_orders = self.__pizza_calculator.users_orders
     sorted_users_orders = OrdersHelper.sort_groups_by_doc_id(grouped_orders=users_orders)
     self.__orders_summaries = [Messages.order(orders[0], len(orders)) for orders in sorted_users_orders]
Пример #9
0
    def __ensure_used_by_organizer(self):
        if self.__organizer.user_id != self._user.id:
            raise Exception(Messages.error_only_owner_can_stop())

        logger.debug("Pizza used by organizer. OK.")
Пример #10
0
 def __send_user_status(self):
     forced_slices = len(self.__forced_orders)
     self._client.send_direct_response(
         Messages.slices_user_status(slices=self._slices,
                                     forced_slices=forced_slices))
Пример #11
0
 def __send_user_status(self):
     self._client.send_direct_response(
         Messages.optional_slices_user_status(optional_slices=self._slices))
Пример #12
0
 def __send_chat_status(self):
     self._client.send_group_response(Messages().start_group(
         self.__organizer))
Пример #13
0
 def __send_user_status(self):
     self._client.send_direct_response(Messages().start_direct(
         self._message.time))