master #31

Merged
saipo merged 26 commits from master into saipo_test 2025-05-22 21:45:42 +08:00
Showing only changes of commit c176402f38 - Show all commits

40
main.py
View File

@ -306,26 +306,32 @@ class MyPlugin(Star):
yield event.plain_result(f"累积结果: {testNumber}")
import astrbot.api.message_components as Comp
import aiohttp # 需要异步HTTP客户端
import requests
import asyncio
@filter.command("Dora")
async def Dora(self, event: AstrMessageEvent):
async with aiohttp.ClientSession() as session:
async with session.get('https://www.doro.asia/api/random-sticker') as resp:
if resp.status == 200:
data = await resp.json()
if data.get('success', False):
image_url = data['sticker']['url']
chain = [
Comp.At(qq=event.get_sender_id()), # At 消息发送者
Comp.Plain("Dora"),
Comp.Image.fromURL(image_url), # 使用API返回的图片URL
]
yield event.chain_result(chain)
else:
yield "获取表情包失败"
else:
yield "API请求失败"
try:
# 使用 asyncio.to_thread 在异步环境中运行同步 requests
def fetch_sticker():
resp = requests.get('https://www.doro.asia/api/random-sticker')
resp.raise_for_status() # 检查 HTTP 错误
return resp.json()
data = await asyncio.to_thread(fetch_sticker)
if data.get('success', False):
image_url = data['sticker']['url']
chain = [
Comp.At(qq=event.get_sender_id()),
Comp.Plain("Dora"),
Comp.Image.fromURL(image_url),
]
yield event.chain_result(chain)
else:
yield "获取表情包失败"
except Exception as e:
yield f"发生错误:{str(e)}"
@filter.command("部署")
async def bushutest(self, event: AstrMessageEvent):