forked from ProjectWIND/ProjectWIND
modfiy:rebuild package wba
This commit is contained in:
parent
93538afaeb
commit
995fba34b4
47
wba/abandoned.go
Normal file
47
wba/abandoned.go
Normal file
@ -0,0 +1,47 @@
|
||||
package wba
|
||||
|
||||
//type APP interface {
|
||||
// Get() AppInfo
|
||||
// Init(Wba interface{}) error
|
||||
// //Init(WspApi WindStandardProtocolAPI, WsdApi WindStandardDataBaseAPI, WstApi WindStandardTools) error
|
||||
// //InitWSD(api WindStandardDataBaseAPI) error
|
||||
//}
|
||||
|
||||
//func (ai AppInfo) Get() AppInfo {
|
||||
// return ai
|
||||
//}
|
||||
//
|
||||
//func (ai AppInfo) Init(Wba interface{}) error {
|
||||
// WBA = Wba.(WindStandardTools)
|
||||
// return nil
|
||||
//}
|
||||
|
||||
//func (ai *AppInfo) Init(WspApi WindStandardProtocolAPI, WsdApi WindStandardDataBaseAPI, WstApi WindStandardTools) error {
|
||||
// WSP = WspApi
|
||||
// WSD = WsdApi
|
||||
// WST = WstApi
|
||||
// return nil
|
||||
//}
|
||||
|
||||
//func (ai *AppInfo) InitWSD(api WindStandardDataBaseAPI) error {
|
||||
// WSD = api
|
||||
// return nil
|
||||
//}
|
||||
|
||||
//func WithName(name string) AppInfoOption {
|
||||
// return func(ei *AppInfo) {
|
||||
// ei.AppKey.Name = name
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//func WithVersion(version string) AppInfoOption {
|
||||
// return func(ei *AppInfo) {
|
||||
// ei.AppKey.Version = version
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//func WithAuthor(author string) AppInfoOption {
|
||||
// return func(ei *AppInfo) {
|
||||
// ei.Author = author
|
||||
// }
|
||||
//}
|
103
wba/api_request_response.go
Normal file
103
wba/api_request_response.go
Normal file
@ -0,0 +1,103 @@
|
||||
package wba
|
||||
|
||||
type APIRequestInfo struct {
|
||||
Action string `json:"action,omitempty"`
|
||||
Params ParamsInfo `json:"params"`
|
||||
Echo string `json:"echo,omitempty"`
|
||||
}
|
||||
|
||||
type APIResponseInfo struct {
|
||||
Status string `json:"status,omitempty"`
|
||||
Retcode int64 `json:"retcode,omitempty"`
|
||||
Data ResponseDataInfo `json:"data,omitempty"`
|
||||
Echo string `json:"echo,omitempty"`
|
||||
}
|
||||
|
||||
type APIResponseListInfo struct {
|
||||
Status string `json:"status,omitempty"`
|
||||
Retcode int64 `json:"retcode,omitempty"`
|
||||
Data []ResponseDataInfo `json:"data,omitempty"`
|
||||
Echo string `json:"echo,omitempty"`
|
||||
}
|
||||
|
||||
type ResponseDataInfo struct {
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
Sex string `json:"sex,omitempty"`
|
||||
Age int32 `json:"age,omitempty"`
|
||||
Remark string `json:"remark,omitempty"`
|
||||
GroupId int64 `json:"group_id,omitempty"`
|
||||
GroupName string `json:"group_name,omitempty"`
|
||||
MemberCount int32 `json:"member_count,omitempty"`
|
||||
MaxMemberCount int32 `json:"max_member_count,omitempty"`
|
||||
Card string `json:"card,omitempty"`
|
||||
Area string `json:"area,omitempty"`
|
||||
JoinTime int32 `json:"join_time,omitempty"`
|
||||
LastSentTime int32 `json:"last_sent_time,omitempty"`
|
||||
Level string `json:"level,omitempty"`
|
||||
Role string `json:"role,omitempty"`
|
||||
Unfriendly bool `json:"unfriendly,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
TitleExpireTime int32 `json:"title_expire_time,omitempty"`
|
||||
CardChangeable bool `json:"card_changeable,omitempty"`
|
||||
CurrentTalkative CurrentTalkativeInfo `json:"current_talkative,omitempty"`
|
||||
TalkativeList []CurrentTalkativeInfo `json:"talkative_list,omitempty"`
|
||||
PerformerList []HonorInfo `json:"performer_list,omitempty"`
|
||||
LegendList []HonorInfo `json:"legend_list,omitempty"`
|
||||
StrongNewbieList []HonorInfo `json:"strong_newbie_list,omitempty"`
|
||||
EmoticonList []HonorInfo `json:"emoticon_list,omitempty"`
|
||||
Cookies string `json:"cookies,omitempty"`
|
||||
Token string `json:"token,omitempty"`
|
||||
CsrfToken string `json:"csrf_token,omitempty"`
|
||||
File string `json:"file,omitempty"`
|
||||
OutFormat string `json:"out_format,omitempty"`
|
||||
Yes bool `json:"yes,omitempty"`
|
||||
Online bool `json:"online,omitempty"`
|
||||
Good bool `json:"good,omitempty"`
|
||||
AppName string `json:"app_name,omitempty"`
|
||||
AppVersion string `json:"app_version,omitempty"`
|
||||
ProtocolVersion string `json:"protocol_version,omitempty"`
|
||||
Time int64 `json:"time,omitempty"`
|
||||
MessageType string `json:"message_type,omitempty"`
|
||||
MessageId int32 `json:"message_id,omitempty"`
|
||||
RealId int32 `json:"real_id,omitempty"`
|
||||
Sender SenderInfo `json:"sender,omitempty"`
|
||||
Message []MessageDataInfo `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
type CurrentTalkativeInfo struct {
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
Avatar string `json:"avatar,omitempty"`
|
||||
DayCount int32 `json:"day_count,omitempty"`
|
||||
}
|
||||
|
||||
type HonorInfo struct {
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
Avatar string `json:"avatar,omitempty"`
|
||||
Description string `json:"Description,omitempty"`
|
||||
}
|
||||
|
||||
// SegmentInfo 消息段
|
||||
type SegmentInfo struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Data SegmentDataInfo `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type SegmentDataInfo struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
QQ string `json:"qq,omitempty"`
|
||||
Id int64 `json:"id,omitempty"`
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
Lat string `json:"lat,omitempty"`
|
||||
Lon string `json:"lon,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Audio string `json:"audio,omitempty"`
|
||||
Image string `json:"image,omitempty"`
|
||||
Video string `json:"video,omitempty"`
|
||||
Data string `json:"data,omitempty"`
|
||||
}
|
158
wba/app.go
Normal file
158
wba/app.go
Normal file
@ -0,0 +1,158 @@
|
||||
package wba
|
||||
|
||||
type AppInfo struct {
|
||||
AppKey AppKey
|
||||
Author string
|
||||
Description string
|
||||
Homepage string
|
||||
License string
|
||||
CmdMap map[string]Cmd
|
||||
MessageEventHandler func(msg MessageEventInfo)
|
||||
NoticeEventHandler func(msg NoticeEventInfo)
|
||||
RequestEventHandler func(msg RequestEventInfo)
|
||||
MetaEventHandler func(msg MetaEventInfo)
|
||||
ScheduledTasks map[string]ScheduledTaskInfo
|
||||
API map[string]interface{}
|
||||
}
|
||||
|
||||
func (ai *AppInfo) AddCmd(name string, cmd Cmd) {
|
||||
ai.CmdMap[name] = cmd
|
||||
}
|
||||
|
||||
func (ai *AppInfo) AddNoticeEventHandler(ScheduledTask ScheduledTaskInfo) {
|
||||
ai.ScheduledTasks[ScheduledTask.Name] = ScheduledTask
|
||||
}
|
||||
|
||||
func (ai *AppInfo) AddScheduledTask(task ScheduledTaskInfo) {
|
||||
ai.ScheduledTasks[task.Name] = task
|
||||
}
|
||||
|
||||
type AppInfoOption func(ei *AppInfo)
|
||||
|
||||
func WithDescription(description string) AppInfoOption {
|
||||
return func(ei *AppInfo) {
|
||||
ei.Description = description
|
||||
}
|
||||
}
|
||||
|
||||
func WithWebUrl(webUrl string) AppInfoOption {
|
||||
return func(ei *AppInfo) {
|
||||
ei.Homepage = webUrl
|
||||
}
|
||||
}
|
||||
|
||||
func WithLicense(license string) AppInfoOption {
|
||||
return func(ei *AppInfo) {
|
||||
ei.License = license
|
||||
}
|
||||
}
|
||||
|
||||
func WithSelector(level uint8, selector string, option string) AppInfoOption {
|
||||
return func(ei *AppInfo) {
|
||||
ei.AppKey.Level = level
|
||||
ei.AppKey.Option = option
|
||||
ei.AppKey.Selector = selector
|
||||
}
|
||||
}
|
||||
|
||||
func WithLevel(level uint8) AppInfoOption {
|
||||
if level < 1 {
|
||||
level = 1
|
||||
}
|
||||
return func(ei *AppInfo) {
|
||||
ei.AppKey.Level = level
|
||||
}
|
||||
}
|
||||
|
||||
func NewApp(name string, version string, author string, opts ...AppInfoOption) AppInfo {
|
||||
Ext := AppInfo{
|
||||
AppKey: AppKey{
|
||||
Name: name,
|
||||
Version: version,
|
||||
Level: 2,
|
||||
Selector: name,
|
||||
Option: name,
|
||||
},
|
||||
Author: author,
|
||||
Description: "A simple and easy-to-use bot framework",
|
||||
Homepage: "https://github.com/Sheyiyuan/wind_app_model",
|
||||
License: "MIT",
|
||||
CmdMap: make(map[string]Cmd),
|
||||
ScheduledTasks: map[string]ScheduledTaskInfo{},
|
||||
API: map[string]interface{}{},
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(&Ext)
|
||||
}
|
||||
return Ext
|
||||
}
|
||||
|
||||
func (ai *AppInfo) NewCmd(name string, description string, solve func(args []string, msg MessageEventInfo)) Cmd {
|
||||
return Cmd{
|
||||
Name: name,
|
||||
Desc: description,
|
||||
Solve: solve,
|
||||
AppKey: ai.AppKey,
|
||||
}
|
||||
}
|
||||
|
||||
func (ai *AppInfo) NewScheduledTask(name string, description string, cron string, task func()) ScheduledTaskInfo {
|
||||
return ScheduledTaskInfo{
|
||||
Name: name,
|
||||
Desc: description,
|
||||
Cron: cron,
|
||||
Task: task,
|
||||
}
|
||||
}
|
||||
|
||||
type Cmd struct {
|
||||
Name string
|
||||
Desc string
|
||||
Solve func(args []string, msg MessageEventInfo)
|
||||
AppKey AppKey
|
||||
}
|
||||
|
||||
type ScheduledTaskInfo struct {
|
||||
Name string `json:"Name,omitempty"`
|
||||
Desc string `json:"desc,omitempty"`
|
||||
Task func() `json:"task,omitempty"`
|
||||
Cron string `json:"cron,omitempty"`
|
||||
}
|
||||
|
||||
type AppKey struct {
|
||||
Name string `json:"name"`
|
||||
Level Priority `json:"level"`
|
||||
Version string `json:"version"`
|
||||
Selector SelectorLabel `json:"selector"`
|
||||
Option OptionLabel `json:"option"`
|
||||
}
|
||||
|
||||
// Priority 是一个整数类型,用于表示命令的优先级。只能是不小于1的整数。
|
||||
type Priority = uint8
|
||||
|
||||
// VersionLabel 是一个字符串类型,用于表示版本标签。
|
||||
type VersionLabel = string
|
||||
|
||||
// SelectorLabel 是一个字符串类型,用于表示选择器的标签。
|
||||
type SelectorLabel = string
|
||||
|
||||
// OptionLabel 是一个字符串类型,用于表示选择器选项的标签。
|
||||
type OptionLabel = string
|
||||
|
||||
// SessionLabel 是一个字符串类型,用于表示聊天会话的标签,格式为[平台:类型-ID],如"QQ:group-1145141919810"
|
||||
type SessionLabel = string
|
||||
|
||||
// CmdList 是一个字符串到 wba.Cmd 的映射,用于存储命令的列表。
|
||||
type CmdList = map[string]Cmd
|
||||
|
||||
type SessionInfo struct {
|
||||
Platform string
|
||||
SessionType string
|
||||
SessionId int64
|
||||
}
|
||||
|
||||
type VersionInfo struct {
|
||||
BigVersion uint8
|
||||
SmallVersion uint8
|
||||
FixVersion uint8
|
||||
}
|
167
wba/event.go
Normal file
167
wba/event.go
Normal file
@ -0,0 +1,167 @@
|
||||
package wba
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// event.go 这里定义协议事件的结构体
|
||||
|
||||
// MessageEventInfo 消息事件结构体
|
||||
type MessageEventInfo struct {
|
||||
// Time 事件发生的时间戳
|
||||
Time int64 `json:"time,omitempty"`
|
||||
// SelfId 机器人的用户 ID
|
||||
SelfId int64 `json:"self_id,omitempty"`
|
||||
PostType string `json:"post_type,omitempty"`
|
||||
MessageType string `json:"message_type,omitempty"`
|
||||
SubType string `json:"sub_type,omitempty"`
|
||||
MessageId int32 `json:"message_id,omitempty"`
|
||||
GroupId int64 `json:"group_id,omitempty"`
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Anonymous AnonymousInfo `json:"anonymous"`
|
||||
Message []MessageInfo `json:"message,omitempty"`
|
||||
RawMessage string `json:"raw_message,omitempty"`
|
||||
Font int32 `json:"font,omitempty"`
|
||||
Sender SenderInfo `json:"sender"`
|
||||
}
|
||||
|
||||
func (msg *MessageEventInfo) GetAt() []string {
|
||||
var at []string
|
||||
for _, v := range msg.Message {
|
||||
if v.Type == "at" {
|
||||
at = append(at, v.Data.Qq)
|
||||
}
|
||||
}
|
||||
return at
|
||||
}
|
||||
|
||||
func (msg *MessageEventInfo) GetText() string {
|
||||
var text string
|
||||
for _, v := range msg.Message {
|
||||
if v.Type == "text" {
|
||||
text += v.Data.Text
|
||||
}
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
func (msg *MessageEventInfo) JsonMarshal() string {
|
||||
jsonData, err := json.Marshal(msg)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(jsonData)
|
||||
}
|
||||
|
||||
type NoticeEventInfo struct {
|
||||
Time int64 `json:"time,omitempty"`
|
||||
SelfId int64 `json:"self_id,omitempty"`
|
||||
PostType string `json:"post_type,omitempty"`
|
||||
NoticeType string `json:"notice_type,omitempty"`
|
||||
GroupId int64 `json:"group_id,omitempty"`
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
File FileInfo `json:"file,omitempty"`
|
||||
SubType string `json:"sub_type,omitempty"`
|
||||
OperatorId int64 `json:"operator_id,omitempty"`
|
||||
Duration int64 `json:"duration,omitempty"`
|
||||
MessageId int64 `json:"message,omitempty"`
|
||||
TargetId int64 `json:"target_id,omitempty"`
|
||||
HonorType string `json:"honor_type,omitempty"`
|
||||
}
|
||||
|
||||
type RequestEventInfo struct {
|
||||
Time int64 `json:"time,omitempty"`
|
||||
SelfId int64 `json:"self_id,omitempty"`
|
||||
PostType string `json:"post_type,omitempty"`
|
||||
RequestType string `json:"request_type,omitempty"`
|
||||
SubType string `json:"sub_type,omitempty"`
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Comment string `json:"comment,omitempty"`
|
||||
Flag string `json:"flag,omitempty"`
|
||||
GroupId int64 `json:"group_id,omitempty"`
|
||||
}
|
||||
|
||||
type MetaEventInfo struct {
|
||||
Time int64 `json:"time,omitempty"`
|
||||
SelfId int64 `json:"self_id,omitempty"`
|
||||
PostType string `json:"post_type,omitempty"`
|
||||
MetaEventType string `json:"meta_event_type,omitempty"`
|
||||
SubType string `json:"sub_type,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Interval int64 `json:"interval,omitempty"`
|
||||
}
|
||||
|
||||
type FileInfo struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
Name string `json:"Name,omitempty"`
|
||||
Size int64 `json:"size,omitempty"`
|
||||
Busid int64 `json:"bucket,omitempty"`
|
||||
}
|
||||
|
||||
type SenderInfo struct {
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
Card string `json:"card,omitempty"`
|
||||
Sex string `json:"sex,omitempty"`
|
||||
Age int32 `json:"age,omitempty"`
|
||||
Area string `json:"area,omitempty"`
|
||||
Level string `json:"level,omitempty"`
|
||||
Role string `json:"role,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
}
|
||||
|
||||
type AnonymousInfo struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
Name string `json:"Name,omitempty"`
|
||||
Flag string `json:"flag,omitempty"`
|
||||
}
|
||||
|
||||
type MessageInfo struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Data MessageDataInfo `json:"data"`
|
||||
}
|
||||
|
||||
type MessageDataInfo struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Text string `json:"text,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
File string `json:"file,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
Magic string `json:"magic,omitempty"`
|
||||
Qq string `json:"qq,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Content any `json:"content,omitempty"` // Content string or []MessageDataInfo
|
||||
Image string `json:"image,omitempty"`
|
||||
Audio string `json:"audio,omitempty"`
|
||||
Lat string `json:"lat,omitempty"`
|
||||
Lon string `json:"lon,omitempty"`
|
||||
Data string `json:"data,omitempty"`
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Nickname string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type ParamsInfo struct {
|
||||
Message string `json:"message,omitempty"`
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
GroupId int64 `json:"group_id,omitempty"`
|
||||
AutoEscape bool `json:"auto_escape,omitempty"`
|
||||
MessageId int32 `json:"message_id,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
RejectAddRequest bool `json:"reject_add_request,omitempty"`
|
||||
Duration int32 `json:"duration,omitempty"`
|
||||
Enable bool `json:"enable,omitempty"`
|
||||
Card string `json:"card,omitempty"`
|
||||
GroupName string `json:"group_name,omitempty"`
|
||||
IsDismiss bool `json:"is_dismiss,omitempty"`
|
||||
SpecialTitle string `json:"special_title,omitempty"`
|
||||
Flag string `json:"flag,omitempty"`
|
||||
Approve bool `json:"approve,omitempty"`
|
||||
Remark string `json:"remark,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
SubType string `json:"sub_type,omitempty"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
NoCache bool `json:"no_cache,omitempty"`
|
||||
File string `json:"file,omitempty"`
|
||||
Times int `json:"times,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
OutFormat string `json:"out_format,omitempty"`
|
||||
Delay int32 `json:"delay,omitempty"`
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
# WBA 文档
|
||||
|
||||
WBA是用于对接WIND核心和APP通信的接口,规定了应用结构规范,并提供了与wind核心交互的接口定义。
|
||||
WBA是用于对接Bot协议、WIND核心和APP通信的接口,规定了应用结构规范,并提供了与wind核心交互的接口定义。
|
||||
|
||||
## 目录
|
||||
- [1. 应用结构规范](#1-应用结构规范)
|
||||
|
@ -1,5 +0,0 @@
|
||||
package wba
|
||||
|
||||
type WindStandardTools interface {
|
||||
MsgUnmarshal(message string) (msg MessageEventInfo)
|
||||
}
|
@ -1,16 +1,5 @@
|
||||
package wba
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type APP interface {
|
||||
Get() AppInfo
|
||||
//Init(api WindStandardProtocolAPI) error
|
||||
//InitWSD(api WindStandardDataBaseAPI) error
|
||||
}
|
||||
|
||||
// WindStandardProtocolAPI Wind标准协议API,提供了onebot11标准中的API接口。
|
||||
type WindStandardProtocolAPI interface {
|
||||
// UnsafelySendMsg [不安全][需要master权限]按照QQ号或群号发送消息到指定的群组或用户。
|
||||
@ -252,19 +241,6 @@ type WindStandardProtocolAPI interface {
|
||||
|
||||
// CleanCache 清理程序的缓存。
|
||||
CleanCache()
|
||||
|
||||
// LogWith 使用指定日志级别记录日志,支持可变参数占位符。
|
||||
// 参数:
|
||||
// - level: 日志级别: "trace", "debug", "info", "notice", "warn", "error"。
|
||||
// - log: 日志内容。
|
||||
// - args: 可变参数,用于格式化日志内容。
|
||||
LogWith(level string, log string, args ...interface{})
|
||||
|
||||
// Log 记录日志,级别为 "info",支持可变参数占位符。
|
||||
// 参数:
|
||||
// - log: 日志内容。
|
||||
// - args: 可变参数,用于格式化日志内容。
|
||||
Log(log string, args ...interface{})
|
||||
}
|
||||
|
||||
type WindStandardDataBaseAPI interface {
|
||||
@ -284,7 +260,7 @@ type WindStandardDataBaseAPI interface {
|
||||
// - value: 变量值。
|
||||
SetGroupVariable(app AppInfo, msg MessageEventInfo, key string, value string)
|
||||
|
||||
// SetOutUserVarialbe [需要master权限]设置其他数据库中的用户变量
|
||||
// SetOutUserVariable [需要master权限]设置其他数据库中的用户变量
|
||||
// 参数:
|
||||
// - app: 应用信息。
|
||||
// - msg: 消息事件信息。
|
||||
@ -293,7 +269,7 @@ type WindStandardDataBaseAPI interface {
|
||||
// - datamap: 数据表名称。
|
||||
SetOutUserVariable(app AppInfo, datamap string, msg MessageEventInfo, key string, value string)
|
||||
|
||||
// SetOutGroupVarialbe [需要master权限]设置其他数据库中的群组变量
|
||||
// SetOutGroupVariable [需要master权限]设置其他数据库中的群组变量
|
||||
// 参数:
|
||||
// - app: 应用信息。
|
||||
// - msg: 消息事件信息。
|
||||
@ -484,420 +460,3 @@ type WindStandardDataBaseAPI interface {
|
||||
// - datamapId: 数据表名称。
|
||||
UnsafelyCreatePublicDatamap(app AppInfo, datamapId string)
|
||||
}
|
||||
|
||||
type AppInfo struct {
|
||||
AppKey AppKey
|
||||
Author string
|
||||
Description string
|
||||
Homepage string
|
||||
License string
|
||||
CmdMap map[string]Cmd
|
||||
MessageEventHandler func(msg MessageEventInfo)
|
||||
NoticeEventHandler func(msg NoticeEventInfo)
|
||||
RequestEventHandler func(msg RequestEventInfo)
|
||||
MetaEventHandler func(msg MetaEventInfo)
|
||||
ScheduledTasks map[string]ScheduledTaskInfo
|
||||
API map[string]interface{}
|
||||
}
|
||||
|
||||
func (ai AppInfo) Get() AppInfo {
|
||||
return ai
|
||||
}
|
||||
|
||||
func (ai *AppInfo) Init(api WindStandardProtocolAPI) error {
|
||||
WSP = api
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ai *AppInfo) InitWSD(api WindStandardDataBaseAPI) error {
|
||||
WSD = api
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ai *AppInfo) AddCmd(name string, cmd Cmd) {
|
||||
ai.CmdMap[name] = cmd
|
||||
}
|
||||
|
||||
func (ai *AppInfo) AddNoticeEventHandler(ScheduledTask ScheduledTaskInfo) {
|
||||
ai.ScheduledTasks[ScheduledTask.Name] = ScheduledTask
|
||||
}
|
||||
|
||||
func (ai *AppInfo) AddScheduledTask(task ScheduledTaskInfo) {
|
||||
ai.ScheduledTasks[task.Name] = task
|
||||
}
|
||||
|
||||
type AppInfoOption func(ei *AppInfo)
|
||||
|
||||
func WithName(name string) AppInfoOption {
|
||||
return func(ei *AppInfo) {
|
||||
ei.AppKey.Name = name
|
||||
}
|
||||
}
|
||||
|
||||
func WithVersion(version string) AppInfoOption {
|
||||
return func(ei *AppInfo) {
|
||||
ei.AppKey.Version = version
|
||||
}
|
||||
}
|
||||
|
||||
func WithAuthor(author string) AppInfoOption {
|
||||
return func(ei *AppInfo) {
|
||||
ei.Author = author
|
||||
}
|
||||
}
|
||||
|
||||
func WithDescription(description string) AppInfoOption {
|
||||
return func(ei *AppInfo) {
|
||||
ei.Description = description
|
||||
}
|
||||
}
|
||||
|
||||
func WithWebUrl(webUrl string) AppInfoOption {
|
||||
return func(ei *AppInfo) {
|
||||
ei.Homepage = webUrl
|
||||
}
|
||||
}
|
||||
|
||||
func WithLicense(license string) AppInfoOption {
|
||||
return func(ei *AppInfo) {
|
||||
ei.License = license
|
||||
}
|
||||
}
|
||||
|
||||
func WithAppType(appType string) AppInfoOption {
|
||||
return func(ei *AppInfo) {
|
||||
ei.AppKey.Type = appType
|
||||
}
|
||||
}
|
||||
|
||||
func WithRule(rule string) AppInfoOption {
|
||||
return func(ei *AppInfo) {
|
||||
ei.AppKey.Rule = fmt.Sprintf("rule_%s", rule)
|
||||
}
|
||||
}
|
||||
|
||||
func NewApp(opts ...AppInfoOption) AppInfo {
|
||||
Ext := AppInfo{
|
||||
AppKey: AppKey{
|
||||
Name: "WSP",
|
||||
Version: "v1.0.0",
|
||||
Type: "fun",
|
||||
Rule: "none",
|
||||
},
|
||||
Author: "WIND",
|
||||
Description: "A simple and easy-to-use bot framework",
|
||||
Homepage: "https://github.com/Sheyiyuan/wind_app_model",
|
||||
License: "MIT",
|
||||
CmdMap: make(map[string]Cmd),
|
||||
ScheduledTasks: map[string]ScheduledTaskInfo{},
|
||||
API: map[string]interface{}{},
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(&Ext)
|
||||
}
|
||||
return Ext
|
||||
}
|
||||
|
||||
func (ai *AppInfo) NewCmd(name string, description string, solve func(args []string, msg MessageEventInfo)) Cmd {
|
||||
return Cmd{
|
||||
Name: name,
|
||||
Desc: description,
|
||||
Solve: solve,
|
||||
AppKey: ai.AppKey,
|
||||
}
|
||||
}
|
||||
|
||||
func (ai *AppInfo) NewScheduledTask(name string, description string, cron string, task func()) ScheduledTaskInfo {
|
||||
return ScheduledTaskInfo{
|
||||
Name: name,
|
||||
Desc: description,
|
||||
Cron: cron,
|
||||
Task: task,
|
||||
}
|
||||
}
|
||||
|
||||
type Cmd struct {
|
||||
Name string
|
||||
Desc string
|
||||
Solve func(args []string, msg MessageEventInfo)
|
||||
AppKey AppKey
|
||||
}
|
||||
|
||||
type MessageEventInfo struct {
|
||||
Time int64 `json:"time,omitempty"`
|
||||
SelfId int64 `json:"self_id,omitempty"`
|
||||
PostType string `json:"post_type,omitempty"`
|
||||
MessageType string `json:"message_type,omitempty"`
|
||||
SubType string `json:"sub_type,omitempty"`
|
||||
MessageId int32 `json:"message_id,omitempty"`
|
||||
GroupId int64 `json:"group_id,omitempty"`
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Anonymous AnonymousInfo `json:"anonymous"`
|
||||
Message []MessageInfo `json:"message,omitempty"`
|
||||
RawMessage string `json:"raw_message,omitempty"`
|
||||
Font int32 `json:"font,omitempty"`
|
||||
Sender SenderInfo `json:"sender"`
|
||||
}
|
||||
|
||||
type NoticeEventInfo struct {
|
||||
Time int64 `json:"time,omitempty"`
|
||||
SelfId int64 `json:"self_id,omitempty"`
|
||||
PostType string `json:"post_type,omitempty"`
|
||||
NoticeType string `json:"notice_type,omitempty"`
|
||||
GroupId int64 `json:"group_id,omitempty"`
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
File FileInfo `json:"file,omitempty"`
|
||||
SubType string `json:"sub_type,omitempty"`
|
||||
OperatorId int64 `json:"operator_id,omitempty"`
|
||||
Duration int64 `json:"duration,omitempty"`
|
||||
MessageId int64 `json:"message,omitempty"`
|
||||
TargetId int64 `json:"target_id,omitempty"`
|
||||
HonorType string `json:"honor_type,omitempty"`
|
||||
}
|
||||
|
||||
type RequestEventInfo struct {
|
||||
Time int64 `json:"time,omitempty"`
|
||||
SelfId int64 `json:"self_id,omitempty"`
|
||||
PostType string `json:"post_type,omitempty"`
|
||||
RequestType string `json:"request_type,omitempty"`
|
||||
SubType string `json:"sub_type,omitempty"`
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Comment string `json:"comment,omitempty"`
|
||||
Flag string `json:"flag,omitempty"`
|
||||
GroupId int64 `json:"group_id,omitempty"`
|
||||
}
|
||||
|
||||
type MetaEventInfo struct {
|
||||
Time int64 `json:"time,omitempty"`
|
||||
SelfId int64 `json:"self_id,omitempty"`
|
||||
PostType string `json:"post_type,omitempty"`
|
||||
MetaEventType string `json:"meta_event_type,omitempty"`
|
||||
SubType string `json:"sub_type,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Interval int64 `json:"interval,omitempty"`
|
||||
}
|
||||
|
||||
type FileInfo struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
Name string `json:"Name,omitempty"`
|
||||
Size int64 `json:"size,omitempty"`
|
||||
Busid int64 `json:"bucket,omitempty"`
|
||||
}
|
||||
|
||||
type SenderInfo struct {
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
Card string `json:"card,omitempty"`
|
||||
Sex string `json:"sex,omitempty"`
|
||||
Age int32 `json:"age,omitempty"`
|
||||
Area string `json:"area,omitempty"`
|
||||
Level string `json:"level,omitempty"`
|
||||
Role string `json:"role,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
}
|
||||
|
||||
type AnonymousInfo struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
Name string `json:"Name,omitempty"`
|
||||
Flag string `json:"flag,omitempty"`
|
||||
}
|
||||
|
||||
type MessageInfo struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Data MessageDataInfo `json:"data"`
|
||||
}
|
||||
|
||||
type MessageDataInfo struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Text string `json:"text,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
File string `json:"file,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
Magic string `json:"magic,omitempty"`
|
||||
Qq string `json:"qq,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Content any `json:"content,omitempty"` // Content string or []MessageDataInfo
|
||||
Image string `json:"image,omitempty"`
|
||||
Audio string `json:"audio,omitempty"`
|
||||
Lat string `json:"lat,omitempty"`
|
||||
Lon string `json:"lon,omitempty"`
|
||||
Data string `json:"data,omitempty"`
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Nickname string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type ParamsInfo struct {
|
||||
Message string `json:"message,omitempty"`
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
GroupId int64 `json:"group_id,omitempty"`
|
||||
AutoEscape bool `json:"auto_escape,omitempty"`
|
||||
MessageId int32 `json:"message_id,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
RejectAddRequest bool `json:"reject_add_request,omitempty"`
|
||||
Duration int32 `json:"duration,omitempty"`
|
||||
Enable bool `json:"enable,omitempty"`
|
||||
Card string `json:"card,omitempty"`
|
||||
GroupName string `json:"group_name,omitempty"`
|
||||
IsDismiss bool `json:"is_dismiss,omitempty"`
|
||||
SpecialTitle string `json:"special_title,omitempty"`
|
||||
Flag string `json:"flag,omitempty"`
|
||||
Approve bool `json:"approve,omitempty"`
|
||||
Remark string `json:"remark,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
SubType string `json:"sub_type,omitempty"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
NoCache bool `json:"no_cache,omitempty"`
|
||||
File string `json:"file,omitempty"`
|
||||
Times int `json:"times,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
OutFormat string `json:"out_format,omitempty"`
|
||||
Delay int32 `json:"delay,omitempty"`
|
||||
}
|
||||
|
||||
type APIRequestInfo struct {
|
||||
Action string `json:"action,omitempty"`
|
||||
Params ParamsInfo `json:"params"`
|
||||
Echo string `json:"echo,omitempty"`
|
||||
}
|
||||
|
||||
type APIResponseInfo struct {
|
||||
Status string `json:"status,omitempty"`
|
||||
Retcode int64 `json:"retcode,omitempty"`
|
||||
Data ResponseDataInfo `json:"data,omitempty"`
|
||||
Echo string `json:"echo,omitempty"`
|
||||
}
|
||||
|
||||
type APIResponseListInfo struct {
|
||||
Status string `json:"status,omitempty"`
|
||||
Retcode int64 `json:"retcode,omitempty"`
|
||||
Data []ResponseDataInfo `json:"data,omitempty"`
|
||||
Echo string `json:"echo,omitempty"`
|
||||
}
|
||||
|
||||
type ResponseDataInfo struct {
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
Sex string `json:"sex,omitempty"`
|
||||
Age int32 `json:"age,omitempty"`
|
||||
Remark string `json:"remark,omitempty"`
|
||||
GroupId int64 `json:"group_id,omitempty"`
|
||||
GroupName string `json:"group_name,omitempty"`
|
||||
MemberCount int32 `json:"member_count,omitempty"`
|
||||
MaxMemberCount int32 `json:"max_member_count,omitempty"`
|
||||
Card string `json:"card,omitempty"`
|
||||
Area string `json:"area,omitempty"`
|
||||
JoinTime int32 `json:"join_time,omitempty"`
|
||||
LastSentTime int32 `json:"last_sent_time,omitempty"`
|
||||
Level string `json:"level,omitempty"`
|
||||
Role string `json:"role,omitempty"`
|
||||
Unfriendly bool `json:"unfriendly,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
TitleExpireTime int32 `json:"title_expire_time,omitempty"`
|
||||
CardChangeable bool `json:"card_changeable,omitempty"`
|
||||
CurrentTalkative CurrentTalkativeInfo `json:"current_talkative,omitempty"`
|
||||
TalkativeList []CurrentTalkativeInfo `json:"talkative_list,omitempty"`
|
||||
PerformerList []HonorInfo `json:"performer_list,omitempty"`
|
||||
LegendList []HonorInfo `json:"legend_list,omitempty"`
|
||||
StrongNewbieList []HonorInfo `json:"strong_newbie_list,omitempty"`
|
||||
EmoticonList []HonorInfo `json:"emoticon_list,omitempty"`
|
||||
Cookies string `json:"cookies,omitempty"`
|
||||
Token string `json:"token,omitempty"`
|
||||
CsrfToken string `json:"csrf_token,omitempty"`
|
||||
File string `json:"file,omitempty"`
|
||||
OutFormat string `json:"out_format,omitempty"`
|
||||
Yes bool `json:"yes,omitempty"`
|
||||
Online bool `json:"online,omitempty"`
|
||||
Good bool `json:"good,omitempty"`
|
||||
AppName string `json:"app_name,omitempty"`
|
||||
AppVersion string `json:"app_version,omitempty"`
|
||||
ProtocolVersion string `json:"protocol_version,omitempty"`
|
||||
Time int64 `json:"time,omitempty"`
|
||||
MessageType string `json:"message_type,omitempty"`
|
||||
MessageId int32 `json:"message_id,omitempty"`
|
||||
RealId int32 `json:"real_id,omitempty"`
|
||||
Sender SenderInfo `json:"sender,omitempty"`
|
||||
Message []MessageDataInfo `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
type CurrentTalkativeInfo struct {
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
Avatar string `json:"avatar,omitempty"`
|
||||
DayCount int32 `json:"day_count,omitempty"`
|
||||
}
|
||||
|
||||
type HonorInfo struct {
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
Avatar string `json:"avatar,omitempty"`
|
||||
Description string `json:"Description,omitempty"`
|
||||
}
|
||||
|
||||
// SegmentInfo 消息段
|
||||
type SegmentInfo struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Data SegmentDataInfo `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type SegmentDataInfo struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
QQ string `json:"qq,omitempty"`
|
||||
Id int64 `json:"id,omitempty"`
|
||||
UserId int64 `json:"user_id,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
Lat string `json:"lat,omitempty"`
|
||||
Lon string `json:"lon,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Audio string `json:"audio,omitempty"`
|
||||
Image string `json:"image,omitempty"`
|
||||
Video string `json:"video,omitempty"`
|
||||
Data string `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type ScheduledTaskInfo struct {
|
||||
Name string `json:"Name,omitempty"`
|
||||
Desc string `json:"desc,omitempty"`
|
||||
Task func() `json:"task,omitempty"`
|
||||
Cron string `json:"cron,omitempty"`
|
||||
}
|
||||
|
||||
var WSP WindStandardProtocolAPI
|
||||
var WSD WindStandardDataBaseAPI
|
||||
|
||||
type AppKey struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Level int32 `json:"level"`
|
||||
Version string `json:"version"`
|
||||
Rule string `json:"rule"`
|
||||
}
|
||||
|
||||
func (msg *MessageEventInfo) GetAt() []string {
|
||||
var at []string
|
||||
for _, v := range msg.Message {
|
||||
if v.Type == "at" {
|
||||
at = append(at, v.Data.Qq)
|
||||
}
|
||||
}
|
||||
return at
|
||||
}
|
||||
|
||||
func (msg *MessageEventInfo) GetText() string {
|
||||
var text string
|
||||
for _, v := range msg.Message {
|
||||
if v.Type == "text" {
|
||||
text += v.Data.Text
|
||||
}
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
func (msg *MessageEventInfo) JsonMarshal() string {
|
||||
jsonData, err := json.Marshal(msg)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(jsonData)
|
||||
}
|
73
wba/wind_standard_tools.go
Normal file
73
wba/wind_standard_tools.go
Normal file
@ -0,0 +1,73 @@
|
||||
package wba
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type WindStandardTools interface {
|
||||
// MsgUnmarshal 解析消息JSON字符串为 MessageEventInfo 结构体。
|
||||
//
|
||||
// 参数:
|
||||
//
|
||||
// - message: 要解析的消息字符串。
|
||||
//
|
||||
// 返回值:
|
||||
//
|
||||
// - msg: 解析后的消息结构体。
|
||||
MsgUnmarshal(message string) (msg MessageEventInfo)
|
||||
// LogWith 使用指定日志级别记录日志,支持可变参数占位符。
|
||||
// 参数:
|
||||
// - level: 日志级别: "trace", "debug", "info", "notice", "warn", "error"。
|
||||
// - log: 日志内容。
|
||||
// - args: 可变参数,用于格式化日志内容。
|
||||
LogWith(level string, log string, args ...interface{})
|
||||
|
||||
// Log 记录日志,级别为 "info",支持可变参数占位符。
|
||||
// 参数:
|
||||
// - log: 日志内容。
|
||||
// - args: 可变参数,用于格式化日志内容。
|
||||
Log(log string, args ...interface{})
|
||||
}
|
||||
|
||||
func (v VersionInfo) String() string {
|
||||
return fmt.Sprintf("%d.%d.%d", v.BigVersion, v.SmallVersion, v.FixVersion)
|
||||
}
|
||||
|
||||
func VersionLabelAnalysis(versionLabel VersionLabel) VersionInfo {
|
||||
version := strings.Split(versionLabel, ".")
|
||||
bigVersion, err := strconv.ParseUint(version[0], 10, 8)
|
||||
if err != nil {
|
||||
return VersionInfo{}
|
||||
}
|
||||
smallVersion, err := strconv.ParseUint(version[1], 10, 8)
|
||||
if err != nil {
|
||||
return VersionInfo{}
|
||||
}
|
||||
fixVersion, err := strconv.ParseUint(version[2], 10, 8)
|
||||
if err != nil {
|
||||
return VersionInfo{}
|
||||
}
|
||||
return VersionInfo{
|
||||
BigVersion: uint8(bigVersion),
|
||||
SmallVersion: uint8(smallVersion),
|
||||
FixVersion: uint8(fixVersion),
|
||||
}
|
||||
}
|
||||
|
||||
func SessionLabelAnalysis(sessionLabel SessionLabel) SessionInfo {
|
||||
platform := strings.Split(sessionLabel, ":")[0]
|
||||
sessionTypeAndId := strings.Split(sessionLabel, ":")[1]
|
||||
sessionType := strings.Split(sessionTypeAndId, "-")[0]
|
||||
sessionId := strings.Split(sessionTypeAndId, "-")[1]
|
||||
Id, err := strconv.ParseInt(sessionId, 10, 64)
|
||||
if err != nil {
|
||||
return SessionInfo{}
|
||||
}
|
||||
return SessionInfo{
|
||||
Platform: platform,
|
||||
SessionType: sessionType,
|
||||
SessionId: Id,
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user