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