-
Notifications
You must be signed in to change notification settings - Fork 921
/
stateinfo.go
63 lines (52 loc) · 1.96 KB
/
stateinfo.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
package stateinfo
import (
"fmt"
"github.com/jonas747/dcmd"
"github.com/jonas747/discordgo"
"github.com/jonas747/yagpdb/bot"
"github.com/jonas747/yagpdb/commands"
)
var Command = &commands.YAGCommand{
Cooldown: 2,
CmdCategory: commands.CategoryDebug,
Name: "stateinfo",
Description: "Responds with state debug info",
HideFromHelp: true,
RunFunc: cmdFuncStateInfo,
}
func cmdFuncStateInfo(data *dcmd.Data) (interface{}, error) {
totalGuilds := 0
totalMembers := 0
guildChannel := 0
totalMessages := 0
state := bot.State
state.RLock()
totalChannels := len(state.Channels)
totalGuilds = len(state.Guilds)
gCop := state.GuildsSlice(false)
state.RUnlock()
for _, g := range gCop {
g.RLock()
guildChannel += len(g.Channels)
totalMembers += len(g.Members)
for _, cState := range g.Channels {
totalMessages += len(cState.Messages)
}
g.RUnlock()
}
stats := bot.State.StateStats()
embed := &discordgo.MessageEmbed{
Title: "State size",
Fields: []*discordgo.MessageEmbedField{
&discordgo.MessageEmbedField{Name: "Guilds", Value: fmt.Sprint(totalGuilds), Inline: true},
&discordgo.MessageEmbedField{Name: "Members", Value: fmt.Sprintf("%d", totalMembers), Inline: true},
&discordgo.MessageEmbedField{Name: "Messages", Value: fmt.Sprintf("%d", totalMessages), Inline: true},
&discordgo.MessageEmbedField{Name: "Guild Channels", Value: fmt.Sprintf("%d", guildChannel), Inline: true},
&discordgo.MessageEmbedField{Name: "Total Channels", Value: fmt.Sprintf("%d", totalChannels), Inline: true},
&discordgo.MessageEmbedField{Name: "Cache Hits/Misses", Value: fmt.Sprintf("%d - %d", stats.CacheHits, stats.CacheMisses), Inline: true},
&discordgo.MessageEmbedField{Name: "Last GC Members Evicted", Value: fmt.Sprintf("%d", stats.MembersRemovedLastGC), Inline: true},
&discordgo.MessageEmbedField{Name: "Last GC Cache Evicted", Value: fmt.Sprintf("%d", stats.UserCachceEvictedLastGC), Inline: true},
},
}
return embed, nil
}