feat: add learn response in ai response

This commit is contained in:
Siwoo Jeon 2025-06-21 16:30:34 +09:00
parent 4e98143c61
commit ee6b2712c3
Signed by: migan
GPG key ID: 036E9A8C5E8E48DA
2 changed files with 21 additions and 3 deletions

View file

@ -116,7 +116,25 @@ func getMuffinResponse(s *discordgo.Session, question string) (string, error) {
return result, nil return result, nil
} }
func getAIResponse(c *Chatbot, user *discordgo.User, question string) (string, error) { func getAIResponse(s *discordgo.Session, c *Chatbot, user *discordgo.User, question string) (string, error) {
var data []databases.Learn
x := rand.Intn(10)
cur, err := databases.Database.Learns.Find(context.TODO(), bson.D{{Key: "command", Value: question}})
if err != nil {
return "살려주ㅅ세요", err
}
defer cur.Close(context.TODO())
cur.All(context.TODO(), &data)
if x == 10 && len(data) != 0 {
data := data[rand.Intn(len(data))]
user, _ := s.User(data.UserId)
return fmt.Sprintf("%s\n%s", data.Result, utils.InlineCode(fmt.Sprintf("%s님이 알려주셨어요.", user.Username))), nil
}
contents, err := GetMemory(user.ID) contents, err := GetMemory(user.ID)
if err != nil { if err != nil {
ChatBot.Mode = ChatbotMuffin ChatBot.Mode = ChatbotMuffin
@ -152,6 +170,6 @@ func (c *Chatbot) GetResponse(user *discordgo.User, question string) (string, er
case ChatbotMuffin: case ChatbotMuffin:
return getMuffinResponse(c.s, question) return getMuffinResponse(c.s, question)
default: default:
return getAIResponse(c, user, question) return getAIResponse(c.s, c, user, question)
} }
} }

View file

@ -7,7 +7,7 @@ import (
"git.wh64.net/muffin/goMuffin/utils" "git.wh64.net/muffin/goMuffin/utils"
) )
const MUFFIN_VERSION = "0.0.0-madeleine_canary.250621a" const MUFFIN_VERSION = "0.0.0-madeleine_canary.250621b"
var updatedString string = utils.RegexpDecimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0] var updatedString string = utils.RegexpDecimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0]