Spaces:
Runtime error
Runtime error
Create link_parser.py
Browse files- bot/youtube/link_parser.py +18 -0
bot/youtube/link_parser.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PATH: bot/youtube/link_parser.py
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
from typing import Tuple, Union
|
| 5 |
+
|
| 6 |
+
from bot.core.link_parser import ChatRef, parse_link
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def parse_telegram_link(link: str) -> Tuple[ChatRef, int]:
|
| 10 |
+
"""
|
| 11 |
+
handlers.py expects this to raise on bad links.
|
| 12 |
+
Returns: (chat_ref, msg_id)
|
| 13 |
+
chat_ref: int (-100... for private channels) or username str
|
| 14 |
+
"""
|
| 15 |
+
out = parse_link(link)
|
| 16 |
+
if not out:
|
| 17 |
+
raise ValueError("invalid_telegram_link")
|
| 18 |
+
return out
|