forked from botlabs-gg/yagpdb
-
Notifications
You must be signed in to change notification settings - Fork 5
/
moderation.go
69 lines (55 loc) · 1.65 KB
/
moderation.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
package moderation
import (
"github.com/jonas747/discordgo"
"github.com/jonas747/yagpdb/common"
"github.com/jonas747/yagpdb/common/configstore"
"golang.org/x/net/context"
)
const (
ActionMuted = "Muted"
ActionUnMuted = "Unmuted"
ActionKicked = "Kicked"
ActionBanned = "Banned"
ActionUnbanned = "Unbanned"
ActionWarned = "Warned"
)
type Plugin struct{}
func (p *Plugin) Name() string {
return "Moderation"
}
func RedisKeyMutedUser(guildID, userID int64) string {
return "moderation_muted_user:" + discordgo.StrID(guildID) + ":" + discordgo.StrID(userID)
}
func RedisKeyBannedUser(guildID, userID int64) string {
return "moderation_banned_user:" + discordgo.StrID(guildID) + ":" + discordgo.StrID(userID)
}
func RedisKeyUnbannedUser(guildID, userID int64) string {
return "moderation_unbanned_user:" + discordgo.StrID(guildID) + ":" + discordgo.StrID(userID)
}
func RedisKeyLockedMute(guildID, userID int64) string {
return "moderation_updating_mute:" + discordgo.StrID(guildID) + ":" + discordgo.StrID(userID)
}
func RegisterPlugin() {
plugin := &Plugin{}
common.RegisterPlugin(plugin)
configstore.RegisterConfig(configstore.SQL, &Config{})
common.GORM.AutoMigrate(&Config{}, &WarningModel{}, &MuteModel{})
}
func getConfigIfNotSet(guildID int64, config *Config) (*Config, error) {
if config == nil {
var err error
config, err = GetConfig(guildID)
if err != nil {
return nil, err
}
}
return config, nil
}
func GetConfig(guildID int64) (*Config, error) {
var config Config
err := configstore.Cached.GetGuildConfig(context.Background(), guildID, &config)
if err == configstore.ErrNotFound {
err = nil
}
return &config, err
}