Skip to content

Commit

Permalink
finalize when final
Browse files Browse the repository at this point in the history
  • Loading branch information
radiantspace committed Mar 16, 2024
1 parent e010cc1 commit 8c6300c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
8 changes: 7 additions & 1 deletion backend/app/converters/ffmpeg_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package converters

import "testing"
import (
"testing"
)

func init() {

}

// test ParseDuration

Expand Down
7 changes: 7 additions & 0 deletions backend/app/payments/billing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

"github.com/DataDog/datadog-go/v5/statsd"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

Expand All @@ -22,6 +23,12 @@ func init() {
config.CONFIG = &config.Config{
DataDogClient: testClient,
}

logrus.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
ForceColors: true,
})
logrus.SetLevel(logrus.DebugLevel)
}

func TestBill(t *testing.T) {
Expand Down
16 changes: 12 additions & 4 deletions backend/app/telegram/message_processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,15 +447,23 @@ func ChunkSendMessage(bot *telego.Bot, chatID telego.ChatID, text string) {
}

// update current message and sends a new message in up to 4000 chars chunks
func ChunkEditSendMessage(ctx context.Context, bot *telego.Bot, chatID telego.ChatID, text string, messageID int, voice bool) (lastMessage *telego.Message, err error) {
func ChunkEditSendMessage(
ctx context.Context,
bot *telego.Bot,
chatID telego.ChatID,
text string,
messageID int,
voice bool,
finalize bool,
) (lastMessage *telego.Message, err error) {
if text == "" {
return nil, nil
}
chunks := util.ChunkString(text, 4000)
for i, chunk := range chunks {
last := false
markup := getLikeDislikeReplyMarkup()
if i == len(chunks)-1 {
if i == len(chunks)-1 && !finalize {
markup = getPendingReplyMarkup()
last = true
}
Expand Down Expand Up @@ -584,7 +592,7 @@ func processMessageChannel(
log.Errorf("Failed to add reaction to message in chat: %s, %v", chatIDString, err)
}
} else {
_, err = ChunkEditSendMessage(ctx, bot, chatID, finalMessageString, responseMessage.MessageID, mode == lib.VoiceGPT)
_, err = ChunkEditSendMessage(ctx, bot, chatID, finalMessageString, responseMessage.MessageID, mode == lib.VoiceGPT, true)
if err != nil {
log.Errorf("Failed to ChunkEditSendMessage message in chat: %s, %v", chatIDString, err)
}
Expand All @@ -606,7 +614,7 @@ func processMessageChannel(
trimmedResponseText := postprocessMessage(responseText, mode, userMessagePrimer)

var nextMessageObject *telego.Message
nextMessageObject, err = ChunkEditSendMessage(ctx, bot, chatID, trimmedResponseText, responseMessage.MessageID, mode == lib.VoiceGPT)
nextMessageObject, err = ChunkEditSendMessage(ctx, bot, chatID, trimmedResponseText, responseMessage.MessageID, mode == lib.VoiceGPT, false)
if err != nil {
log.Errorf("Failed to ChunkEditSendMessage message in chat: %s, %v", chatIDString, err)
}
Expand Down
6 changes: 3 additions & 3 deletions backend/app/telegram/message_processors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"

"github.com/mymmrac/telego"
log "github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
"github.com/undefinedlabs/go-mpatch"
)

Expand All @@ -31,11 +31,11 @@ func init() {
setupTestBot()
setupCommandHandlers()

log.SetFormatter(&log.TextFormatter{
logrus.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
ForceColors: true,
})
log.SetLevel(log.DebugLevel)
logrus.SetLevel(logrus.DebugLevel)
}

func TestProcessThreadedStreamingMessage(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions backend/app/telegram/telegram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func init() {

setupTestBot()
setupCommandHandlers()

log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
ForceColors: true,
})
log.SetLevel(log.DebugLevel)
}

func getTestBot() *telego.Bot {
Expand Down

0 comments on commit 8c6300c

Please sign in to comment.