Added multiple categories and subcategories possibility
This commit is contained in:
@@ -175,8 +175,10 @@ async def continue_or_finish(update: Update, context: CallbackContext):
|
||||
markup = InlineKeyboardMarkup(helpers.create_continue_keyboard())
|
||||
last_step = context.user_data.get('last_step', '')
|
||||
query = update.callback_query
|
||||
|
||||
try:
|
||||
qd = query.data
|
||||
logging.info(f"Query Data: {qd}")
|
||||
except:
|
||||
qd = ''
|
||||
|
||||
@@ -187,13 +189,58 @@ async def continue_or_finish(update: Update, context: CallbackContext):
|
||||
context.user_data.clear()
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id, text=f'Borrado')
|
||||
return ConversationHandler.END
|
||||
|
||||
if last_step == 'category':
|
||||
category = int(query.data)
|
||||
|
||||
if qd == 'add_subcategory':
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text=f"Categoría escogida: {helpers.get_category_name(category)}")
|
||||
context.user_data['category'] = category
|
||||
context.user_data['last_step'] = ''
|
||||
text='Escoge la categoría', reply_markup=InlineKeyboardMarkup(helpers.create_categories_keyboard(context.user_data['category'])))
|
||||
context.user_data['last_step'] = 'choose_subcategory'
|
||||
return CONTINUE_OR_FINISH
|
||||
if qd == 'finish_subcategory':
|
||||
pass
|
||||
if qd == 'add_category':
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text='Categoría', reply_markup=InlineKeyboardMarkup(helpers.create_category_keyboard()))
|
||||
context.user_data['last_step'] = 'category'
|
||||
return CONTINUE_OR_FINISH
|
||||
if last_step == "choose_subcategory":
|
||||
category = query.data
|
||||
if category != 'finish':
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text='Escoge la subcategoría', reply_markup=InlineKeyboardMarkup(helpers.create_subcategory_keyboard(category)))
|
||||
context.user_data['last_step'] = 'subcategory'
|
||||
return CONTINUE_OR_FINISH
|
||||
else:
|
||||
context.user_data['last_step'] = ''
|
||||
if last_step == 'subcategory':
|
||||
subcategory = query.data
|
||||
if subcategory != 'finish':
|
||||
text = f"✅Subcategoría escogida: {helpers.get_subcategory_name(subcategory)}✅"
|
||||
if context.user_data.get('subcategory'):
|
||||
if subcategory not in context.user_data['subcategory'].split(','):
|
||||
context.user_data['subcategory'] = context.user_data['subcategory'] + ',' + subcategory
|
||||
else:
|
||||
text = f"❌La subcategoría {helpers.get_subcategory_name(subcategory)} ya estaba añadida❌"
|
||||
else:
|
||||
context.user_data['subcategory'] = subcategory
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text=text)
|
||||
logging.info(f"{context.user_data['subcategory']}")
|
||||
context.user_data['last_step'] = ''
|
||||
if last_step == 'category':
|
||||
category = query.data
|
||||
if category != 'finish':
|
||||
text = f"✅Categoría escogida: {helpers.get_category_name(category)}✅"
|
||||
if context.user_data.get('category'):
|
||||
if category not in context.user_data['category'].split(','):
|
||||
context.user_data['category'] = context.user_data['category'] + ',' + category
|
||||
else:
|
||||
text = f"❌La categoría {helpers.get_category_name(category)} ya estaba añadida❌"
|
||||
else:
|
||||
context.user_data['category'] = category
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
text=text)
|
||||
logging.info(f"{context.user_data['category']}")
|
||||
context.user_data['last_step'] = ''
|
||||
|
||||
if qd == 'title_exclude':
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||
@@ -250,6 +297,9 @@ async def continue_or_finish(update: Update, context: CallbackContext):
|
||||
if context.user_data['last_step'] == '':
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id, text=f'Añadir?', reply_markup=markup)
|
||||
return CONTINUE_OR_FINISH
|
||||
|
||||
async def add_subcategory(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
pass
|
||||
|
||||
async def cancel(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
logging.info('Conversation cancelled')
|
||||
@@ -304,7 +354,7 @@ async def add_premium_user_command(update: Update, context: ContextTypes.DEFAULT
|
||||
telegram_user_id = update.message.text.split('/add_premium_user ')[1].split(' ')[0]
|
||||
days = update.message.text.split('/add_premium_user ')[1].split(' ')[1]
|
||||
until = helpers.get_date_ahead(int(days))
|
||||
if not walladb.add_premium_user(telegram_user_id, '', until):
|
||||
if not walladb.add_premium_user(telegram_user_id, until):
|
||||
products = walladb.get_products_from_user(telegram_user_id)
|
||||
|
||||
for product in products:
|
||||
|
||||
Reference in New Issue
Block a user