2017-03-27 14:15:02 +02:00
|
|
|
// Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
|
2017-03-11 13:01:40 +01:00
|
|
|
// released under the MIT license
|
|
|
|
|
|
|
|
package irc
|
|
|
|
|
|
|
|
import (
|
2020-08-05 03:46:16 +02:00
|
|
|
"encoding/json"
|
2017-03-11 13:01:40 +01:00
|
|
|
"time"
|
|
|
|
|
2021-05-25 06:34:38 +02:00
|
|
|
"github.com/ergochat/ergo/irc/modes"
|
|
|
|
"github.com/ergochat/ergo/irc/utils"
|
2017-03-11 13:01:40 +01:00
|
|
|
)
|
|
|
|
|
2017-11-09 04:19:50 +01:00
|
|
|
// this is exclusively the *persistence* layer for channel registration;
|
|
|
|
// channel creation/tracking/destruction is in channelmanager.go
|
|
|
|
|
2018-04-04 03:49:40 +02:00
|
|
|
// these are bit flags indicating what part of the channel status is "dirty"
|
|
|
|
// and needs to be read from memory and written to the db
|
|
|
|
const (
|
|
|
|
IncludeInitial uint = 1 << iota
|
|
|
|
IncludeTopic
|
|
|
|
IncludeModes
|
|
|
|
IncludeLists
|
2020-02-19 01:38:42 +01:00
|
|
|
IncludeSettings
|
2018-04-04 03:49:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// this is an OR of all possible flags
|
|
|
|
const (
|
2020-03-02 07:46:22 +01:00
|
|
|
IncludeAllAttrs = ^uint(0)
|
2018-04-04 03:49:40 +02:00
|
|
|
)
|
|
|
|
|
2017-03-11 13:01:40 +01:00
|
|
|
// RegisteredChannel holds details about a given registered channel.
|
|
|
|
type RegisteredChannel struct {
|
|
|
|
// Name of the channel.
|
|
|
|
Name string
|
2023-01-04 11:06:21 +01:00
|
|
|
// UUID for the datastore.
|
|
|
|
UUID utils.UUID
|
2017-03-11 13:01:40 +01:00
|
|
|
// RegisteredAt represents the time that the channel was registered.
|
|
|
|
RegisteredAt time.Time
|
|
|
|
// Founder indicates the founder of the channel.
|
|
|
|
Founder string
|
|
|
|
// Topic represents the channel topic.
|
|
|
|
Topic string
|
|
|
|
// TopicSetBy represents the host that set the topic.
|
|
|
|
TopicSetBy string
|
|
|
|
// TopicSetTime represents the time the topic was set.
|
|
|
|
TopicSetTime time.Time
|
2018-04-04 03:49:40 +02:00
|
|
|
// Modes represents the channel modes
|
|
|
|
Modes []modes.Mode
|
|
|
|
// Key represents the channel key / password
|
|
|
|
Key string
|
2020-12-14 11:00:21 +01:00
|
|
|
// Forward is the forwarding/overflow (+f) channel
|
|
|
|
Forward string
|
2020-01-08 08:14:41 +01:00
|
|
|
// UserLimit is the user limit (0 for no limit)
|
|
|
|
UserLimit int
|
2018-04-04 03:49:40 +02:00
|
|
|
// AccountToUMode maps user accounts to their persistent channel modes (e.g., +q, +h)
|
|
|
|
AccountToUMode map[string]modes.Mode
|
2019-10-10 10:17:44 +02:00
|
|
|
// Bans represents the bans set on the channel.
|
|
|
|
Bans map[string]MaskInfo
|
|
|
|
// Excepts represents the exceptions set on the channel.
|
|
|
|
Excepts map[string]MaskInfo
|
|
|
|
// Invites represents the invite exceptions set on the channel.
|
|
|
|
Invites map[string]MaskInfo
|
2020-02-19 01:38:42 +01:00
|
|
|
// Settings are the chanserv-modifiable settings
|
|
|
|
Settings ChannelSettings
|
2017-03-11 13:01:40 +01:00
|
|
|
}
|
|
|
|
|
2023-01-04 11:06:21 +01:00
|
|
|
func (r *RegisteredChannel) Serialize() ([]byte, error) {
|
|
|
|
return json.Marshal(r)
|
2017-06-05 04:01:37 +02:00
|
|
|
}
|
|
|
|
|
2023-01-04 11:06:21 +01:00
|
|
|
func (r *RegisteredChannel) Deserialize(b []byte) (err error) {
|
|
|
|
return json.Unmarshal(b, r)
|
2017-11-09 04:19:50 +01:00
|
|
|
}
|
|
|
|
|
2023-01-04 11:06:21 +01:00
|
|
|
type ChannelPurgeRecord struct {
|
|
|
|
NameCasefolded string `json:"Name"`
|
|
|
|
UUID utils.UUID
|
|
|
|
Oper string
|
|
|
|
PurgedAt time.Time
|
|
|
|
Reason string
|
2019-12-17 01:50:15 +01:00
|
|
|
}
|
|
|
|
|
2023-01-04 11:06:21 +01:00
|
|
|
func (c *ChannelPurgeRecord) Serialize() ([]byte, error) {
|
|
|
|
return json.Marshal(c)
|
2019-12-17 01:50:15 +01:00
|
|
|
}
|
|
|
|
|
2023-01-04 11:06:21 +01:00
|
|
|
func (c *ChannelPurgeRecord) Deserialize(b []byte) error {
|
|
|
|
return json.Unmarshal(b, c)
|
2019-12-17 01:50:15 +01:00
|
|
|
}
|