-
Notifications
You must be signed in to change notification settings - Fork 927
/
analytics.go
54 lines (42 loc) · 1.5 KB
/
analytics.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
package analytics
import (
"sync"
"github.com/jonas747/yagpdb/common"
"github.com/jonas747/yagpdb/common/config"
"github.com/mediocregopher/radix/v3"
)
var logger = common.GetPluginLogger(&Plugin{})
type Plugin struct {
stopWorkers chan *sync.WaitGroup
}
func (p *Plugin) PluginInfo() *common.PluginInfo {
return &common.PluginInfo{
Name: "analytics",
SysName: "analytics",
Category: common.PluginCategoryCore,
}
}
func RegisterPlugin() {
common.RegisterPlugin(&Plugin{
stopWorkers: make(chan *sync.WaitGroup),
})
common.InitSchemas("analytics", dbSchemas...)
}
func RecordActiveUnit(guildID int64, plugin common.Plugin, analyticName string) {
err := recordActiveUnit(guildID, plugin, analyticName)
if err != nil {
logger.WithError(err).WithField("guild", guildID).WithField("plugin", plugin.PluginInfo().SysName).WithField("analytic", analyticName).Error("Failed updating analytic in redis")
}
}
var confEnableAnalytics = config.RegisterOption("yagpdb.enable_analytics", "Enable usage analytics tracking", false)
func recordActiveUnit(guildID int64, plugin common.Plugin, analyticName string) error {
if !confEnableAnalytics.GetBool() {
return nil
}
err := common.RedisPool.Do(radix.FlatCmd(nil, "HINCRBY", "anaylytics_active_units."+plugin.PluginInfo().SysName+"."+analyticName, guildID, 1))
if err != nil {
return err
}
// logger.Debug("Incrementing analytic " + plugin.PluginInfo().SysName + "." + analyticName)
return nil
}