config bans, cascade deletion, add albemic, add enable_stan and get_quotes
This commit is contained in:
+6
-9
@@ -7,18 +7,16 @@ from . import rules
|
|||||||
from .helpers import represent_as_get, detect_args, update_stats
|
from .helpers import represent_as_get, detect_args, update_stats
|
||||||
from .filters import *
|
from .filters import *
|
||||||
from .config import *
|
from .config import *
|
||||||
from .database import session
|
|
||||||
from .models import Chat
|
|
||||||
|
|
||||||
""" [ ANTISPAM ] """
|
""" [ ANTISPAM ] """
|
||||||
|
|
||||||
|
|
||||||
@bot.edited_message_handler(func=in_spam_list)
|
@bot.edited_message_handler(func=in_spam_list, chat_types=["supergroup", "group"])
|
||||||
@bot.message_handler(func=in_spam_list)
|
@bot.message_handler(func=in_spam_list, chat_types=["supergroup", "group"])
|
||||||
def moderate_messages(message: types.Message):
|
def moderate_messages(message: types.Message):
|
||||||
"""Ban user and delete their message."""
|
"""Ban user and delete their message."""
|
||||||
logging.info(
|
logging.info(
|
||||||
f"[BAN] {message.from_user.id} {message.from_user.username} - {message.text}"
|
f"[BAN] [{message.from_user.id}] {message.from_user.username}: {message.text}"
|
||||||
)
|
)
|
||||||
bot.delete_message(message.chat.id, message.id)
|
bot.delete_message(message.chat.id, message.id)
|
||||||
bot.ban_chat_member(message.chat.id, message.from_user.id)
|
bot.ban_chat_member(message.chat.id, message.from_user.id)
|
||||||
@@ -26,7 +24,7 @@ def moderate_messages(message: types.Message):
|
|||||||
s["Banned"] += 1
|
s["Banned"] += 1
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(func=in_caption_spam_list, content_types=["video"])
|
@bot.message_handler(func=in_caption_spam_list, content_types=["video"], chat_types=["supergroup", "group"])
|
||||||
def catch_videos(message: types.Message):
|
def catch_videos(message: types.Message):
|
||||||
"""Catch offensive videos"""
|
"""Catch offensive videos"""
|
||||||
logging.info(
|
logging.info(
|
||||||
@@ -38,10 +36,9 @@ def catch_videos(message: types.Message):
|
|||||||
s["Banned"] += 1
|
s["Banned"] += 1
|
||||||
|
|
||||||
|
|
||||||
@bot.edited_message_handler(func=in_delete_list)
|
@bot.edited_message_handler(func=in_delete_list, chat_types=["supergroup", "group"])
|
||||||
@bot.message_handler(func=in_delete_list)
|
@bot.message_handler(func=in_delete_list, chat_types=["supergroup", "group"])
|
||||||
def delete_message(message: types.Message):
|
def delete_message(message: types.Message):
|
||||||
if session.query(Chat.antispam).filter_by(chat_id=message.chat.id).first()[0]:
|
|
||||||
"""Delete unwanted message."""
|
"""Delete unwanted message."""
|
||||||
bot.delete_message(message.chat.id, message.id)
|
bot.delete_message(message.chat.id, message.id)
|
||||||
with shelve.open(f"{DATA}{message.chat.id}") as s:
|
with shelve.open(f"{DATA}{message.chat.id}") as s:
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime as dt
|
from datetime import datetime as dt
|
||||||
|
from ..models import Chat
|
||||||
|
from ..database import session
|
||||||
from ..config import bot, ADMIN_ID, types
|
from ..config import bot, ADMIN_ID, types
|
||||||
from .. import reminder
|
from .. import reminder
|
||||||
from .. import report
|
from .. import report
|
||||||
@@ -66,3 +68,29 @@ def send_stats(message: types.Message):
|
|||||||
logging.warning("reset_stats")
|
logging.warning("reset_stats")
|
||||||
report.reset_report_stats(message.chat.id)
|
report.reset_report_stats(message.chat.id)
|
||||||
bot.send_message(message.chat.id, report.reset_report_stats(message.chat.id))
|
bot.send_message(message.chat.id, report.reset_report_stats(message.chat.id))
|
||||||
|
|
||||||
|
|
||||||
|
@bot.message_handler(commands=["enable_stan"], chat_types=["supergroup", "group"])
|
||||||
|
def enable_stan(message: types.Message):
|
||||||
|
"""Add group to database."""
|
||||||
|
|
||||||
|
logging.info(
|
||||||
|
f"[{message.chat.title}] [{message.from_user.id}] {message.from_user.username}: {message.text}"
|
||||||
|
)
|
||||||
|
if not session.query(Chat.id).filter(Chat.id == message.chat.id).first():
|
||||||
|
logging.info('[TRUE] chat.id == message.chat.id')
|
||||||
|
session.add(Chat(chat_id=message.chat.id, title=message.chat.title, antispam=1, report=0, reminder=1))
|
||||||
|
session.commit()
|
||||||
|
bot.send_message(message.chat.id, f"""Группа "{message.chat.title}"
|
||||||
|
Добавлена в БД
|
||||||
|
|
||||||
|
Текущие настройки:
|
||||||
|
Антиспам: {session.query(Chat.antispam).filter(Chat.chat_id == message.chat.id).first()[0]}
|
||||||
|
Ежедневные отчёты: {session.query(Chat.report).filter(Chat.chat_id == message.chat.id).first()[0]}
|
||||||
|
Праздники: {session.query(Chat.reminder).filter(Chat.chat_id == message.chat.id).first()[0]}""")
|
||||||
|
|
||||||
|
@bot.message_handler(commands=["get_quotes"], chat_types=["supergroup", "group"])
|
||||||
|
def get_quotes(message: types.Message):
|
||||||
|
logging.info('[TRUE] getting quotes...')
|
||||||
|
quotes = session.query(Chat.quotes).filter(Chat.id == message.chat.id).all()
|
||||||
|
bot.send_message(message.chat.id, f"{quotes}")
|
||||||
+6
-2
@@ -1,9 +1,12 @@
|
|||||||
|
from .database import session
|
||||||
|
from .models import Chat
|
||||||
from .config import *
|
from .config import *
|
||||||
|
|
||||||
|
|
||||||
def in_spam_list(message: types.Message) -> bool:
|
def in_spam_list(message: types.Message) -> bool:
|
||||||
"""Check for mentioning unwanted persons in text."""
|
"""Check for mentioning unwanted persons in text."""
|
||||||
if message.from_user.id not in WHITEIDS:
|
antispam_is_enabled = session.query(Chat.antispam).filter_by(chat_id=message.chat.id).first()[0]
|
||||||
|
if message.from_user.id not in WHITEIDS and antispam_is_enabled:
|
||||||
for url in SPAM:
|
for url in SPAM:
|
||||||
if url in message.text.casefold():
|
if url in message.text.casefold():
|
||||||
return True
|
return True
|
||||||
@@ -25,7 +28,8 @@ def in_not_allowed(word_list, msg):
|
|||||||
|
|
||||||
def in_delete_list(message: types.Message) -> bool:
|
def in_delete_list(message: types.Message) -> bool:
|
||||||
"""Check for URLs in message and delete."""
|
"""Check for URLs in message and delete."""
|
||||||
if message.from_user.id not in WHITEIDS:
|
antispam_is_enabled = session.query(Chat.antispam).filter_by(chat_id=message.chat.id).first()[0]
|
||||||
|
if message.from_user.id not in WHITEIDS and antispam_is_enabled:
|
||||||
if URL_RX.search(message.text) and in_not_allowed(
|
if URL_RX.search(message.text) and in_not_allowed(
|
||||||
ALLOWED_WORDS, message.text
|
ALLOWED_WORDS, message.text
|
||||||
):
|
):
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ class Chat(Base):
|
|||||||
title = Column(String)
|
title = Column(String)
|
||||||
|
|
||||||
# Settings
|
# Settings
|
||||||
quotes = relationship('Quote', backref='chat')
|
quotes = relationship('Quote', backref='chat', cascade='all, delete')
|
||||||
antispam = Column(Boolean)
|
antispam = Column(Boolean)
|
||||||
report = Column(Boolean)
|
report = Column(Boolean)
|
||||||
reminder = Column(Boolean)
|
reminder = Column(Boolean)
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user