
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
lagrange.onebot
Advanced tools

基于 Lagrange.Core 实现的 NTQQ 接入框架。Typescript 版本。
文档请看这里:Lagrange.onebot TS 官方文档
本项目由于使用了装饰器特性,所以目前只支持使用 typescript 进行开发。
| Lagrange.onebot | TypeScript 实现轻量级 OneBot 协议的机器人框架(👈你在这里 |
| Lagrange.Core | NTQQ 的协议实现 |
| OpenShamrock | 基于 Lsposed 实现 OneBot 标准的机器人框架 |
| Chronocat | 基于 Electron 的、模块化的 Satori 框架 |
请使用 screen, tmux 或者 pm2 工具将拉格朗日挂在后台。
请使用默认配置!目前我们只支持拉格朗日默认的反向ws连接,虽然我知道你们肯定懒得折腾另外两种连接方式。
新建一个 ts 项目,然后在你的项目文件夹中安装 lagrange.onebot
npm install lagrange.onebot
修改 tsconfig.json,开启装饰器
{
"compilerOptions": {
"experimentalDecorators": true,
}
}
我们新建两个文件 main.ts 和 impl.ts. 也就是本项目 ./test 文件夹下的内容。
下面的代码演示了如何开启服务,并在服务开启和关闭时给某个人发送消息。
// main.ts
import { server } from 'lagrange.onebot';
import { TestController } from './test.controller';
// server 刚启动的时候要做的事情
server.onMounted(c => {
// 向 QQ 号为 1193466151 的好友发送文本信息 "成功上线"
c.sendPrivateMsg(1193466151, '成功上线');
});
// server 即将关闭时要做的事情
server.onUnmounted(c => {
// 向 QQ 号为 1193466151 的好友发送文本信息 "成功下线"
c.sendPrivateMsg(1193466151, '成功下线');
})
server.run({
// 拉格朗日服务器中的配置参数
host: '127.0.0.1',
port: 8080,
path: '/onebot/v11/ws',
// 你启动的机器人的 QQ 号
qq: 1542544558
});
如果想要自定义对于某个人或者某个群的回答行为,可以通过 mapper 注解/装饰器 的方式将您写的业务函数装配进事务管线中, lagrange.onebot 会自动去处理这些信息。写法综合了 java 的 springboot 和 go 的 gin ,对于熟悉后端开发的同学而言,应该非常简单。
// test.controller.ts
import { mapper, LagrangeContext, PrivateMessage } from 'lagrange.onebot';
export class TestController {
// 将对于用于 1193466151 的应答函数装配进管线中
@mapper.onPrivateUser(1193466151, {
memorySize: 50, // 当前处理管线自动记录最近 50 条的信息, 通过 mapper.getMemoryStorage(c) 来获取队列数据
autoDownloadImage: true // 自动下载图片,通过 c.getImagePath(fileName, subType) 获取图片绝对路径
})
async handleJinhui(c: LagrangeContext<PrivateMessage>) {
const msg = c.message.raw_message;
const reply = '你刚刚的回答是 ' + msg;
// 和下面几种写法完全等价
// c.sendPrivateMsg(1193466151, reply);
// c.sendMessage(reply);
c.sendPrivateMsg(c.message.user_id, reply);
// finishSession 会标记当前事务为“已完成”,此时 c.fin 为 true
// c.fin 为 true 的情况下,所有 onebot v11 API 全部失效
c.finishSession();
}
}
效果预览

更多使用方法,请参考:
FAQs
基于 Lagrange.Core 实现的 NTQQ 接入框架
The npm package lagrange.onebot receives a total of 24 weekly downloads. As such, lagrange.onebot popularity was classified as not popular.
We found that lagrange.onebot demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.