40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
|
import random
|
||
|
from aiogram import Bot, Dispatcher, types
|
||
|
from aiogram.fsm.storage.memory import MemoryStorage
|
||
|
from aiogram.utils import executor
|
||
|
import logging
|
||
|
|
||
|
|
||
|
# Инициализация бота
|
||
|
API_TOKEN = '7827459383:AAEDbHx51j9nOWgM4HtGMN_i8_3S12D__XQ'
|
||
|
bot = Bot(token=API_TOKEN)
|
||
|
storage = MemoryStorage()
|
||
|
dp = Dispatcher(bot)
|
||
|
|
||
|
# Функция для получения случайной фразы из документа
|
||
|
def get_random_phrase(document):
|
||
|
with open(document, 'r', encoding='utf-8') as file:
|
||
|
phrases = file.readlines()
|
||
|
return random.choice(phrases).strip()
|
||
|
|
||
|
# Обработка команды /generate
|
||
|
@dp.message_handler(commands=['generate'])
|
||
|
async def generate_sentence(message: types.Message):
|
||
|
# Имя документов (замените на ваши файлы)
|
||
|
doc_x = 'document_x.txt'
|
||
|
doc_y = 'document_y.txt'
|
||
|
doc_z = 'document_z.txt'
|
||
|
|
||
|
# Получение случайных фраз
|
||
|
phrase_x = get_random_phrase(doc_x)
|
||
|
phrase_y = get_random_phrase(doc_y)
|
||
|
phrase_z = get_random_phrase(doc_z)
|
||
|
|
||
|
# Формирование предложения
|
||
|
result_sentence = f"{phrase_x} {phrase_y} {phrase_z} = {phrase_x} {phrase_y} {phrase_z}"
|
||
|
|
||
|
# Отправка предложения
|
||
|
await message.answer(result_sentence)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
executor.start_polling(dp, skip_updates=True)
|