Cooldown Logic is now distributed

This commit is contained in:
2023-12-27 12:47:14 -07:00
parent 53c81941db
commit f75db108a7
5 changed files with 89 additions and 4 deletions

32
main.go
View File

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"himbot/lib"
"io"
"log"
"net/http"
@ -122,12 +123,23 @@ func newHandler(s *state.State) *handler {
}
func (h *handler) cmdPing(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData {
// Command Logic
return &api.InteractionResponseData{
Content: option.NewNullableString("Pong!"),
}
}
func (h *handler) cmdAsk(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData {
// Cooldown Logic
cachedVal := lib.GetCache(data.Event.User.ID.String() + ":" + "ask")
if cachedVal != "nil" {
return &api.InteractionResponseData{
Content: option.NewNullableString("Please wait for the cooldown!"),
}
}
lib.SetCache(data.Event.User.ID.String()+":"+"ask", data.Event.User.ID.String()+":"+"ask", 1)
// Command Logic
var options struct {
Arg string `discord:"prompt"`
}
@ -166,6 +178,16 @@ 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
cachedVal := lib.GetCache(data.Event.User.ID.String() + ":" + "pic")
if cachedVal != "nil" {
return &api.InteractionResponseData{
Content: option.NewNullableString("Please wait for the cooldown!"),
}
}
lib.SetCache(data.Event.User.ID.String()+":"+"pic", data.Event.User.ID.String()+":"+"pic", 1)
// Command Logic
var options struct {
Prompt string `discord:"prompt"`
}
@ -234,6 +256,16 @@ 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
cachedVal := lib.GetCache(data.Event.User.ID.String() + ":" + "hdpic")
if cachedVal != "nil" {
return &api.InteractionResponseData{
Content: option.NewNullableString("Please wait for the cooldown!"),
}
}
lib.SetCache(data.Event.User.ID.String()+":"+"hdpic", data.Event.User.ID.String()+":"+"hdpic", 10)
// Command Logic
var options struct {
Prompt string `discord:"prompt"`
}