-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
irc.go
139 lines (124 loc) · 4.69 KB
/
irc.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright (c) 2021 - 2023, Ludvig Lundgren and the autobrr contributors.
// SPDX-License-Identifier: GPL-2.0-or-later
package domain
import (
"context"
"encoding/json"
"time"
)
type IrcChannel struct {
ID int64 `json:"id"`
Enabled bool `json:"enabled"`
Name string `json:"name"`
Password string `json:"password"`
Detached bool `json:"detached"`
Monitoring bool `json:"monitoring"`
}
type IRCAuthMechanism string
const (
IRCAuthMechanismNone IRCAuthMechanism = "NONE"
IRCAuthMechanismSASLPlain IRCAuthMechanism = "SASL_PLAIN"
IRCAuthMechanismNickServ IRCAuthMechanism = "NICKSERV"
)
type IRCAuth struct {
Mechanism IRCAuthMechanism `json:"mechanism,omitempty"`
Account string `json:"account,omitempty"`
Password string `json:"password,omitempty"`
}
type IrcNetwork struct {
ID int64 `json:"id"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
Server string `json:"server"`
Port int `json:"port"`
TLS bool `json:"tls"`
Pass string `json:"pass"`
Nick string `json:"nick"`
Auth IRCAuth `json:"auth,omitempty"`
InviteCommand string `json:"invite_command"`
UseBouncer bool `json:"use_bouncer"`
BouncerAddr string `json:"bouncer_addr"`
BotMode bool `json:"bot_mode"`
Channels []IrcChannel `json:"channels"`
Connected bool `json:"connected"`
ConnectedSince *time.Time `json:"connected_since"`
}
type IrcNetworkWithHealth struct {
ID int64 `json:"id"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
Server string `json:"server"`
Port int `json:"port"`
TLS bool `json:"tls"`
Pass string `json:"pass"`
Nick string `json:"nick"`
Auth IRCAuth `json:"auth,omitempty"`
InviteCommand string `json:"invite_command"`
UseBouncer bool `json:"use_bouncer"`
BouncerAddr string `json:"bouncer_addr"`
BotMode bool `json:"bot_mode"`
CurrentNick string `json:"current_nick"`
PreferredNick string `json:"preferred_nick"`
Channels []ChannelWithHealth `json:"channels"`
Connected bool `json:"connected"`
ConnectedSince time.Time `json:"connected_since"`
ConnectionErrors []string `json:"connection_errors"`
Healthy bool `json:"healthy"`
}
type ChannelWithHealth struct {
ID int64 `json:"id"`
Enabled bool `json:"enabled"`
Name string `json:"name"`
Password string `json:"password"`
Detached bool `json:"detached"`
Monitoring bool `json:"monitoring"`
MonitoringSince time.Time `json:"monitoring_since"`
LastAnnounce time.Time `json:"last_announce"`
}
type ChannelHealth struct {
Name string `json:"name"`
Monitoring bool `json:"monitoring"`
MonitoringSince time.Time `json:"monitoring_since"`
LastAnnounce time.Time `json:"last_announce"`
}
type SendIrcCmdRequest struct {
NetworkId int64 `json:"network_id"`
Server string `json:"server"`
Channel string `json:"channel"`
Nick string `json:"nick"`
Message string `json:"msg"`
}
type IrcMessage struct {
Channel string `json:"channel"`
Nick string `json:"nick"`
Message string `json:"msg"`
Time time.Time `json:"time"`
}
func (m IrcMessage) ToJsonString() string {
j, err := json.Marshal(m)
if err != nil {
return ""
}
return string(j)
}
func (m IrcMessage) Bytes() []byte {
j, err := json.Marshal(m)
if err != nil {
return nil
}
return j
}
type IrcRepo interface {
StoreNetwork(ctx context.Context, network *IrcNetwork) error
UpdateNetwork(ctx context.Context, network *IrcNetwork) error
StoreChannel(ctx context.Context, networkID int64, channel *IrcChannel) error
UpdateChannel(channel *IrcChannel) error
UpdateInviteCommand(networkID int64, invite string) error
StoreNetworkChannels(ctx context.Context, networkID int64, channels []IrcChannel) error
CheckExistingNetwork(ctx context.Context, network *IrcNetwork) (*IrcNetwork, error)
FindActiveNetworks(ctx context.Context) ([]IrcNetwork, error)
ListNetworks(ctx context.Context) ([]IrcNetwork, error)
ListChannels(networkID int64) ([]IrcChannel, error)
GetNetworkByID(ctx context.Context, id int64) (*IrcNetwork, error)
DeleteNetwork(ctx context.Context, id int64) error
}