-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructs.go
More file actions
92 lines (76 loc) · 2.56 KB
/
structs.go
File metadata and controls
92 lines (76 loc) · 2.56 KB
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
package uchatbot
import (
swissknife "github.com/Sagleft/swiss-knife"
utopiago "github.com/Sagleft/utopialib-go/v2"
"github.com/Sagleft/utopialib-go/v2/pkg/structs"
"github.com/Sagleft/utopialib-go/v2/pkg/websocket"
"github.com/beefsack/go-rate"
)
type wsHandler func(event websocket.WsEvent)
type ChatBot struct {
client utopiago.Client
data ChatBotData
wsHandlers map[string]wsHandler
queues eventBuffers
rateLimiters botRateLimiters
wsConn websocket.Handler
}
type botRateLimiters struct {
InstantMessage rateLimiter
ChannelPrivateMessage rateLimiter
}
type rateLimiter struct {
L *rate.RateLimiter
Enabled bool
}
type eventBuffers struct {
// receivers
Auth *swissknife.ChannelWorker
Contact *swissknife.ChannelWorker
ChannelLobby *swissknife.ChannelWorker
PrivateChannelLobby *swissknife.ChannelWorker
// senders
InstantMessages *swissknife.ChannelWorker
SendPrivateChannelMessage *swissknife.ChannelWorker
}
type ChatBotCallbacks struct {
// required
OnContactMessage func(structs.InstantMessage)
OnChannelMessage func(structs.WsChannelMessage)
OnPrivateChannelMessage func(structs.WsChannelMessage)
// optional
WelcomeMessage func(userPubkey string) string
}
type ChatBotData struct {
// required
Config utopiago.Config `json:"client"`
Chats []Chat `json:"chats"` // channel ids
Callbacks ChatBotCallbacks
// optional
SkipConnectionCheck bool `json:"skipConnCheck"`
Notifications string `json:"notifications"` // by default: all
UseErrorCallback bool `json:"useErrorCallback"`
EnableWsSSL bool `json:"enableSSL"` // SSL for websocket connection
BuffersCapacity EventBuffersCapacity `json:"buffersCapacity"`
RateLimiters EventBufferLimiters `json:"rateLimiters"`
DisableEvents bool `json:"disableEvents"`
ErrorCallback func(err error) `json:"-"`
}
// for limit max events per second
type EventBufferLimiters struct {
InstantMessages int `json:"instantMessages"`
ChannelPrivateMessages int `json:"channelPrivateMessages"`
}
type EventBuffersCapacity struct {
Auth int `json:"auth"`
ContactMessage int `json:"contactMessage"`
ChannelMessage int `json:"channelMessage"`
PrivateChannelMessage int `json:"privateChannelMessage"`
InstantMessages int `json:"instantMessages"`
}
type Chat struct {
// required
ID string `json:"id"`
// optional
Password string `json:"password"`
}