Esempio n. 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)
Esempio n. 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
Esempio n. 3
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))
Esempio n. 4
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))
Esempio n. 5
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)
Esempio n. 6
0
 def display_help(self):
     return Message.ephemeral([
         Block.section('''*Available commands :*
         • help : display this message
         • menu : display today's menu
         • order : place an order
         • call : display current orders
         • points : display points
         • free : there is a free box available
         • charge : an additional TR is required
         ''')
     ])
Esempio n. 7
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))
Esempio n. 8
0
 def display_menu(self):
     self.menu_provider.get()
     blocks = self.ui.menu(self.menu_provider.date, self.menu)
     return Message(f'Menu for {self.menu_provider.date}',
                    blocks=list(blocks))
Esempio n. 9
0
 def charge_box(self):
     pref_user = self.points.least_user()
     self.points.update(pref_user.user, 85)
     return Message(
         f'<@{pref_user.user.id}> needs to pay an additional TR and was credited 85 points',
         replace_original=True)
Esempio n. 10
0
 def free_box(self):
     pref_user = self.points.pref_user()
     self.points.update(pref_user.user, -85)
     return Message(
         f'<@{pref_user.user.id}> receives a free box and had 85 points deducted',
         replace_original=True)
Esempio n. 11
0
 def display_points(self):
     return Message(blocks=list(
         self.ui.points(self.points.pref_user(), self.points.find_all())))
Esempio n. 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))
Esempio n. 13
0
 def on_dismiss(self):
     return Message(delete_original=True)
Esempio n. 14
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))
Esempio n. 15
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))
Esempio n. 16
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()
Esempio n. 17
0
def message(blocks: Iterable[Block], **kwargs) -> Message:
    return Message(blocks=list(blocks), **kwargs)