fix los buguos

This commit is contained in:
unintendedfraud
2025-05-22 12:43:10 +02:00
parent fb3f2261de
commit f11ca7d61f
2 changed files with 13 additions and 2 deletions
+1
View File
@@ -39,6 +39,7 @@ func (client Client) GenerateContent(content []*genai.Content) (*genai.GenerateC
content, content,
&genai.GenerateContentConfig{ &genai.GenerateContentConfig{
Temperature: &temp, Temperature: &temp,
MaxOutputTokens: 800,
SystemInstruction: &genai.Content{ SystemInstruction: &genai.Content{
Role: "system", Role: "system",
Parts: []*genai.Part{ Parts: []*genai.Part{
+11 -1
View File
@@ -16,6 +16,8 @@ import (
const MAX_HISTORY = 50 const MAX_HISTORY = 50
const DISCORD_MAX_CHAR = 4000
const ( const (
SPAM_PERIOD = 5 * time.Minute SPAM_PERIOD = 5 * time.Minute
MESSAGES_PER_PERIOD = 10 MESSAGES_PER_PERIOD = 10
@@ -118,11 +120,19 @@ func cleanMessage(p string) string {
} }
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, truncateIfNeeded(response)); err != nil {
log.Printf("\nfailed to send the response [%s] to the discord channel [%s]", response, err.Error()) log.Printf("\nfailed to send the response [%s] to the discord channel [%s]", response, err.Error())
} }
} }
func truncateIfNeeded(response string) string {
if len(response) > DISCORD_MAX_CHAR {
return response
}
return fmt.Sprintf("%s %s", response[:3990], "[...]")
}
func containHal(users []*discordgo.User, userID string) bool { func containHal(users []*discordgo.User, userID string) bool {
for _, u := range users { for _, u := range users {
if u.ID == userID { if u.ID == userID {