Giter Club home page Giter Club logo

kokkoro's Introduction

pixiv: 104321865

Kokkoro

> とある咕咕の QQ 机器人框架 <

priconne group package engine downloads

介绍

本项目是一个基于 Amesu SDK,使用 TypeScript 语言开发的 QQ 机器人框架。

使用

你可以使用 CLI 来快速构建项目:

npm i -g @kokkoro/cli
kokkoro init
✔ Please enter the project name: … <your-project-name>
✔ Your robot appid: … <appid>
✔ Your robot token … <token>
✔ Your robot secret … <secret>
✔ Is it a public domain robot? … No / Yes

SUCCESS Project initialization completed.

目录结构

.
├─ data               项目资源
├─ logs               日志列表
├─ plugins            插件目录
├─ index.js           程序入口
└─ kokkoro.json       配置文件

安装好依赖文件后,使用 kokkoro start 启动项目。

配置项

{
  // web 服务
  "server": {
    // 端口号
    "port": 2333,
    // 域名
    "domain": "http://localhost"
  },
  // 日志等级
  "log_level": "INFO",
  // 订阅事件
  "events": [],
  // bot 信息,可添加多个
  "bots": [
    {
      "appid": "1145141919",
      "token": "38bc73e16208135fb111c0c573a44eaa",
      "secret": "6208135fb111c0c5"
    }
  ]
}

若要开发插件,可以在项目根目录使用下列命令:

kokkoro plugin <name>
✔ Which plugin style would you like to use:
>   Javascript
    Typescript (Hook)
    Typescript (Decorator)

INFO Plugin creation has been aborted.

插件

Javascript (Hook)

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

Typescript (Hook)

import { Metadata, useCommand, useEvent } from '@kokkoro/core';

export const metadata: Metadata = {
  name: 'example',
  description: '示例插件',
};

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

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

Typescript (Decorator)

import { Command, CommandContext, Context, Event, Plugin } from '@kokkoro/core';

@Plugin({
  name: 'example',
  description: '示例插件',
})
export default class Example {
  @Event('session.ready')
  onReady(ctx: Context<'session.ready'>) {
    ctx.logger.mark('link start');
  }

  @Command('/测试')
  testMessage() {
    return 'hello world';
  }

  @Command('/复读 <message>')
  replayMessage(ctx: CommandContext<{ message: string }>) {
    return ctx.query.message;
  }
}

kokkoro's People

Contributors

xueelf avatar miaow233 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.