-
Notifications
You must be signed in to change notification settings - Fork 911
/
plugin.go
59 lines (49 loc) · 1.35 KB
/
plugin.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
package bot
import (
"github.com/jonas747/discordgo"
"github.com/jonas747/yagpdb/common"
"github.com/mediocregopher/radix.v2/redis"
"github.com/sirupsen/logrus"
"sync"
)
const (
// How long after removing a guild the config for it gets cleared
GuildRemoveConfigExpire = 60 * 60 * 24 // <- 1 day
)
type Plugin interface {
// Called when the plugin is supposed to be initialized
// That is add comnands, discord event handlers
InitBot()
Name() string
}
// Used for deleting configuration about servers
type RemoveGuildHandler interface {
RemoveGuild(client *redis.Client, guildID int64) error
}
// Used for intializing stuff for new servers
type NewGuildHandler interface {
NewGuild(client *redis.Client, guild *discordgo.Guild) error
}
// Fired when the bot it starting up, not for the webserver
type BotStarterHandler interface {
StartBot()
}
// Fired after the bot has connected all shards
type BotStartedHandler interface {
BotStarted()
}
type BotStopperHandler interface {
StopBot(wg *sync.WaitGroup)
}
func EmitGuildRemoved(guildID int64) {
client := common.MustGetRedisClient()
defer common.RedisPool.Put(client)
for _, v := range common.Plugins {
if remover, ok := v.(RemoveGuildHandler); ok {
err := remover.RemoveGuild(client, guildID)
if err != nil {
logrus.WithError(err).Error("Error Running RemoveGuild on ", v.Name())
}
}
}
}