rename UserModes -> UserPerms and parseUserModes -> parseUserPrefix

This commit is contained in:
Liam Stanley 2017-02-06 03:26:32 -05:00
parent 62d007b448
commit 10d5bfd60f
3 changed files with 17 additions and 15 deletions

@ -33,6 +33,8 @@ const (
HalfOperatorPrefix = "%" // user half operator +h (non-rfc) HalfOperatorPrefix = "%" // user half operator +h (non-rfc)
OperatorPrefix = "@" // user operator +o OperatorPrefix = "@" // user operator +o
VoicePrefix = "+" // user has voice +v VoicePrefix = "+" // user has voice +v
ModeAddPrefix = "+" // modes are being added
ModeDelPrefix = "-" // modes are being removed
) )
// User modes :: RFC1459; section 4.2.3.2 // User modes :: RFC1459; section 4.2.3.2

@ -322,7 +322,7 @@ func handleNAMES(c *Client, e Event) {
c.state.mu.Lock() c.state.mu.Lock()
for i := 0; i < len(parts); i++ { for i := 0; i < len(parts); i++ {
modes, nick, ok := parseUserModes(parts[i]) modes, nick, ok := parseUserPrefix(parts[i])
if !ok { if !ok {
continue continue
} }
@ -333,7 +333,7 @@ func handleNAMES(c *Client, e Event) {
} }
// Don't append modes, overwrite them. // Don't append modes, overwrite them.
user.Modes.setModes(modes, false) user.Perms.set(modes, false)
} }
c.state.mu.Unlock() c.state.mu.Unlock()
} }

@ -74,11 +74,11 @@ type User struct {
// Only usable if from state, not in past. // Only usable if from state, not in past.
LastActive time.Time LastActive time.Time
// Modes are the user modes applied to this user that affect the given // Perms are the user permissions applied to this user that affect the given
// channel. This supports non-rfc style modes like Admin, Owner, and HalfOp. // channel. This supports non-rfc style modes like Admin, Owner, and HalfOp.
// If you want to easily check if a user has permissions equal or greater // If you want to easily check if a user has permissions equal or greater
// than OP, use Modes.IsAdmin(). // than OP, use Perms.IsAdmin().
Modes UserModes Perms UserPerms
// Extras are things added on by additional tracking methods, which may // Extras are things added on by additional tracking methods, which may
// or may not work on the IRC server in mention. // or may not work on the IRC server in mention.
@ -324,10 +324,10 @@ func (s *state) lookupUsers(matchType, toMatch string) []*User {
return users return users
} }
// UserModes contains all channel-based user permissions. The minimum op, and // UserPerms contains all channel-based user permissions. The minimum op, and
// voice should be supported on all networks. This also supports non-rfc // voice should be supported on all networks. This also supports non-rfc
// Owner, Admin, and HalfOp, if the network has support for it. // Owner, Admin, and HalfOp, if the network has support for it.
type UserModes struct { type UserPerms struct {
// Owner (non-rfc) indicates that the user has full permissions to the // Owner (non-rfc) indicates that the user has full permissions to the
// channel. More than one user can have owner permission. // channel. More than one user can have owner permission.
Owner bool Owner bool
@ -347,7 +347,7 @@ type UserModes struct {
// IsAdmin indicates that the user has banning abilities, and are likely a // IsAdmin indicates that the user has banning abilities, and are likely a
// very trustable user (e.g. op+). // very trustable user (e.g. op+).
func (m UserModes) IsAdmin() bool { func (m UserPerms) IsAdmin() bool {
if m.Owner || m.Admin || m.Op { if m.Owner || m.Admin || m.Op {
return true return true
} }
@ -357,7 +357,7 @@ func (m UserModes) IsAdmin() bool {
// IsAdmin indicates that the user at least has modes set upon them, higher // IsAdmin indicates that the user at least has modes set upon them, higher
// than a regular joining user. // than a regular joining user.
func (m UserModes) IsTrusted() bool { func (m UserPerms) IsTrusted() bool {
if m.IsAdmin() || m.HalfOp || m.Voice { if m.IsAdmin() || m.HalfOp || m.Voice {
return true return true
} }
@ -366,7 +366,7 @@ func (m UserModes) IsTrusted() bool {
} }
// reset resets the modes of a user. // reset resets the modes of a user.
func (m *UserModes) reset() { func (m *UserPerms) reset() {
m.Owner = false m.Owner = false
m.Admin = false m.Admin = false
m.Op = false m.Op = false
@ -374,9 +374,9 @@ func (m *UserModes) reset() {
m.Voice = false m.Voice = false
} }
// setMode translates raw mode characters into proper permissions. Only use // set translates raw mode characters into proper permissions. Only
// this function when you have a session lock. // use this function when you have a session lock.
func (m *UserModes) setModes(modes string, append bool) { func (m *UserPerms) set(modes string, append bool) {
if !append { if !append {
m.reset() m.reset()
} }
@ -397,8 +397,8 @@ func (m *UserModes) setModes(modes string, append bool) {
} }
} }
// parseUserModes parses a raw mode line, like "@user" or "@+user". // parseUserPrefix parses a raw mode line, like "@user" or "@+user".
func parseUserModes(raw string) (modes, nick string, success bool) { func parseUserPrefix(raw string) (modes, nick string, success bool) {
for i := 0; i < len(raw); i++ { for i := 0; i < len(raw); i++ {
char := string(raw[i]) char := string(raw[i])