forked from botlabs-gg/yagpdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
currentshard.go
43 lines (35 loc) · 1.07 KB
/
currentshard.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
package currentshard
import (
"fmt"
"github.com/jonas747/dcmd"
"github.com/jonas747/yagpdb/bot"
"github.com/jonas747/yagpdb/commands"
)
var Command = &commands.YAGCommand{
CmdCategory: commands.CategoryDebug,
Name: "CurrentShard",
Aliases: []string{"cshard"},
Description: "Shows the current shard this server is on (or the one specified",
Arguments: []*dcmd.ArgDef{
&dcmd.ArgDef{Name: "serverid", Type: dcmd.Int, Default: int64(0)},
},
RunFunc: func(data *dcmd.Data) (interface{}, error) {
gID := data.GS.ID
if data.Args[0].Int64() != 0 {
gID = data.Args[0].Int64()
}
shard := bot.GuildShardID(gID)
totalShards := bot.GetTotalShards()
status := ""
if bot.IsGuildOnCurrentProcess(gID) {
session := bot.ShardManager.SessionForGuild(gID)
if session == nil {
return "Unknown shard...?", nil
}
status = session.GatewayManager.Status().String()
} else {
status = "unknown (on another node than this one)"
}
return fmt.Sprintf("`%d` on shard `%d` out of total `%d` shards, status: `%s`", gID, shard, totalShards, status), nil
},
}