Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

WEBAPP_HOST = "0.0.0.0"
WEBAPP_PORT = int(os.environ.get("PORT", 5000))
user_message = 'Пользователь'
admin_message = 'Админ'
user_message = 'User'
admin_message = 'Admin'


@dp.message_handler(commands='start')
Expand All @@ -23,17 +23,17 @@ async def cmd_start(message: types.Message):

markup.row(user_message, admin_message)

await message.answer('''Привет! 👋
await message.answer('''Hi! 👋

🤖 Я бот-магазин по подаже товаров любой категории.
🤖 I'm a marketplace bot to buy products from any category.

🛍️ Чтобы перейти в каталог и выбрать приглянувшиеся товары возпользуйтесь командой /menu.
🛍️ To access the catalog and see the products use /menu command.

💰 Пополнить счет можно через Яндекс.кассу, Сбербанк или Qiwi.
💰 For deposits you can use Yandex, Sber and Qivi .

Возникли вопросы? Не проблема! Команда /sos поможет связаться с админами, которые постараются как можно быстрее откликнуться.
Have questions? Not a problem! /sos command will help you to cantact the admins.

🤝 Заказать похожего бота? Свяжитесь с разработчиком <a href="https://t.me/NikolaySimakov">Nikolay Simakov</a>, он не кусается)))
🤝 Want to order a similar bot? Contact the developer <a href="https://t.me/NikolaySimakov">Nikolay Simakov</a>, he doesn't bite)))
''', reply_markup=markup)


Expand All @@ -44,7 +44,7 @@ async def user_mode(message: types.Message):
if cid in config.ADMINS:
config.ADMINS.remove(cid)

await message.answer('Включен пользовательский режим.', reply_markup=ReplyKeyboardRemove())
await message.answer('User mode is on.', reply_markup=ReplyKeyboardRemove())


@dp.message_handler(text=admin_message)
Expand All @@ -54,7 +54,7 @@ async def admin_mode(message: types.Message):
if cid not in config.ADMINS:
config.ADMINS.append(cid)

await message.answer('Включен админский режим.', reply_markup=ReplyKeyboardRemove())
await message.answer('Admin mode is on.', reply_markup=ReplyKeyboardRemove())


async def on_startup(dp):
Expand Down
50 changes: 25 additions & 25 deletions handlers/admin/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
category_cb = CallbackData('category', 'id', 'action')
product_cb = CallbackData('product', 'id', 'action')

add_product = '➕ Добавить товар'
delete_category = '🗑️ Удалить категорию'
add_product = '➕ Add product'
delete_category = '🗑️ Delete a category'


@dp.message_handler(IsAdmin(), text=settings)
Expand All @@ -29,9 +29,9 @@ async def process_settings(message: Message):
title, callback_data=category_cb.new(id=idx, action='view')))

markup.add(InlineKeyboardButton(
'+ Добавить категорию', callback_data='add_category'))
'+ Add a category', callback_data='add_category'))

await message.answer('Настройка категорий:', reply_markup=markup)
await message.answer('Category settings:', reply_markup=markup)


@dp.callback_query_handler(IsAdmin(), category_cb.filter(action='view'))
Expand All @@ -44,7 +44,7 @@ async def category_callback_handler(query: CallbackQuery, callback_data: dict, s
(category_idx,))

await query.message.delete()
await query.answer('Все добавленные товары в эту категорию.')
await query.answer('All products added to the category.')
await state.update_data(category_index=category_idx)
await show_products(query.message, products, category_idx)

Expand All @@ -55,7 +55,7 @@ async def category_callback_handler(query: CallbackQuery, callback_data: dict, s
@dp.callback_query_handler(IsAdmin(), text='add_category')
async def add_category_callback_handler(query: CallbackQuery):
await query.message.delete()
await query.message.answer('Название категории?')
await query.message.answer('What\'s the category\'s name?')
await CategoryState.title.set()


Expand Down Expand Up @@ -83,7 +83,7 @@ async def delete_category_handler(message: Message, state: FSMContext):
'DELETE FROM products WHERE tag IN (SELECT title FROM categories WHERE idx=?)', (idx,))
db.query('DELETE FROM categories WHERE idx=?', (idx,))

await message.answer('Готово!', reply_markup=ReplyKeyboardRemove())
await message.answer('All ready!', reply_markup=ReplyKeyboardRemove())
await process_settings(message)


Expand All @@ -98,13 +98,13 @@ async def process_add_product(message: Message):
markup = ReplyKeyboardMarkup(resize_keyboard=True)
markup.add(cancel_message)

await message.answer('Название?', reply_markup=markup)
await message.answer('Name?', reply_markup=markup)


@dp.message_handler(IsAdmin(), text=cancel_message, state=ProductState.title)
async def process_cancel(message: Message, state: FSMContext):

await message.answer('Ок, отменено!', reply_markup=ReplyKeyboardRemove())
await message.answer('Okay, canceled!', reply_markup=ReplyKeyboardRemove())
await state.finish()

await process_settings(message)
Expand All @@ -122,7 +122,7 @@ async def process_title(message: Message, state: FSMContext):
data['title'] = message.text

await ProductState.next()
await message.answer('Описание?', reply_markup=back_markup())
await message.answer('Description?', reply_markup=back_markup())


@dp.message_handler(IsAdmin(), text=back_message, state=ProductState.body)
Expand All @@ -132,7 +132,7 @@ async def process_body_back(message: Message, state: FSMContext):

async with state.proxy() as data:

await message.answer(f"Изменить название с <b>{data['title']}</b>?", reply_markup=back_markup())
await message.answer(f"Change the name from <b>{data['title']}</b>?", reply_markup=back_markup())


@dp.message_handler(IsAdmin(), state=ProductState.body)
Expand All @@ -142,7 +142,7 @@ async def process_body(message: Message, state: FSMContext):
data['body'] = message.text

await ProductState.next()
await message.answer('Фото?', reply_markup=back_markup())
await message.answer('Photo?', reply_markup=back_markup())


@dp.message_handler(IsAdmin(), content_types=ContentType.PHOTO, state=ProductState.image)
Expand All @@ -156,7 +156,7 @@ async def process_image_photo(message: Message, state: FSMContext):
data['image'] = downloaded_file

await ProductState.next()
await message.answer('Цена?', reply_markup=back_markup())
await message.answer('Price?', reply_markup=back_markup())


@dp.message_handler(IsAdmin(), content_types=ContentType.TEXT, state=ProductState.image)
Expand All @@ -168,11 +168,11 @@ async def process_image_url(message: Message, state: FSMContext):

async with state.proxy() as data:

await message.answer(f"Изменить описание с <b>{data['body']}</b>?", reply_markup=back_markup())
await message.answer(f"Change the description from <b>{data['body']}</b>?", reply_markup=back_markup())

else:

await message.answer('Вам нужно прислать фото товара.')
await message.answer('You need to send the product\'s photo.')


@dp.message_handler(IsAdmin(), lambda message: not message.text.isdigit(), state=ProductState.price)
Expand All @@ -184,11 +184,11 @@ async def process_price_invalid(message: Message, state: FSMContext):

async with state.proxy() as data:

await message.answer("Другое изображение?", reply_markup=back_markup())
await message.answer("Different image?", reply_markup=back_markup())

else:

await message.answer('Укажите цену в виде числа!')
await message.answer('The price should be a number!')


@dp.message_handler(IsAdmin(), lambda message: message.text.isdigit(), state=ProductState.price)
Expand All @@ -203,7 +203,7 @@ async def process_price(message: Message, state: FSMContext):
price = data['price']

await ProductState.next()
text = f'<b>{title}</b>\n\n{body}\n\nЦена: {price} рублей.'
text = f'<b>{title}</b>\n\n{body}\n\nPrice: {price} dollars.'

markup = check_markup()

Expand All @@ -214,7 +214,7 @@ async def process_price(message: Message, state: FSMContext):

@dp.message_handler(IsAdmin(), lambda message: message.text not in [back_message, all_right_message], state=ProductState.confirm)
async def process_confirm_invalid(message: Message, state: FSMContext):
await message.answer('Такого варианта не было.')
await message.answer('There is no such choice.')


@dp.message_handler(IsAdmin(), text=back_message, state=ProductState.confirm)
Expand All @@ -224,7 +224,7 @@ async def process_confirm_back(message: Message, state: FSMContext):

async with state.proxy() as data:

await message.answer(f"Изменить цену с <b>{data['price']}</b>?", reply_markup=back_markup())
await message.answer(f"Change the price from <b>{data['price']}</b>?", reply_markup=back_markup())


@dp.message_handler(IsAdmin(), text=all_right_message, state=ProductState.confirm)
Expand All @@ -246,7 +246,7 @@ async def process_confirm(message: Message, state: FSMContext):
(idx, title, body, image, int(price), tag))

await state.finish()
await message.answer('Готово!', reply_markup=ReplyKeyboardRemove())
await message.answer('Ready!', reply_markup=ReplyKeyboardRemove())
await process_settings(message)


Expand All @@ -258,7 +258,7 @@ async def delete_product_callback_handler(query: CallbackQuery, callback_data: d

product_idx = callback_data['id']
db.query('DELETE FROM products WHERE idx=?', (product_idx,))
await query.answer('Удалено!')
await query.answer('Deleted!')
await query.message.delete()


Expand All @@ -268,11 +268,11 @@ async def show_products(m, products, category_idx):

for idx, title, body, image, price, tag in products:

text = f'<b>{title}</b>\n\n{body}\n\nЦена: {price} рублей.'
text = f'<b>{title}</b>\n\n{body}\n\nPrice: {price} dollars.'

markup = InlineKeyboardMarkup()
markup.add(InlineKeyboardButton(
'🗑️ Удалить', callback_data=product_cb.new(id=idx, action='delete')))
'🗑️ Delete', callback_data=product_cb.new(id=idx, action='delete')))

await m.answer_photo(photo=image,
caption=text,
Expand All @@ -282,4 +282,4 @@ async def show_products(m, products, category_idx):
markup.add(add_product)
markup.add(delete_category)

await m.answer('Хотите что-нибудь добавить или удалить?', reply_markup=markup)
await m.answer('Want to delete or add something?', reply_markup=markup)
4 changes: 2 additions & 2 deletions handlers/admin/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ async def process_orders(message: Message):

orders = db.fetchall('SELECT * FROM orders')

if len(orders) == 0: await message.answer('У вас нет заказов.')
if len(orders) == 0: await message.answer('You don\'t have active orders.')
else: await order_answer(message, orders)

async def order_answer(message, orders):

res = ''

for order in orders:
res += f'Заказ <b>№{order[3]}</b>\n\n'
res += f'Order <b>№{order[3]}</b>\n\n'

await message.answer(res)
14 changes: 7 additions & 7 deletions handlers/admin/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ async def process_questions(message: Message):

if len(questions) == 0:

await message.answer('Нет вопросов.')
await message.answer('No questions.')

else:

for cid, question in questions:

markup = InlineKeyboardMarkup()
markup.add(InlineKeyboardButton(
'Ответить', callback_data=question_cb.new(cid=cid, action='answer')))
'Answer', callback_data=question_cb.new(cid=cid, action='answer')))

await message.answer(question, reply_markup=markup)

Expand All @@ -39,7 +39,7 @@ async def process_answer(query: CallbackQuery, callback_data: dict, state: FSMCo
async with state.proxy() as data:
data['cid'] = callback_data['cid']

await query.message.answer('Напиши ответ.', reply_markup=ReplyKeyboardRemove())
await query.message.answer('Write an answer.', reply_markup=ReplyKeyboardRemove())
await AnswerState.answer.set()


Expand All @@ -50,12 +50,12 @@ async def process_submit(message: Message, state: FSMContext):
data['answer'] = message.text

await AnswerState.next()
await message.answer('Убедитесь, что не ошиблись в ответе.', reply_markup=submit_markup())
await message.answer('Make sure everything is correct.', reply_markup=submit_markup())


@dp.message_handler(IsAdmin(), text=cancel_message, state=AnswerState.submit)
async def process_send_answer(message: Message, state: FSMContext):
await message.answer('Отменено!', reply_markup=ReplyKeyboardRemove())
await message.answer('Canceled!', reply_markup=ReplyKeyboardRemove())
await state.finish()


Expand All @@ -70,9 +70,9 @@ async def process_send_answer(message: Message, state: FSMContext):
question = db.fetchone(
'SELECT question FROM questions WHERE cid=?', (cid,))[0]
db.query('DELETE FROM questions WHERE cid=?', (cid,))
text = f'Вопрос: <b>{question}</b>\n\nОтвет: <b>{answer}</b>'
text = f'Question: <b>{question}</b>\n\nAnswer: <b>{answer}</b>'

await message.answer('Отправлено!', reply_markup=ReplyKeyboardRemove())
await message.answer('Sent!', reply_markup=ReplyKeyboardRemove())
await bot.send_message(cid, text)

await state.finish()
Loading