-
Notifications
You must be signed in to change notification settings - Fork 177
/
types.go
58 lines (46 loc) · 1.44 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2012-2014 Jeremy Latt
// Copyright (c) 2014-2015 Edmund Huber
// Copyright (c) 2016 Daniel Oaks <daniel@danieloaks.net>
// released under the MIT license
package irc
import "github.com/oragono/oragono/irc/modes"
// ClientSet is a set of clients.
type ClientSet map[*Client]bool
// Add adds the given client to this set.
func (clients ClientSet) Add(client *Client) {
clients[client] = true
}
// Remove removes the given client from this set.
func (clients ClientSet) Remove(client *Client) {
delete(clients, client)
}
// Has returns true if the given client is in this set.
func (clients ClientSet) Has(client *Client) bool {
return clients[client]
}
// MemberSet is a set of members with modes.
type MemberSet map[*Client]*modes.ModeSet
// Add adds the given client to this set.
func (members MemberSet) Add(member *Client) {
members[member] = modes.NewModeSet()
}
// Remove removes the given client from this set.
func (members MemberSet) Remove(member *Client) {
delete(members, member)
}
// Has returns true if the given client is in this set.
func (members MemberSet) Has(member *Client) bool {
_, ok := members[member]
return ok
}
// AnyHasMode returns true if any of our clients has the given mode.
func (members MemberSet) AnyHasMode(mode modes.Mode) bool {
for _, modes := range members {
if modes.HasMode(mode) {
return true
}
}
return false
}
// ChannelSet is a set of channels.
type ChannelSet map[*Channel]bool