// HasOpFlag returns whether the user has the given op flag. // This both checks for the presence of the flag, and, if the flag is default, // the "on" keyword for default privileges. This function should not be used as // a direct means of determining a user's ability to do something; instead, // the appropriate permission check should be used, as this permits module to // hook the check on other conditions. It should be used IN said permission // hooks. // // If ch is non-nil, this is a channel op flag check and the user's membership // entry on the channel will be checked. If no such entry exists, the check // automatically fails. If ch is nil, this is a server op flag check, and the user's own metadata will be checked. func HasOpFlag(u *core.User, ch *core.Channel, flag string) bool { var e core.Extensible var defwords []string if ch == nil { e = u defwords = defServerOp } else { if m := ch.GetMember(u); m != nil { e = m } else { return false } defwords = defChanOp } words := strings.Fields(e.Data("op")) for _, word := range words { if word == flag { return true } if word == "on" { for _, defword := range defwords { if defword == flag { return true } } } } return false }
// GetModes gets the modeline associated with a user or channel. // It caches its result via metadata on the user, using the mode parser's // mode ID to disambiguate it from other mode parsers. func (p *ModeParser) GetModes(e core.Extensible) string { var modes string var params string for name, char := range p.nameToSimple { data := e.Data(name) if v, ok := p.getExt[char]; ok { data = v(e) } if data != "" { modes += string(char) } } for name, char := range p.nameToParametered { data := e.Data(name) if v, ok := p.getExt[char]; ok { data = v(e) } if data != "" { modes += string(char) params += " " + data } } return modes + params }
// Restricted returns whether the user is restricted by a restriction of the // given type on the given extensible. It handles checking for unrestriction // modes, as well as the given restriction being set. func Restricted(u *core.User, e core.Extensible, restrict string) bool { if e.Data("restrict "+restrict) != "" { if !banMatch(u, e, "unrestrict", restrict) { return true } } return false }