FEATURE 14.1: autoreaction on invalid nick

- если фулл_нейм НЕ содержит букв английских или русских то считаем его невалидным, сообщение удаляем, юзеру пишем о правиле 6
This commit is contained in:
kotolex
2023-12-26 17:53:21 +05:00
parent 800870f9a9
commit 0603ced4e3
5 changed files with 50 additions and 9 deletions
+2 -2
View File
@@ -6,7 +6,7 @@ from telebot import types
from .admin_commands import bot
from .constants import (LOG_COMM, FAQ, LIB, RULES, RUS, RUS_ENG_TABLE, ENG_RUS_TABLE, PYTHONCHATRU, ZEN, LUTZ_ID,
BDMTSS_ID)
from .filters import in_spam_list, in_caption_spam_list, in_delete_list, is_hello_text, is_empty_name
from .filters import in_spam_list, in_caption_spam_list, in_delete_list, is_hello_text, is_invalid_name
from .helpers import represent_as_get, detect_args, is_admin, fetch_rule
from .report import update_stats, increment
from .stan import act, speak
@@ -352,7 +352,7 @@ async def default_query(inline_query):
await bot.answer_inline_query(inline_query.id, zen, cache_time=1200)
@bot.message_handler(func=is_empty_name, chat_types=["supergroup", "group"])
@bot.message_handler(func=is_invalid_name, chat_types=["supergroup", "group"])
async def handle_hello(message: types.Message):
await bot.delete_message(message.chat.id, message.id)
nick_rule = 6
+6 -3
View File
@@ -4,7 +4,7 @@ from telebot import types
from .config import WHITEIDS
from .constants import LOG_COMM, ALLOWED_WORDS, URL_RX, HELLO_EXAMPLES
from .helpers import is_spam, is_in_not_allowed, is_ban_words_in_caption, cleaned_text, remove_spaces
from .helpers import is_spam, is_in_not_allowed, is_ban_words_in_caption, cleaned_text, remove_spaces, has_no_letters
from .models import is_antispam_enabled
@@ -52,5 +52,8 @@ def is_hello_text(message: types.Message) -> bool:
return any(hello == text for hello in HELLO_EXAMPLES)
def is_empty_name(message: types.Message) -> bool:
return message.from_user.full_name.strip() == ''
def is_invalid_name(message: types.Message) -> bool:
name = message.from_user.full_name
if name is None or name.strip() == '':
return True
return has_no_letters(name)
+6
View File
@@ -69,6 +69,12 @@ def is_admin(message: types.Message) -> bool:
return message.from_user.id == ADMIN_ID
def has_no_letters(text: str) -> bool:
text = text.lower()
letters = f'{ONLY_RUS_LETTERS}{ONLY_ENG_LETTERS}'
return not any(letter in text for letter in letters)
def my_ip():
ip_service = "https://icanhazip.com"
ip = urlopen(ip_service)