Пример #1
0
 def update_displayed_orders(self, channel: Channel):
     orders = list(self.orders.find_all(today()))
     for cmd_message in self.messages.find_all('orders', date=today()):
         new_ts = self.api.update_message(
             channel.id, cmd_message.timestamp,
             Message(blocks=list(self.ui.all_orders(orders)))).ts
         self.messages.update_timestamp(cmd_message.id, new_ts)
Пример #2
0
 def display_orders(self, channel: Channel) -> SlackMessage:
     orders = list(self.orders.find_all(today()))
     reply = self.api.post_message(
         channel.id, Message(blocks=list(self.ui.all_orders(orders))))
     message = SlackMessage.create_today('orders', reply.ts, reply.channel)
     self.messages.create(message)
     return message
Пример #3
0
 def create_new_order(self, user: User):
     order = self.orders.find(today(), user)
     if order is None:
         order = self.orders.create(user)
     return Message(self.display_order(order),
                    response_type=MessageType.ephemeral,
                    attachments=self.ui.create_order_attachments(self.menu, order))
Пример #4
0
    def add_dessert(self, action: BlockAction, user: User):
        order = self.orders.find(today(), user)
        dessert = self.find_dessert(action.selected_option.value)
        if dessert:
            order = replace(order, desserts=order.desserts + [dessert])
        self.orders.update(order)

        return Message.replace(self.ui.my_order(self.menu, order))
Пример #5
0
    def add_box(self, action: BlockAction, user: User):
        order = self.orders.find(today(), user)
        box = self.find_box(action.selected_option.value)
        if box:
            order = replace(order, boxes=order.boxes + [box])
        self.orders.update(order)

        return Message.replace(self.ui.my_order(self.menu, order))
Пример #6
0
 def pref_user(self) -> Optional[UserPoints]:
     today_users = [
         order.user.id for order in self.orders.find_all(today())
     ]
     candidates = [
         up for up in self.find_all() if up.user.id in today_users
     ]
     if candidates:
         return candidates[0]
Пример #7
0
 def complete_order(self, channel: Channel, user: User, new_order: bool):
     cmds = list(self.messages.find_all('orders', date=today()))
     if len(cmds) == 0:
         cmds = [self.display_orders(channel)]
     link = self.api.get_permalink(cmds[-1].channel_id, cmds[-1].timestamp)
     if new_order:
         message = f'{user.display_name} placed an order\n<{link}|View all orders>'
     else:
         message = f'{user.display_name} updated an order\n<{link}|View all orders>'
     self.api.post_message(channel.id, Message(message))
     self.update_displayed_orders(channel)
Пример #8
0
    def order_confirm(self, channel: Channel, user: User):
        order = self.orders.find(today(), user)
        new_order = not order.complete
        points = self.update_points(order)
        order = replace(order,
                        complete=True,
                        in_edition=False,
                        points_given=points)
        self.orders.update(order)
        self.complete_order(channel, user, new_order)

        return Message.replace(self.ui.my_order(self.menu, order))
Пример #9
0
 def complete_order(self, channel: Channel, user: User, new_order: bool):
     cmds = list(self.messages.find_all('orders', date=today()))
     if len(cmds) == 0:
         cmds = [self.display_orders(channel)]
     link = self.api.get_permalink(channel.id, cmds[-1].timestamp)
     if new_order:
         message = '{} placed an order\n<{}|View all orders>'
     else:
         message = '{} updated an order\n<{}|View all orders>'
     msg = Message(attachments=[
         Attachment('', message.format(user.display_name, link), natcolor)
     ])
     self.api.post_message(channel.id, msg)
     self.update_displayed_orders(channel)
Пример #10
0
 def create(self, user: User) -> Order:
     order = Order(str(uuid4()), user, today())
     self.collection.insert_one(serialize(order))
     return order
Пример #11
0
 def create_new_order(self, user: User):
     order = self.orders.find(today(), user)
     if order is None:
         order = self.orders.create(user)
     return Message.ephemeral(self.ui.my_order(self.menu, order))
Пример #12
0
 def order_edit(self, user: User):
     order = self.orders.find(today(), user)
     order = replace(order, in_edition=True)
     self.orders.update(order)
     return Message.replace(self.ui.my_order(self.menu, order))
Пример #13
0
 def order_cancel(self, user: User):
     order = self.orders.find(today(), user)
     self.orders.delete(order.id)
     self.points.update(order.user, -1 * order.points_given)
     return Message.delete()
Пример #14
0
 def display_orders(self, channel: Channel) -> SlackMessage:
     orders = list(self.orders.find_all(today()))
     timestamp = self.api.post_message(channel.id, Message(self.ui.orders_text(orders)))
     message = SlackMessage.create_today('orders', timestamp)
     self.messages.create(message)
     return message
Пример #15
0
    def clear_dessert(self, user: User):
        order = self.orders.find(today(), user)
        order = replace(order, desserts=[])
        self.orders.update(order)

        return Message.replace(self.ui.my_order(self.menu, order))
Пример #16
0
 def create_today(type: str, timestamp: str) -> 'SlackMessage':
     return SlackMessage(str(uuid4()), type, today(), timestamp)
Пример #17
0
 def create_today(type: str, timestamp: str, channel_id: Optional[str] = None) -> 'SlackMessage':
     return SlackMessage(str(uuid4()), type, today(), timestamp, channel_id)
Пример #18
0
 def create(self, user: User) -> Order:
     order = Order(str(uuid4()), user, today())
     self.collection.insert_one(serialize(order))
     return order
Пример #19
0
 def update_displayed_orders(self, channel: Channel):
     orders = list(self.orders.find_all(today()))
     for cmd_message in self.messages.find_all('orders', date=today()):
         new_ts = self.api.update_message(channel.id, cmd_message.timestamp,
                                          Message(text=self.ui.orders_text(orders)))
         self.messages.update_timestamp(cmd_message._id, new_ts)