1 Star 0 Fork 0

Samle/XYBotV2

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.py 1.61 KB
一键复制 编辑 原始数据 按行查看 历史
HenryXiaoYang 提交于 2025-02-20 22:08 +08:00 . feat: 修改插件架构
import tomllib
import traceback
import aiohttp
from loguru import logger
from WechatAPI import WechatAPIClient
from utils.decorators import *
from utils.plugin_base import PluginBase
class RandomPicture(PluginBase):
description = "随机图片"
author = "HenryXiaoYang"
version = "1.0.0"
def __init__(self):
super().__init__()
with open("plugins/RandomPicture/config.toml", "rb") as f:
plugin_config = tomllib.load(f)
config = plugin_config["RandomPicture"]
self.enable = config["enable"]
self.command = config["command"]
@on_text_message
async def handle_text(self, bot: WechatAPIClient, message: dict):
if not self.enable:
return
content = str(message["Content"]).strip()
command = content.split(" ")
if not len(command) or command[0] not in self.command:
return
api_url = "https://api.52vmy.cn/api/img/tu/man?type=text"
try:
conn_ssl = aiohttp.TCPConnector(ssl=False)
async with aiohttp.request("GET", url=api_url, connector=conn_ssl) as req:
pic_url = await req.text()
async with aiohttp.request("GET", url=pic_url, connector=conn_ssl) as req:
content = await req.read()
await conn_ssl.close()
await bot.send_image_message(message["FromWxid"], image=content)
except Exception as error:
out_message = f"-----XYBot-----\n出现错误❌!\n{error}"
logger.error(traceback.format_exc())
await bot.send_text_message(message["FromWxid"], out_message)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/CZJpython/XYBotV2.git
git@gitee.com:CZJpython/XYBotV2.git
CZJpython
XYBotV2
XYBotV2
dev

搜索帮助