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