refactor bot.py

This commit is contained in:
Rykov7
2022-12-20 05:16:08 +03:00
parent a12b9ea0b3
commit 498b71e166
3 changed files with 15 additions and 24 deletions
+8 -20
View File
@@ -12,13 +12,11 @@ from .check import *
from .config import *
# https://core.telegram.org/bots/api Telegram Bot API
# https://github.com/eternnoir/pyTelegramBotAPI/tree/master/examples
# https://github.com/eternnoir/pyTelegramBotAPI/tree/master/
logging.basicConfig(level=logging.INFO, format='%(message)s')
app = Flask(__name__)
logging.warning('>>> PYBOT STARTED!')
@bot.message_handler(commands=['start'])
def start(message: types.Message):
@@ -198,14 +196,12 @@ def admin_panel(message: types.Message):
@bot.message_handler(commands=['tsya'])
def send_tsya_link(message: types.Message):
""" тся/ться """
def send_tsya(message: types.Message):
send_or_reply(message, '<a href="https://tsya.ru/">-тся/-ться</a>')
@bot.message_handler(commands=['nometa'])
def send_nometa(message: types.Message):
""" No meta """
send_or_reply(message, """Не задавай мета-вопросов, вроде:
<i> «Можно задать вопрос?»
«Кто-нибудь пользовался .. ?»
@@ -220,13 +216,8 @@ def send_neprivet(message: types.Message):
send_or_reply(message, '<a href="https://neprivet.com/">Непривет</a>')
"""
Caution commands: nojob, nobot, nogui
"""
@bot.message_handler(commands=['nojob'])
def send_no_job(message):
def send_nojob(message):
logging.warning('Sent no job')
answer = """Мы здесь не для того, чтобы за тебя решать задачи.
@@ -265,19 +256,16 @@ def google_it(message: types.Message):
bot.reply_to(message, f"{search_engine}{r}")
""" Tease for blogger mentions. """
@bot.message_handler(func=check_nongrata)
def unwanted_mentions(message: types.Message):
""" Reply to unwanted mentions. """
def tease_nongrata(message: types.Message):
""" Reply to non grata mentions. """
bot.reply_to(message, f'у нас тут таких не любят')
@bot.message_handler(func=check_chat, content_types=['text', 'sticker', 'photo', 'animation', 'video',
'audio', 'document'])
def unwanted_mentions(message: types.Message):
""" Count messages. """
def handle_msg(message: types.Message):
""" Count messages, Stan speak. """
with shelve.open('chat_stats', writeback=True) as s:
if message.from_user.id not in s['Messages']:
s['Messages'][message.from_user.id] = {'User': message.from_user, 'Count': 0}
+2 -4
View File
@@ -1,4 +1,3 @@
import logging
from telebot import types
from .config import *
@@ -13,8 +12,7 @@ def check_spam_list(type_message: types.Message) -> bool:
def check_caption_spam_list(type_message: types.Message) -> bool:
""" Check for mentioning unwanted words in caption. """
unwanted_phrases = ['GREEN ROOM']
for phrase in unwanted_phrases:
for phrase in BAN_WORDS:
if type_message.caption and phrase in type_message.caption:
return True
@@ -41,7 +39,7 @@ def check_delete_list(type_message: types.Message) -> bool:
def check_nongrata(type_message: types.Message) -> bool:
""" Check for bloggers. """
""" Check for non grata persons. """
for phrase in NON_GRATA:
if phrase in type_message.text.casefold():
return True
+5
View File
@@ -1,8 +1,12 @@
import os
import re
import logging
from telebot import TeleBot
from dotenv import load_dotenv
logging.basicConfig(level=logging.DEBUG, format='%(message)s')
logging.warning('>>> PYBOT STARTED!')
load_dotenv()
TOKEN = os.environ.get('LUTZPYBOT', 'Token not in ENVIRON')
@@ -29,6 +33,7 @@ LIB = '📚 <b><a href="https://telegra.ph/what-to-read-10-06">Библиоте
SPAM = ['me.sv/', 'tg.sv/', 'goo.by/', 'go.sv/', 'intim.video/', 'uclck.ru/']
NON_GRATA = ['дудар', 'хауди', 'dudar']
BAN_WORDS = ['GREEN ROOM']
ZEN = ['Beautiful is better than ugly.', 'Explicit is better than implicit.', 'Simple is better than complex.',
'Complex is better than complicated.', 'Flat is better than nested.', 'Sparse is better than dense.',