mirror of
https://github.com/gissleh/irc.git
synced 2026-11-17 05:05:49 +00:00
Added Target interface and target types
This commit is contained in:
@@ -242,6 +242,32 @@ func (list *List) Users() []User {
|
||||
return result
|
||||
}
|
||||
|
||||
// Patch allows editing a limited subset of the user's properties.
|
||||
func (list *List) Patch(nick string, patch UserPatch) (ok bool) {
|
||||
list.mutex.Lock()
|
||||
defer list.mutex.Unlock()
|
||||
|
||||
for _, user := range list.users {
|
||||
if strings.EqualFold(nick, user.Nick) {
|
||||
if patch.Account != "" || patch.ClearAccount {
|
||||
user.Account = patch.Account
|
||||
}
|
||||
|
||||
if patch.User != "" {
|
||||
user.User = patch.User
|
||||
}
|
||||
|
||||
if patch.Host != "" {
|
||||
user.Host = patch.Host
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// SetAutoSort enables or disables automatic sorting, which by default is enabled.
|
||||
// Dislabing it makes sense when doing a massive operation. Enabling it will trigger
|
||||
// a sort.
|
||||
@@ -264,6 +290,11 @@ func (list *List) Clear() {
|
||||
list.mutex.Unlock()
|
||||
}
|
||||
|
||||
// Immutable gets an immutable version of the list.
|
||||
func (list *List) Immutable() Immutable {
|
||||
return Immutable{list: list}
|
||||
}
|
||||
|
||||
func (list *List) sort() {
|
||||
sort.Slice(list.users, func(i, j int) bool {
|
||||
a := list.users[i]
|
||||
|
||||
@@ -11,6 +11,14 @@ type User struct {
|
||||
PrefixedNick string `json:"prefixedNick"`
|
||||
}
|
||||
|
||||
// UserPatch is used in List.Patch to apply changes to a user
|
||||
type UserPatch struct {
|
||||
User string
|
||||
Host string
|
||||
Account string
|
||||
ClearAccount bool
|
||||
}
|
||||
|
||||
// HighestMode returns the highest mode.
|
||||
func (user *User) HighestMode() rune {
|
||||
if len(user.Modes) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user