-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
mqueue.go
93 lines (78 loc) · 2.21 KB
/
mqueue.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
package mqueue
import (
"net"
"net/http"
"time"
"github.com/mrbentarikau/pagst/bot"
"github.com/mrbentarikau/pagst/common"
"github.com/jonas747/discordgo/v2"
"github.com/sirupsen/logrus"
)
var (
sources = make(map[string]PluginWithSourceDisabler)
webhookSession *discordgo.Session
logger = common.GetPluginLogger(&Plugin{})
)
// PluginWithSourceDisabler
type PluginWithSourceDisabler interface {
DisableFeed(elem *QueuedElement, err error)
}
// PluginWithWebhookAvatar can be implemented by plugins for custom avatars
type PluginWithWebhookAvatar interface {
WebhookAvatar() string
}
var (
_ bot.LateBotInitHandler = (*Plugin)(nil)
_ bot.BotStopperHandler = (*Plugin)(nil)
)
// Plugin represents the mqueue plugin
type Plugin struct {
server *MqueueServer
}
// PluginInfo implements common.Plugin
func (p *Plugin) PluginInfo() *common.PluginInfo {
return &common.PluginInfo{
Name: "mqueue",
SysName: "mqueue",
Category: common.PluginCategoryCore,
}
}
// RegisterPlugin registers the mqueue plugin into the plugin system and also initializes it
func RegisterPlugin() {
var err error
webhookSession, err = discordgo.New()
if err != nil {
logger.WithError(err).Error("failed initiializing webhook session")
}
webhookSession.AddHandler(handleWebhookSessionRatelimit)
innerTransport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 10 * time.Second,
KeepAlive: 10 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 10,
IdleConnTimeout: 90 * time.Second,
MaxIdleConnsPerHost: 10,
TLSHandshakeTimeout: 5 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
webhookSession.Client.Transport = innerTransport
_, err = common.PQ.Exec(DBSchema)
if err != nil {
logrus.WithError(err).Error("[mqueue] failed initiializing db schema")
}
p := &Plugin{}
common.RegisterPlugin(p)
}
// RegisterSource registers a mqueue source, used for error handling
func RegisterSource(name string, source PluginWithSourceDisabler) {
sources[name] = source
}
type Storage interface {
GetFullQueue() ([]*workItem, error)
AppendItem(elem *QueuedElement) error
DelItem(elem *workItem) error
NextID() (int64, error)
}