From f7905c7f569f487b352add572a77c6dd20595726 Mon Sep 17 00:00:00 2001 From: Sheyiyuan <2125107118@qq.com> Date: Thu, 13 Feb 2025 13:32:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E9=83=A8=E5=88=86ap?= =?UTF-8?q?i=E8=A1=A8=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_demo.zip | Bin 0 -> 1744 bytes core/api.go | 93 +++++++++++++++++++++++++++++++++++++++++------ core/app_core.go | 2 +- wba/wind.go | 9 +++-- 4 files changed, 88 insertions(+), 16 deletions(-) create mode 100644 app_demo.zip diff --git a/app_demo.zip b/app_demo.zip new file mode 100644 index 0000000000000000000000000000000000000000..99872b4172f27eabd426ccd88da4b0ecba2da458 GIT binary patch literal 1744 zcmWIWW@Zs#0D+h=>nJb-N^mkLFeDZf#HXa@=Ie)s@G`JZ{4y(IX=JK{^$<>+bNfih6~9F_~bCPxJ+PoI?Bbv2H!l1n zk|toVAnnthv>VeNGfjNnl6kzUNu*rQ)Ku@e_(F&6CECg#IOk1IHORWH8C>ibV6C*? z>Yv}g+iZuG7k(5u6?y ze3yURp0X+OmF)H8DHrF=-YOHA;Q4>HV9*{v)rz=|pY~3C*K~qK-l?@ua{k}DXnWWf zZFR%{g)O4)o9|9AoP5<_K|M!=SHrVq*<2~vx!Cq=saED*?kw@R<)^bm?_IrJFDcslZA*a@*Zuz{BFoa>`z|@w z65&vsQF!g5tK#cjW^&V>^4vYGt0sDS!sl5lPkq!_fBBQt+tY_POQbplPw31Hn!Ivm zw2As6maA-<*PCu}oezB2c8ROiWAe9K^DF!euSmAsow4B<&s0wDY08tcdpAUJ1-&_v zz5e?x)v`y^?^nGo{-0yJ;%$qX&wZs5BZ)Km3D+;4>0#lS!?}Kji^OI2@_NphdcieK zp7S10TX3!^!SAy(cTW4hZBImiJvxW`i$vwxPpo$I$Q&uaC-}P3w`!7`Wz%FF;imIClj8OZ>qW)SIiAI z7;G{#-fm)MYT&(zk7r97r11F5tMsWJ=o64{0=yZSM3`|Go|3!cqvLn~oe}p!kP@ iC5^!>NX~~_Lv(5g@MdKL8O8#H^^6P**1)94zyJWvb9vqX literal 0 HcmV?d00001 diff --git a/core/api.go b/core/api.go index 4d8d444..e4ed3bf 100644 --- a/core/api.go +++ b/core/api.go @@ -24,7 +24,76 @@ type apiInfo struct{} //1.无响应API,使用ws协议处理 // SendMsg 发送消息(自动判断消息类型) -func (a *apiInfo) SendMsg(msg wba.MessageEventInfo, message string, autoEscape bool) { +func (a *apiInfo) SendMsg(messageType string, groupId int64, userId int64, message string, autoEscape bool) { + // 构建发送消息的JSON数据 + var messageData wba.APIRequestInfo + messageData.Action = "send_msg" + switch messageType { + case "private": + { + messageData.Params.UserId = userId + break + } + case "group": + { + messageData.Params.GroupId = groupId + break + } + default: + { + LOG.ERROR("发送消息(SendMsg)时,消息类型错误: %v", messageType) + } + } + messageData.Params.Message = message + messageData.Params.AutoEscape = autoEscape + // 发送消息 + _, err := wsAPI(messageData) + if err != nil { + LOG.ERROR("发送消息时,发送失败: %v", err) + return + } + LOG.INFO("发送消息(SendMsg)(至:%v-%v:%v):%v", messageType, groupId, userId, message) + return +} + +// SendPrivateMsg 发送私聊消息 +func (a *apiInfo) SendPrivateMsg(userId int64, message string, autoEscape bool) { + // 构建发送消息的JSON数据 + var messageData wba.APIRequestInfo + messageData.Action = "send_private_msg" + messageData.Params.UserId = userId + messageData.Params.Message = message + messageData.Params.AutoEscape = autoEscape + // 发送消息 + _, err := wsAPI(messageData) + if err != nil { + LOG.ERROR("发送私聊消息(SendPrivateMsg)时,发送失败: %v", err) + return + } + LOG.INFO("发送私聊消息(SendPrivateMsg)(至:%v):%v", userId, message) + return +} + +// SendGroupMsg 发送群消息 +func (a *apiInfo) SendGroupMsg(groupId int64, message string, autoEscape bool) { + // 构建发送消息的JSON数据 + var messageData wba.APIRequestInfo + messageData.Action = "send_group_msg" + messageData.Params.GroupId = groupId + messageData.Params.Message = message + messageData.Params.AutoEscape = autoEscape + // 发送消息 + _, err := wsAPI(messageData) + if err != nil { + LOG.ERROR("发送群消息(SendGroupMsg)时,发送失败: %v", err) + return + } + LOG.INFO("发送群消息(SendGroupMsg)(至:%v):%v", groupId, message) + return +} + +// ReplyMsg 回复消息(自动判断消息类型) +func (a *apiInfo) ReplyMsg(msg wba.MessageEventInfo, message string, autoEscape bool) { // 构建发送消息的JSON数据 var messageData wba.APIRequestInfo @@ -44,7 +113,7 @@ func (a *apiInfo) SendMsg(msg wba.MessageEventInfo, message string, autoEscape b } default: { - LOG.ERROR("发送消息(SendMsg)时,消息类型错误: %v", messageType) + LOG.ERROR("回复消息(ReplyMsg)时,消息类型错误: %v", messageType) } } messageData.Params.Message = message @@ -52,15 +121,15 @@ func (a *apiInfo) SendMsg(msg wba.MessageEventInfo, message string, autoEscape b // 发送消息 _, err := wsAPI(messageData) if err != nil { - LOG.ERROR("发送消息时,发送失败: %v", err) + LOG.ERROR("回复消息时,发送失败: %v", err) return } - LOG.INFO("发送消息(SendMsg)(至:%v-%v:%v-%v):%v", msg.MessageType, msg.GroupId, msg.UserId, msg.Sender.Nickname, message) + LOG.INFO("回复消息(ReplyMsg)(至:%v-%v:%v-%v):%v", msg.MessageType, msg.GroupId, msg.UserId, msg.Sender.Nickname, message) return } -// SendPrivateMsg 发送私聊消息 -func (a *apiInfo) SendPrivateMsg(msg wba.MessageEventInfo, message string, autoEscape bool) { +// ReplyPrivateMsg 回复私聊消息 +func (a *apiInfo) ReplyPrivateMsg(msg wba.MessageEventInfo, message string, autoEscape bool) { // 构建发送消息的JSON数据 var messageData wba.APIRequestInfo messageData.Action = "send_private_msg" @@ -70,15 +139,15 @@ func (a *apiInfo) SendPrivateMsg(msg wba.MessageEventInfo, message string, autoE // 发送消息 _, err := wsAPI(messageData) if err != nil { - LOG.ERROR("发送消息(SendPrivateMsg)时,发送失败: %v", err) + LOG.ERROR("回复消息(ReplyPrivateMsg)时,发送失败: %v", err) return } - LOG.INFO("发送消息(SendPrivateMsg)(至:%v-%v:%v-%v):%v", msg.MessageType, msg.GroupId, msg.UserId, msg.Sender.Nickname, message) + LOG.INFO("回复消息(ReplyPrivateMsg)(至:%v-%v:%v-%v):%v", msg.MessageType, msg.GroupId, msg.UserId, msg.Sender.Nickname, message) return } -// SendGroupMsg 发送群消息 -func (a *apiInfo) SendGroupMsg(msg wba.MessageEventInfo, message string, autoEscape bool) { +// ReplyGroupMsg 回复群消息 +func (a *apiInfo) ReplyGroupMsg(msg wba.MessageEventInfo, message string, autoEscape bool) { // 构建发送消息的JSON数据 var messageData wba.APIRequestInfo messageData.Action = "send_group_msg" @@ -88,10 +157,10 @@ func (a *apiInfo) SendGroupMsg(msg wba.MessageEventInfo, message string, autoEsc // 发送消息 _, err := wsAPI(messageData) if err != nil { - LOG.ERROR("发送消息(SendGroupMsg)时,发送失败: %v", err) + LOG.ERROR("回复消息(ReplyGroupMsg)时,发送失败: %v", err) return } - LOG.INFO("发送消息(SendGroupMsg)(至:%v-%v:%v-%v):%v", msg.MessageType, msg.GroupId, msg.UserId, msg.Sender.Nickname, message) + LOG.INFO("回复消息(ReplyGroupMsg)(至:%v-%v:%v-%v):%v", msg.MessageType, msg.GroupId, msg.UserId, msg.Sender.Nickname, message) return } diff --git a/core/app_core.go b/core/app_core.go index d9480d2..7905462 100644 --- a/core/app_core.go +++ b/core/app_core.go @@ -47,7 +47,7 @@ var AppCore = AppInfo{ "bot", "显示WIND版本信息", func(args []string, msg wba.MessageEventInfo) { - AppApi.SendMsg(msg, "WIND 0.1.0", false) + AppApi.ReplyMsg(msg, "WIND 0.1.0", false) LOG.INFO("发送核心版本信息:(至:%v-%v:%v-%v)", msg.MessageType, msg.GroupId, msg.UserId, msg.Sender.Nickname) }, ), diff --git a/wba/wind.go b/wba/wind.go index 14fd035..450fbb5 100644 --- a/wba/wind.go +++ b/wba/wind.go @@ -10,9 +10,12 @@ type APP interface { } type WindAPI interface { - SendMsg(msg MessageEventInfo, message string, autoEscape bool) - SendPrivateMsg(msg MessageEventInfo, message string, autoEscape bool) - SendGroupMsg(msg MessageEventInfo, message string, autoEscape bool) + SendMsg(msgType string, groupId int64, userId int64, message string, autoEscape bool) + SendPrivateMsg(userId int64, message string, autoEscape bool) + SendGroupMsg(groupId int64, message string, autoEscape bool) + ReplyMsg(msg MessageEventInfo, message string, autoEscape bool) + ReplyPrivateMsg(msg MessageEventInfo, message string, autoEscape bool) + ReplyGroupMsg(msg MessageEventInfo, message string, autoEscape bool) DeleteMsg(msg MessageEventInfo) SendLike(userId int64, times int) SetGroupKick(groupId int64, userId int64, rejectAddRequest bool)