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
|
|
|
|
|
2021-01-21 03:13:18 +01:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2021-05-25 06:34:38 +02:00
|
|
|
"github.com/ergochat/ergo/irc/modes"
|
2022-03-30 06:44:51 +02:00
|
|
|
"github.com/ergochat/ergo/irc/utils"
|
2021-01-21 03:13:18 +01:00
|
|
|
)
|
2014-02-25 20:11:34 +01:00
|
|
|
|
2017-10-05 15:29:34 +02:00
|
|
|
// ClientSet is a set of clients.
|
2022-03-30 06:44:51 +02:00
|
|
|
type ClientSet = utils.HashSet[*Client]
|
2014-02-17 02:23:47 +01:00
|
|
|
|
2021-01-21 03:13:18 +01:00
|
|
|
type memberData struct {
|
2023-04-14 08:15:56 +02:00
|
|
|
modes modes.ModeSet
|
2021-01-21 03:13:18 +01:00
|
|
|
joinTime int64
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:29:34 +02:00
|
|
|
// MemberSet is a set of members with modes.
|
2023-04-14 08:15:56 +02:00
|
|
|
type MemberSet map[*Client]*memberData
|
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) {
|
2023-04-14 08:15:56 +02:00
|
|
|
members[member] = &memberData{
|
2021-01-21 03:13:18 +01:00
|
|
|
joinTime: time.Now().UnixNano(),
|
|
|
|
}
|
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
|
|
|
// ChannelSet is a set of channels.
|
2022-03-30 06:44:51 +02:00
|
|
|
type ChannelSet = utils.HashSet[*Channel]
|