- Notifications
You must be signed in to change notification settings - Fork1
A bot framework for muity platform
License
SoraYama/octo-bot
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
'Octo-Bot' means octopus-bot, with one head and several adapters to different platforms
octo-bot
is a bot framework which focuses on multi-platform adaption, aims towrite once, run everywhere
.
- CLI
COMING SOON
- 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
- install dependencies
yarn# or npm i
- configure your bots
- add
<PLATFORM_NAME>.config.ts
tosrc/config
folder
exportdefault{BOT_TOKEN:'YOUR_BOT_TOKEN',// ... other bot configs};
- run
yarn dev
Then go to your bot app and enter '/echo test HELLO', see what will happen!
Some basic objects in framework should be clear before you start usingocto-bot
.
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.
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.
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.
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:
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
.
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
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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.