Skip to content

Commit

Permalink
Don't message funding error on anon quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
rcy committed Dec 24, 2024
1 parent 1698d0a commit ebe6bb0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 6 additions & 2 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,13 @@ func addHandlers(b *bot.Bot) {
Privmsgf: b.MakePrivmsgf(),
})
if err != nil {
if !errors.Is(err, linkpool.NoNoteFoundError) {
b.Conn.Privmsg(b.Channel, "error: "+err.Error())
if errors.Is(err, ai.ErrBilling) {
return
}
if errors.Is(err, linkpool.NoNoteFoundError) {
return
}
b.Conn.Privmsg(b.Channel, "error: "+err.Error())
}
}()
})
Expand Down
3 changes: 2 additions & 1 deletion image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"goirc/db/model"
"goirc/internal/ai"
db "goirc/model"
"io"
"log"
Expand Down Expand Up @@ -49,7 +50,7 @@ func GenerateDALLE(ctx context.Context, prompt string) (*GeneratedImage, error)
imgResp, err := client.CreateImage(ctx, req)
if err != nil {
if strings.Contains(strings.ToLower(err.Error()), "billing") {
return nil, fmt.Errorf("I need money: https://rcy.sh/fundannie")
return nil, ai.ErrBilling
}
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions internal/ai/complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package ai

import (
"context"
"fmt"
"errors"
"os"
"strings"

"github.com/sashabaranov/go-openai"
)

var ErrBilling = errors.New("I need money: https://rcy.sh/fundannie")

func Complete(ctx context.Context, model string, system string, message string) (string, error) {
client := openai.NewClient(os.Getenv("OPENAI_API_KEY"))

Expand All @@ -28,7 +30,7 @@ func Complete(ctx context.Context, model string, system string, message string)
})
if err != nil {
if strings.Contains(err.Error(), "billing") {
return "", fmt.Errorf("I need money: https://rcy.sh/fundannie")
return "", ErrBilling
}

return "", err
Expand Down

0 comments on commit ebe6bb0

Please sign in to comment.