canopeas/discord/unban.go

42 lines
1005 B
Go

package discord
import (
"fmt"
"strconv"
"strings"
"time"
"go.etztech.xyz/sedbot/database"
)
func init() {
commands = append(commands, &command{
staffOnly: true,
name: "unban",
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) < 3 {
return "This command requires an in-game username and number of days (use 0 days to unban on next schedule).", nil
}
days, err := strconv.Atoi(args[2])
if err != nil {
return "number of days must be an integer", nil
}
target := args[1]
expiration := time.Now().Add(time.Hour * 24 * time.Duration(days))
record := database.UnbanRecord{
Username: target,
Expiration: expiration,
}
return fmt.Sprintf("%s will be unbanned on %s", target, record.ExpirationString()),
cmd.database.AddUnban(record)
},
help: "Unban a player",
})
}