warp-beacon 2.3.5__py3-none-any.whl → 2.3.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- __version__ = "2.3.5"
1
+ __version__ = "2.3.7"
2
2
 
@@ -167,7 +167,10 @@ class Bot(object):
167
167
  caption += job.message_leftover
168
168
  caption += "\n—\n"
169
169
  if job.source_username:
170
- caption += f"Requested by <b>@{job.source_username}</b>"
170
+ if job.source_username.startswith("<a href="):
171
+ caption += f"Requested by <b>{job.source_username}</b>"
172
+ else:
173
+ caption += f"Requested by <b>@{job.source_username}</b>"
171
174
  if job.source_username and job.url:
172
175
  caption += " | "
173
176
  if job.url:
@@ -333,7 +336,6 @@ class Bot(object):
333
336
  else:
334
337
  args["disable_notification"] = True
335
338
  args["reply_to_message_id"] = job.message_id
336
- #args["reply_to_message_id"] = None
337
339
 
338
340
  if os.environ.get("ENABLE_DONATES", None) == "true" and job.media_type is not JobType.COLLECTION:
339
341
  args["reply_markup"] = InlineKeyboardMarkup([[InlineKeyboardButton("❤ Donate", url=os.environ.get("DONATE_LINK", "https://pay.cryptocloud.plus/pos/W5BMtNQt5bJFoW2E"))]])
@@ -138,6 +138,7 @@ class Handlers(object):
138
138
  urls, msg_leftover = [], ''
139
139
  if urls_raw:
140
140
  msg_leftover = Utils.compute_leftover(urls_raw, message_text)
141
+ msg_leftover = Utils.handle_mentions(chat.id, client, msg_leftover)
141
142
  # remove duplicates
142
143
  urls = list(set(urls_raw))
143
144
 
@@ -1,8 +1,11 @@
1
- from typing import Union
1
+ from typing import Union, Optional
2
2
 
3
3
  import re
4
4
 
5
+ from pyrogram import Client
5
6
  from pyrogram.types import Message
7
+ from pyrogram.types import ChatMember
8
+ from pyrogram import enums
6
9
 
7
10
  from warp_beacon.jobs import Origin
8
11
  from warp_beacon.jobs.types import JobType
@@ -11,9 +14,10 @@ import logging
11
14
 
12
15
  class Utils(object):
13
16
  expected_patronum_compiled_re = re.compile(r'Expected ([A-Z]+), got ([A-Z]+) file id instead')
17
+ mention_re = re.compile(r'@[A-Za-z0-9_.]{4,}')
14
18
 
15
19
  @staticmethod
16
- def extract_file_id(message: Message) -> Union[None, str]:
20
+ def extract_file_id(message: Message) -> Optional[str]:
17
21
  possible_attrs = ("video", "photo", "audio", "animation", "document")
18
22
  for attr in possible_attrs:
19
23
  if hasattr(message, attr):
@@ -71,15 +75,17 @@ class Utils(object):
71
75
  if message.from_user:
72
76
  if message.from_user.username:
73
77
  return message.from_user.username
78
+ if message.from_user.first_name:
79
+ return message.from_user.first_name
74
80
  if message.from_user.id:
75
- return str(message.from_user.id)
81
+ return str(message.from_user.mention(style=enums.ParseMode.HTML))
76
82
  if message.sender_chat:
77
83
  if message.sender_chat.username:
78
84
  return message.sender_chat.username
79
85
  if message.sender_chat.title:
80
86
  return message.sender_chat.title
81
87
  return ''
82
-
88
+
83
89
  @staticmethod
84
90
  def compute_leftover(urls: list, message: str) -> str:
85
91
  msg_leftover = ""
@@ -88,3 +94,34 @@ class Utils(object):
88
94
  for u in urls:
89
95
  msg_leftover = msg_leftover.replace(u, '')
90
96
  return msg_leftover.strip()
97
+
98
+ @staticmethod
99
+ async def find_chat_user_by_id(client: Client, chat_id: int, user_id: int) -> Optional[ChatMember]:
100
+ ret = None
101
+ async for member in client.get_chat_members(chat_id):
102
+ user_id = 0
103
+ if member.user.id == user_id:
104
+ ret = member.user
105
+ break
106
+ return ret
107
+
108
+ @staticmethod
109
+ def handle_mentions(chat_id: int, client: Client, message: str) -> str:
110
+ try:
111
+ username = ''
112
+ members = client.get_chat_members(chat_id)
113
+ mentions = Utils.mention_re.findall(message)
114
+ for mention in mentions:
115
+ username = mention[1:].strip()
116
+ if username:
117
+ user_id = 0
118
+ for member in members:
119
+ if member.user.username == username:
120
+ user_id = member.user.id
121
+ break
122
+ if user_id:
123
+ message.replace(f"@{username}", f'<a href="tg://user?id={user_id}">{username}</a>')
124
+ except Exception as e:
125
+ logging.warning("Exception occurred while handling TG mentions!")
126
+ logging.exception(e)
127
+ return message
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: warp_beacon
3
- Version: 2.3.5
3
+ Version: 2.3.7
4
4
  Summary: Telegram bot for expanding external media links
