MCPcopy Index your code
hub / github.com/LSTM-Kirigaya/LBot

github.com/LSTM-Kirigaya/LBot @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
396 symbols 663 edges 32 files 80 documented · 20%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Lagrange.onebot

Document | 文档

Lagrange.onebot TS

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

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

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

相关项目

Lagrange.onebot TypeScript 实现轻量级 OneBot 协议的机器人框架(👈你在这里
Lagrange.Core NTQQ 的协议实现
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();
    }
}

效果预览

更多使用方法,请参考: - Lagrange.onebot 官方文档 - Langrange.RagBot 一个将 RAG 加持下的大模型接入 QQ 的项目

Extension points exported contracts — how you extend this code

PluginsDescriptor (Interface)
(no doc)
src/plugin/index.ts
CommonLaunchOption (Interface)
(no doc)
src/core/dto.ts
TaskSandbox (Interface)
(no doc)
src/mcp/executor.ts
QueryMessageItem (Interface)
(no doc)
src/util/query-message.dto.ts
ForwardWebsocketLaunchOption (Interface)
(no doc)
src/core/dto.ts
WebSearchResult (Interface)
(no doc)
src/mcp/extraTool.ts
QueryMessageDto (Interface)
(no doc)
src/util/query-message.dto.ts
BackwardWebsocketLaunchOption (Interface)
(no doc)
src/core/dto.ts

Core symbols most depended-on inside this repo

send
called by 44
src/core/context.ts
get
called by 16
src/core/mapper.ts
sendPrivateMsg
called by 8
src/core/context.ts
set
called by 7
src/core/mapper.ts
close
called by 7
src/mcp/transport.ts
launch
called by 6
src/core/context.ts
finishSession
called by 5
src/core/context.ts
getGroupMsgHistory
called by 5
src/core/context.ts

Shape

Method 136
Function 132
Interface 102
Class 26

Languages

TypeScript100%

Modules by API surface

src/core/type.ts77 symbols
src/core/context.ts66 symbols
src/api/onebot.ts40 symbols
src/core/mapper.ts31 symbols
src/core/factory.ts22 symbols
src/core/message.ts21 symbols
src/mcp/memory.ts17 symbols
src/util/index.ts16 symbols
src/plugin/index.ts12 symbols
src/mcp/index.ts9 symbols
src/core/event.ts9 symbols
src/core/dto.ts9 symbols

For agents

$ claude mcp add LBot \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact