|
14 | 14 | from tg_bot import dispatcher, LOGGER |
15 | 15 | from tg_bot.modules.helper_funcs.chat_status import user_admin |
16 | 16 | from tg_bot.modules.sql import log_channel_sql as sql |
| 17 | + import requests |
17 | 18 |
|
18 | 19 | def loggable(func): |
19 | 20 | @wraps(func) |
@@ -57,20 +58,28 @@ def log_resource(bot: Bot, update: Update): |
57 | 58 | f"<b>Risorsa inviata da @{update.effective_user.username}:</b>\n" |
58 | 59 | ) |
59 | 60 | 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) |
| 61 | + try: |
| 62 | + response = requests.get(entity) |
| 63 | + if response.status_code == requests.codes.ok: |
| 64 | + result += f"{entity}" |
| 65 | + send_log(bot, log_chat, chat.id, result) |
| 66 | + except Exception as e: |
| 67 | + LOGGER.info(f"Resource {entity} is not a valid url") |
| 68 | + LOGGER.error(e) |
63 | 69 |
|
64 | 70 | for descriptor, entity in caption_entities.items(): |
65 | 71 | result = ( |
66 | 72 | "<b>Risorsa inviata da @{update.effective_user.username}:</b>\n" |
67 | 73 | ) |
68 | 74 | if descriptor["type"] in ["url", "text_link"]: |
69 | | - result += f"{entity}" |
70 | | - LOGGER.debug(f"Found message entity: {descriptor['type']} {entity}") |
71 | | - send_log(bot, log_chat, chat.id, result) |
72 | | - else: |
73 | | - send_log(bot, log_chat, chat.id, result) |
| 75 | + try: |
| 76 | + response = requests.get(entity) |
| 77 | + if response.status_code == requests.codes.ok: |
| 78 | + result += f"{entity}" |
| 79 | + send_log(bot, log_chat, chat.id, result) |
| 80 | + except Exception as e: |
| 81 | + LOGGER.info(f"Resource {entity} is not a valid url") |
| 82 | + LOGGER.error(e) |
74 | 83 |
|
75 | 84 | def send_log(bot: Bot, log_chat_id: str, orig_chat_id: str, result: str): |
76 | 85 | try: |
@@ -207,7 +216,12 @@ def __chat_settings__(chat_id, user_id): |
207 | 216 | UNSET_LOG_HANDLER = CommandHandler("unsetlog", unsetlog) |
208 | 217 |
|
209 | 218 | LOG_RESOURCES_HANDLER = MessageHandler( |
210 | | - (Filters.entity("url") | Filters.entity("text_link")), log_resource |
| 219 | + ( |
| 220 | + Filters.entity("url") |
| 221 | + | Filters.entity("text_link") |
| 222 | + | Filters.entity("hashtag") |
| 223 | + ), |
| 224 | + log_resource, |
211 | 225 | ) |
212 | 226 |
|
213 | 227 | dispatcher.add_handler(LOG_HANDLER) |
|
0 commit comments