generated from A-kirami/nonebot-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
52 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from nonebot.plugin import on_command, PluginMetadata | ||
from nonebot import on_message, logger | ||
from nonebot.adapters.onebot.v11 import Bot, Message, MessageEvent, MessageSegment | ||
from httpx import AsyncClient | ||
|
||
face_extractor = on_command('save', aliases={'保存图片', '保存表情', '保存'}, priority=10, block=True) | ||
|
||
@face_extractor.handle() | ||
async def handle_face_extraction(bot: Bot, event: MessageEvent): | ||
if event.reply: | ||
# 获取被回复的消息内容 | ||
original_message = event.reply.message | ||
# 提取表情包并发送回去,静态表情包可以直接被保存 | ||
for seg in original_message: | ||
logger.debug("seg: " + seg + " type: " + str(seg.type)) | ||
if seg.type == "image": | ||
content = MessageSegment.text("表情:") + MessageSegment.image(seg.data["url"], type_=0) | ||
async with AsyncClient() as client: | ||
# 用于 .gif 格式的表情包保存,加上一层短链接防止可能的检测,可以修改不同的 API | ||
url = "https://t.apii.cn/?url=" + str(seg.data["url"]) | ||
try: | ||
req = await client.get(url=url) | ||
result = req.json() | ||
data = result.get("url") | ||
except Exception as e: | ||
await bot.send(event, "获取短链接失败") | ||
await bot.send(event, content + "原始链接:" + data) | ||
return | ||
await bot.send(event, "未在回复内容中检测到表情...") | ||
# 如果没有回复消息 | ||
else: | ||
await bot.send(event, "只有回复表情才可以用捏") |