Compare commits

...
5 Commits
Author SHA1 Message Date
YoursFunny cf44c3ddd7 minor changes and adding /start command 2025-08-21 09:59:37 +08:00
YoursFunny cbb15e6a33 fix tag check 2024-11-12 17:35:11 +08:00
YoursFunny afc31430e7 new bsky sensitive contents 2024-11-12 17:23:46 +08:00
YoursFunny 282cf46d58 minor fix 2024-11-12 17:12:47 +08:00
YoursFunny 6c53a1429d update to python 3.13 2024-11-10 19:02:18 +08:00
7 changed files with 38 additions and 7 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
FROM python:3.12-slim-bullseye FROM python:3.13-slim-bullseye
LABEL maintainer="admin@yoursfunny.top" LABEL maintainer="admin@yoursfunny.top"
+16
View File
@@ -162,6 +162,22 @@ async def query_template(update: Update, context: CustomContext) -> None:
await _edit_message.forward[0].edit_caption(context.chat_data.template[name]) await _edit_message.forward[0].edit_caption(context.chat_data.template[name])
@send_action(ChatAction.TYPING)
async def cmd_start(update: Update, context: CustomContext) -> None:
await update.effective_message.reply_text(
"Welcome to the Twitter Fetcher Bot!\n"
"You can use this bot to fetch tweets from Twitter and forward them to a channel.\n"
"Use /set_forward_channel to set a channel to forward tweets.\n"
"Use /remove_forward_channel to remove the channel.\n"
"Use /edit_before_forward to enable or disable edit before forward.\n"
"Use /set_template to set a template for the forwarded message.\n"
"Use /bot_dict to see the bot's data.\n"
"Use /clear_edit_message to clear the edit message cache.\n"
"You can also reply to a message with a tweet URL to fetch the tweet and forward it to the channel.\n"
"You can also use inline query to search for tweets."
)
@send_action(ChatAction.TYPING) @send_action(ChatAction.TYPING)
async def cmd_set_forward_channel(update: Update, context: CustomContext) -> None: async def cmd_set_forward_channel(update: Update, context: CustomContext) -> None:
if not context.args: if not context.args:
+1 -1
View File
@@ -1,4 +1,4 @@
python-telegram-bot[webhooks]~=21.7 python-telegram-bot[webhooks]~=21.7
httpx[http2]~=0.27 httpx[http2]~=0.27
uvloop~=0.19.0; sys_platform != 'win32' uvloop~=0.21; sys_platform != 'win32'
async-pixiv @ git+https://github.com/TheFunny/async-pixiv@main async-pixiv @ git+https://github.com/TheFunny/async-pixiv@main
+11 -2
View File
@@ -11,6 +11,7 @@ if TYPE_CHECKING:
bsky_api_url = 'https://public.api.bsky.app/xrpc/app.bsky.feed.getPostThread' bsky_api_url = 'https://public.api.bsky.app/xrpc/app.bsky.feed.getPostThread'
SENSITIVE_TAG = {'sexual', 'nudity', 'porn', 'graphic-media'}
class BskyMedia: class BskyMedia:
__slots__ = ('_url', '_thumb', '_type', '__dict__') __slots__ = ('_url', '_thumb', '_type', '__dict__')
@@ -101,7 +102,7 @@ class ProcessBsky:
author_id=self._bsky['author']['handle'], author_id=self._bsky['author']['handle'],
text=self._bsky['record']['text'], text=self._bsky['record']['text'],
media=self._bsky_media, media=self._bsky_media,
sensitive=False # TODO: implement sensitive sensitive=self._sensitive
) )
async def __aexit__(self, exc_type, exc_val, exc_tb): async def __aexit__(self, exc_type, exc_val, exc_tb):
@@ -151,4 +152,12 @@ class ProcessBsky:
) )
] ]
case _: case _:
raise NotImplementedError(f"Unknown Bsky embed type: {embed['type']}") raise NotImplementedError(f"Unknown Bsky embed type: {embed['$type']}")
@property
def _sensitive(self) -> bool:
return any(
tag in label['val']
for label in self._bsky['labels']
for tag in SENSITIVE_TAG
)
+3 -2
View File
@@ -1,10 +1,11 @@
import re import re
x_url = re.compile(r"^(?:https?://)?(?:www\.|mobile\.)?(?:x|twitter|fixvx|vxtwitter)\.com/(.+)/status/(\d+)") x_url = re.compile(
r"^(?:https?://)?(?:www\.|mobile\.)?(?:x|twitter|fixvx|vxtwitter|fixupx|fxtwitter)\.com/(.+)/status/(\d+)")
x_media_url = re.compile(r"^(?:https?://)?(pbs|video)\.twimg\.com/(.*)") x_media_url = re.compile(r"^(?:https?://)?(pbs|video)\.twimg\.com/(.*)")
x_tco_url = re.compile(r"(?:https?://)?t\.co/.+$", re.M) x_tco_url = re.compile(r"(?:https?://)?t\.co/.+$", re.M)
message_url = re.compile(r"\[.+]", re.S) message_url = re.compile(r"\[.+]", re.S)
pixiv_url = re.compile(r"^(?:https?://)?(?:www\.)?pixiv\.net/(?:en/)?(?:artworks/|i/)(\d+)") pixiv_url = re.compile(r"^(?:https?://)?(?:www\.)?pixiv\.net/(?:en/)?(?:artworks/|i/)(\d+)")
bsky_url = re.compile(r"^(?:https?://)?(?:bsky)\.app/profile/(.+)/post/(.+)") bsky_url = re.compile(r"^(?:https?://)?bsky\.app/profile/(.+)/post/(.+)")
+1 -1
View File
@@ -136,7 +136,7 @@ class ProcessTweet:
@property @property
def _tweet_text(self) -> str: def _tweet_text(self) -> str:
match = x_tco_url.search(self._tweet['text']) match = x_tco_url.search(self._tweet['text'])
return self._tweet['text'][:match.start()].strip(" ") if match else self._tweet['text'] return self._tweet['text'][:match.start()].strip() if match else self._tweet['text']
@property @property
def _tweet_media(self) -> list[TweetMedia]: def _tweet_media(self) -> list[TweetMedia]:
+5
View File
@@ -31,6 +31,7 @@ class BskyPost(TypedDict):
author: BskyAuthor author: BskyAuthor
record: BskyPostRecord record: BskyPostRecord
embed: BskyEmbedImages | BskyEmbedVideo | BskyEmbedExternal embed: BskyEmbedImages | BskyEmbedVideo | BskyEmbedExternal
labels: list[BskyLabel]
class BskyAuthor(TypedDict): class BskyAuthor(TypedDict):
@@ -42,6 +43,10 @@ class BskyPostRecord(TypedDict):
text: str text: str
class BskyLabel(TypedDict):
val: str
class BskyEmbedImage(TypedDict): class BskyEmbedImage(TypedDict):
thumb: str thumb: str
fullsize: str fullsize: str