mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-09-23 23:32:05 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e14363dd1d
|
||
|
|
0cffd5c297
|
||
|
|
b83bed5423
|
||
|
|
0f3131aec7
|
||
|
|
5483855de8
|
||
|
|
052163084b
|
||
|
|
cdee105c60
|
||
|
|
fae3dad43a
|
||
|
|
f4c53719d8
|
||
|
|
cf44c3ddd7
|
||
|
|
cbb15e6a33
|
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
FROM python:3.13-slim-bullseye
|
FROM python:3.12-slim-bullseye
|
||||||
|
|
||||||
LABEL maintainer="admin@yoursfunny.top"
|
LABEL maintainer="admin@yoursfunny.top"
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ ADMIN = [int(i) for i in os.getenv("BOT_ADMIN", "").split(",") if i]
|
|||||||
|
|
||||||
PIXIV_REFRESH_TOKEN = os.getenv("PIXIV_REFRESH_TOKEN")
|
PIXIV_REFRESH_TOKEN = os.getenv("PIXIV_REFRESH_TOKEN")
|
||||||
|
|
||||||
WEBHOOK = os.getenv("WEBHOOK", False)
|
WEBHOOK = os.getenv("WEBHOOK").strip().lower() in ("true", "yes", "1")
|
||||||
if WEBHOOK:
|
if WEBHOOK:
|
||||||
WEBHOOK_LISTEN = os.getenv("WEBHOOK_LISTEN", "0.0.0.0")
|
WEBHOOK_LISTEN = os.getenv("WEBHOOK_LISTEN", "0.0.0.0")
|
||||||
WEBHOOK_PORT = int(os.getenv("WEBHOOK_PORT", 8443))
|
WEBHOOK_PORT = int(os.getenv("WEBHOOK_PORT", 8443))
|
||||||
|
|||||||
@@ -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:
|
||||||
@@ -289,6 +305,7 @@ def main():
|
|||||||
MessageHandler((filters.Regex(regex.x_url) | filters.Regex(regex.pixiv_url)) | filters.Regex(
|
MessageHandler((filters.Regex(regex.x_url) | filters.Regex(regex.pixiv_url)) | filters.Regex(
|
||||||
regex.bsky_url) & filters.ChatType.PRIVATE,
|
regex.bsky_url) & filters.ChatType.PRIVATE,
|
||||||
handel_url_media),
|
handel_url_media),
|
||||||
|
CommandHandler("start", cmd_start),
|
||||||
CommandHandler("set_forward_channel", cmd_set_forward_channel),
|
CommandHandler("set_forward_channel", cmd_set_forward_channel),
|
||||||
CommandHandler("remove_forward_channel", cmd_remove_forward_channel),
|
CommandHandler("remove_forward_channel", cmd_remove_forward_channel),
|
||||||
CommandHandler("edit_before_forward", cmd_edit_before_forward),
|
CommandHandler("edit_before_forward", cmd_edit_before_forward),
|
||||||
|
|||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
python-telegram-bot[webhooks]~=21.7
|
python-telegram-bot[webhooks]~=22.8
|
||||||
httpx[http2]~=0.27
|
httpx[http2]~=0.27
|
||||||
uvloop~=0.21; sys_platform != 'win32'
|
uvloop~=0.22; sys_platform != 'win32'
|
||||||
async-pixiv @ git+https://github.com/TheFunny/async-pixiv@main
|
async-pixiv~=1.1.2
|
||||||
+2
-1
@@ -157,6 +157,7 @@ class ProcessBsky:
|
|||||||
@property
|
@property
|
||||||
def _sensitive(self) -> bool:
|
def _sensitive(self) -> bool:
|
||||||
return any(
|
return any(
|
||||||
tag in self._bsky['labels']
|
tag in label['val']
|
||||||
|
for label in self._bsky['labels']
|
||||||
for tag in SENSITIVE_TAG
|
for tag in SENSITIVE_TAG
|
||||||
)
|
)
|
||||||
|
|||||||
+8
-8
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
from typing import Literal, TYPE_CHECKING
|
from typing import Literal, TYPE_CHECKING
|
||||||
|
|
||||||
from async_pixiv import PixivClient
|
from async_pixiv import PixivClient
|
||||||
from async_pixiv.error import ApiError
|
from async_pixiv.error import APIError
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from async_pixiv.model.illust import Illust
|
from async_pixiv.model.illust import Illust
|
||||||
@@ -73,27 +73,27 @@ class Pixiv:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def is_nsfw(self) -> bool:
|
def is_nsfw(self) -> bool:
|
||||||
return self._illust.is_nsfw
|
return self._illust.sanity_level > 5
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_ai(self) -> bool:
|
def is_ai(self) -> bool:
|
||||||
return self._illust.ai_type.value == 2
|
return self._illust.ai_type == 2
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def images(self) -> list[PixivMedia]:
|
def images(self) -> list[PixivMedia]:
|
||||||
if self.is_multiple_pages:
|
if self.is_multiple_pages:
|
||||||
return [
|
return [
|
||||||
PixivMedia(
|
PixivMedia(
|
||||||
url=page.image_urls.original,
|
url=str(page.image_urls.original),
|
||||||
thumb=page.image_urls.medium
|
thumb=str(page.image_urls.medium)
|
||||||
)
|
)
|
||||||
for page in self._illust.meta_pages
|
for page in self._illust.meta_pages
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
return [
|
return [
|
||||||
PixivMedia( # should observe if image_url.original is always None for single page
|
PixivMedia( # should observe if image_url.original is always None for single page
|
||||||
url=self._illust.image_urls.original or self._illust.meta_single_page.original,
|
url=str(self._illust.image_urls.original or self._illust.meta_single_page.original),
|
||||||
thumb=self._illust.image_urls.medium
|
thumb=str(self._illust.image_urls.medium)
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ class ProcessPixiv(_ProcessPixiv):
|
|||||||
illust_id = self._parse_illust_id()
|
illust_id = self._parse_illust_id()
|
||||||
try:
|
try:
|
||||||
return (await self._client.ILLUST.detail(illust_id)).illust
|
return (await self._client.ILLUST.detail(illust_id)).illust
|
||||||
except ApiError:
|
except APIError:
|
||||||
await self.refresh_token()
|
await self.refresh_token()
|
||||||
return (await self._client.ILLUST.detail(illust_id)).illust # TODO use retry here
|
return (await self._client.ILLUST.detail(illust_id)).illust # TODO use retry here
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -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/(.+)")
|
||||||
|
|||||||
+2
-2
@@ -84,7 +84,7 @@ class Tweet:
|
|||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def url(self) -> str:
|
def url(self) -> str:
|
||||||
return f"https://twitter.com/{self._author_id}/status/{self._id}"
|
return f"https://x.com/{self._author_id}/status/{self._id}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def author(self) -> str:
|
def author(self) -> str:
|
||||||
@@ -92,7 +92,7 @@ class Tweet:
|
|||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def author_url(self) -> str:
|
def author_url(self) -> str:
|
||||||
return f"https://twitter.com/{self._author_id}"
|
return f"https://x.com/{self._author_id}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def text(self) -> str:
|
def text(self) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user