-
Notifications
You must be signed in to change notification settings - Fork 927
/
safebrowsing.go
49 lines (38 loc) · 978 Bytes
/
safebrowsing.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
package safebrowsing
import (
"github.com/jonas747/yagpdb/common"
"github.com/jonas747/yagpdb/common/backgroundworkers"
"goji.io/pat"
"net/http"
"sync"
)
var _ backgroundworkers.BackgroundWorkerPlugin = (*Plugin)(nil)
type Plugin struct {
}
var logger = common.GetPluginLogger(&Plugin{})
func RegisterPlugin() {
common.RegisterPlugin(&Plugin{})
}
func (p *Plugin) PluginInfo() *common.PluginInfo {
return &common.PluginInfo{
Name: "SafeBrowsing",
SysName: "safe_browsing",
Category: common.PluginCategoryModeration,
}
}
func (p *Plugin) RunBackgroundWorker() {
if SafeBrowser == nil {
err := runDatabase()
if err != nil {
logger.WithError(err).Error("failed starting database")
return
}
}
backgroundworkers.RESTServerMuxer.Handle(pat.Post("/safebroswing/checkmessage"), http.HandlerFunc(handleCheckMessage))
}
func (p *Plugin) StopBackgroundWorker(wg *sync.WaitGroup) {
if SafeBrowser != nil {
SafeBrowser.Close()
}
wg.Done()
}