🐟 Myfish
我的鱼,我做主。 一个Python的现代化、纯异步、跨平台的Bot开发框架。现已内置闲鱼适配器与微信ClawBot适配器支持。
🚀 已实现功能/特性
🛠️ 框架核心 (core)
- 跨平台微内核架构:引擎与协议彻底解耦。一套插件代码,无缝多端运行。
- 开发体验 (DX) 优先:高度标准化的声明式插件路由与泛型依赖注入 (DI)。
- 云原生 DevOps 规范:开箱即用的 12-Factor 容器化存储与动态配置引擎。
- 全链路纯异步调度:基于
asyncio的非阻塞事件循环,轻松应对海量并发。
🔌 内置适配器支持
🐟 Fish (闲鱼websocket协议) 适配器
- 完整的扫码登录与动态鉴权生命周期管理。
- 高性能计算 Sign 签名与解包 MessagePack。
- 核心加密算法编译为二进制模块,提供物理级防逆向保护。
- 深度集成 Web 端常用 API 与实时 WebSocket 长连接通讯。
🦞 ClawBot (微信ilink协议) 适配器
- 零配置、开箱即用的扫码登录快速接入。
- 全面覆盖绝大部分图文、媒体等核心消息类型的双向收发。
- 基于纯异步底层构建,提供极高的高并发消息吞吐性能。
📦 安装与使用
1. 包管理器 (推荐使用 uv)
uv pip install myfish
# 初始化项目并生成 config.toml
myfish init my-project
cd my-project
# 启动引擎
myfish run
初次启动会自动生成 config.toml,按需修改其中的适配器参数后重启即可。
2. 源码构建
git clone https://github.com/Kaguya233qwq/myfish
cd myfish
uv sync
uv run src/myfish/main.py
3. Docker 部署
新建 docker-compose.yml:
version: '3.8'
services:
myfish:
image: kaguya233qwq/myfish:latest
container_name: myfish
restart: always
environment:
- TZ=Asia/Shanghai
- MYFISH_CONFIG_PATH=/app/data/config.toml
volumes:
- ./plugins:/app/plugins
- ./data:/app/data
- ./logs:/app/logs
后台运行:docker-compose up -d
🧩 开发用户插件
采用声明式路由与泛型依赖注入 (DI)。
from myfish.core.plugin import Plugin, PluginMetadata
from myfish.core.event import MessageEvent
from myfish.adapters.fish import FishBot
plugin = Plugin(
metadata=PluginMetadata(
id="auto_reply",
name="客服自动回复",
version="1.0.0",
author="YourName",
support_adapters=["fish"] # 声明为仅支持闲鱼适配器的插件,此项设置可以提升性能
)
)
# 自定义匹配规则
def reject_rule(event: MessageEvent) -> bool:
return any(word in event.plain_text for word in ["刀", "低价", "便宜"])
@plugin.on_message(rule=reject_rule)
async def handle_bargain(event: MessageEvent):
await event.reply("抱歉老板,底价出回血了,不议价哦😭")
# 依赖注入:跨平台通用逻辑
@plugin.on_keywords(("ping",))
async def handle_ping(event: MessageEvent):
await event.reply("pong!")
# 依赖注入:注入特定平台的 Bot,获取调用对应平台api的能力
@plugin.on_keywords(("我的信息", "我是谁"))
async def handle_user_info(event: MessageEvent, bot: FishBot):
user_info = await bot.adapter.api.get_user_info(event.sender_id)
await event.reply(f"您的信息:\n{user_info}")
🔌 开发适配器 (Adapter)
Myfish 核心采用两阶段初始化与注册表装配协议。开发自定义适配器必须继承 BaseAdapter 并实现 setup 组装流水线。
import json
from myfish.core.adapter import BaseAdapter, AdapterMetaData
from myfish.core.registry import AdapterRegistry
from myfish.core.event import MessageEvent
from myfish.core.message import MessageChain, Text
@AdapterRegistry.register
class MockAdapter(BaseAdapter[MockAPI]):
# 框架通过 SSOT 提取 ID 与注册信息
meta_data = AdapterMetaData(
id="mock",
name="Mock适配器",
description="用于本地测试的开发适配器",
version="1.0.0",
author="YourName"
)
def __init__(self, api: MockAPI):
super().__init__(api=api)
self.bot_id = "unknown"
@classmethod
def setup(cls, **kwargs) -> "MockAdapter":
"""同步装配 (由 Config 驱动)"""
token = kwargs.get("token")
if not token:
raise ValueError("MockAdapter 必须在配置中提供 token")
return cls(api=MockAPI(token=token))
async def run(self):
"""异步启动与鉴权"""
self.bot_id = await self.api.get_self_id()
await self._listen()
async def _listen(self):
raw_payload = '{"user": "1001", "text": "你好,Myfish"}'
data = json.loads(raw_payload)
event = MessageEvent(
cid=f"group_{data['user']}",
sender_id=data["user"],
sender_name="MockUser",
messages=MessageChain([Text(text=data["text"])]),
raw_payload=data
)
if self._on_receive_callback:
await self._on_receive_callback(event)
async def send(self, target_id: str, message: MessageChain, cid: str = ""):
plain_text = "".join([seg.text for seg in message if isinstance(seg, Text)])
payload = {"to": target_id, "content": plain_text}
# await self.api.send_msg(payload)
📝 TODO
- 适配器扩展:支持更多平台内置适配器。
- 适配器API 扩展:增加适配器中如闲鱼的自动擦亮等移动端实用 API。
- 闲鱼适配器增强:尝试实现纯 JS 补环境,在本地全自动计算
x5sec过滑块。 - 持久化存储:引入基于 SQLite 的标准插件数据层 (ORM)。
🙏 致谢
- nonebot/nonebot2 为本项目的微内核架构、依赖注入、适配器模式等底层系统工程提供了启蒙与极具价值的参考范式。
- cv-cat/XianYuApis 闲鱼适配器核心 Sign 加密与消息解包算法的 JS 参考,fish适配器 在此基础上完成了纯 Python 算法的移植与升华。
- corespeed-io/wechatbot 微信ClawBot适配器(ilink协议)参考。
本项目欢迎任何有能力的开发者提交 Pull Request,共同建设生态。
Metadata
Release files for myfish 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| myfish-1.1.0-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details |
| myfish-1.1.0-py3-none-manylinux2014_x86_64.whl | Python 3 | none | Linux glibc 2.17+ x86-64 | Details |
| myfish-1.1.0-py3-none-manylinux2014_aarch64.whl | Python 3 | none | Linux glibc 2.17+ ARM64 | Details |
Total release size: 3.5 MB
Release files / myfish-1.1.0-py3-none-win_amd64.whl
| Download URL | myfish-1.1.0-py3-none-win_amd64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
247b1854b889fa08dc4f3b3f200cdab20ac775f57f7729202635db48b792c738
|
|
BLAKE2b-256 checksum How to use checksums |
50c2a051f225ca48f7112438facb3d77d6d92e79e46a4023292b0b7c92cf3695
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.
Transparency logRelease files / myfish-1.1.0-py3-none-manylinux2014_x86_64.whl
| Download URL | myfish-1.1.0-py3-none-manylinux2014_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | Linux glibc 2.17+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
7569efa3ff526defabe32457089806246206d29c8763c4e2684d5d34061a9dcd
|
|
BLAKE2b-256 checksum How to use checksums |
7a9bbeab7c08be927c255c4711afd73d3e407388c38ac54c160dc11eae7e5ff1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.
Transparency logRelease files / myfish-1.1.0-py3-none-manylinux2014_aarch64.whl
| Download URL | myfish-1.1.0-py3-none-manylinux2014_aarch64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | Linux glibc 2.17+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
ac1d891ad88625e99c1506e75b016e7a7bc86b75764c6db3b17252e5a147518f
|
|
BLAKE2b-256 checksum How to use checksums |
4a95a608aaec8f2b06c32eed2f4f9c4bef3131aa029a607f2f20b8739e1b0cf8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.
Transparency log