Доброго времени суток. Не знав, чем заняться, решил попробовать написать простого бота на библиотеке aiogram, да и изучить чутка. Суть бота: Когда юзеры переписываются, бот запоминает их фразы, после рандомно отправляет любое словосочетание. Сразу говорю, что aiogram я установил 30 минут назад, из-за перехода от telebot'а. Жду вашу критику, чтобы сделать код бота лучше :) Библиотеки pip3 install aiogram pip3 install mc Скачать: Яндекс (Клик) Код: (Не забудьте создать папку Dialogs) Спойлер from aiogram import Bot, types from aiogram.dispatcher import Dispatcher from aiogram.utils import executor import os import mc import random bot = Bot(token='token') dp = Dispatcher(bot) dir_to_txt = 'Dialogs/dialogs' @dp.message_handler(commands=['start']) async def process_start_command(msg: types.Message): await msg.reply("Привет!\nДобавь меня в беседу, и посмотри, как я работаю :)") @dp.message_handler(commands=['wipe']) async def process_help_command(msg: types.Message): await msg.reply("Моя база данных снова чиста, вау!") f = open(dir_to_txt + str(msg.chat.id) + '.txt', 'w', encoding='utf8') f.write('') f.close() @dp.message_handler() async def echo_message(msg: types.Message): if msg.chat.type == 'supergroup' and not msg['from'].is_bot and msg.text != "": if not os.path.exists(dir_to_txt + str(msg.chat.id) + '.txt'): f = open(dir_to_txt + str(msg.chat.id) + '.txt', 'w', encoding='utf8') f.write('') f.close() with open(dir_to_txt + str(msg.chat.id) + '.txt', "a", encoding="utf8") as f: f.write(msg.text + ",") with open(dir_to_txt + str(msg.chat.id) + '.txt', encoding="utf8") as file: txt = file.read().split(",") if len(txt) >= 4 and random.randint(0, 5) == 0: generator = mc.StringGenerator(samples=txt) message = generator.generate_string() await bot.send_message(msg.chat.id, message.lower()) else: await bot.send_message(msg.chat.id, 'Я работаю только в беседах :)') executor.start_polling(dp) Код from aiogram import Bot, types from aiogram.dispatcher import Dispatcher from aiogram.utils import executor import os import mc import random bot = Bot(token='token') dp = Dispatcher(bot) dir_to_txt = 'Dialogs/dialogs' @dp.message_handler(commands=['start']) async def process_start_command(msg: types.Message): await msg.reply("Привет!\nДобавь меня в беседу, и посмотри, как я работаю :)") @dp.message_handler(commands=['wipe']) async def process_help_command(msg: types.Message): await msg.reply("Моя база данных снова чиста, вау!") f = open(dir_to_txt + str(msg.chat.id) + '.txt', 'w', encoding='utf8') f.write('') f.close() @dp.message_handler() async def echo_message(msg: types.Message): if msg.chat.type == 'supergroup' and not msg['from'].is_bot and msg.text != "": if not os.path.exists(dir_to_txt + str(msg.chat.id) + '.txt'): f = open(dir_to_txt + str(msg.chat.id) + '.txt', 'w', encoding='utf8') f.write('') f.close() with open(dir_to_txt + str(msg.chat.id) + '.txt', "a", encoding="utf8") as f: f.write(msg.text + ",") with open(dir_to_txt + str(msg.chat.id) + '.txt', encoding="utf8") as file: txt = file.read().split(",") if len(txt) >= 4 and random.randint(0, 5) == 0: generator = mc.StringGenerator(samples=txt) message = generator.generate_string() await bot.send_message(msg.chat.id, message.lower()) else: await bot.send_message(msg.chat.id, 'Я работаю только в беседах :)') executor.start_polling(dp)
Уф, имел с ним дело. Я не понимаю зачем нужны подобные боты. Они не могут генерировать что-то логичное. Опять же из-за проблемы здравого смысла у нейросетей. (Углубляться не буду)
BlitGaming, возможно, но раз многие любят таких ботов, почему бы не сделать? (У самого 3 таких бота, у всех есть актив.)
infinityjq, В целом, возможно создать бота, который будет генерировать более менее логичные сообщения. Но это не так просто :)
и можно ли как то сделать, что бы два бота например друг другу отвечали, а то они не видят сообщений друг друга