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

@kokkoro/core

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kokkoro/core

Core features for kokkoro.

latest
Source
npmnpm
Version
3.0.13
Version published
Maintainers
2
Created
Source

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 实例针对不同插件来管理。

Keywords

bot

FAQs

Package last updated on 26 Jan 2024

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