From 10d5bfd60f689805f6d616f090be64e3ddb00c8a Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Mon, 6 Feb 2017 03:26:32 -0500 Subject: [PATCH] rename UserModes -> UserPerms and parseUserModes -> parseUserPrefix --- contants.go | 2 ++ handlers.go | 4 ++-- state.go | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/contants.go b/contants.go index 4192737..d4eb542 100644 --- a/contants.go +++ b/contants.go @@ -33,6 +33,8 @@ const ( HalfOperatorPrefix = "%" // user half operator +h (non-rfc) OperatorPrefix = "@" // user operator +o VoicePrefix = "+" // user has voice +v + ModeAddPrefix = "+" // modes are being added + ModeDelPrefix = "-" // modes are being removed ) // User modes :: RFC1459; section 4.2.3.2 diff --git a/handlers.go b/handlers.go index 3a7ef99..ad39f38 100644 --- a/handlers.go +++ b/handlers.go @@ -322,7 +322,7 @@ func handleNAMES(c *Client, e Event) { c.state.mu.Lock() for i := 0; i < len(parts); i++ { - modes, nick, ok := parseUserModes(parts[i]) + modes, nick, ok := parseUserPrefix(parts[i]) if !ok { continue } @@ -333,7 +333,7 @@ func handleNAMES(c *Client, e Event) { } // Don't append modes, overwrite them. - user.Modes.setModes(modes, false) + user.Perms.set(modes, false) } c.state.mu.Unlock() } diff --git a/state.go b/state.go index ebf590b..ed1c126 100644 --- a/state.go +++ b/state.go @@ -74,11 +74,11 @@ type User struct { // Only usable if from state, not in past. 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. // If you want to easily check if a user has permissions equal or greater - // than OP, use Modes.IsAdmin(). - Modes UserModes + // than OP, use Perms.IsAdmin(). + Perms UserPerms // Extras are things added on by additional tracking methods, which may // or may not work on the IRC server in mention. @@ -324,10 +324,10 @@ func (s *state) lookupUsers(matchType, toMatch string) []*User { 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 // 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 // channel. More than one user can have owner permission. Owner bool @@ -347,7 +347,7 @@ type UserModes struct { // IsAdmin indicates that the user has banning abilities, and are likely a // very trustable user (e.g. op+). -func (m UserModes) IsAdmin() bool { +func (m UserPerms) IsAdmin() bool { if m.Owner || m.Admin || m.Op { return true } @@ -357,7 +357,7 @@ func (m UserModes) IsAdmin() bool { // IsAdmin indicates that the user at least has modes set upon them, higher // than a regular joining user. -func (m UserModes) IsTrusted() bool { +func (m UserPerms) IsTrusted() bool { if m.IsAdmin() || m.HalfOp || m.Voice { return true } @@ -366,7 +366,7 @@ func (m UserModes) IsTrusted() bool { } // reset resets the modes of a user. -func (m *UserModes) reset() { +func (m *UserPerms) reset() { m.Owner = false m.Admin = false m.Op = false @@ -374,9 +374,9 @@ func (m *UserModes) reset() { m.Voice = false } -// setMode translates raw mode characters into proper permissions. Only use -// this function when you have a session lock. -func (m *UserModes) setModes(modes string, append bool) { +// set translates raw mode characters into proper permissions. Only +// use this function when you have a session lock. +func (m *UserPerms) set(modes string, append bool) { if !append { m.reset() } @@ -397,8 +397,8 @@ func (m *UserModes) setModes(modes string, append bool) { } } -// parseUserModes parses a raw mode line, like "@user" or "@+user". -func parseUserModes(raw string) (modes, nick string, success bool) { +// parseUserPrefix parses a raw mode line, like "@user" or "@+user". +func parseUserPrefix(raw string) (modes, nick string, success bool) { for i := 0; i < len(raw); i++ { char := string(raw[i])