3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-27 05:02:35 +01:00
ergo/irc/types.go

64 lines
1.4 KiB
Go
Raw Normal View History

// 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>
// released under the MIT license
package irc
import (
"time"
2021-05-25 06:34:38 +02:00
"github.com/ergochat/ergo/irc/modes"
)
type empty struct{}
2017-10-05 15:29:34 +02:00
// ClientSet is a set of clients.
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) {
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.
func (clients ClientSet) Has(client *Client) bool {
_, ok := clients[client]
return ok
}
type memberData struct {
modes *modes.ModeSet
joinTime int64
}
2017-10-05 15:29:34 +02:00
// MemberSet is a set of members with modes.
type MemberSet map[*Client]memberData
2017-10-05 15:29:34 +02:00
// Add adds the given client to this set.
func (members MemberSet) Add(member *Client) {
members[member] = memberData{
modes: modes.NewModeSet(),
joinTime: time.Now().UnixNano(),
}
}
2017-10-05 15:29:34 +02:00
// Remove removes the given client from this set.
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.
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.
2020-07-01 01:24:56 +02:00
type ChannelSet map[*Channel]empty