// ListMode calls the given function for every entry in the list mode, // with the parameter of this mode list entry, and its metadata value. If // there are none, it will not be called. func (p *ModeParser) ListMode(e core.Extensible, char int, f func(param, value string)) bool { prefix := p.list[char] if prefix != "" { e.DataRange(prefix+" ", func(name, value string) { if v, ok := p.nameToExt[prefix]; ok { _, addpar, _, _ := v(e, name, "", value) for _, par := range addpar { f(par, value) } } else { f(name[len(prefix)+1:], value) } }) return true } return false }
// banMatch returns whether the user has a ban on the given Extensible, // matching the given restriction, under the given prefix for ban types. // It handles checking for default bans, if this ban type is part of the // default. func banMatch(u *core.User, e core.Extensible, prefix, restrict string) (match bool) { def := defaultBan if prefix == "unrestrict" { def = defaultUnrestrict } defwords := strings.Fields(def) // Create matcher closure, to run for each ban. var reverse bool var prefixlen int var t string var hook func(u *core.User, mask string) bool matcher := func(name, value string) { words := strings.Fields(value) var found bool for _, word := range words { if word == restrict { found = true break } if word == "on" { var deffound bool for _, defword := range defwords { if defword == restrict { deffound = true break } } if deffound { found = true break } } } if !found { return } // If the hook returns true and we're NOT reversed, match. // If the hook returns false and we are reversed, match. if hook(u, name[prefixlen:]) == !reverse { match = true } } for t, hook = range banTypes { reverse = false prefixlen = len(prefix) + len(t) + 2 e.DataRange(prefix+" "+t+" ", matcher) if match == true { break } reverse = true prefixlen = len(prefix) + len(t) + 3 e.DataRange(prefix+" ~"+t+" ", matcher) if match == true { break } } return }