clean messages
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"hal/env"
|
||||
"hal/openai"
|
||||
"log"
|
||||
"regexp"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
@@ -53,7 +54,7 @@ func addMessageToHistory(m *discordgo.Message, isHal bool) {
|
||||
|
||||
messagesHistory = append(messagesHistory, &openai.ChatMessage{
|
||||
Role: role,
|
||||
Content: m.Content,
|
||||
Content: cleanMessage(m.Content),
|
||||
})
|
||||
|
||||
if len(messagesHistory) > MAX_HISTORY {
|
||||
@@ -61,6 +62,11 @@ func addMessageToHistory(m *discordgo.Message, isHal bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func cleanMessage(p string) string {
|
||||
regex := regexp.MustCompile(`<@\d+>`)
|
||||
return regex.ReplaceAllString(p, "")
|
||||
}
|
||||
|
||||
func sendResponse(s *discordgo.Session, channelID string, response string) {
|
||||
if _, err := s.ChannelMessageSend(channelID, response); err != nil {
|
||||
log.Panicf("failed to send the response [%s] to the discord channel [%s]", response, err.Error())
|
||||
|
||||
Reference in New Issue
Block a user