diff --git a/config/config.go b/config/config.go index 3a4a1e5..1198b1a 100644 --- a/config/config.go +++ b/config/config.go @@ -10,12 +10,18 @@ import ( var defaultConfig = []byte("") type Config struct { - Token string `toml:"token"` - Prefix string `toml:"prefix"` - MCMToken string `toml:"mcm_token"` - MCMURL string `toml:"mcm_url"` - DBPath string `toml:"db_path"` - MCPath string `toml:"mc_path"` + Token string `toml:"token"` + Prefix string `toml:"prefix"` + MCM struct { + 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"` + MCPath string `toml:"mc_path"` StaffRoles []string `toml:"staff_roles"` Echoes []Echo `toml:"echoes"` diff --git a/discord/register.go b/discord/register.go index 6d4c7a4..4bac30a 100644 --- a/discord/register.go +++ b/discord/register.go @@ -30,7 +30,7 @@ func init() { 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() players, err := models.Player(models.NewDjangoBuilder().IExact(django.PlayerUsername, username)) diff --git a/discord/status.go b/discord/status.go new file mode 100644 index 0000000..d7d3e73 --- /dev/null +++ b/discord/status.go @@ -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 +} diff --git a/go.mod b/go.mod index 1da66bc..69cbd96 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( go.etztech.xyz/go-mcm v1.3.0 go.etztech.xyz/inspiro v0.0.0-20200606185551-edfdf9da2359 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/sys v0.0.0-20200625212154-ddb9806d33ae // indirect ) diff --git a/go.sum b/go.sum index 0ed717f..2e1439d 100644 --- a/go.sum +++ b/go.sum @@ -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.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/gojang v0.0.1 h1:hK4ELqfY+FFNjf/juU0nszxV/fbdlNl1guyJRS3LETs= -go.jolheiser.com/gojang v0.0.1/go.mod h1:hUBULFDoampNM97E1IaYUhkLBJ30sb7iGsoFOdDU76I= +go.jolheiser.com/gojang v0.0.2 h1:CvQETKT9sFfvuDeYVUkiR0Jh7xIs7Cayi0rZuDrXoZg= +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/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/sedbot.example.toml b/sedbot.example.toml index 0b7d594..8297124 100644 --- a/sedbot.example.toml +++ b/sedbot.example.toml @@ -4,12 +4,6 @@ token = "" # prefix is the bot command 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 = "sedbot.db" @@ -31,6 +25,20 @@ staff_roles = [] # meme_rate is the rate limit for memes 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 # , your looks like , you [insult]