package discord import ( "fmt" "net/http" "strings" "time" "git.jojodev.com/Minecraft/go-serverapi" ) func init() { commands = append(commands, &command{ staffOnly: true, name: "ban", 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", }) }