Skip to content

Commit

Permalink
fix: move all strings to locale
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitosKey committed Jan 24, 2025
1 parent 87995be commit f5eea79
Show file tree
Hide file tree
Showing 5 changed files with 298 additions and 246 deletions.
31 changes: 17 additions & 14 deletions bot/roles/barman.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,26 @@ def __handle_queue_button(self):
markup = self.__build_queue_menu()
return text, markup

def __pre_complete_order_text(self, order, customer_name, barman_name):
return (
self.texts["order_time"]
+ str(order.date[:-7])
+ self.texts["order_product"]
+ str(order.product)
+ self.texts["order_customer"]
+ str(customer_name)
+ self.texts["order_barman"]
+ str(barman_name)
+ self.texts["order_status"]
+ str(order.status)
)

def __handle_pre_complete_order(self, data):
logging.getLogger(__name__).info("%s watch for the %s", self.tg_user_id, data)
order = self.db.get_order_by_date(data[9:])
customer_name = self.db.get_user_by_id(order.customer_id).name
barman = self.db.get_user_by_id(order.barman_id)
text = (
f"""Заказ от: {order.date[:-7]}\n"""
f"""Продукт: {order.product}\n"""
f"""Покупатель: {customer_name}\n"""
f"""Бармен: {barman}\n"""
f"""Статус: {order.status}"""
)
text = self.__pre_complete_order_text(order, customer_name, barman)
markup = self.__build_pre_complete_order_menu(data)
return text, markup

Expand All @@ -105,13 +113,8 @@ def __handle_complete_order(self, data):
self.db.update_order(order)
customer_name = self.db.get_user_by_id(order.customer_id).name
barman_name = self.db.get_user_by_id(order.barman_id).name
text = (
f"""Заказ завершён!!!\n"""
f"""От: {order.date[:-7]}\n"""
f"""Продукт: {order.product}\n"""
f"""Покупатель: {customer_name}\n"""
f"""Бармен: {barman_name}\n"""
f"""Статус: {order.status}"""
text = self.texts["order_completed"] + self.__pre_complete_order_text(
order, customer_name, barman_name
)
markup = self.__build_complete_order_menu()
return text, markup
Expand Down
40 changes: 21 additions & 19 deletions bot/roles/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ def build_menu(self) -> InlineKeyboardMarkup:
buttons = self.create_customer_menu_buttons()
return InlineKeyboardMarkup(buttons)

def __build_show_products_menu(self) -> InlineKeyboardMarkup:
def __build_products_menu(self, prefix) -> InlineKeyboardMarkup:
"""
Build the menu to show products.
Build the menu to show products to make an order or show product information.
"""
my_products = self.db.get_all_products()
buttons = []
if my_products is not None:
for product in my_products:
button = InlineKeyboardButton(
product.name, callback_data=f"shown_{product.name}"
product.name, callback_data=prefix + product.name
)
buttons.append([button])
else:
Expand Down Expand Up @@ -169,7 +169,7 @@ def __handle_show_products_button(self):
self.tg_user_id,
)
text = self.texts["show_products_text"]
markup = self.__build_show_products_menu()
markup = self.__build_products_menu("shown_")
return text, markup

def __handle_make_order_button(self):
Expand All @@ -181,7 +181,7 @@ def __handle_make_order_button(self):
self.tg_user_id,
)
text = self.texts["make_order_text"]
markup = self.__build_show_products_menu()
markup = self.__build_products_menu("chose_")
return text, markup

def __handle_show_orders_button(self):
Expand All @@ -205,9 +205,9 @@ def __handle_product_info(self, data):
)
product: Product = self.db.get_product_by_name(data[6:])
text = (
f"""<b>{product.name}</b>\n"""
f"""<b>Описание:</b>\n{product.description}\n"""
f"""<b>Цена:</b> {product.price}руб."""
f"<b>{product.name}</b>"
f"{self.texts['product_description']} {product.description}"
f"{self.texts['product_price']} {product.price}"
)
markup = self.__build_show_product_info_menu(data)
return text, markup
Expand All @@ -217,7 +217,10 @@ def __handle_pre_approve_order(self, data):
Handle the pre-approve order button press.
"""
logging.getLogger(__name__).info("%s chosen the %s", self.tg_user_id, data)
text = f"Выбран <b>{data[6:]},</b>.\nПодтвердите ваш заказ."
text = (
f"{self.texts['chosen_product']} <b>{data[6:]}</b>"
f'{self.texts["confirm_order"]}'
)
markup = self.__build_pre_approve_order_menu(f"next{data}")
return text, markup

Expand All @@ -231,9 +234,10 @@ def __handle_approve_order(self, data):
)
self.db.insert_order(order)
text = (
f"<b>Заказ оформлен!</b>\n"
f"Время заказа: {order.date[:-7]}\n"
f"Продукт:\n{order.product}\nСтатус: {order.status}"
f'{self.texts["order_created"]}'
f'{self.texts["order_time"]} {order.date[:-7]}'
f'{self.texts["order_product"]} \n{order.product}'
f'{self.texts["order_status"]} {order.status}'
)
markup = self.__build_approve_order_menu(data[4:])
return text, markup
Expand All @@ -246,10 +250,10 @@ def __handle_order_info(self, data):
order = self.db.get_order_by_date(data)
barman = self.db.get_user_by_id(order.barman_id)
text = (
f"""<b>Заказ от:</b> {order.date[:-7]}\n"""
f"""<b>Продукт:</b> {order.product}\n"""
f"""<b>Бармен:</b> {barman if barman is None else barman.name}\n"""
f"""<b>Статус:</b> {order.status}"""
f'{self.texts["order_date"]} {order.date[:-7]}'
f'{self.texts["order_product"]} {order.product}'
f'{self.texts["order_barman"]} {barman if barman is None else barman.name}'
f'{self.texts["order_status"]} {order.status}'
)
markup = self.__build_show_order_info_menu()
return text, markup
Expand All @@ -270,9 +274,7 @@ def on_button_tap(self, data) -> (str, InlineKeyboardMarkup):
for callback_prefix, action in [
("shown_", self.__handle_product_info),
("chose_", self.__handle_pre_approve_order),
("hown_", self.__handle_pre_approve_order),
("nextchose_", self.__handle_approve_order),
("nextshown_", self.__handle_approve_order),
]:
if data.startswith(callback_prefix):
return action(data)
Expand All @@ -284,4 +286,4 @@ def on_button_tap(self, data) -> (str, InlineKeyboardMarkup):
return top_menus_associations[data]()

logging.getLogger(__name__).error("Incorrect button pressed")
return "Err0r", self.build_menu()
return self.texts["error"], self.build_menu()
Loading

0 comments on commit f5eea79

Please sign in to comment.