Fixed error handling!
This commit is contained in:
parent
e90e4b6a0f
commit
0c236f1da3
4 changed files with 12 additions and 8 deletions
|
@ -28,7 +28,7 @@ func Ask(ctx context.Context, data cmdroute.CommandData) *api.InteractionRespons
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := data.Options.Unmarshal(&options); err != nil {
|
if err := data.Options.Unmarshal(&options); err != nil {
|
||||||
lib.CancelCooldown(data.Event.User.ID.String(), "ask")
|
lib.CancelCooldown(data.Event.Member.User.ID.String(), "ask")
|
||||||
return lib.ErrorResponse(err)
|
return lib.ErrorResponse(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ func Ask(ctx context.Context, data cmdroute.CommandData) *api.InteractionRespons
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("ChatCompletion error: %v\n", err)
|
fmt.Printf("ChatCompletion error: %v\n", err)
|
||||||
lib.CancelCooldown(data.Event.User.ID.String(), "ask")
|
lib.CancelCooldown(data.Event.Member.User.ID.String(), "ask")
|
||||||
return &api.InteractionResponseData{
|
return &api.InteractionResponseData{
|
||||||
Content: option.NewNullableString("ChatCompletion Error!"),
|
Content: option.NewNullableString("ChatCompletion Error!"),
|
||||||
AllowedMentions: &api.AllowedMentions{},
|
AllowedMentions: &api.AllowedMentions{},
|
||||||
|
|
|
@ -27,7 +27,7 @@ func Pic(ctx context.Context, data cmdroute.CommandData) *api.InteractionRespons
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := data.Options.Unmarshal(&options); err != nil {
|
if err := data.Options.Unmarshal(&options); err != nil {
|
||||||
lib.CancelCooldown(data.Event.User.ID.String(), "pic")
|
lib.CancelCooldown(data.Event.Member.User.ID.String(), "pic")
|
||||||
return lib.ErrorResponse(err)
|
return lib.ErrorResponse(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ func Pic(ctx context.Context, data cmdroute.CommandData) *api.InteractionRespons
|
||||||
imageFile, err := lib.OpenAIImageGeneration(options.Prompt, filename)
|
imageFile, err := lib.OpenAIImageGeneration(options.Prompt, filename)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lib.CancelCooldown(data.Event.User.ID.String(), "pic")
|
lib.CancelCooldown(data.Event.Member.User.ID.String(), "pic")
|
||||||
return lib.ErrorResponse(err)
|
return lib.ErrorResponse(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,13 @@ func (m *CooldownManager) IsOnCooldown(userID string, key string) (bool, time.Du
|
||||||
|
|
||||||
func CancelCooldown(userID string, key string) {
|
func CancelCooldown(userID string, key string) {
|
||||||
manager := GetInstance()
|
manager := GetInstance()
|
||||||
|
|
||||||
|
// Handle non-existent keys gracefully
|
||||||
|
if _, exists := manager.cooldowns[userID+":"+key]; !exists {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
manager.mu.Lock()
|
manager.mu.Lock()
|
||||||
defer manager.mu.Unlock()
|
defer manager.mu.Unlock()
|
||||||
|
|
||||||
delete(manager.cooldowns, userID+":"+key)
|
delete(manager.cooldowns, userID+":"+key)
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,7 @@ func OpenAITextGeneration(prompt string) (string, error) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Ask command error: %v\n", err)
|
fmt.Printf("Ask command error: %v\n", err)
|
||||||
return "", errors.New("there was an error generating the response based on this prompt... please reach out to @himbothyswaggins to fix this issue")
|
return "", errors.New("https://fly.storage.tigris.dev/atridad/himbot/no.gif")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp.Choices[0].Message.Content, nil
|
return resp.Choices[0].Message.Content, nil
|
||||||
|
@ -64,7 +63,7 @@ func OpenAIImageGeneration(prompt string, filename string) (*bytes.Buffer, error
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Pic command error: %v\n", err)
|
fmt.Printf("Pic command error: %v\n", err)
|
||||||
return nil, errors.New("there was an error generating the image based on this prompt... please reach out to @himbothyswaggins to fix this issue")
|
return nil, errors.New("https://fly.storage.tigris.dev/atridad/himbot/hornypolice.gif")
|
||||||
}
|
}
|
||||||
|
|
||||||
imgUrl := imageResponse.Data[0].URL
|
imgUrl := imageResponse.Data[0].URL
|
||||||
|
|
Loading…
Add table
Reference in a new issue