This commit is contained in:
unintendedfraud
2023-08-27 08:59:55 +02:00
parent 79e95067b6
commit 3cafbb3d20
3 changed files with 1 additions and 14 deletions
+1 -7
View File
@@ -10,26 +10,20 @@ import (
)
func OnMessageCreated(s *discordgo.Session, m *discordgo.MessageCreate) {
fmt.Printf("\nmessage received 1: [%s]", m.Message.Content)
fmt.Printf("\nmessage received: [%s] [%s]", m.ID, m.Message.Content)
if m.Author.ID == s.State.User.ID {
return
}
if containUser(m.Mentions, s.State.User.ID) {
fmt.Printf("\nmessage received 2: [%s]", m.Message.Content)
aiclient := openai.NewClient(env.GetEnvVariables().OpenaiHalToken)
fmt.Printf("\nAfter openai client: %+v", aiclient)
res, err := aiclient.Completions(m.Content)
if err != nil {
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 {
aiResponse := res.Choices[0].Text
if _, err = s.ChannelMessageSend(m.ChannelID, aiResponse); err != nil {