diff --git a/core/api.go b/core/api.go index c6d38df..cb53bb4 100644 --- a/core/api.go +++ b/core/api.go @@ -9,8 +9,10 @@ import ( type apiInfo struct{} +//一、Protocol模块 + /* -关于API的说明: +关于Protocol模块的说明 1.所有API请求按照OneBot11标准,使用JSON格式进行数据交换。api命名为由原文档中蛇形命名法改为双驼峰命名法。 @@ -204,7 +206,7 @@ func (a *apiInfo) SetGroupCard(groupId int64, userId int64, card string) { } // SetGroupName 设置群名称(可能需要群主或管理员权限) -func (a apiInfo) SetGroupName(groupId int64, groupName string) { +func (a *apiInfo) SetGroupName(groupId int64, groupName string) { var messageData wba.APIRequestInfo messageData.Action = "set_group_name" messageData.Params.GroupId = groupId @@ -219,7 +221,7 @@ func (a apiInfo) SetGroupName(groupId int64, groupName string) { } // SetGroupLeave 退出群聊 -func (a apiInfo) SetGroupLeave(groupId int64, isDismiss bool) { +func (a *apiInfo) SetGroupLeave(groupId int64, isDismiss bool) { var messageData wba.APIRequestInfo messageData.Action = "set_group_leave" messageData.Params.GroupId = groupId @@ -234,7 +236,7 @@ func (a apiInfo) SetGroupLeave(groupId int64, isDismiss bool) { } // SetGroupSpecialTitle 设置群专属头衔(需要群主权限) -func (a apiInfo) SetGroupSpecialTitle(groupId int64, userId int64, specialTitle string, duration int32) { +func (a *apiInfo) SetGroupSpecialTitle(groupId int64, userId int64, specialTitle string, duration int32) { var messageData wba.APIRequestInfo messageData.Action = "set_group_special_title" messageData.Params.GroupId = groupId @@ -251,7 +253,7 @@ func (a apiInfo) SetGroupSpecialTitle(groupId int64, userId int64, specialTitle } // SetFriendAddRequest 处理加好友请求 -func (a apiInfo) SetFriendAddRequest(flag string, approve bool, remark string) { +func (a *apiInfo) SetFriendAddRequest(flag string, approve bool, remark string) { var messageData wba.APIRequestInfo messageData.Action = "set_friend_add_request" messageData.Params.Flag = flag @@ -267,7 +269,7 @@ func (a apiInfo) SetFriendAddRequest(flag string, approve bool, remark string) { } // SetGroupAddRequest 处理加群请求/邀请 -func (a apiInfo) SetGroupAddRequest(flag string, subType string, approve bool, reason string) { +func (a *apiInfo) SetGroupAddRequest(flag string, subType string, approve bool, reason string) { var messageData wba.APIRequestInfo messageData.Action = "set_group_add_request" messageData.Params.Flag = flag @@ -283,9 +285,37 @@ func (a apiInfo) SetGroupAddRequest(flag string, subType string, approve bool, r return } +// SetRestart 重启 +func (a *apiInfo) SetRestart(delay int32) { + var messageData wba.APIRequestInfo + messageData.Action = "set_restart" + messageData.Params.Delay = delay + _, err := wsAPI(messageData) + if err != nil { + LOG.ERROR("设置重启(SetRestart)时,执行失败: %v", err) + return + } + LOG.INFO("设置重启(SetRestart):%v", delay) + return +} + +// CleanCache 清理缓存 +func (a *apiInfo) CleanCache() { + var messageData wba.APIRequestInfo + messageData.Action = "clean_cache" + _, err := wsAPI(messageData) + if err != nil { + LOG.ERROR("清理缓存(CleanCache)时,执行失败: %v", err) + return + } + LOG.INFO("清理缓存(CleanCache)") + return +} + // 2.有响应API,需添加echo字段 -func (a apiInfo) GetLoginInfo() (Response wba.APIResponseInfo) { +// GetLoginInfo 获取登录信息 +func (a *apiInfo) GetLoginInfo() (Response wba.APIResponseInfo) { LOG.INFO("获取登录信息(GetLoginInfo)") var messageData wba.APIRequestInfo var err error @@ -303,6 +333,401 @@ func (a apiInfo) GetLoginInfo() (Response wba.APIResponseInfo) { return Response } +// GetVersionInfo 获取协议信息 +func (a *apiInfo) GetVersionInfo() (Response wba.APIResponseInfo) { + LOG.INFO("获取协议信息(GetVersionInfo)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_version_info" + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取协议信息(GetVersionInfo)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取登录信息(GetVersionInfo)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// GetMsg 获取消息 +func (a *apiInfo) GetMsg(messageId int32) (Response wba.APIResponseInfo) { + LOG.INFO("获取消息(GetMsg)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_msg" + messageData.Params.MessageId = messageId + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取消息(GetMsg)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取消息(GetMsg)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// GetForwardMsg 获取合并转发消息 +func (a *apiInfo) GetForwardMsg(id string) (Response wba.APIResponseInfo) { + LOG.INFO("获取合并转发消息(GetForwardMsg)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_forward_msg" + messageData.Params.Id = id + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取合并转发消息(GetForwardMsg)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取合并转发消息(GetForwardMsg)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// GetStrangerInfo 获取陌生人信息 +func (a *apiInfo) GetStrangerInfo(userId int64, noCache bool) (Response wba.APIResponseInfo) { + LOG.INFO("获取陌生人信息(GetStrangerInfo)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_stranger_info" + messageData.Params.UserId = userId + messageData.Params.NoCache = noCache + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取陌生人信息(GetStrangerInfo)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取陌生人信息(GetStrangerInfo)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// GetFriendList 获取好友列表 +func (a *apiInfo) GetFriendList() (Response wba.APIResponseInfo) { + LOG.INFO("获取好友列表(GetFriendList)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_friend_list" + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取好友列表(GetFriendList)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取好友列表(GetFriendList)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// GetGroupList 获取群列表 +func (a *apiInfo) GetGroupList() (Response wba.APIResponseInfo) { + LOG.INFO("获取群列表(GetGroupList)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_group_list" + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取群列表(GetGroupList)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取群列表(GetGroupList)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// GetGroupInfo 获取群信息 +func (a *apiInfo) GetGroupInfo(groupId int64, noCache bool) (Response wba.APIResponseInfo) { + LOG.INFO("获取群信息(GetGroupInfo)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_group_info" + messageData.Params.GroupId = groupId + messageData.Params.NoCache = noCache + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取群信息(GetGroupInfo)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取群信息(GetGroupInfo)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// GetGroupMemberInfo 获取群成员信息 +func (a *apiInfo) GetGroupMemberInfo(groupId int64, userId int64, noCache bool) (Response wba.APIResponseInfo) { + LOG.INFO("获取群成员信息(GetGroupMemberInfo)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_group_member_info" + messageData.Params.GroupId = groupId + messageData.Params.UserId = userId + messageData.Params.NoCache = noCache + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取群成员信息(GetGroupMemberInfo)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取群成员信息(GetGroupMemberInfo)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// GetGroupMemberList 获取群成员列表 +func (a *apiInfo) GetGroupMemberList(groupId int64) (Response wba.APIResponseInfo) { + LOG.INFO("获取群成员列表(GetGroupMemberList)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_group_member_list" + messageData.Params.GroupId = groupId + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取群成员列表(GetGroupMemberList)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取群成员列表(GetGroupMemberList)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// GetGroupHonorInfo 获取群荣誉信息 +func (a *apiInfo) GetGroupHonorInfo(groupId int64, userId int64) (Response wba.APIResponseInfo) { + LOG.INFO("获取群荣誉信息(GetGroupHonorInfo)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_group_honor_info" + messageData.Params.GroupId = groupId + messageData.Params.UserId = userId + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取群荣誉信息(GetGroupHonorInfo)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取群荣誉信息(GetGroupHonorInfo)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// GetCookies 获取Cookies +func (a *apiInfo) GetCookies(domain string) (Response wba.APIResponseInfo) { + LOG.INFO("获取Cookies(GetCookies)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_cookies" + messageData.Params.Domain = domain + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取Cookies(GetCookies)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取Cookies(GetCookies)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// GetCSRFToken 获取CSRF Token +func (a *apiInfo) GetCSRFToken() (Response wba.APIResponseInfo) { + LOG.INFO("获取CSRF Token(GetCSRFToken)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_csrf_token" + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取CSRF Token(GetCSRFToken)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取CSRF Token(GetCSRFToken)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// GetCredentials 获取登录令牌 +func (a *apiInfo) GetCredentials(domain string) (Response wba.APIResponseInfo) { + LOG.INFO("获取登录令牌(GetCredentials)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_credentials" + messageData.Params.Domain = domain + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取登录令牌(GetCredentials)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取登录令牌(GetCredentials)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// GetRecord 获取语音 +func (a *apiInfo) GetRecord(file string, outFormat string) (Response wba.APIResponseInfo) { + LOG.INFO("获取语音(GetRecord)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_record" + messageData.Params.File = file + messageData.Params.OutFormat = outFormat + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取语音(GetRecord)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取语音(GetRecord)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// GetImage 获取图片 +func (a *apiInfo) GetImage(file string) (Response wba.APIResponseInfo) { + LOG.INFO("获取图片(GetImage)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_image" + messageData.Params.File = file + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取图片(GetImage)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取图片(GetImage)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// CanSendImage 检查是否可以发送图片 +func (a *apiInfo) CanSendImage() (Response wba.APIResponseInfo) { + LOG.INFO("检查是否可以发送图片(CanSendImage)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "can_send_image" + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("检查是否可以发送图片(CanSendImage)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("检查是否可以发送图片(CanSendImage)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// CanSendRecord 检查是否可以发送语音 +func (a *apiInfo) CanSendRecord() (Response wba.APIResponseInfo) { + LOG.INFO("检查是否可以发送语音(CanSendRecord)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "can_send_record" + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("检查是否可以发送语音(CanSendRecord)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("检查是否可以发送语音(CanSendRecord)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +// GetStatus 获取状态 +func (a *apiInfo) GetStatus() (Response wba.APIResponseInfo) { + LOG.INFO("获取状态(GetStatus)") + var messageData wba.APIRequestInfo + var err error + messageData.Action = "get_status" + messageData.Echo, err = GenerateUUID() + if err != nil { + LOG.ERROR("获取状态(GetStatus)时,生成UUID失败: %v", err) + return wba.APIResponseInfo{} + } + Response, err = wsAPI(messageData) + if err != nil { + LOG.ERROR("获取状态(GetStatus)时,执行失败: %v", err) + return wba.APIResponseInfo{} + } + return Response +} + +//二、LOG模块 + +/* +关于LOG模块的说明 + +1.日志模块使用go-logging库,日志级别分为DEBUG、INFO、WARN、ERROR。 + +2.日志模块提供LogWith方法,可以自定义日志级别,调用级别为DEBUG时,会打印输出调用者的文件名、函数名、行号。 + +3.日志模块提供Log方法,默认日志级别为INFO。 +*/ + +func (a *apiInfo) LogWith(level string, content string, args ...interface{}) { + switch level { + case "DEBUG": + LOG.DEBUG(content, args...) + return + case "WARN": + LOG.WARN(content, args...) + return + case "ERROR": + LOG.ERROR(content, args...) + return + default: + LOG.INFO(content, args...) + return + } +} + +func (a *apiInfo) Log(content string, args ...interface{}) { + LOG.INFO(content, args...) +} + +//database模块 +//TODO: 数据库模块待实现 + var AppApi apiInfo func GenerateUUID() (string, error) { diff --git a/core/app_admin.go b/core/app_admin.go index 86cf8e1..cf39942 100644 --- a/core/app_admin.go +++ b/core/app_admin.go @@ -39,7 +39,7 @@ func reloadAPP(file os.DirEntry, appsDir string) (totalDelta int, successDelta i pluginPath := filepath.Join(appsDir, file.Name()) p, err := plugin.Open(pluginPath) if err != nil { - LOG.ERROR("Error opening app %s: %v\n", pluginPath, err) + LOG.ERROR("Error opening app %s: %v", pluginPath, err) return 1, 0 } diff --git a/core/web_socket.go b/core/web_socket.go index 844487c..1832ad2 100644 --- a/core/web_socket.go +++ b/core/web_socket.go @@ -44,7 +44,9 @@ func WebSocketHandler(protocolAddr string, token string) error { LOG.ERROR("Close error: %v", err) } }(conn) - LOG.INFO("WebSocket connection to %v established.", u.String()) + LOG.INFO("已连接到WebSocket服务器: %v", u.String()) + ProtocolInfo := AppApi.GetVersionInfo() + LOG.INFO("协议端信息: %v-%v", ProtocolInfo.Data.AppName, ProtocolInfo.Data.AppVersion) logInfo := AppApi.GetLoginInfo() LOG.INFO("连接到账号: %v(%v)", logInfo.Data.Nickname, logInfo.Data.UserId) diff --git a/doc/developer_doc.html b/doc/developer_doc.html new file mode 100644 index 0000000..1c442c1 --- /dev/null +++ b/doc/developer_doc.html @@ -0,0 +1,12 @@ + + + + + wind开发手册 + + +

wind开发手册

+

本文档将介绍wind框架的开发规范、开发流程、开发工具、开发示例等。

+

注意:如果您只是想使用本系统搭建一个骰娘或者类似的项目,请移步至wind chime手册

+ + \ No newline at end of file diff --git a/doc/index.html b/doc/index.html index 9ef6c8a..e084104 100644 --- a/doc/index.html +++ b/doc/index.html @@ -1,25 +1,32 @@ - - - - WIND - - -

WIND

-
WIND is not
Dice
-
-
Hello World!
-
-
简单
-
开箱即用,web界面,简单易懂
-
快捷
-
app一键安装,一键启动,一键更新
-
方便
-
开发者友好,代码开源,可定制化
-
小巧
-
体积小,启动快,占用资源少
-
- 点击这里关注我们 - - \ No newline at end of file + + + + WIND + + + +
+

Wind

+

Wind is not dice

+

+ 查看手册 + GitHub +
+
+
+

开箱即用

+

多种部署方式,快速部署于 Windows/Linux/macOS 等主流架构平台。

+
+
+

内存轻量

+

不依赖框架加载,不依赖 Electron,内存占用低至 50-100 MB。

+
+
+

适配快速

+

使用web ui可视化配置,远程管理,一键部署。

+
+
+ + diff --git a/doc/styles.css b/doc/styles.css new file mode 100644 index 0000000..c3fd594 --- /dev/null +++ b/doc/styles.css @@ -0,0 +1,43 @@ +body { + font-family: Arial, sans-serif; + background-color: #f0f0f0; + color: #333; + margin: 0; + padding: 0; +} +header { + text-align: center; + padding: 20px; +} +h1 { + color: #333; + font-size: 36px; + margin: 0; +} +p { + color: #555; + font-size: 18px; +} +.container { + display: flex; + justify-content: center; + margin-top: 40px; + gap: 20px; +} +.card { + background: white; + padding: 20px; + border-radius: 10px; + box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); + width: 250px; +} +.button { + background-color: #ee82ee; + color: white; + padding: 10px 20px; + border: none; + border-radius: 5px; + cursor: pointer; + margin: 5px; + text-decoration: none; +} \ No newline at end of file diff --git a/doc/wind_chime_doc.html b/doc/wind_chime_doc.html new file mode 100644 index 0000000..cc6fd81 --- /dev/null +++ b/doc/wind_chime_doc.html @@ -0,0 +1,12 @@ + + + + + Wind Chime 使用说明 + + +

风铃(Wind Chime)TRPG辅助系统使用手册

+

什么是风铃?

+

风铃是一款TRPG辅助系统,它可以帮助你在线上社交平台完成跑团

+ + \ No newline at end of file diff --git a/utils.go b/utils.go index 015abef..96d10b2 100644 --- a/utils.go +++ b/utils.go @@ -297,9 +297,9 @@ func startProtocol() { func AutoSave() { for { + time.Sleep(time.Second * 60) LOG.INFO("自动保存") //TODO: 这里要添加自动保存的代码 - time.Sleep(time.Second * 60) } } diff --git a/wba/wind.go b/wba/wind.go index 9260d42..41e11a3 100644 --- a/wba/wind.go +++ b/wba/wind.go @@ -28,6 +28,9 @@ type WindAPI interface { SetFriendAddRequest(flag string, approve bool, remark string) SetGroupAddRequest(flag string, subType string, approve bool, reason string) GetLoginInfo() APIResponseInfo + GetVersionInfo() APIResponseInfo + LogWith(level string, log string, args ...interface{}) + Log(log string, args ...interface{}) } type AppInfo struct { @@ -279,6 +282,9 @@ type ParamsInfo struct { 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 {