f
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"hal/env"
|
"hal/env"
|
||||||
"hal/openai"
|
"hal/openai"
|
||||||
"log"
|
"log"
|
||||||
@@ -9,10 +10,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func OnMessageCreated(s *discordgo.Session, m *discordgo.MessageCreate) {
|
func OnMessageCreated(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
|
fmt.Printf("\nmessage received: [%s]", m.Message.Content)
|
||||||
|
|
||||||
if m.Author.ID == s.State.User.ID {
|
if m.Author.ID == s.State.User.ID {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if containUser(m.Mentions, s.State.User.ID) {
|
if containUser(m.Mentions, s.State.User.ID) {
|
||||||
|
fmt.Printf("\nmessage received: [%s]", m.Message.Content)
|
||||||
|
|
||||||
aiclient := openai.NewClient(env.GetEnvVariables().OpenaiHalToken)
|
aiclient := openai.NewClient(env.GetEnvVariables().OpenaiHalToken)
|
||||||
|
|
||||||
res, err := aiclient.Completions(m.Content)
|
res, err := aiclient.Completions(m.Content)
|
||||||
@@ -20,6 +26,8 @@ func OnMessageCreated(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||||||
log.Panicf("failed to query open ai with the following prompt [%s]. Error: %s", m.Content, err.Error())
|
log.Panicf("failed to query open ai with the following prompt [%s]. Error: %s", m.Content, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("\nopen ai responses: [%d]", len(res.Choices))
|
||||||
|
|
||||||
if len(res.Choices) > 0 {
|
if len(res.Choices) > 0 {
|
||||||
aiResponse := res.Choices[0].Text
|
aiResponse := res.Choices[0].Text
|
||||||
if _, err = s.ChannelMessageSend(m.ChannelID, aiResponse); err != nil {
|
if _, err = s.ChannelMessageSend(m.ChannelID, aiResponse); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user