npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

lagrange.onebot

v1.0.12

Published

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

Readme

Lagrange.onebot

Document | 文档

Lagrange.onebot TS

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

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

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

相关项目

安装与使用

启动拉格朗日服务器

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();
    }
}

效果预览

更多使用方法,请参考: