diff --git a/bot/bot.go b/bot/bot.go index 85298fc..b5817c6 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -30,7 +30,7 @@ type Bot struct { extractor *extractor.Extractor stats *stats.Stats models ModelSelection - history map[int64]*MessageRingBuffer + history map[int64]*MessageHistory profile BotInfo markdownV1Replacer *strings.Replacer @@ -48,7 +48,7 @@ func NewBot( extractor: extractor, stats: stats.NewStats(), models: models, - history: make(map[int64]*MessageRingBuffer), + history: make(map[int64]*MessageHistory), profile: BotInfo{0, "", ""}, markdownV1Replacer: strings.NewReplacer( diff --git a/bot/message_history.go b/bot/message_history.go index 8e2f8bf..1bdab0d 100644 --- a/bot/message_history.go +++ b/bot/message_history.go @@ -16,19 +16,19 @@ type MessageData struct { ReplyTo *MessageData } -type MessageRingBuffer struct { +type MessageHistory struct { messages []MessageData capacity int } -func NewMessageBuffer(capacity int) *MessageRingBuffer { - return &MessageRingBuffer{ +func NewMessageHistory(capacity int) *MessageHistory { + return &MessageHistory{ messages: make([]MessageData, 0, capacity), capacity: capacity, } } -func (b *MessageRingBuffer) Push(element MessageData) { +func (b *MessageHistory) Push(element MessageData) { if len(b.messages) >= b.capacity { b.messages = b.messages[1:] } @@ -36,7 +36,7 @@ func (b *MessageRingBuffer) Push(element MessageData) { b.messages = append(b.messages, element) } -func (b *MessageRingBuffer) GetAll() []MessageData { +func (b *MessageHistory) GetAll() []MessageData { return b.messages } @@ -53,7 +53,7 @@ func (b *Bot) saveChatMessageToHistory(message *telego.Message) { _, ok := b.history[chatId] if !ok { - b.history[chatId] = NewMessageBuffer(HistoryLength) + b.history[chatId] = NewMessageHistory(HistoryLength) } msgData := tgUserMessageToMessageData(message) @@ -74,7 +74,7 @@ func (b *Bot) saveBotReplyToHistory(message *telego.Message, text string) { _, ok := b.history[chatId] if !ok { - b.history[chatId] = NewMessageBuffer(HistoryLength) + b.history[chatId] = NewMessageHistory(HistoryLength) } msgData := MessageData{