Last active
December 27, 2020 12:12
-
-
Save vsecoder-old-account/db409a84e66f6ab148dd5a4a38055dd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# импорт модулей библиотеки aiogram | |
from aiogram import Bot, types | |
from aiogram.dispatcher import Dispatcher | |
from aiogram.utils import executor | |
import string | |
# token бота | |
bot_token = '<token>' | |
# Создание бота | |
bot = Bot(token=bot_token) | |
dp = Dispatcher(bot) | |
# Обработчик команды /start | |
@dp.message_handler(commands=['start']) | |
async def welcome(message: types.Message): | |
await bot.send_message(message.chat.id, 'Здравствуйте!') | |
# встречаем | |
@dp.message_handler(content_types=["new_chat_members"]) | |
async def newuser(message: types.Message): | |
await message.reply('Приветствую вас в чате') | |
# провожаем | |
@dp.message_handler(content_types=["left_chat_member"]) | |
async def leftuser(message: types.Message): | |
await bot.send_message( | |
message.chat.id, 'Эх... минус один пользователь чата...') | |
# всё что текст, но не /start повторить | |
@dp.message_handler(content_types=['text']) | |
async def reply(message: types.Message): | |
try: | |
# dist/mats.txt - путь к файлу словарю с матами | |
with open("dist/mats.txt", encoding='utf-8') as openfile: | |
mat = False | |
text = message.text.lower() | |
ntext = text.translate(str.maketrans('', '', string.punctuation)).lower() | |
for line in openfile: | |
mat = False | |
for part in line.split(): | |
part = part.rstrip(',') | |
if part == 'endmats': | |
if mat == True: | |
await bot.delete_message( | |
message.chat.id, message.message_id) | |
if message.from_user.username != None: | |
await bot.send_message( | |
message.chat.id, '🤐 @' + message.from_user.username + '\n' + text) | |
else: | |
await bot.send_message( | |
message.chat.id, '🤐 ' + message.from_user.first_name + '\n' + text) | |
break | |
for word in ntext.split(): | |
if word == part: | |
text = text.replace(part, '. . .', 1000) | |
mat = True | |
except BaseException as e: | |
await bot.send_message(message.chat.id, 'Упс, ошибка...\n<code>' + str(e) + '</code>', parse_mode='html') | |
# запуск бота | |
if __name__ == "__main__": | |
executor.start_polling(dp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment