2020-08-06 20:07:32 +00:00
|
|
|
package discord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2021-05-05 03:24:39 +00:00
|
|
|
"gitea.com/jolheiser/gojang/query"
|
2020-08-06 20:07:32 +00:00
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-02-23 05:53:55 +00:00
|
|
|
commands = append(commands, &command{
|
|
|
|
name: "status",
|
|
|
|
aliases: []string{"version", "online"},
|
2020-08-06 20:07:32 +00:00
|
|
|
validate: func(cmd commandInit) bool {
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
run: func(cmd commandInit) (string, error) {
|
|
|
|
server := query.NewServer(cmd.config.Server.Address, cmd.config.Server.Port)
|
|
|
|
|
2021-05-05 03:24:39 +00:00
|
|
|
q, err := server.Query(query.DefaultTimeout, query.DefaultDeadline)
|
2020-08-06 20:07:32 +00:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
{
|
2021-01-20 22:13:30 +00:00
|
|
|
Name: "~~Players~~ Birbs Online",
|
2020-08-06 20:07:32 +00:00
|
|
|
Value: fmt.Sprintf("%d / %d", q.CurrentPlayers, q.MaxPlayers),
|
|
|
|
Inline: true,
|
|
|
|
},
|
|
|
|
{
|
2021-01-20 22:13:30 +00:00
|
|
|
Name: "~~Players~~ Birbs",
|
2020-08-06 20:07:32 +00:00
|
|
|
Value: strings.Join(q.Players, ", "),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
sendEmbed(cmd.session, cmd.message.ChannelID, embed)
|
|
|
|
return "", nil
|
|
|
|
},
|
|
|
|
help: "Get the server status",
|
2021-02-23 05:53:55 +00:00
|
|
|
})
|
2020-08-06 20:07:32 +00:00
|
|
|
}
|