forked from botlabs-gg/yagpdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_bot.go
46 lines (36 loc) · 1.05 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
46
package premium
import (
"github.com/jonas747/dstate"
"github.com/jonas747/yagpdb/bot"
"github.com/jonas747/yagpdb/commands"
"github.com/sirupsen/logrus"
"time"
)
var _ bot.BotInitHandler = (*Plugin)(nil)
var _ commands.CommandProvider = (*Plugin)(nil)
func (p *Plugin) BotInit() {
go runMonitor()
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 := IsGuildPremium(cs.Guild.ID)
if err != nil {
logrus.WithError(err).WithField("guild", cs.Guild.ID).Error("Failed checking if guild is premium")
}
if premium {
return PremiumStateMaxMessags, PremiumStateMaxMessageAge
}
return NormalStateMaxMessages, NormalStateMaxMessageAge
}