Merge pull request 'hotfix' (#97) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m29s
All checks were successful
BuildImage / build-image (push) Successful in 1m29s
Reviewed-on: #97
This commit is contained in:
commit
ec1948c6ce
@ -4,7 +4,7 @@ system:
|
||||
alApiToken: xxx
|
||||
# urlc.cn的Token,用来生成短链接
|
||||
urlcApiToken: xxx
|
||||
# 系统访问域名
|
||||
# 系统访问域名,必须是包括 http[s]:// 的完整域名
|
||||
domain: https://wechat.abc.com
|
||||
# 添加新好友或群之后通知给指定的人
|
||||
newFriendNotify:
|
||||
|
@ -35,7 +35,7 @@ func Plugin() {
|
||||
}, plugins.NotifyRemoveFromChatroom)
|
||||
// 响应好友添加成功消息
|
||||
dispatcher.RegisterHandler(func(m *dto.Message) bool {
|
||||
return m.Type == types.MsgTypeSys
|
||||
return m.IsNewFriendAdd() || m.IsJoinToGroup() || m.IsOldFriendBack()
|
||||
}, plugins.ReplyNewFriend)
|
||||
|
||||
// 私聊指令消息
|
||||
|
@ -219,3 +219,36 @@ func (m Message) IsInvitationJoinGroup() (flag bool, str string) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IsNewFriendAdd
|
||||
// @description: 是否是新好友添加消息
|
||||
// @receiver m
|
||||
// @return flag
|
||||
func (m Message) IsNewFriendAdd() (flag bool) {
|
||||
if m.Type != types.MsgTypeSys {
|
||||
return
|
||||
}
|
||||
return strings.HasPrefix(m.Content, "你已添加了") && strings.HasSuffix(m.Content, ",现在可以开始聊天了。")
|
||||
}
|
||||
|
||||
// IsOldFriendBack
|
||||
// @description: 是否是老好友回归消息
|
||||
// @receiver m
|
||||
// @return flag
|
||||
func (m Message) IsOldFriendBack() (flag bool) {
|
||||
if m.Type != types.MsgTypeSys {
|
||||
return
|
||||
}
|
||||
return m.Content == "以上是打招呼的内容"
|
||||
}
|
||||
|
||||
// IsJoinToGroup
|
||||
// @description: 是否是加入群聊消息
|
||||
// @receiver m
|
||||
// @return flag
|
||||
func (m Message) IsJoinToGroup() (flag bool) {
|
||||
if m.Type != types.MsgTypeSys {
|
||||
return
|
||||
}
|
||||
return strings.Contains(m.Content, "\"邀请你加入了群聊,群聊参与人还有:")
|
||||
}
|
||||
|
@ -19,8 +19,12 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// 已经通知过的群组或者好友map
|
||||
var notifyMap = make(map[string]bool)
|
||||
|
||||
// 拉取最近消息条数
|
||||
const fetchMessageCount = 20
|
||||
|
||||
// AI
|
||||
// @description: AI消息
|
||||
// @param m
|
||||
@ -198,7 +202,7 @@ func getGroupUserMessages(msgId int64, groupId, groupUserId string) (records []e
|
||||
Where("create_at >= DATE_SUB(NOW(),INTERVAL 30 MINUTE)").
|
||||
Where(subQuery).
|
||||
Order("create_at desc").
|
||||
Limit(4).Find(&records)
|
||||
Limit(fetchMessageCount).Find(&records)
|
||||
return
|
||||
}
|
||||
|
||||
@ -214,6 +218,6 @@ func getUserPrivateMessages(userId string) (records []entity.Message) {
|
||||
Where("create_at >= DATE_SUB(NOW(),INTERVAL 30 MINUTE)").
|
||||
Where(subQuery).
|
||||
Order("create_at desc").
|
||||
Limit(4).Find(&records)
|
||||
Limit(fetchMessageCount).Find(&records)
|
||||
return
|
||||
}
|
||||
|
@ -3,16 +3,16 @@ package plugins
|
||||
import (
|
||||
"go-wechat/plugin"
|
||||
"go-wechat/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ReplyNewFriend
|
||||
// @description: 响应好友添加成功消息
|
||||
// @param m
|
||||
func ReplyNewFriend(m *plugin.MessageContext) {
|
||||
isNewFriend := strings.HasPrefix(m.Content, "你已添加了") && strings.HasSuffix(m.Content, ",现在可以开始聊天了。")
|
||||
isNewChatroom := strings.Contains(m.Content, "\"邀请你加入了群聊,群聊参与人还有:")
|
||||
if isNewFriend || isNewChatroom {
|
||||
utils.SendMessage(m.FromUser, m.GroupUser, "AI正在初始化,请稍等几分钟,初始化完成之后我将主动告知您。", 0)
|
||||
if m.IsNewFriendAdd() || m.IsJoinToGroup() {
|
||||
_ = utils.SendMessage(m.FromUser, m.GroupUser, "AI正在初始化,请稍等几分钟,初始化完成之后我将主动告知您。", 0)
|
||||
}
|
||||
if m.IsOldFriendBack() {
|
||||
_ = utils.SendMessage(m.FromUser, m.GroupUser, "嘿,我的朋友,你为何要离我而去?又为何去而复返?", 0)
|
||||
}
|
||||
}
|
||||
|
@ -110,9 +110,9 @@ func Sync() {
|
||||
}
|
||||
// 发送配置网页
|
||||
if config.Conf.System.Domain != "" {
|
||||
title := "欢迎使用微信机器人"
|
||||
title := "欢迎使用微信机器人(切勿转发)"
|
||||
desc := "点我可以配置功能喔,提示非微信官方网页,点击继续访问即可"
|
||||
url := config.Conf.System.Domain + "/manager.html?id=" + friend.Wxid
|
||||
url := utils.GetManagerUrl(friend.Wxid)
|
||||
utils.SendPublicMsg(friend.Wxid, title, desc, url, 0)
|
||||
}
|
||||
|
||||
@ -150,9 +150,9 @@ func Sync() {
|
||||
}
|
||||
// 发送配置网页
|
||||
if config.Conf.System.Domain != "" {
|
||||
title := "欢迎使用微信机器人"
|
||||
title := "欢迎使用微信机器人(切勿转发)"
|
||||
desc := "点我可以配置功能喔,提示非微信官方网页,点击继续访问即可"
|
||||
url := config.Conf.System.Domain + "/manager.html?id=" + friend.Wxid
|
||||
url := utils.GetManagerUrl(friend.Wxid)
|
||||
utils.SendPublicMsg(friend.Wxid, title, desc, url, 0)
|
||||
}
|
||||
}
|
||||
|
21
utils/url.go
Normal file
21
utils/url.go
Normal file
@ -0,0 +1,21 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"go-wechat/config"
|
||||
)
|
||||
|
||||
// GetManagerUrl
|
||||
// @description: 获取管理页面链接
|
||||
// @param wxId
|
||||
// @return newUrl
|
||||
func GetManagerUrl(wxId string) (url string) {
|
||||
// 生成管理页面链接
|
||||
url = fmt.Sprintf("%s/manager.html?id=%s", config.Conf.System.Domain, wxId)
|
||||
// base64一下
|
||||
encodeString := base64.StdEncoding.EncodeToString([]byte(url))
|
||||
// 拼接新链接(这个是一个已备案的域名)
|
||||
url = "https://redirect.wjg95.cn/?s=" + encodeString
|
||||
return
|
||||
}
|
@ -83,7 +83,12 @@
|
||||
</div>
|
||||
<!-- 今日 AI 对话已使用次数 -->
|
||||
<div class="flex justify-between gap-x-4 py-3 items-center">
|
||||
<dt class="text-gray-500">今日 AI 对话已使用次数</dt>
|
||||
<dt class="text-gray-500">
|
||||
今日 AI 对话已使用次数
|
||||
<br/>
|
||||
<span class="text-red-300">* 每天0点重置</span>
|
||||
<p class="text-gray-400">需要扩容请添加微信: _Elixir</p>
|
||||
</dt>
|
||||
<dd class="flex items-start gap-x-2">
|
||||
{{ .info.AiUsedToday }}次{{ if lt 1 .info.AiFreeLimit }}(限制{{ .info.AiFreeLimit }}次){{ end }}
|
||||
</dd>
|
||||
|
Loading…
Reference in New Issue
Block a user