Skip to content

Commit

Permalink
🐛 Fix: 修复短链接失效导致报错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
colasama committed Jun 25, 2024
1 parent 3f0918e commit ac3528b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions nonebot_plugin_sticker_saver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

face_extractor = on_command('save', aliases={'保存图片', '保存表情', '保存'}, priority=10, block=True)

TARGET_REDIRECT_URL="https://pic.colanns.me"

@face_extractor.handle()
async def handle_face_extraction(bot: Bot, event: MessageEvent):
if event.reply:
Expand All @@ -24,16 +26,18 @@ async def handle_face_extraction(bot: Bot, event: MessageEvent):
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)
# 用于 .gif 格式的表情包保存,加上一层跳转防止可能的检测
url = str(seg.data["url"]).replace("https://gchat.qpic.cn", TARGET_REDIRECT_URL)
# async with AsyncClient() as client:
# # @deprecated 用于 .gif 格式的表情包保存,加上一层短链接防止可能的检测
# url = str(seg.data["url"]).replace("https://gchat.qpic.cn", TARGET_REDIRECT_URL)
# try:
# req = await client.get(url=url, timeout=3000)
# result = req.json()
# data = result.get("url")
# except Exception as e:
# data = "原始链接服务暂时不可用..."
await bot.send(event, content + "原始链接:" + url)
return
await bot.send(event, "未在回复内容中检测到表情...")
# 如果没有回复消息
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nonebot-plugin-sticker-saver"
version = "0.1.2"
version = "0.1.3"
description = "A very simple Nonebot plugin for saving QQ emoticons that no longer have a save option."
authors = ["Colanns <mycolands@gmail.com>"]
license = "MIT"
Expand Down

0 comments on commit ac3528b

Please sign in to comment.