Skip to content

Commit

Permalink
Правки
Browse files Browse the repository at this point in the history
  • Loading branch information
HamletSargsyan committed May 12, 2024
1 parent 211ce6d commit 0edfa06
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Добавлено
- Добавлен лимит на продажу придметов на рынке
- Добавлена возможность отменить продажу придмета

### Изменено
- На рынке сначало отображаются новые товары
Expand Down
11 changes: 8 additions & 3 deletions src/base/user_input/add_new_market_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from database.funcs import database, cache
from database.models import MarketItemModel
from helpers.exceptions import NoResult
from helpers.markups import InlineMarkup


class AddNewItemState(StatesGroup):
Expand All @@ -30,7 +31,8 @@ def name_state(call: CallbackQuery):
user = database.users.get(id=call.from_user.id)
user_item = database.items.get(name=item.name, owner=user._id)

bot.edit_message_text(f"<b>Продажа придмета {item.emoji}</b>\nВведи кол-во ({user_item.quantity})", call.message.chat.id, call.message.id)
markup = InlineMarkup.delate_state(user)
bot.edit_message_text(f"<b>Продажа придмета {item.emoji}</b>\nВведи кол-во ({user_item.quantity})", call.message.chat.id, call.message.id, reply_markup=markup)
bot.set_state(call.from_user.id, AddNewItemState.quantity, call.message.chat.id)

cache.setex(f"{user.id}_item_add_message", 300, call.message.id)
Expand All @@ -39,7 +41,9 @@ def name_state(call: CallbackQuery):

@bot.message_handler(state=[AddNewItemState.quantity, AddNewItemState.price], is_digit=False)
def invalid_int_input(message: Message):
bot.reply_to(message, "Введите число")
user = database.users.get(id=message.from_user.id)
markup = InlineMarkup.delate_state(user)
bot.reply_to(message, "Введите число", reply_markup=markup)


@bot.message_handler(state=AddNewItemState.quantity, is_digit=True)
Expand All @@ -59,7 +63,8 @@ def quantity_state(message: Message):
bot.delete_message(message.chat.id, message.id)

item = get_item(user_item.name)
bot.edit_message_text(f"<b>Продажа придмета {item.emoji}</b>\nВведи прайс (+-{get_middle_item_price(item.name)}/шт)", message.chat.id, call_message_id)
markup = InlineMarkup.delate_state(user)
bot.edit_message_text(f"<b>Продажа придмета {item.emoji}</b>\nВведи прайс (+-{get_middle_item_price(item.name)}/шт)", message.chat.id, call_message_id, reply_markup=markup)
bot.set_state(message.from_user.id, AddNewItemState.price, message.chat.id)


Expand Down
16 changes: 16 additions & 0 deletions src/bot/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,3 +772,19 @@ def market_item_open_callback(call: CallbackQuery):

markup = InlineMarkup.market_item_open(user, market_item)
bot.edit_message_text(mess, call.message.chat.id, call.message.id, reply_markup=markup)


@bot.callback_query_handler(lambda c: c.data.startswith("delate_state"), state="*")
def delate_state_callback(call: CallbackQuery):
data = call.data.split(" ")

if data[-1] != str(call.from_user.id):
return

if not bot.get_state(call.from_user.id, call.message.chat.id):
bot.answer_callback_query(call.id, "Что отменять собрался?", show_alert=True)
return

bot.delete_state(call.from_user.id, call.message.chat.id)
bot.delete_message(call.message.chat.id, call.message.id)
bot.answer_callback_query(call.id, "Отменил")
6 changes: 6 additions & 0 deletions src/helpers/markups.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,9 @@ def market_view_my_items(cls, user: UserModel) -> InlineKeyboardMarkup:
markup.add(*buttons)
markup.row(InlineKeyboardButton("◀️", callback_data=f"market start 0 {user.id}"))
return markup

@classmethod
def delate_state(cls, user: UserModel) -> InlineKeyboardMarkup:
return quick_markup({
"Отмена": {"callback_data": f"delate_state {user.id}"}
})

0 comments on commit 0edfa06

Please sign in to comment.