canopeas/discord/broadcast.go

43 lines
957 B
Go
Raw Permalink Normal View History

package discord
import (
"fmt"
"net/http"
"strings"
"git.jojodev.com/Minecraft/go-serverapi"
)
func init() {
commands = append(commands, &command{
staffOnly: true,
name: "broadcast",
validate: func(cmd commandInit) bool {
return isStaff(cmd.message.Member.Roles, cmd.config.StaffRoles)
},
run: func(cmd commandInit) (string, error) {
args := strings.Fields(cmd.message.Content)
if len(args) < 2 {
return "This command requires a message to broadcast", nil
}
message := strings.Join(args[1:], " ")
broadcast := serverapi.Broadcast{
From: cmd.message.Author.Username,
Message: message,
}
status, err := cmd.sapiClient.Broadcast(broadcast)
if err != nil {
return "", err
}
if status != http.StatusOK {
return fmt.Sprintf("ServerAPI returned status %d when trying to broadcast.", status), nil
}
return "Broadcast sent!", nil
},
help: "Send an in-game broadcast",
})
}