mirror of
https://github.com/TeamPGM/PagerMaid_Plugins_Pyro.git
synced 2024-11-16 07:05:24 +00:00
tgbg 解析 Telegram 聊天窗口背景图
This commit is contained in:
parent
9396e76aab
commit
02da0685e4
10
list.json
10
list.json
@ -349,6 +349,16 @@
|
||||
"supported": true,
|
||||
"des-short": "测速。",
|
||||
"des": "测速。\n指令:,speedtest"
|
||||
},
|
||||
{
|
||||
"name": "tgbg",
|
||||
"version": "1.0",
|
||||
"section": "chat",
|
||||
"maintainer": "xtaodada",
|
||||
"size": "1.25 kb",
|
||||
"supported": true,
|
||||
"des-short": "解析 Telegram 聊天窗口背景图。",
|
||||
"des": "解析 Telegram 聊天窗口背景图。\n指令:,tgbg"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
27
tgbg/main.py
Normal file
27
tgbg/main.py
Normal file
@ -0,0 +1,27 @@
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from pyrogram.raw.functions.account import GetWallPaper
|
||||
from pyrogram.raw.types import InputWallPaperSlug, WallPaper
|
||||
from pyrogram.types.messages_and_media.document import Document
|
||||
|
||||
from pagermaid.listener import listener
|
||||
from pagermaid.single_utils import Message
|
||||
|
||||
|
||||
@listener(command="tgbg", description="解析 Telegram 聊天窗口背景图",
|
||||
parameters="t.me/bg/xxx")
|
||||
async def tg_bg(message: Message):
|
||||
argument = message.obtain_message()
|
||||
if url := urlparse(argument):
|
||||
if path := url.path:
|
||||
if url.hostname == "t.me" and path.startswith("/bg/"):
|
||||
slug = path[4:]
|
||||
try:
|
||||
bg: WallPaper = await message.bot.invoke(GetWallPaper(wallpaper=InputWallPaperSlug(slug=slug)))
|
||||
except Exception as e:
|
||||
return await message.edit(f"获取失败: {str(e)}")
|
||||
if bg.document:
|
||||
bg_doc = Document._parse(message.bot, document=bg.document, file_name="bg.jpg") # noqa
|
||||
await message.bot.send_document(message.chat.id, bg_doc.file_id, file_name="bg.jpg")
|
||||
return await message.safe_delete()
|
||||
await message.edit("获取失败,请检查 URL")
|
Loading…
Reference in New Issue
Block a user