Add option to resolve redirects in invite links. Fixes #559
This commit is contained in:
@@ -18,6 +18,8 @@ import codecs
|
||||
import base64
|
||||
import re
|
||||
|
||||
from aiohttp import ClientSession, InvalidURL
|
||||
|
||||
from telethon.errors import (InviteHashInvalidError, InviteHashExpiredError, OptionsTooMuchError,
|
||||
UserAlreadyParticipantError, ChatIdInvalidError,
|
||||
TakeoutInitDelayError, EmoticonInvalidError)
|
||||
@@ -145,9 +147,17 @@ async def join(evt: CommandEvent) -> Optional[EventID]:
|
||||
if len(evt.args) == 0:
|
||||
return await evt.reply("**Usage:** `$cmdprefix+sp join <invite link>`")
|
||||
|
||||
url = evt.args[0]
|
||||
if evt.config["bridge.invite_link_resolve"]:
|
||||
try:
|
||||
async with ClientSession() as sess, sess.get(url) as resp:
|
||||
url = resp.url
|
||||
except InvalidURL:
|
||||
return await evt.reply("That doesn't look like a Telegram invite link.")
|
||||
|
||||
regex = re.compile(r"(?:https?://)?t(?:elegram)?\.(?:dog|me)"
|
||||
r"(?:/(?P<type>joinchat|s))?/(?P<id>[^/]+)/?", flags=re.IGNORECASE)
|
||||
arg = regex.match(evt.args[0])
|
||||
arg = regex.match(url)
|
||||
if not arg:
|
||||
return await evt.reply("That doesn't look like a Telegram invite link.")
|
||||
|
||||
|
||||
@@ -114,6 +114,7 @@ class Config(BaseBridgeConfig):
|
||||
else:
|
||||
copy("bridge.login_shared_secret_map")
|
||||
copy("bridge.telegram_link_preview")
|
||||
copy("bridge.invite_link_resolve")
|
||||
copy("bridge.inline_images")
|
||||
copy("bridge.image_as_file_size")
|
||||
copy("bridge.max_document_size")
|
||||
|
||||
@@ -194,6 +194,9 @@ bridge:
|
||||
example.com: foobar
|
||||
# Set to false to disable link previews in messages sent to Telegram.
|
||||
telegram_link_preview: true
|
||||
# Whether or not the !tg join command should do a HTTP request
|
||||
# to resolve redirects in invite links.
|
||||
invite_link_resolve: false
|
||||
# Use inline images instead of a separate message for the caption.
|
||||
# N.B. Inline images are not supported on all clients (e.g. Riot iOS).
|
||||
inline_images: false
|
||||
|
||||
Reference in New Issue
Block a user