diff --git a/applogic/gensokyo.go b/applogic/gensokyo.go index 71369e8..60d5a94 100644 --- a/applogic/gensokyo.go +++ b/applogic/gensokyo.go @@ -264,7 +264,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) { } if utils.BlacklistIntercept(message, selfid) { - fmtf.Printf("userid:[%v]这位用户在黑名单中,被拦截", message.UserID) + fmtf.Printf("userid:[%v]groupid:[%v]这位用户或群在黑名单中,被拦截", message.UserID, message.GroupID) return } diff --git a/utils/blacklist.go b/utils/blacklist.go index 6d3b1f2..77b1aea 100644 --- a/utils/blacklist.go +++ b/utils/blacklist.go @@ -94,6 +94,26 @@ func WatchBlacklist(filePath string) { // BlacklistIntercept 检查用户ID是否在黑名单中,如果在,则发送预设消息 func BlacklistIntercept(message structs.OnebotGroupMessage, selfid string) bool { + // 检查群ID是否在黑名单中 + if IsInBlacklist(strconv.FormatInt(message.GroupID, 10)) { + // 获取黑名单响应消息 + responseMessage := config.GetBlacklistResponseMessages() + + // 根据消息类型发送响应 + if message.RealMessageType == "group_private" || message.MessageType == "private" { + if !config.GetUsePrivateSSE() { + SendPrivateMessage(message.UserID, responseMessage, selfid) + } else { + SendSSEPrivateMessage(message.UserID, responseMessage) + } + } else { + SendGroupMessage(message.GroupID, message.UserID, responseMessage, selfid) + } + + fmt.Printf("groupid:[%v]这个群在黑名单中,被拦截\n", message.GroupID) + return true // 拦截 + } + // 检查用户ID是否在黑名单中 if IsInBlacklist(strconv.FormatInt(message.UserID, 10)) { // 获取黑名单响应消息 @@ -113,5 +133,6 @@ func BlacklistIntercept(message structs.OnebotGroupMessage, selfid string) bool fmt.Printf("userid:[%v]这位用户在黑名单中,被拦截\n", message.UserID) return true // 拦截 } + return false // 用户ID不在黑名单中,不拦截 }