diff --git a/docs/configuration/subscription.md b/docs/configuration/subscription.md index 23f4dd4..fc1eef9 100644 --- a/docs/configuration/subscription.md +++ b/docs/configuration/subscription.md @@ -11,6 +11,8 @@ "exclude": [], "filter_type": [], "exclude_type": [], + "invert": false, + "remove": false, "rename": {}, "remove_emoji": false, "rewrite_multiplex": {} @@ -56,19 +58,27 @@ Process rules. #### process.filter -Regexp filter rules, non-matching outbounds will be removed. +Regexp filter rules, match outbound tag name. #### process.exclude -Regexp exclude rules, matching outbounds will be removed. +Regexp exclude rules, match outbound tag name. #### process.filter_type -Outbound type filter rules, non-matching outbounds will be removed. +Filter rules, match outbound type. #### process.exclude_type -Outbound type exclude rules, matching outbounds will be removed. +Exclude rules, match outbound type. + +#### process.invert + +Invert filter results. + +#### process.remove + +Remove outbounds that match the rules. #### process.rename diff --git a/option/options.go b/option/options.go index 7feb53f..ea6c8c1 100644 --- a/option/options.go +++ b/option/options.go @@ -66,6 +66,8 @@ type OutboundProcessOptions struct { Exclude option.Listable[string] `json:"exclude,omitempty"` FilterType option.Listable[string] `json:"filter_type,omitempty"` ExcludeType option.Listable[string] `json:"exclude_type,omitempty"` + Invert bool `json:"invert,omitempty"` + Remove bool `json:"remove,omitempty"` Rename *badjson.TypedMap[string, string] `json:"rename,omitempty"` RemoveEmoji bool `json:"remove_emoji,omitempty"` RewriteMultiplex *option.OutboundMultiplexOptions `json:"rewrite_multiplex,omitempty"` diff --git a/subscription/process.go b/subscription/process.go index f3edfd2..36629ea 100644 --- a/subscription/process.go +++ b/subscription/process.go @@ -67,29 +67,44 @@ func (o *ProcessOptions) Process(outbounds []boxOption.Outbound) []boxOption.Out newOutbounds := make([]boxOption.Outbound, 0, len(outbounds)) renameResult := make(map[string]string) for _, outbound := range outbounds { - if len(o.filter) > 0 { - if !common.Any(o.filter, func(it *regexp.Regexp) bool { - return it.MatchString(outbound.Tag) - }) { - continue + var inProcess bool + if len(o.filter) == 0 && len(o.FilterType) == 0 && len(o.exclude) == 0 && len(o.ExcludeType) == 0 { + inProcess = true + } else { + if len(o.filter) > 0 { + if !common.Any(o.filter, func(it *regexp.Regexp) bool { + return it.MatchString(outbound.Tag) + }) { + inProcess = true + } + } + if !inProcess && len(o.FilterType) > 0 { + if !common.Contains(o.FilterType, outbound.Type) { + inProcess = true + } + } + if !inProcess && len(o.exclude) > 0 { + if common.Any(o.exclude, func(it *regexp.Regexp) bool { + return it.MatchString(outbound.Tag) + }) { + inProcess = true + } + } + if !inProcess && len(o.ExcludeType) > 0 { + if common.Contains(o.ExcludeType, outbound.Type) { + inProcess = true + } } } - if len(o.FilterType) > 0 { - if !common.Contains(o.FilterType, outbound.Type) { - continue - } + if o.Invert { + inProcess = !inProcess } - if len(o.exclude) > 0 { - if common.Any(o.exclude, func(it *regexp.Regexp) bool { - return it.MatchString(outbound.Tag) - }) { - continue - } + if !inProcess { + newOutbounds = append(newOutbounds, outbound) + continue } - if len(o.ExcludeType) > 0 { - if common.Contains(o.ExcludeType, outbound.Type) { - continue - } + if o.Remove { + continue } originTag := outbound.Tag if len(o.rename) > 0 {