package channelbridge import ( "git.yeij.top/AskaEth/Cyrene_v2/internal/channel/adapter" ) // This file holds the per-account allow/deny black-or-white lists (design/16 §4.6 // §6) enforced at the head of the inbound pipeline, plus the config readers the // list matching depends on. // blacklisted applies the per-account allow/deny black-or-white lists (design/16 // §4.6 §6) to a non-owner inbound message. Group messages are matched by GroupID // against allowGroups/denyGroups; direct messages are matched by the sender's user // id against allowUsers/denyUsers. An empty allow list means "allow all" (only the // deny list applies); a non-empty allow list becomes a white list. The owner is // never blacklisted (the caller skips this for owner messages). func (b *Bridge) blacklisted(msg adapter.UnifiedMessage, a adapter.PlatformAdapter) (bool, string) { if a == nil { return false, "" } allowGroups, denyGroups, allowUsers, denyUsers := channelLists(a.Config()) if msg.IsGroup() { if sliceContains(denyGroups, msg.GroupID) { return true, "group_denied" } if len(allowGroups) > 0 && !sliceContains(allowGroups, msg.GroupID) { return true, "group_not_allowed" } return false, "" } uid := firstNonEmptyStr(msg.SenderID, msg.Sender.UserID) if sliceContains(denyUsers, uid) { return true, "user_denied" } if len(allowUsers) > 0 && !sliceContains(allowUsers, uid) { return true, "user_not_allowed" } return false, "" } // channelLists reads the allow/deny string lists off an adapter's Config snapshot. // The lists are stored as plain []string values (set by the multi-account wiring); // an absent key yields an empty list. func channelLists(cfg map[string]any) (allowGroups, denyGroups, allowUsers, denyUsers []string) { if cfg == nil { return nil, nil, nil, nil } return cfgStrings(cfg, "allowGroups"), cfgStrings(cfg, "denyGroups"), cfgStrings(cfg, "allowUsers"), cfgStrings(cfg, "denyUsers") } // cfgStrings reads a []string field from an adapter config map, returning nil when // absent or of a different type. func cfgStrings(m map[string]any, key string) []string { if m == nil { return nil } switch v := m[key].(type) { case []string: return v case []any: out := make([]string, 0, len(v)) for _, e := range v { if s, ok := e.(string); ok { out = append(out, s) } } return out default: return nil } }