Renaming MessageRingBuffer to MessageHistory (#30).

This commit is contained in:
Alexey Skobkin 2024-11-04 01:18:18 +03:00
parent 093372dd91
commit a783a84faa
Signed by: skobkin
GPG key ID: 4389E670595BF8A8
2 changed files with 9 additions and 9 deletions

View file

@ -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(

View file

@ -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{