canopeas/discord/status.go

52 lines
1.2 KiB
Go

package discord
import (
"fmt"
"strings"
"github.com/bwmarrin/discordgo"
"go.jolheiser.com/gojang/query"
)
func init() {
commands = append(commands, &command{
name: "status",
aliases: []string{"version", "online"},
validate: func(cmd commandInit) bool {
return true
},
run: func(cmd commandInit) (string, error) {
server := query.NewServer(cmd.config.Server.Address, cmd.config.Server.Port)
q, err := server.Query(query.DefaultTimeout)
if err != nil {
return "", err
}
embed := &discordgo.MessageEmbed{
Title: fmt.Sprintf("Server Status for `%s`", cmd.config.Server.Address),
Description: q.MOTD,
Fields: []*discordgo.MessageEmbedField{
{
Name: "Version",
Value: fmt.Sprintf("%s %s", q.ServerMod.Name, q.Version),
Inline: true,
},
{
Name: "~~Players~~ Birbs Online",
Value: fmt.Sprintf("%d / %d", q.CurrentPlayers, q.MaxPlayers),
Inline: true,
},
{
Name: "~~Players~~ Birbs",
Value: strings.Join(q.Players, ", "),
},
},
}
sendEmbed(cmd.session, cmd.message.ChannelID, embed)
return "", nil
},
help: "Get the server status",
})
}