2021-02-22 18:27:49 +00:00
|
|
|
package discord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"go.etztech.xyz/go-serverapi"
|
|
|
|
)
|
|
|
|
|
|
|
|
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: "ban",
|
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 an in-game username.", nil
|
|
|
|
}
|
|
|
|
target := args[1]
|
|
|
|
reason := "You have been banned. Appeal at https://birbmc.com/appeal"
|
|
|
|
if len(args) >= 3 {
|
|
|
|
reason = fmt.Sprintf("%s. Appeal at https://birbmc.com/appeal", strings.Join(args[2:], " "))
|
|
|
|
}
|
|
|
|
|
|
|
|
ban := serverapi.Ban{
|
|
|
|
Kick: serverapi.Kick{
|
|
|
|
Unban: serverapi.Unban{
|
|
|
|
Target: target,
|
|
|
|
},
|
|
|
|
Reason: reason,
|
|
|
|
},
|
|
|
|
Source: "Discord",
|
|
|
|
Created: time.Now().Unix(),
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := cmd.sapiClient.Ban(ban)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
if status != http.StatusOK {
|
|
|
|
return fmt.Sprintf("ServerAPI returned status %d when trying to ban %s", status, target), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s was banned by %s", target, cmd.message.Author.Username), nil
|
|
|
|
},
|
|
|
|
help: "Ban a player",
|
2021-02-23 05:53:55 +00:00
|
|
|
})
|
2021-02-22 18:27:49 +00:00
|
|
|
}
|