Skip to content

Commit ee51226

Browse files
authored
Merge pull request #17 from iflare3g/fix/issue-#16
FIX ISSUE #16 BUG
2 parents 8f20490 + 6cc544d commit ee51226

3 files changed

Lines changed: 25 additions & 22 deletions

File tree

tg_bot/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@
5151

5252
DB_URI = os.environ.get('DATABASE_URL')
5353
DONATION_LINK = os.environ.get('DONATION_LINK')
54-
LOAD = os.environ.get("LOAD", "").split()
55-
NO_LOAD = os.environ.get("NO_LOAD", "translation").split()
54+
LOAD = os.environ.get("LOAD", "").split(",") if "," in os.environ.get("LOAD", "") else os.environ.get("LOAD", "").split()
55+
NO_LOAD = os.environ.get("NO_LOAD", "translation").split(",")
5656
DEL_CMDS = bool(os.environ.get('DEL_CMDS', False))
5757
STRICT_GBAN = bool(os.environ.get('STRICT_GBAN', False))
5858
WORKERS = int(os.environ.get('WORKERS', 8))
5959
BAN_STICKER = os.environ.get('BAN_STICKER', 'CAADAgADOwADPPEcAXkko5EB3YGYAg')
6060
ALLOW_EXCL = os.environ.get('ALLOW_EXCL', False)
6161
DEFAULT_CHAT_ID = os.environ.get('DEFAULT_CHAT_ID', None)
62-
VERSION = os.environ.get('DEFAULT_CHAT_ID', 'Production.version')
62+
VERSION = __version__
6363

6464
else:
6565
from tg_bot.config import Development as Config

tg_bot/modules/log_channel.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,24 @@ def log_resource(bot: Bot, update: Update):
4444
entities = update.effective_message.parse_entities()
4545
caption_entities = update.effective_message.parse_caption_entities()
4646
chat = update.effective_chat # type: Optional[Chat]
47-
if chat.type == chat.SUPERGROUP:
48-
log_chat = sql.get_chat_log_channel(chat.id)
49-
if log_chat:
50-
for descriptor, entity in entities.items():
51-
result = f'<b>Risorsa inviata da @{update.effective_user.username}:</b>\n'
52-
if descriptor['type'] in ['url', 'text_link']:
53-
result += f'{entity}'
54-
LOGGER.debug(f"Found message entity: {descriptor['type']} {entity}")
55-
send_log(bot, log_chat, chat.id, result)
56-
57-
for descriptor, entity in caption_entities.items():
58-
result = '<b>Risorsa inviata da @{update.effective_user.username}:</b>\n'
59-
if descriptor['type'] in ['url', 'text_link']:
60-
result += f'{entity}'
61-
LOGGER.debug(f"Found message entity: {descriptor['type']} {entity}")
62-
send_log(bot, log_chat, chat.id, result)
47+
log_chat = sql.get_chat_log_channel(chat.id)
48+
if log_chat:
49+
result = f'<b>Risorsa inviata da @{update.effective_user.username}:</b>\n'
50+
for descriptor, entity in entities.items():
51+
result = f'<b>Risorsa inviata da @{update.effective_user.username}:</b>\n'
52+
if descriptor['type'] in ['url', 'text_link']:
53+
result += f'{entity}'
54+
LOGGER.debug(f"Found message entity: {descriptor['type']} {entity}")
55+
send_log(bot, log_chat, chat.id, result)
56+
57+
for descriptor, entity in caption_entities.items():
58+
result = '<b>Risorsa inviata da @{update.effective_user.username}:</b>\n'
59+
if descriptor['type'] in ['url', 'text_link']:
60+
result += f'{entity}'
61+
LOGGER.debug(f"Found message entity: {descriptor['type']} {entity}")
62+
send_log(bot, log_chat, chat.id, result)
63+
else:
64+
send_log(bot, log_chat, chat.id, result)
6365

6466

6567
def send_log(bot: Bot, log_chat_id: str, orig_chat_id: str, result: str):
@@ -182,7 +184,7 @@ def __chat_settings__(chat_id, user_id):
182184
SET_LOG_HANDLER = CommandHandler("setlog", setlog)
183185
UNSET_LOG_HANDLER = CommandHandler("unsetlog", unsetlog)
184186

185-
LOG_RESOURCES_HANDLER = MessageHandler(Filters.all & Filters.group, log_resource)
187+
LOG_RESOURCES_HANDLER = MessageHandler((Filters.entity("url") | Filters.entity("text_link")), log_resource)
186188

187189
dispatcher.add_handler(LOG_HANDLER)
188190
dispatcher.add_handler(SET_LOG_HANDLER)

tg_bot/modules/spam.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def spam_filter(bot: Bot, update: Update):
2020
found = False
2121
for descriptor, entity in message_entities.items():
2222
LOGGER.debug(f"Found message entity: {descriptor['type']} {entity}")
23-
found = True
23+
if descriptor["type"] in FORBIDDEN_ENTITY_TYPES:
24+
found = True
2425

2526
if found:
2627
spam_action(update)
@@ -40,4 +41,4 @@ def white_spam_add(bot: Bot, update: Update):
4041

4142
SPAM_HANDLER = MessageHandler(Filters.all & Filters.group, spam_filter)
4243
WHITE_SPAM_HANDLER = CommandHandler("whitespam", white_spam_add)
43-
#dispatcher.add_handler(SPAM_HANDLER)
44+
dispatcher.add_handler(SPAM_HANDLER)

0 commit comments

Comments
 (0)