Fixed cooldown logic
This commit is contained in:
parent
aa0e484dce
commit
6a30ccc662
4 changed files with 7 additions and 5 deletions
2
go.mod
2
go.mod
|
@ -19,6 +19,6 @@ require (
|
||||||
github.com/mediocregopher/radix/v4 v4.1.4
|
github.com/mediocregopher/radix/v4 v4.1.4
|
||||||
github.com/redis/go-redis/v9 v9.3.1
|
github.com/redis/go-redis/v9 v9.3.1
|
||||||
github.com/replicate/replicate-go v0.14.2
|
github.com/replicate/replicate-go v0.14.2
|
||||||
github.com/sashabaranov/go-openai v1.17.9
|
github.com/sashabaranov/go-openai v1.17.10
|
||||||
golang.org/x/time v0.5.0 // indirect
|
golang.org/x/time v0.5.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -24,6 +24,8 @@ github.com/replicate/replicate-go v0.14.2 h1:XgK+REvYrWs7qDeyugxHA93h31qBhEFk/3p
|
||||||
github.com/replicate/replicate-go v0.14.2/go.mod h1:otIrl1vDmyjNhTzmVmp/mQU3Wt1+3387gFNEsAZq0ig=
|
github.com/replicate/replicate-go v0.14.2/go.mod h1:otIrl1vDmyjNhTzmVmp/mQU3Wt1+3387gFNEsAZq0ig=
|
||||||
github.com/sashabaranov/go-openai v1.17.9 h1:QEoBiGKWW68W79YIfXWEFZ7l5cEgZBV4/Ow3uy+5hNY=
|
github.com/sashabaranov/go-openai v1.17.9 h1:QEoBiGKWW68W79YIfXWEFZ7l5cEgZBV4/Ow3uy+5hNY=
|
||||||
github.com/sashabaranov/go-openai v1.17.9/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
|
github.com/sashabaranov/go-openai v1.17.9/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
|
||||||
|
github.com/sashabaranov/go-openai v1.17.10 h1:ybvWN+d/rgEK/64U6dsjnOQ9AUya2wBoJKj3Wuaonqo=
|
||||||
|
github.com/sashabaranov/go-openai v1.17.10/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/tilinna/clock v1.0.2 h1:6BO2tyAC9JbPExKH/z9zl44FLu1lImh3nDNKA0kgrkI=
|
github.com/tilinna/clock v1.0.2 h1:6BO2tyAC9JbPExKH/z9zl44FLu1lImh3nDNKA0kgrkI=
|
||||||
github.com/tilinna/clock v1.0.2/go.mod h1:ZsP7BcY7sEEz7ktc0IVy8Us6boDrK8VradlKRUGfOao=
|
github.com/tilinna/clock v1.0.2/go.mod h1:ZsP7BcY7sEEz7ktc0IVy8Us6boDrK8VradlKRUGfOao=
|
||||||
|
|
|
@ -64,7 +64,7 @@ func GetUserObject(event discord.InteractionEvent) Userish {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CooldownHandler(event discord.InteractionEvent) bool {
|
func CooldownHandler(event discord.InteractionEvent, command string, cooldownMinutes int64) bool {
|
||||||
user := GetUserObject(event)
|
user := GetUserObject(event)
|
||||||
allowList := strings.Split(os.Getenv("COOLDOWN_ALLOW_LIST"), ",")
|
allowList := strings.Split(os.Getenv("COOLDOWN_ALLOW_LIST"), ",")
|
||||||
|
|
||||||
|
|
6
main.go
6
main.go
|
@ -132,7 +132,7 @@ func (h *handler) cmdPing(ctx context.Context, data cmdroute.CommandData) *api.I
|
||||||
|
|
||||||
func (h *handler) cmdAsk(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData {
|
func (h *handler) cmdAsk(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData {
|
||||||
// Cooldown Logic
|
// Cooldown Logic
|
||||||
allowed := lib.CooldownHandler(*data.Event)
|
allowed := lib.CooldownHandler(*data.Event, "ask", 1)
|
||||||
|
|
||||||
if !allowed {
|
if !allowed {
|
||||||
return errorResponse(errors.New("please wait for the cooldown"))
|
return errorResponse(errors.New("please wait for the cooldown"))
|
||||||
|
@ -194,7 +194,7 @@ func (h *handler) cmdAsk(ctx context.Context, data cmdroute.CommandData) *api.In
|
||||||
|
|
||||||
func (h *handler) cmdPic(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData {
|
func (h *handler) cmdPic(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData {
|
||||||
// Cooldown Logic
|
// Cooldown Logic
|
||||||
allowed := lib.CooldownHandler(*data.Event)
|
allowed := lib.CooldownHandler(*data.Event, "pic", 1)
|
||||||
|
|
||||||
if !allowed {
|
if !allowed {
|
||||||
return errorResponse(errors.New("please wait for the cooldown"))
|
return errorResponse(errors.New("please wait for the cooldown"))
|
||||||
|
@ -270,7 +270,7 @@ func (h *handler) cmdPic(ctx context.Context, data cmdroute.CommandData) *api.In
|
||||||
|
|
||||||
func (h *handler) cmdHDPic(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData {
|
func (h *handler) cmdHDPic(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData {
|
||||||
// Cooldown Logic
|
// Cooldown Logic
|
||||||
allowed := lib.CooldownHandler(*data.Event)
|
allowed := lib.CooldownHandler(*data.Event, "hdPic", 1)
|
||||||
|
|
||||||
if !allowed {
|
if !allowed {
|
||||||
return errorResponse(errors.New("please wait for the cooldown"))
|
return errorResponse(errors.New("please wait for the cooldown"))
|
||||||
|
|
Loading…
Add table
Reference in a new issue