-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdMainCommand.go
More file actions
84 lines (73 loc) · 2.13 KB
/
Copy pathdMainCommand.go
File metadata and controls
84 lines (73 loc) · 2.13 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"github.com/bwmarrin/discordgo"
)
func dMainCommand(s *discordgo.Session, i *discordgo.InteractionCreate, cfg config) {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral,
},
})
embeds := []*discordgo.MessageEmbed{}
runningServers := ccGetRunningServers(cfg.Servers)
for _, v := range runningServers {
embeds = append(embeds, getServerEmbed(v))
}
embeds = append(embeds, &discordgo.MessageEmbed{
Title: func() string {
if len(embeds) > 0 {
return loc("selector.titleSwitch")
}
return loc("selector.title")
}(),
Description: loc("selector.desc"),
Footer: &discordgo.MessageEmbedFooter{
Text: fmt.Sprintf(loc("selector.count"), len(cfg.Servers)),
},
Color: hexToInt(loc("color.generic")),
})
s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Embeds: &embeds,
Components: bSingleComp(discordgo.SelectMenu{
MenuType: discordgo.StringSelectMenu,
CustomID: "serverSelect",
Placeholder: loc("selector.selectPlaceholder"),
Options: func() []discordgo.SelectMenuOption {
var options []discordgo.SelectMenuOption
for _, v := range cfg.Servers {
options = append(options, discordgo.SelectMenuOption{
Label: v.DisplayName,
Value: v.ServerID,
Emoji: bEmojiFromUrl(v.DisplayIcon, cfg.GuildId),
})
}
return options
}(),
}),
})
}
func getServerEmbed(v configServer) *discordgo.MessageEmbed {
onlineCount := ccGetPlayerCount(v)
var color int
if onlineCount >= 0 {
color = hexToInt(loc("color.success"))
} else {
color = hexToInt(loc("color.generic"))
}
return &discordgo.MessageEmbed{
Title: v.DisplayName,
Description: v.DisplayDesc,
Thumbnail: &discordgo.MessageEmbedThumbnail{URL: v.DisplayIcon},
Footer: &discordgo.MessageEmbedFooter{
Text: func() string {
if onlineCount < 0 {
return loc("pack.onlineCount.empty")
}
return fmt.Sprintf(loc("pack.onlineCount"), onlineCount)
}(),
},
Color: color,
}
}