2016-06-15 13:50:56 +02:00
|
|
|
// Copyright (c) 2012-2014 Jeremy Latt
|
|
|
|
// Copyright (c) 2014-2015 Edmund Huber
|
2017-03-27 14:15:02 +02:00
|
|
|
// Copyright (c) 2016 Daniel Oaks <daniel@danieloaks.net>
|
2016-06-15 13:50:56 +02:00
|
|
|
// released under the MIT license
|
|
|
|
|
2014-02-09 07:06:10 +01:00
|
|
|
package irc
|
|
|
|
|
2018-02-03 11:21:32 +01:00
|
|
|
import "github.com/oragono/oragono/irc/modes"
|
2014-02-25 20:11:34 +01:00
|
|
|
|
2019-12-05 12:52:07 +01:00
|
|
|
type empty struct{}
|
|
|
|
|
2017-10-05 15:29:34 +02:00
|
|
|
// ClientSet is a set of clients.
|
2019-12-05 12:52:07 +01:00
|
|
|
type ClientSet map[*Client]empty
|
2014-02-09 08:15:05 +01:00
|
|
|
|
2017-10-05 15:29:34 +02:00
|
|
|
// Add adds the given client to this set.
|
2014-02-09 08:15:05 +01:00
|
|
|
func (clients ClientSet) Add(client *Client) {
|
2019-12-05 12:52:07 +01:00
|
|
|
clients[client] = empty{}
|
2014-02-09 08:15:05 +01:00
|
|
|
}
|
|
|
|
|
2017-10-05 15:29:34 +02:00
|
|
|
// Remove removes the given client from this set.
|
2014-02-09 08:15:05 +01:00
|
|
|
func (clients ClientSet) Remove(client *Client) {
|
|
|
|
delete(clients, client)
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:29:34 +02:00
|
|
|
// Has returns true if the given client is in this set.
|
2014-02-17 02:23:47 +01:00
|
|
|
func (clients ClientSet) Has(client *Client) bool {
|
2019-12-05 12:52:07 +01:00
|
|
|
_, ok := clients[client]
|
|
|
|
return ok
|
2014-02-17 02:23:47 +01:00
|
|
|
}
|
|
|
|
|
2017-10-05 15:29:34 +02:00
|
|
|
// MemberSet is a set of members with modes.
|
2018-04-23 00:47:10 +02:00
|
|
|
type MemberSet map[*Client]*modes.ModeSet
|
2014-02-17 02:23:47 +01:00
|
|
|
|
2017-10-05 15:29:34 +02:00
|
|
|
// Add adds the given client to this set.
|
2014-02-17 02:23:47 +01:00
|
|
|
func (members MemberSet) Add(member *Client) {
|
2018-04-23 00:47:10 +02:00
|
|
|
members[member] = modes.NewModeSet()
|
2014-02-17 02:23:47 +01:00
|
|
|
}
|
|
|
|
|
2017-10-05 15:29:34 +02:00
|
|
|
// Remove removes the given client from this set.
|
2014-02-17 02:23:47 +01:00
|
|
|
func (members MemberSet) Remove(member *Client) {
|
|
|
|
delete(members, member)
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:29:34 +02:00
|
|
|
// Has returns true if the given client is in this set.
|
2014-02-17 02:23:47 +01:00
|
|
|
func (members MemberSet) Has(member *Client) bool {
|
|
|
|
_, ok := members[member]
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:29:34 +02:00
|
|
|
// AnyHasMode returns true if any of our clients has the given mode.
|
2018-02-03 11:21:32 +01:00
|
|
|
func (members MemberSet) AnyHasMode(mode modes.Mode) bool {
|
2014-03-22 22:25:24 +01:00
|
|
|
for _, modes := range members {
|
2018-04-23 00:47:10 +02:00
|
|
|
if modes.HasMode(mode) {
|
2014-03-22 22:25:24 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:29:34 +02:00
|
|
|
// ChannelSet is a set of channels.
|
2014-02-09 08:15:05 +01:00
|
|
|
type ChannelSet map[*Channel]bool
|