/
mapb14ator
/
tg_bot
Обзор
Документация
Войти
/
mapb14ator
/
tg_bot
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
test_bot.py
60 строк
2 KB
mapb14ator
create test_bot.py
19 дек 2025, 17:09
19 дек 2025, 17:09
0bcee0b
Код
Авторство
О чём код?
import asyncio from aiogram import Bot, Dispatcher, types from aiogram.utils import executor from super_bot import megamozg import time TOKEN = '8334167487:AAF8EyDD608cBvrH3gC_u1SlWluBsJlAT58' bot = Bot(token=TOKEN) dp = Dispatcher(bot) @dp.message_handler(commands=['start']) async def start_handler(message: types.Message): button_text_1 = "направления" button_text_2 = "направление: safasfa" button1 = types.InlineKeyboardButton(button_text_1, callback_data=button_text_1) button2 = types.InlineKeyboardButton(button_text_2, callback_data=button_text_2) keyboard = types.InlineKeyboardMarkup().add(button1, button2) await message.answer("Привет! Нажми кнопку или отправь вопрос.", reply_markup=keyboard) @dp.callback_query_handler(lambda c: True) async def handle_button(callback_query: types.CallbackQuery): text_from_button = callback_query.data chat_id = callback_query.message.chat.id await bot.send_message(chat_id, text_from_button) response = megamozg(text_from_button) words = response.split() buttons = [] for i in range(0, len(words) - 1, 2): button_text = f"{words[i]} {words[i+1]}" buttons.append(types.InlineKeyboardButton(text=button_text, callback_data=button_text)) if len(words) % 2 != 0: last_word = words[-1] buttons.append(types.InlineKeyboardButton(text=last_word, callback_data=last_word)) keyboard = types.InlineKeyboardMarkup().add(*buttons) await bot.send_message(chat_id, "Выберите вариант:", reply_markup=keyboard) await callback_query.answer() @dp.message_handler() async def handle_message(message: types.Message): response = megamozg(message.text) await message.reply(response) if __name__ == '__main__': time.sleep(2) executor.start_polling(dp)