From 4fc2417ec268235501c2af566a5bdd63a8bec3a2 Mon Sep 17 00:00:00 2001 From: Rykov7 Date: Wed, 30 Nov 2022 21:28:03 +0300 Subject: [PATCH] replace trolling.py to bot.py --- app/bot.py | 36 ++++++++++++++++++++++++++++++++---- app/config.py | 2 +- app/trolling.py | 34 ---------------------------------- 3 files changed, 33 insertions(+), 39 deletions(-) delete mode 100644 app/trolling.py diff --git a/app/bot.py b/app/bot.py index 41aa724..60388ad 100644 --- a/app/bot.py +++ b/app/bot.py @@ -3,9 +3,9 @@ from datetime import datetime as dt from flask import Flask, request, abort from telebot import types import logging +from urllib import parse from . import reminder -from . import trolling from . import admin from . import report from .config import bot, URL_RX, ALLOWED_WORDS, ADMIN_ID, TOKEN, PYTHONCHATRU, WHITEUN, WHITEIDS @@ -31,9 +31,6 @@ zen_rows = ['Beautiful is better than ugly.', 'Explicit is better than implicit. 'If the implementation is easy to explain, it may be a good idea.', "Namespaces are one honking great idea — let's do more of those!"] -if trolling: - pass - def check_spam_list(type_message: types.Message) -> bool: """ Check for mentioning unwanted persons in text. """ @@ -241,6 +238,37 @@ def check_chat(message: types.Message): return True +@bot.message_handler(commands=['tsya']) +def send_tsya_link(message: types.Message): + """ тся/ться """ + link = '-тся/-ться' + if message.reply_to_message: + bot.reply_to(message.reply_to_message, link, parse_mode='HTML', disable_web_page_preview=True) + + +@bot.message_handler(commands=['g']) +def google_it(message: types.Message): + """ Google it! """ + if message.reply_to_message.text: + search = parse.quote_plus(message.reply_to_message.text) + bot.reply_to(message.reply_to_message, f"https://www.google.ru/search?q={search}", parse_mode='HTML', + disable_web_page_preview=True) + + +def check_unwanted_list(type_message: types.Message) -> bool: + """ Check for bloggers. """ + unwanted_phrases = ['дудар', 'хауди', 'dudar'] + for phrase in unwanted_phrases: + if phrase in type_message.text.casefold(): + return True + + +@bot.message_handler(func=check_unwanted_list) +def unwanted_mentions(message: types.Message): + """ Reply to unwanted mentions. """ + bot.reply_to(message, f'У нас таких не любят! 🥴', parse_mode='HTML') + + @bot.message_handler(func=check_chat, content_types=['text', 'sticker', 'photo', 'animation', 'video', 'audio', 'document']) def unwanted_mentions(message: types.Message): diff --git a/app/config.py b/app/config.py index 403b151..33108e8 100644 --- a/app/config.py +++ b/app/config.py @@ -17,7 +17,7 @@ PYTHONCHATRU = -1001338616632 # pythonchatru URL_RX = re.compile(r'\w+\.\w+/\w+') ALLOWED_WORDS = ['pastebin', 'github', 'google', 'nometa', 'python', 'django', 'flask', 'fastapi', - 'stackoverflow', 'habr', 'medium', 'youtube', 'stepik', 'telegraph'] + 'stackoverflow', 'habr', 'medium', 'youtube', 'stepik', 'telegraph', '#rtfm'] WHITEUN = set(os.environ.get('whitelist', '<< bool: - """ Check for bloggers. """ - unwanted_phrases = ['дудар', 'хауди', 'dudar'] - for phrase in unwanted_phrases: - if phrase in type_message.text.casefold(): - return True - - -@bot.message_handler(func=check_unwanted_list) -def unwanted_mentions(message: types.Message): - """ Reply to unwanted mentions. """ - bot.reply_to(message, f'У нас таких не любят! 🥴', parse_mode='HTML')