5
5
  Home-page: https://github.com/sb0y/warp_beacon
6
6
  Author: Andrey Bagrintsev
@@ -4,7 +4,7 @@ var/warp_beacon/accounts.json,sha256=OsXdncs6h88xrF_AP6_WDCK1waGBn9SR-uYdIeK37GM
4
4
  var/warp_beacon/placeholder.gif,sha256=cE5CGJVaop4Sx21zx6j4AyoHU0ncmvQuS2o6hJfEH88,6064
5
5
  var/warp_beacon/proxies.json,sha256=VnjlQDXumOEq72ZFjbh6IqHS1TEHqn8HPYAZqWCeSIA,95
6
6
  warp_beacon/__init__.py,sha256=_rThNODmz0nDp_n4mWo_HKaNFE5jk1_7cRhHyYaencI,163
7
- warp_beacon/__version__.py,sha256=GYHJBA3mHcPUREmuhd1jHfnftqjLPTFLFmRUdDBqHAo,23
7
+ warp_beacon/__version__.py,sha256=Fdm6rnbh0XX1W_9L7tTwDxi3444GXEyAwtL0RR5fzF4,23
8
8
  warp_beacon/warp_beacon.py,sha256=7KEtZDj-pdhtl6m-zFLsSojs1ZR4o7L0xbqtdmYPvfE,342
9
9
  warp_beacon/compress/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  warp_beacon/compress/video.py,sha256=_PDMVYCyzLYxHv1uZmmzGcG_8rjaZr7BTXsXTTy_oS4,2846
@@ -36,14 +36,14 @@ warp_beacon/scraper/youtube/youtube.py,sha256=fGrbjBngvvNdpzhb1yZVedNW0_tCrLc31V
36
36
  warp_beacon/storage/__init__.py,sha256=2uvyIR0APIW6gOxwJRvCji7wS2q6I7dghvLyWsRqRxo,3312
37
37
  warp_beacon/storage/mongo.py,sha256=qC4ZiO8XXvPnP0rJwz4CJx42pqFsyAjCiW10W5QdT6E,527
38
38
  warp_beacon/telegram/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
- warp_beacon/telegram/bot.py,sha256=9HchhsYV_Ky2uTrovp-T6TLx5E8fC65ISZ28UraIcXg,15641
40
- warp_beacon/telegram/handlers.py,sha256=sefkG9jU85m4oMxkJ8WqA4aiJLLBv98OIgYxY49c1Rs,7627
39
+ warp_beacon/telegram/bot.py,sha256=u3yvXIcqFtVkrf82IXiC4y-UnrEySw49_immBoXIBN4,15725
40
+ warp_beacon/telegram/handlers.py,sha256=WUIZ62JuU9g_bTyV_XzboC487wkt_cTm2Z6eVoQj8Wg,7698
41
41
  warp_beacon/telegram/placeholder_message.py,sha256=wN9-BRiyrtHG-EvXtZkGJHt2CX71munQ57ITttjt0mw,6400
42
- warp_beacon/telegram/utils.py,sha256=6oEOEzyN9fAmUZVbk5sjFyHcsPrrb2IlI3zXnRCwjHU,2403
42
+ warp_beacon/telegram/utils.py,sha256=U6MnHhUv_eI8aghonyBZjWWv0st-N8G2kw6thxx2g0A,3601
43
43
  warp_beacon/uploader/__init__.py,sha256=5KRWsxPRGuQ56YhCEnJsXnb-yQp8dpvWEsPDf0dD-fw,4964
44
- warp_beacon-2.3.5.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
45
- warp_beacon-2.3.5.dist-info/METADATA,sha256=OjdCEARXpPHBqOnSghv0OMk4ih_n1J64KZA-BIeZuaA,21703
46
- warp_beacon-2.3.5.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
47
- warp_beacon-2.3.5.dist-info/entry_points.txt,sha256=eSB61Rb89d56WY0O-vEIQwkn18J-4CMrJcLA_R_8h3g,119
48
- warp_beacon-2.3.5.dist-info/top_level.txt,sha256=XusFB1mGUStI2gqbtRuJzQrfrAXmdMaT3QTyfvdLEXI,1064
49
- warp_beacon-2.3.5.dist-info/RECORD,,
44
+ warp_beacon-2.3.7.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
45
+ warp_beacon-2.3.7.dist-info/METADATA,sha256=-w8ArGjPvsi0eS1MJLjccB6fLNMjxZIR8gZPcbYAt6o,21703
46
+ warp_beacon-2.3.7.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
47
+ warp_beacon-2.3.7.dist-info/entry_points.txt,sha256=eSB61Rb89d56WY0O-vEIQwkn18J-4CMrJcLA_R_8h3g,119
48
+ warp_beacon-2.3.7.dist-info/top_level.txt,sha256=XusFB1mGUStI2gqbtRuJzQrfrAXmdMaT3QTyfvdLEXI,1064
49
+ warp_beacon-2.3.7.dist-info/RECORD,,