Skip to content

Commit ec49d4f

Browse files
committed
Added filters to url MessageEntity for locks module
1 parent c5a8f55 commit ec49d4f

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

tg_bot/modules/locks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
'contact': Filters.contact,
2727
'photo': Filters.photo,
2828
'gif': Filters.animation,
29-
'url': Filters.entity(MessageEntity.URL) | Filters.caption_entity(MessageEntity.URL),
29+
'url': Filters.entity(MessageEntity.URL) | Filters.caption_entity(MessageEntity.URL) |
30+
Filters.entity(MessageEntity.TEXT_LINK) | Filters.caption_entity(MessageEntity.TEXT_LINK),
3031
'bots': Filters.status_update.new_chat_members,
3132
'forward': Filters.forwarded,
3233
'game': Filters.game,

tg_bot/modules/spam.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
11
from tg_bot import dispatcher, LOGGER
2+
from tg_bot.modules.helper_funcs.chat_status import bot_can_delete
23
from telegram import Update, Bot
3-
from telegram.ext import MessageHandler, Filters
4+
from telegram.ext import MessageHandler, Filters, CommandHandler
5+
from telegram.ext.dispatcher import run_async
46

57

8+
FORBIDDEN_ENTITY_TYPES = ['url', 'text_link', 'email', 'phone_number']
9+
10+
@run_async
11+
@bot_can_delete
612
def spam_filter(bot: Bot, update: Update):
713
msg = update.effective_message.text
8-
LOGGER.debug("spam" in msg)
9-
if msg and "spam" in msg:
10-
user = update.effective_user.username
11-
update.effective_message.reply_text(f"Non spammare! @{user}", quote=False)
12-
update.effective_message.delete()
14+
message_entities = update.effective_message.parse_entities()
15+
message_caption_entities = update.effective_message.parse_caption_entities()
1316

17+
found = False
18+
for descriptor, entity in message_entities.items():
19+
LOGGER.debug(f"Found message entity: {descriptor['type']} {entity}")
20+
found = True
1421

15-
SPAM_HANDLER = MessageHandler(Filters.all & Filters.group, spam_filter)
22+
if found:
23+
spam_action(update)
24+
25+
26+
def spam_action(update: Update):
27+
user = update.effective_user.username
28+
update.effective_message.reply_text(f"Non spammare! @{user}", quote=False)
29+
update.effective_message.delete()
1630

17-
dispatcher.add_handler(SPAM_HANDLER)
31+
32+
def white_spam_add(bot: Bot, update: Update):
33+
if update.effective_message.reply_to_message:
34+
pass
35+
else:
36+
update.effective_message.reply_text("Cosa vuoi aggiungere in whitelist?")
37+
38+
SPAM_HANDLER = MessageHandler(Filters.all & Filters.group, spam_filter)
39+
WHITE_SPAM_HANDLER = CommandHandler("whitespam", white_spam_add)
40+
#dispatcher.add_handler(SPAM_HANDLER)

0 commit comments

Comments
 (0)