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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kokkoro/core

v3.0.13

Published

Core features for kokkoro.

Downloads

14

Readme

core

package engine

如果你想快速开发机器人,建议直接使用 kokkoro 框架,该库不包含 web 与 database 等服务。

作为 kokkoro 的核心依赖库,特性与 amesu 保持一致,并在此基础上扩展了插件体系。

Install:

npm i @kokkoro/core

Usage:

import { Bot } from '@kokkoro/core';

/**
 * @type {import('@kokkoro/core').BotConfig}
 */
const config = {};
const bot = new Bot(config);

bot.online();

Plugin:

你可以在根目录创建 plugins 文件夹来存放你编写的插件。

.
├ plugins/
│ └ example/
└ index.js

当然,这并不是强制要求,推荐这么做只是为了方便插件的分类与管理。

// plugins/example/index.js
import { useCommand, useEvent } from '@kokkoro/core';

/**
 * @type {import('@kokkoro/core').Metadata}
 */
export const metadata = {
  name: 'example',
  description: '插件示例',
};

export default function Example() {
  useEvent(
    ctx => {
      ctx.logger.mark('link start');
    },
    ['session.ready'],
  );

  useCommand('/测试', () => 'hello world');
  useCommand('/复读 <message>', ctx => ctx.query.message);
}

只要对插件进行 mountPlugin 操作,就可将其挂载:

// index.js
import { Bot, mountPlugin } from '@kokkoro/core';

await mountPlugin('./plugins/example/index.js');

/**
 * @type {import('@kokkoro/core').BotConfig}
 */
const config = {};
const bot = new Bot(config);

bot.online();

你也可以直接安装 npm 插件来进行使用。

npm i kokkoro-plugin-hitokoto
// index.js
import { Bot, mountPlugin } from '@kokkoro/core';

await mountPlugin('./plugins/example/index.js');
await mountPlugin('kokkoro-plugin-hitokoto');

/**
 * @type {import('@kokkoro/core').BotConfig}
 */
const config = {};
const bot = new Bot(config);

bot.online();

使用 mountPlugin 方法所传入的路径,与 import 的规则是保持一致的。不过值得注意的是,kokkoro 是一个 esm 模块包,完全遵守 ESModule 规范,而不是 Commonjs。

import { mountPlugin } from '@kokkoro/core';

// Good
await mountPlugin('./example.js');
await mountPlugin('example');

// Bad
await mountPlugin('example.js');
await mountPlugin('./example');
await mountPlugin('./plugins/example');

Config:

配置项与 amesu 基本一致,在此基础上添加了 plugins 属性,传入字符串数组。

import { Bot, mountPlugin } from '@kokkoro/core';

await mountPlugin('./plugins/example/index.js');
await mountPlugin('kokkoro-plugin-hitokoto');

/**
 * @type {import('@kokkoro/core').BotConfig}
 */
const config = {
  // ...
  plugins: ['hitokoto'],
};
const bot = new Bot(config);

bot.online();

如果 plugins 不传入,则默认所有已挂载的插件会对 bot 生效。如果添加了相应字段,那么只有被添加 name(编写插件时导出的 metadata 属性)的插件才会被实例对象使用。

例如上面的例子,当前 bot 只有 hitokoto 插件被应用,example 插件不会对指令作出响应,这便于多个 bot 实例针对不同插件来管理。