New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

lagrange.onebot

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lagrange.onebot

基于 Lagrange.Core 实现的 NTQQ 接入框架

latest
Source
npmnpm
Version
2.0.2
Version published
Weekly downloads
24
-45.45%
Maintainers
1
Weekly downloads
 
Created
Source

Lagrange.onebot

Document | 文档

Lagrange.onebot TS

基于 Lagrange.Core 实现的 NTQQ 接入框架。Typescript 版本。

文档请看这里:Lagrange.onebot TS 官方文档

本项目由于使用了装饰器特性,所以目前只支持使用 typescript 进行开发。

相关项目

Lagrange.onebot TypeScript 实现轻量级 OneBot 协议的机器人框架(👈你在这里
Lagrange.CoreNTQQ 的协议实现
OpenShamrock基于 Lsposed 实现 OneBot 标准的机器人框架
Chronocat基于 Electron 的、模块化的 Satori 框架

安装与使用

启动拉格朗日服务器

Lagrange文档 - 快速部署 & 配置

请使用 screen, tmux 或者 pm2 工具将拉格朗日挂在后台。

请使用默认配置!目前我们只支持拉格朗日默认的反向ws连接,虽然我知道你们肯定懒得折腾另外两种连接方式。

安装与配置本项目

新建一个 ts 项目,然后在你的项目文件夹中安装 lagrange.onebot

npm install lagrange.onebot

修改 tsconfig.json,开启装饰器

{
    "compilerOptions": {
        "experimentalDecorators": true,
    }
}

开始你的第一个 hello world

我们新建两个文件 main.tsimpl.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();
    }
}

效果预览

更多使用方法,请参考:

Keywords

qq

FAQs

Package last updated on 07 Mar 2026

Did you know?

Socket

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.

Install

Related posts