-
Notifications
You must be signed in to change notification settings - Fork 915
/
currentshard.go
63 lines (54 loc) · 1.59 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package currentshard
import (
"fmt"
"github.com/jonas747/dcmd/v4"
"github.com/jonas747/yagpdb/bot"
"github.com/jonas747/yagpdb/bot/botrest"
"github.com/jonas747/yagpdb/commands"
"github.com/jonas747/yagpdb/common"
)
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.BigInt, Default: int64(0)},
},
RunFunc: func(data *dcmd.Data) (interface{}, error) {
gID := data.GuildData.GS.ID
if data.Args[0].Int64() != 0 {
gID = data.Args[0].Int64()
}
totalShards := bot.ShardManager.GetNumShards()
shard := bot.GuildShardID(int64(totalShards), gID)
status := ""
if bot.ReadyTracker.IsGuildOnProcess(gID) {
session := bot.ShardManager.SessionForGuild(gID)
if session == nil {
return "Unknown shard...?", nil
}
status = session.GatewayManager.Status().String()
} else {
node, err := common.ServicePoller.GetShardNode(shard)
if err != nil {
status = "Unknown node... May not be running"
} else {
nodeStatus, err := botrest.GetNodeStatus(node.NodeID)
if err != nil {
status = "Failed querying status"
} else {
for _, v := range nodeStatus.Shards {
if v.ShardID == shard {
status = v.ConnStatus.String()
}
}
}
}
}
if status == "" {
status = "Unknown"
}
return fmt.Sprintf("`%d` on shard `%d` out of total `%d` shards, status: `%s`", gID, shard, totalShards, status), nil
},
}