canopeas/discord/unban.go

42 lines
1007 B
Go
Raw Normal View History

package discord
import (
"fmt"
"strconv"
"strings"
"time"
"git.birbmc.com/canopeas/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",
})
}