Compare commits

..
4 Commits
Author SHA1 Message Date
YoursFunny a6325d5bc8 fix check instance 2024-06-20 15:46:47 +08:00
YoursFunny 6c0e581135 fix regex match group 2024-06-20 15:40:18 +08:00
YoursFunny 494fc50446 fix missing aexit 2024-06-20 15:29:30 +08:00
YoursFunny a4e568667c fix type import error 2024-06-20 15:25:17 +08:00
6 changed files with 25 additions and 24 deletions
+1 -1
View File
@@ -3,4 +3,4 @@ __pycache__/
cert/
data/
docker-compose.yml
x.py
utils/x.py
+2 -2
View File
@@ -10,7 +10,7 @@ from telegram.ext import (ApplicationBuilder, CallbackQueryHandler, CommandHandl
InlineQueryHandler, MessageHandler, PicklePersistence, filters)
import common
from tweet import Telegram
from utils.tweet import Telegram
if TYPE_CHECKING:
from telegram import Chat, Message, Update
@@ -51,7 +51,7 @@ async def url_media(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
media,
caption=tweet.message_text,
reply_to_message_id=update.message.message_id,
) if not isinstance(tuple, media[0]) else await update.effective_message.reply_animation(
) if not isinstance(media[0], tuple) else await update.effective_message.reply_animation(
media[0][0],
caption=tweet.message_text,
reply_to_message_id=update.message.message_id,
-19
View File
@@ -1,19 +0,0 @@
from typing import Type, TypedDict
from telegram import InlineQueryResultMpeg4Gif, InlineQueryResultPhoto, InlineQueryResultVideo, InputMediaPhoto, \
InputMediaVideo
TypeInlineQueryResult: Type[
InlineQueryResultMpeg4Gif | InlineQueryResultPhoto | InlineQueryResultVideo] = InlineQueryResultMpeg4Gif | InlineQueryResultPhoto | InlineQueryResultVideo
InputMediaAnimation = tuple[str, bool]
TypeMessageMediaResult: Type[
InputMediaPhoto | InputMediaVideo | InputMediaAnimation] = InputMediaPhoto | InputMediaVideo | InputMediaAnimation
class TweetInfo(TypedDict):
tweetID: str
user_name: str
user_screen_name: str
text: str
media_extended: list[dict]
possibly_sensitive: bool
View File
+5 -2
View File
@@ -12,7 +12,7 @@ from telegram import (InlineQueryResultMpeg4Gif, InlineQueryResultPhoto, InlineQ
from common import get_logger, x_media_regex, x_tco_regex, x_url_regex
if TYPE_CHECKING:
from types import TweetInfo, TypeInlineQueryResult, TypeMessageMediaResult
from .types import TweetInfo, TypeInlineQueryResult, TypeMessageMediaResult
logger = get_logger(__name__)
@@ -158,7 +158,7 @@ class ProcessTweet:
async def _fetch_tweet(self) -> TweetInfo:
match = x_url_regex.match(self._url)
assert match, f"Invalid URL: {self._url}"
auther_id, tweet_id = match.group()
auther_id, tweet_id = match.groups()
return await fetch_json(self._httpx_client, vx_api_url.format(auther_id, tweet_id))
@property
@@ -273,6 +273,9 @@ class Telegram:
async with TelegramTweet(self._httpx_client, self._url) as tweet:
return tweet
async def __aexit__(self, exc_type, exc_val, exc_tb):
pass
@classmethod
def init_client(cls) -> None:
cls._httpx_client = create_client()
+17
View File
@@ -0,0 +1,17 @@
from typing import TypedDict
from telegram import InlineQueryResultMpeg4Gif, InlineQueryResultPhoto, InlineQueryResultVideo, InputMediaPhoto, \
InputMediaVideo
TypeInlineQueryResult = InlineQueryResultMpeg4Gif | InlineQueryResultPhoto | InlineQueryResultVideo
InputMediaAnimation = tuple[str, bool]
TypeMessageMediaResult = InputMediaPhoto | InputMediaVideo | InputMediaAnimation
class TweetInfo(TypedDict):
tweetID: str
user_name: str
user_screen_name: str
text: str
media_extended: list[dict]
possibly_sensitive: bool