forked from botlabs-gg/yagpdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.go
64 lines (53 loc) · 1.55 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
60
61
62
63
64
package bot
import (
"github.com/jonas747/discordgo"
"github.com/jonas747/dshardorchestrator"
"github.com/jonas747/dstate"
"github.com/jonas747/yagpdb/common"
"github.com/sirupsen/logrus"
"sync"
)
const (
// How long after removing a guild the config for it gets cleared
GuildRemoveConfigExpire = 60 * 60 * 24 // <- 1 day
)
// Used for deleting configuration about servers
type RemoveGuildHandler interface {
RemoveGuild(guildID int64) error
}
// Used for intializing stuff for new servers
type NewGuildHandler interface {
NewGuild(guild *discordgo.Guild) error
}
// Fired when the bot it starting up, not for the webserver
type BotInitHandler interface {
BotInit()
}
// Fired when the bot it starting up, after BotInit
type LateBotInitHandler interface {
LateBotInit()
}
// BotStopperHandler runs when the bot is shuttdown down
// you need to call wg.Done when you have completed your plugin shutdown (stopped background workers)
type BotStopperHandler interface {
StopBot(wg *sync.WaitGroup)
}
type ShardMigrationHandler interface {
GuildMigrated(guild *dstate.GuildState, toThisSlave bool)
}
func EmitGuildRemoved(guildID int64) {
for _, v := range common.Plugins {
if remover, ok := v.(RemoveGuildHandler); ok {
err := remover.RemoveGuild(guildID)
if err != nil {
logrus.WithError(err).Error("Error Running RemoveGuild on ", v.Name())
}
}
}
}
type ShardMigrationSender interface {
ShardMigrationSend(shard int) int
}
type ShardMigrationReceiver interface {
ShardMigrationReceive(evt dshardorchestrator.EventType, data interface{})
}