Added allowlist
This commit is contained in:
parent
27a400a720
commit
aa10576330
3 changed files with 31 additions and 14 deletions
|
@ -3,4 +3,6 @@ DISCORD_TOKEN=""
|
|||
OPENAI_API_KEY=""
|
||||
REPLICATE_API_TOKEN=""
|
||||
REDIS_HOST=""
|
||||
REDIS_PASSWORD=""
|
||||
REDIS_PASSWORD=""
|
||||
# Comma separated
|
||||
COOLDOWN_ALLOW_LIST=""
|
|
@ -1,6 +1,9 @@
|
|||
package lib
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/diamondburned/arikawa/v3/discord"
|
||||
)
|
||||
|
||||
|
@ -60,3 +63,22 @@ func GetUserObject(event discord.InteractionEvent) Userish {
|
|||
return directUser{event.User}
|
||||
}
|
||||
}
|
||||
|
||||
func CooldownHandler(event discord.InteractionEvent) bool {
|
||||
user := GetUserObject(event)
|
||||
allowList := strings.Split(os.Getenv("COOLDOWN_ALLOW_LIST"), ",")
|
||||
|
||||
// Check if the user ID is in the allowList
|
||||
for _, id := range allowList {
|
||||
if id == user.ID().String() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
cachedVal := GetCache(user.ID().String() + ":" + "hdpic")
|
||||
if cachedVal != "nil" {
|
||||
return false
|
||||
}
|
||||
SetCache(user.ID().String()+":"+"hdpic", user.ID().String()+":"+"hdpic", 10)
|
||||
return true
|
||||
}
|
||||
|
|
19
main.go
19
main.go
|
@ -132,13 +132,11 @@ func (h *handler) cmdPing(ctx context.Context, data cmdroute.CommandData) *api.I
|
|||
|
||||
func (h *handler) cmdAsk(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData {
|
||||
// Cooldown Logic
|
||||
user := lib.GetUserObject(*data.Event)
|
||||
allowed := lib.CooldownHandler(*data.Event)
|
||||
|
||||
cachedVal := lib.GetCache(user.ID().String() + ":" + "ask")
|
||||
if cachedVal != "nil" {
|
||||
if !allowed {
|
||||
return errorResponse(errors.New("please wait for the cooldown"))
|
||||
}
|
||||
lib.SetCache(user.ID().String()+":"+"ask", user.ID().String()+":"+"ask", 1)
|
||||
|
||||
// Command Logic
|
||||
var options struct {
|
||||
|
@ -180,14 +178,11 @@ func (h *handler) cmdAsk(ctx context.Context, data cmdroute.CommandData) *api.In
|
|||
|
||||
func (h *handler) cmdPic(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData {
|
||||
// Cooldown Logic
|
||||
user := lib.GetUserObject(*data.Event)
|
||||
allowed := lib.CooldownHandler(*data.Event)
|
||||
|
||||
cachedVal := lib.GetCache(user.ID().String() + ":" + "pic")
|
||||
if cachedVal != "nil" {
|
||||
if !allowed {
|
||||
return errorResponse(errors.New("please wait for the cooldown"))
|
||||
|
||||
}
|
||||
lib.SetCache(user.ID().String()+":"+"pic", user.ID().String()+":"+"pic", 1)
|
||||
|
||||
// Command Logic
|
||||
var options struct {
|
||||
|
@ -259,13 +254,11 @@ func (h *handler) cmdPic(ctx context.Context, data cmdroute.CommandData) *api.In
|
|||
|
||||
func (h *handler) cmdHDPic(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData {
|
||||
// Cooldown Logic
|
||||
user := lib.GetUserObject(*data.Event)
|
||||
allowed := lib.CooldownHandler(*data.Event)
|
||||
|
||||
cachedVal := lib.GetCache(user.ID().String() + ":" + "hdpic")
|
||||
if cachedVal != "nil" {
|
||||
if !allowed {
|
||||
return errorResponse(errors.New("please wait for the cooldown"))
|
||||
}
|
||||
lib.SetCache(user.ID().String()+":"+"hdpic", user.ID().String()+":"+"hdpic", 10)
|
||||
|
||||
// Command Logic
|
||||
var options struct {
|
||||
|
|
Loading…
Add table
Reference in a new issue