Skip to content

Commit

Permalink
Multiple game server embeds and fixed minecrafts name
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaprit committed Apr 23, 2022
1 parent a508759 commit a41fa60
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/Config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Server struct {
Port int `toml:"port"`
Colour int `toml:"colour"`
PublicHostname string `toml:"public_hostname"`
ShowMap bool `toml:"show_map"`
HideMap bool `toml:"hide_map"`
ChannelID string `toml:"channel"`
Country string `toml:"country"`
SteamID string `toml:"steamid"`
Expand Down
4 changes: 3 additions & 1 deletion config/PrettyGameNames.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ func GetGameNames() {
for _, line := range strings.Split(string(gameNames), "\n") {
if len(line) > 0 && !strings.HasPrefix(line, "#") {
parts := strings.Split(line, "|")
PrettyGameNames[parts[0]] = parts[1]
for _, altNames := range strings.Split(parts[0], ",") {
PrettyGameNames[strings.ToLower(altNames)] = parts[1]
}
}
}

Expand Down
38 changes: 31 additions & 7 deletions discord/ServerStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ var goGSMEmbedFooter = discordgo.MessageEmbedFooter{
Text: "GoGSM 1.0",
}

func cacheContainsMessageID(id string) bool {
for _, v := range config.GlobalCache.Items() {
switch v.Object.(type) {
case string:
if v.Object.(string) == id {
return true
}
default:
continue
}
}
return false
}

// RefreshServerStatus refreshes the status embeds for all servers
// TODO: This is too monolithic. It should be broken up into smaller functions
func RefreshServerStatus(s *discordgo.Session) {
Expand Down Expand Up @@ -61,6 +75,9 @@ func RefreshServerStatus(s *discordgo.Session) {
if message, ok := config.GlobalCache.Get(name); ok {
messageToEdit = message.(string)
} else {
if cacheContainsMessageID(i2.ID) {
continue
}
err := s.ChannelMessageDelete(server.ChannelID, i2.ID)
if err != nil {
log.Println("Error deleting message:", err)
Expand All @@ -83,9 +100,15 @@ func RefreshServerStatus(s *discordgo.Session) {
game = prettyGame
}

// TODO: This is really hacky but minecraft has forced me to do this
serverName := resp.Name
if serverName[0] == 239 {
serverName = resp.Name[4:]
}

embedFields = append(embedFields, &discordgo.MessageEmbedField{
Name: "Name",
Value: resp.Name,
Value: serverName,
Inline: true,
})
embedFields = append(embedFields, &discordgo.MessageEmbedField{
Expand All @@ -101,12 +124,13 @@ func RefreshServerStatus(s *discordgo.Session) {
Value: strconv.Itoa(len(resp.Players)) + "/" + maxPlayers,
Inline: true,
})
embedFields = append(embedFields, &discordgo.MessageEmbedField{
Name: "Map",
Value: "`" + resp.Map + "`",
Inline: true,
})

if !server.HideMap {
embedFields = append(embedFields, &discordgo.MessageEmbedField{
Name: "Map",
Value: "`" + resp.Map + "`",
Inline: true,
})
}
embedFields = append(embedFields, &spacer)

hostname := server.Hostname
Expand Down

0 comments on commit a41fa60

Please sign in to comment.