I make a ChatGPT bot in telegram, everything works fine. I decided to add the /image command, by which the user first select the size, quantity and then a request to the image, and Dall'e will generate an image.
I made the command, but the problem is that they don't want to work with chatgpt at the same time. I made variables so that gpt_answer does not respond to the message until /image completes, but it did not work out here is the code:
@dp.message_handler()
async def gpt_answer(message: types.Message):
global is_image_processing
if message.text.startswith('/image'):
await images(message)
return
if not is_image_processing:
#the rest of the code has no errors in it
#image
@dp.message_handler(commands=['image'])
async def images(message: types.Message):
is_image_processing = True
image_zapiska()
zapiska()
ins1 = InlineKeyboardButton('256x256', callback_data='size_256x256')
ins2 = InlineKeyboardButton('512x512', callback_data='size_512x512')
ins3 = InlineKeyboardButton('1024x1024', callback_data='size_1024x1024')
keyboard = InlineKeyboardMarkup().add(ins1, ins2, ins3)
await message.reply("Выберите размеры изображения:", reply_markup=keyboard)
@dp.callback_query_handler(lambda c: c.data.startswith('size_'))
async def process_callback_size(callback_query: types.CallbackQuery):
size = callback_query.data.split('_')[1]
await bot.answer_callback_query(callback_query.id)
inn1 = InlineKeyboardButton('1', callback_data='num_1')
inn2 = InlineKeyboardButton('2', callback_data='num_2')
inn3 = InlineKeyboardButton('3', callback_data='num_3')
inn4 = InlineKeyboardButton('4', callback_data='num_4')
keyboard = InlineKeyboardMarkup().add(inn1, inn2, inn3, inn4)
await bot.edit_message_text(chat_id=callback_query.message.chat.id, message_id=callback_query.message.message_id, text=f'Размер изображения: {size}\nВыберите количество изображений:', reply_markup=keyboard)
@dp.callback_query_handler(lambda c: c.data.startswith('num_'))
async def process_callback_num(callback_query: types.CallbackQuery):
global is_image_processing
count = callback_query.data.split('_')[1]
await bot.answer_callback_query(callback_query.id)
# Добавляем обработку выбранного количества изображений
await bot.send_message(chat_id=callback_query.message.chat.id, text=f'Выбрано количество изображений: {count} \nвведите запрос:')
is_image_processing = True
@dp.message_handler()
async def process_user_input(message: types.Message):
global is_image_processing
if is_image_processing:
# Обработка запроса пользователя
promt = message.text
print(promt)
is_image_processing = False
return
else:
print(is_image_processing)
return