Support tg://resolve
This commit is contained in:
parent
d1b7145255
commit
439191f736
|
@ -35,6 +35,7 @@ from nyx_bot.utils import (
|
|||
make_divergence,
|
||||
parse_matrixdotto_link,
|
||||
parse_wordcloud_args,
|
||||
tg_link_to_tdotme_link,
|
||||
)
|
||||
from nyx_bot.wordcloud import send_wordcloud
|
||||
|
||||
|
@ -186,6 +187,8 @@ class Command:
|
|||
if not self.args:
|
||||
raise NyxBotValueError("No external URL given.")
|
||||
target_url = self.args[0]
|
||||
if target_url.startswith("tg://resolve"):
|
||||
target_url = tg_link_to_tdotme_link(target_url)
|
||||
result = (
|
||||
MatrixMessage.select()
|
||||
.where(
|
||||
|
|
|
@ -5,7 +5,7 @@ from html.parser import HTMLParser
|
|||
from io import StringIO
|
||||
from random import Random
|
||||
from typing import Dict, Optional, Tuple
|
||||
from urllib.parse import unquote, urlparse
|
||||
from urllib.parse import parse_qs, unquote, urlparse
|
||||
|
||||
import xxhash
|
||||
from nio import AsyncClient, Event, MatrixRoom, RoomGetEventError, RoomMessageText
|
||||
|
@ -121,6 +121,14 @@ def make_datetime(origin_server_ts: int):
|
|||
return datetime.fromtimestamp(ts)
|
||||
|
||||
|
||||
def tg_link_to_tdotme_link(tg_link: str):
|
||||
parsed = urlparse(tg_link)
|
||||
qs_parsed = parse_qs(parsed.query)
|
||||
domain = qs_parsed["domain"][0]
|
||||
post_id = qs_parsed["post"][0]
|
||||
return f"https://t.me/{domain}/{post_id}"
|
||||
|
||||
|
||||
def parse_matrixdotto_link(link: str):
|
||||
replaced = link.replace("https://matrix.to/#/", "https://matrix.to/")
|
||||
parsed = urlparse(replaced)
|
||||
|
|
Loading…
Reference in New Issue