⌚Yet another chatbot SDK that compatible for multiple chatbot backend implementations.🌧
Firstly you may need to introduce this library to local as follow:
$ go get github.com/arttnba3/Shigure-BotThen just import the module into your project, and create a bot simply as follow:
import "github.com/arttnba3/Shigure-Bot/bot"
//...
bot, err = shigure.NewShigureBot(botType, configJson, Logger, handlers)You can refer to example directory for a detailed usage.
Note that you project should be run together with a supported backend individually, as this is only a SDK for communicating with corresponding backend implementations.
Currently, we support part of OneBot V11 API, which can be known by examining the source code.
For the connection, we support following:
To configure a Shigure-Bot for an OneBot backend, we need to provide the configuration in following format(if one of which was not configured, it won't be invoked):
{
"http_post": {
"host": "example.com",
"port": 11451
},
"http_server": {
"port": 19198
}
}To handle events reported by OneBot-compatible backend, we need to prepare a function-table-like structure as the handler to the bot constructor. This should be a map like:
func HandleExampleEvent(params ...any) {
bot, ok1 := params[0].(*onebot_v11_impl.V11Bot)
event, ok2 := params[1].(onebot_v11_api_event.ExampleEvent)
// replace ExampleEvent to your expected type, e.g., PrivateMessage
// refer to the OneBot v11 specification for details
//...
}
var handlers map[string]func(params ...any) = map[string]func(params ...any){
"example_key": HandleExampleEvent,
//...
}For the key of the map, it consists of two parts. The first part is the type, which can be message, meta, notice, request, and the second part is the subtype. An example key of handling received private message is message_private. Another example for handling recalled message event from friend is to use notice_friend_recall, as it's notice in OneBot-V11 specification, and it's :notice_type is friend_recall. You can refer to OneBot's docs and the bot/onebot/v11/handler.go for details.
You can refer to example/onebot-v11.go for an example usage.
- Code: arttnba3 [email protected]
- Illustration: Sumi Kiriko [email protected]
GPL V2
