-
Notifications
You must be signed in to change notification settings - Fork 919
/
plugin_bot.go
45 lines (34 loc) · 1.01 KB
/
plugin_bot.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
package premium
import (
"time"
"github.com/jonas747/dstate"
"github.com/jonas747/yagpdb/bot"
"github.com/jonas747/yagpdb/commands"
)
var _ bot.BotInitHandler = (*Plugin)(nil)
var _ commands.CommandProvider = (*Plugin)(nil)
func (p *Plugin) BotInit() {
bot.State.CustomLimitProvider = p
}
func (p *Plugin) AddCommands() {
commands.AddRootCommands(cmdGenerateCode)
}
const (
NormalStateMaxMessages = 1000
NormalStateMaxMessageAge = time.Hour
PremiumStateMaxMessags = 10000
PremiumStateMaxMessageAge = time.Hour * 12
)
func (p *Plugin) MessageLimits(cs *dstate.ChannelState) (maxMessages int, maxMessageAge time.Duration) {
if cs.Guild == nil {
return NormalStateMaxMessages, NormalStateMaxMessageAge
}
premium, err := IsGuildPremiumCached(cs.Guild.ID)
if err != nil {
logger.WithError(err).WithField("guild", cs.Guild.ID).Error("Failed checking if guild is premium")
}
if premium {
return PremiumStateMaxMessags, PremiumStateMaxMessageAge
}
return NormalStateMaxMessages, NormalStateMaxMessageAge
}