2021-02-22 18:27:49 +00:00
|
|
|
package discord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
2021-05-05 03:24:39 +00:00
|
|
|
"git.birbmc.com/Etzelia/go-serverapi"
|
2021-02-22 18:27:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-02-23 05:53:55 +00:00
|
|
|
commands = append(commands, &command{
|
2021-02-22 18:27:49 +00:00
|
|
|
staffOnly: true,
|
2021-02-23 05:53:55 +00:00
|
|
|
name: "broadcast",
|
2021-02-22 18:27:49 +00:00
|
|
|
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",
|
2021-02-23 05:53:55 +00:00
|
|
|
})
|
2021-02-22 18:27:49 +00:00
|
|
|
}
|