Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A bot framework for muity platform

License

NotificationsYou must be signed in to change notification settings

SoraYama/octo-bot

Repository files navigation

'Octo-Bot' means octopus-bot, with one head and several adapters to different platforms

For bot developers

octo-bot is a bot framework which focuses on multi-platform adaption, aims towrite once, run everywhere.

Download

  1. CLI

COMING SOON

  1. clone this repo
git clone git@github.com:SoraYama/octo-bot.git OCTO_TMP_DIRcp -r ./OCTO_TMP_DIR/packages/app ./MY_AWESOME_BOTrm -rf ./OCTO_TMP_DIRcd ./MY_AWESOME_BOT

Usage

  1. install dependencies
yarn# or npm i
  1. configure your bots
  • add<PLATFORM_NAME>.config.ts tosrc/config folder
exportdefault{BOT_TOKEN:'YOUR_BOT_TOKEN',// ... other bot configs};
  1. run
yarn dev

Then go to your bot app and enter '/echo test HELLO', see what will happen!

Developing

Inner Objects

Some basic objects in framework should be clear before you start usingocto-bot.

  1. config

octo-bot is a "convention-over-configuration" framework,module,service andconfig folder should be directly set undersrc folder, framework will load each file and handle them automaticly.

  1. module

octo-bot regards every message handler set as a module to implement functions you want. A module inocto-bot is a class which should extendsBaseModule, and each method in the module is a specific message handler triggered by message sent to the channel or group.module should be named likeA.module.ts,A will be recorded as a key stores in the memory.

  1. Trigger

octo-bot use decorators to simplify code.Trigger can decorate bothmodule and methods in amodule, describe what kind of incoming message can trigger this module or method.

  1. service

service is an abstract layer which is usually used to encapsulate business logics in complex business circumstances. A wise usage ofservice will keep logics inmodule cleaner and clearer and can be reused in different modules.service should be named likeA.module.ts,A will be recorded as a key stores in the memory, and can be called as param inService decorator.Service can decorate a property in amodule class to inject properService instance.

Here is an examplemodule file:

  1. Schedule

Schedule decorator can decorate a module method to handle cron job. The decorator function accepts acron expression to trigger method properly.

// echo.module.ts@Trigger('/echo')classEchoModuleextendsBaseModule{  @Service('echo')privateechoService!:EchoService;  @Trigger({match:'test',methods:[TriggerMethod.Prefix],helpText:'repeat test'})publicasyncecho(){awaitthis.event.reply({content:this.echoService.getRemain(),});}}

We split a text message by space character, the initial word will be regarded as main module trigger. In upper case, theTrigger decorator register a handler triggered by message start with '/echo' toEchoMoudle, and the second word is set to be the method trigger text. Simply say, a text message like '/echo test ramain params' will call 'echo' method inEchoModule, and framework will inject converted message event (OctoEvent) toEchoModule instance, can be visited bythis.event.

Project structure

A possible project stucture may like below:

├── package.json├── node_modules├── src│   ├── config│   │   ├── discord.config.ts│   │   ├── telegram.config.ts│   │   └── tomon.config.ts│   ├── index.ts│   ├── log│   │   └── main.log│   ├── module│   │   └── echo.module.ts│   └── service│       └── echo.service.ts├── tsconfig.json└── yarn.lock

Forocto-bot contributors

Developing an adapter for a new platform

Three classes and their abstract methods should be implemented in your bot project:

  • OctoBot

  • OctoGroup

  • OctoEvent

Make sure bot developer can import your customBot class properly.

About

A bot framework for muity platform

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp