Add status command (#11)

Add status command

Signed-off-by: Etzelia <etzelia@hotmail.com>

Reviewed-on: https://git.etztech.xyz/Etzelia/sedbot/pulls/11
fix-app
Etzelia 2020-08-06 22:07:32 +02:00
parent 1683cc6214
commit ff397f14e6
6 changed files with 84 additions and 16 deletions

View File

@ -12,8 +12,14 @@ var defaultConfig = []byte("")
type Config struct { type Config struct {
Token string `toml:"token"` Token string `toml:"token"`
Prefix string `toml:"prefix"` Prefix string `toml:"prefix"`
MCMToken string `toml:"mcm_token"` MCM struct {
MCMURL string `toml:"mcm_url"` Token string `toml:"token"`
URL string `toml:"url"`
} `toml:"mcm"`
Server struct {
Address string `toml:"address"`
Port int `toml:"port"`
} `toml:"server"`
DBPath string `toml:"db_path"` DBPath string `toml:"db_path"`
MCPath string `toml:"mc_path"` MCPath string `toml:"mc_path"`

View File

@ -30,7 +30,7 @@ func init() {
sendTyping(cmd.session, cmd.message.ChannelID) sendTyping(cmd.session, cmd.message.ChannelID)
manager := mcm.NewMCM(cmd.config.MCMToken, cmd.config.MCMURL) manager := mcm.NewMCM(cmd.config.MCM.Token, cmd.config.MCM.URL)
models := manager.NewModel() models := manager.NewModel()
players, err := models.Player(models.NewDjangoBuilder().IExact(django.PlayerUsername, username)) players, err := models.Player(models.NewDjangoBuilder().IExact(django.PlayerUsername, username))

54
discord/status.go 100644
View File

@ -0,0 +1,54 @@
package discord
import (
"fmt"
"strings"
"github.com/bwmarrin/discordgo"
"go.jolheiser.com/gojang/query"
)
func init() {
cmd := command{
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{
Color: 0x007D96,
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: "Player's Online",
Value: fmt.Sprintf("%d / %d", q.CurrentPlayers, q.MaxPlayers),
Inline: true,
},
{
Name: "Players",
Value: strings.Join(q.Players, ", "),
},
},
}
sendEmbed(cmd.session, cmd.message.ChannelID, embed)
return "", nil
},
help: "Get the server status",
}
commands["status"] = cmd
commands["version"] = cmd
commands["online"] = cmd
}

2
go.mod
View File

@ -10,7 +10,7 @@ require (
go.etztech.xyz/go-mcm v1.3.0 go.etztech.xyz/go-mcm v1.3.0
go.etztech.xyz/inspiro v0.0.0-20200606185551-edfdf9da2359 go.etztech.xyz/inspiro v0.0.0-20200606185551-edfdf9da2359
go.jolheiser.com/beaver v1.0.2 go.jolheiser.com/beaver v1.0.2
go.jolheiser.com/gojang v0.0.1 go.jolheiser.com/gojang v0.0.2
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
) )

4
go.sum
View File

@ -14,8 +14,8 @@ go.etztech.xyz/inspiro v0.0.0-20200606185551-edfdf9da2359 h1:j/ZeoAj185wHfCSYD52
go.etztech.xyz/inspiro v0.0.0-20200606185551-edfdf9da2359/go.mod h1:+fC1WzJm/oS4UEgqr1jPouWerxBys52lTTDA94/5bf8= go.etztech.xyz/inspiro v0.0.0-20200606185551-edfdf9da2359/go.mod h1:+fC1WzJm/oS4UEgqr1jPouWerxBys52lTTDA94/5bf8=
go.jolheiser.com/beaver v1.0.2 h1:KA2D6iO8MQhZi1nZYi/Chak/f1Cxfrs6b1XO623+Khk= go.jolheiser.com/beaver v1.0.2 h1:KA2D6iO8MQhZi1nZYi/Chak/f1Cxfrs6b1XO623+Khk=
go.jolheiser.com/beaver v1.0.2/go.mod h1:7X4F5+XOGSC3LejTShoBdqtRCnPWcnRgmYGmG3EKW8g= go.jolheiser.com/beaver v1.0.2/go.mod h1:7X4F5+XOGSC3LejTShoBdqtRCnPWcnRgmYGmG3EKW8g=
go.jolheiser.com/gojang v0.0.1 h1:hK4ELqfY+FFNjf/juU0nszxV/fbdlNl1guyJRS3LETs= go.jolheiser.com/gojang v0.0.2 h1:CvQETKT9sFfvuDeYVUkiR0Jh7xIs7Cayi0rZuDrXoZg=
go.jolheiser.com/gojang v0.0.1/go.mod h1:hUBULFDoampNM97E1IaYUhkLBJ30sb7iGsoFOdDU76I= go.jolheiser.com/gojang v0.0.2/go.mod h1:hUBULFDoampNM97E1IaYUhkLBJ30sb7iGsoFOdDU76I=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

View File

@ -4,12 +4,6 @@ token = ""
# prefix is the bot command prefix # prefix is the bot command prefix
prefix = "!" prefix = "!"
# mcm_token is the token for the MCM API
mcm_token = ""
# mcm_url is the base URL to the MCM API
mcm_url = ""
# db_path is the path to the database (default is next to binary) # db_path is the path to the database (default is next to binary)
db_path = "sedbot.db" db_path = "sedbot.db"
@ -31,6 +25,20 @@ staff_roles = []
# meme_rate is the rate limit for memes # meme_rate is the rate limit for memes
meme_rate = "0" meme_rate = "0"
# Server options
[server]
# connection address
address = ""
# connection port
port = 25565
# MCM options
[mcm]
# the token for the MCM API
token = ""
# the base URL to the MCM API
url = ""
# insults # insults
# <args>, your <target> looks like <comparison>, you <adjective> <noun> # <args>, your <target> looks like <comparison>, you <adjective> <noun>
[insult] [insult]