-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In this release, we've released the first version v0.0.1 of the Shigure-Bot project as a preview. To be honest, we're still at a very early stage now. But I believe that my passion can last at least for a while... Change log: - Introduce basic bot framework - Add partial support for OneBot-V11 API - Add a simple bot that compatible with OneBot-V11 backend - Add an example for using OneBot-V11 bot
- Loading branch information
0 parents
commit 4bcaf55
Showing
19 changed files
with
1,140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# JetBrains IDE | ||
.idea/ | ||
|
||
# Vscode | ||
.vscode/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# 時雨 (Shigure) | ||
|
||
Yet another chatbot SDK that satisfies multiple chatbot backend specifications. | ||
|
||
## Usage | ||
|
||
> TBD | ||
## Supported bot specifications | ||
|
||
### [OneBot V11](https://github.com/botuniverse/onebot-11/) | ||
|
||
Currently, we support part of OneBot V11 API, which can be known by examining the source code. | ||
|
||
For the connection, we support following: | ||
|
||
- [HTTP](https://github.com/botuniverse/onebot-11/blob/master/communication/http.md) | ||
- [HTTP-Post](https://github.com/botuniverse/onebot-11/blob/master/communication/http-post.md) | ||
|
||
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): | ||
|
||
```json | ||
{ | ||
"http_post": { | ||
"host": "example.com", | ||
"port": 11451 | ||
}, | ||
"http_server": { | ||
"port": 19198 | ||
} | ||
} | ||
``` | ||
|
||
You can refer to [example/onebot-v11.go](example/onebot-v11.go) for an example usage. | ||
|
||
## Author | ||
|
||
arttnba3 <[email protected]> | ||
|
||
## License | ||
|
||
GPL V2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// OneBot V11 API | ||
// | ||
// Refer to following link for detailed docs: | ||
// | ||
// https://github.com/botuniverse/onebot-11/blob/master/api/public.md | ||
// https://github.com/botuniverse/onebot-11/blob/master/api/hidden.md | ||
// | ||
|
||
package onebot_v11_api | ||
|
||
type V11BotAPI interface { | ||
SendPrivateMsg(userId int64, message interface{}, autoEscape bool) (int32, error) | ||
SendGroupMsg(groupId int64, message interface{}, autoEscape bool) (int32, error) | ||
SendMsg(messageType string, userId int64, groupId int64, message interface{}, autoEscape bool) (int32, error) | ||
DeleteMsg(messageID int32) error | ||
GetMsg(messageID int32) (interface{}, error) | ||
// TODO: implement more API | ||
} | ||
|
||
type BotAction struct { | ||
Action string `json:"action"` | ||
Params interface{} `json:"params"` | ||
UUID string `json:"uuid"` | ||
} | ||
|
||
// send_private_msg | ||
|
||
type SendPrivateMsgReq struct { | ||
UserID int64 `json:"user_id"` | ||
Message interface{} `json:"message"` | ||
AutoEscape bool `json:"auto_escape"` | ||
} | ||
|
||
type SendPrivateMsgResp struct { | ||
MessageID int32 `json:"message_id"` | ||
} | ||
|
||
// send_group_msg | ||
|
||
type SendGroupMsgReq struct { | ||
GroupID int64 `json:"group_id"` | ||
Message interface{} `json:"message"` | ||
AutoEscape bool `json:"auto_escape"` | ||
} | ||
|
||
type SendGroupMsgResp struct { | ||
MessageID int32 `json:"message_id"` | ||
} | ||
|
||
type SendMsgReq struct { | ||
MessageType string `json:"message_type"` | ||
UserID int64 `json:"user_id"` | ||
GroupID int64 `json:"group_id"` | ||
Message interface{} `json:"message"` | ||
AutoEscape bool `json:"auto_escape"` | ||
} | ||
|
||
type SendMsgResp struct { | ||
MessageID int32 `json:"message_id"` | ||
} | ||
|
||
type DeleteMsgReq struct { | ||
MessageID int32 `json:"message_id"` | ||
} | ||
|
||
// DeleteMsgResp : Only a placeholder here | ||
type DeleteMsgResp struct { | ||
} | ||
|
||
type GetMsgReq struct { | ||
MessageID int32 `json:"message_id"` | ||
} | ||
type GetMsgResp struct { | ||
Time int32 `json:"time"` | ||
MessageType string `json:"message_type"` | ||
MessageID int32 `json:"message_id"` | ||
RealID int32 `json:"real_id"` | ||
Sender interface{} `json:"sender"` | ||
Message interface{} `json:"message"` | ||
} | ||
|
||
// TODO: implement more APIs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Event base and sub-events | ||
// | ||
// Refer to following link for detailed docs: | ||
// | ||
// https://github.com/botuniverse/onebot-11/blob/master/event/README.md | ||
// https://github.com/botuniverse/onebot-11/blob/master/event/meta.md | ||
// | ||
|
||
package onebot_v11_api | ||
|
||
// EventBase | ||
// This struct ONLY indicates what an event should have | ||
type EventBase struct { | ||
Time int64 `json:"time"` | ||
SelfId int64 `json:"self_id"` | ||
PostType string `json:"post_type"` | ||
} | ||
|
||
type LifeCycle struct { | ||
Time int64 `json:"time"` | ||
SelfId int64 `json:"self_id"` | ||
PostType string `json:"post_type"` | ||
MetaEventType string `json:"meta_event_type"` | ||
SubType string `json:"sub_type"` | ||
} | ||
|
||
type HeartBeat struct { | ||
Time int64 `json:"time"` | ||
SelfId int64 `json:"self_id"` | ||
PostType string `json:"post_type"` | ||
MetaEventType string `json:"meta_event_type"` | ||
Status interface{} `json:"status"` | ||
Interval int64 `json:"interval"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// HTTP API | ||
// | ||
// Refer to following link for detailed docs: | ||
// | ||
// https://github.com/botuniverse/onebot-11/blob/master/communication/http.md | ||
// | ||
|
||
package onebot_v11_api | ||
|
||
type HTTPResponseBody struct { | ||
Status string `json:"status"` | ||
RetCode int `json:"retcode"` | ||
Data interface{} `json:"data"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// Message Event | ||
// | ||
// Refer to following link for detailed docs: | ||
// | ||
// https://github.com/botuniverse/onebot-11/blob/master/event/message.md | ||
// | ||
|
||
package onebot_v11_api | ||
|
||
type PrivateMessageSender struct { | ||
UserId int64 `json:"user_id"` | ||
Nickname string `json:"nickname"` | ||
Sex string `json:"sex"` | ||
Age int32 `json:"age"` | ||
} | ||
|
||
type GroupMessageSender struct { | ||
UserId int64 `json:"user_id"` | ||
Nickname string `json:"nickname"` | ||
Card string `json:"card"` | ||
Sex string `json:"sex"` | ||
Age int32 `json:"age"` | ||
Area string `json:"area"` | ||
Level string `json:"level"` | ||
Role string `json:"role"` | ||
Title string `json:"title"` | ||
} | ||
|
||
type PrivateMessage struct { | ||
Time int64 `json:"time"` | ||
SelfId int64 `json:"self_id"` | ||
PostType string `json:"post_type"` | ||
MessageType string `json:"message_type"` | ||
SubType string `json:"sub_type"` | ||
MessageId int32 `json:"message_id"` | ||
UserId int64 `json:"user_id"` | ||
Message interface{} `json:"message"` | ||
RawMessage string `json:"raw_message"` | ||
Font int32 `json:"font"` | ||
Sender PrivateMessageSender `json:"sender"` | ||
} | ||
|
||
type GroupMessage struct { | ||
Time int64 `json:"time"` | ||
SelfId int64 `json:"self_id"` | ||
PostType string `json:"post_type"` | ||
MessageType string `json:"message_type"` | ||
SubType string `json:"sub_type"` | ||
MessageId int32 `json:"message_id"` | ||
GroupId int64 `json:"group_id"` | ||
UserId int64 `json:"user_id"` | ||
Anonymous interface{} `json:"anonymous"` | ||
Message interface{} `json:"message"` | ||
RawMessage string `json:"raw_message"` | ||
Font int32 `json:"font"` | ||
Sender GroupMessageSender `json:"sender"` | ||
} | ||
|
||
type MessageSegment struct { | ||
Type string `json:"type"` | ||
Data interface{} `json:"data"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// | ||
// Notice Event | ||
// | ||
// Refer to following link for detailed docs: | ||
// | ||
// https://github.com/botuniverse/onebot-11/blob/master/event/notice.md | ||
// | ||
|
||
package onebot_v11_api | ||
|
||
// TODO: complete this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package onebot_v11_api | ||
|
||
type V11ReceiverAPI interface { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Request Event | ||
// | ||
// Refer to following link for detailed docs: | ||
// | ||
// https://github.com/botuniverse/onebot-11/blob/master/event/request.md | ||
// | ||
|
||
package onebot_v11_api | ||
|
||
type FriendAddRequest struct { | ||
Time int64 `json:"time"` | ||
SelfId int64 `json:"self_id"` | ||
PostType string `json:"post_type"` | ||
RequestType string `json:"request_type"` | ||
UserId int64 `json:"user_id"` | ||
Comment string `json:"comment"` | ||
Flag string `json:"flag"` | ||
} | ||
|
||
type GroupAddRequest struct { | ||
Time int64 `json:"time"` | ||
SelfId int64 `json:"self_id"` | ||
PostType string `json:"post_type"` | ||
RequestType string `json:"request_type"` | ||
SubType string `json:"sub_type"` | ||
GroupId int64 `json:"group_id"` | ||
UserId int64 `json:"user_id"` | ||
Comment string `json:"comment"` | ||
Flag string `json:"flag"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package onebot_v11_api | ||
|
||
type V11SenderAPI interface { | ||
SendRequest(request BotAction) error | ||
GetRequestResult(uuid string) ([]byte, error) | ||
SendRequestAndGetResult(action string, params interface{}) ([]byte, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package shigure | ||
|
||
import ( | ||
"errors" | ||
"github.com/arttnba3/Shigure-Bot/bot/onebot/v11" | ||
) | ||
|
||
type ShigureBot struct { | ||
Bot interface{} | ||
handlers map[string]func(...any) | ||
} | ||
|
||
func NewShigureBot(botType string, configJson []byte, logger func(...any), handler func(rawData []byte)) (*ShigureBot, error) { | ||
switch botType { | ||
case "OneBot-V11": | ||
bot, err := onebot_v11_impl.NewV11Bot(configJson, logger, handler) // TODO: switch from handler to handlers table | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &ShigureBot{ | ||
Bot: bot, | ||
handlers: nil, | ||
}, nil | ||
default: | ||
return nil, errors.New("unknown bot type [" + botType + "]") | ||
} | ||
} |
Oops, something went wrong.