Renaming MessageRingBuffer to MessageHistory (#30).
This commit is contained in:
parent
093372dd91
commit
a783a84faa
|
@ -30,7 +30,7 @@ type Bot struct {
|
||||||
extractor *extractor.Extractor
|
extractor *extractor.Extractor
|
||||||
stats *stats.Stats
|
stats *stats.Stats
|
||||||
models ModelSelection
|
models ModelSelection
|
||||||
history map[int64]*MessageRingBuffer
|
history map[int64]*MessageHistory
|
||||||
profile BotInfo
|
profile BotInfo
|
||||||
|
|
||||||
markdownV1Replacer *strings.Replacer
|
markdownV1Replacer *strings.Replacer
|
||||||
|
@ -48,7 +48,7 @@ func NewBot(
|
||||||
extractor: extractor,
|
extractor: extractor,
|
||||||
stats: stats.NewStats(),
|
stats: stats.NewStats(),
|
||||||
models: models,
|
models: models,
|
||||||
history: make(map[int64]*MessageRingBuffer),
|
history: make(map[int64]*MessageHistory),
|
||||||
profile: BotInfo{0, "", ""},
|
profile: BotInfo{0, "", ""},
|
||||||
|
|
||||||
markdownV1Replacer: strings.NewReplacer(
|
markdownV1Replacer: strings.NewReplacer(
|
||||||
|
|
|
@ -16,19 +16,19 @@ type MessageData struct {
|
||||||
ReplyTo *MessageData
|
ReplyTo *MessageData
|
||||||
}
|
}
|
||||||
|
|
||||||
type MessageRingBuffer struct {
|
type MessageHistory struct {
|
||||||
messages []MessageData
|
messages []MessageData
|
||||||
capacity int
|
capacity int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMessageBuffer(capacity int) *MessageRingBuffer {
|
func NewMessageHistory(capacity int) *MessageHistory {
|
||||||
return &MessageRingBuffer{
|
return &MessageHistory{
|
||||||
messages: make([]MessageData, 0, capacity),
|
messages: make([]MessageData, 0, capacity),
|
||||||
capacity: capacity,
|
capacity: capacity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *MessageRingBuffer) Push(element MessageData) {
|
func (b *MessageHistory) Push(element MessageData) {
|
||||||
if len(b.messages) >= b.capacity {
|
if len(b.messages) >= b.capacity {
|
||||||
b.messages = b.messages[1:]
|
b.messages = b.messages[1:]
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ func (b *MessageRingBuffer) Push(element MessageData) {
|
||||||
b.messages = append(b.messages, element)
|
b.messages = append(b.messages, element)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *MessageRingBuffer) GetAll() []MessageData {
|
func (b *MessageHistory) GetAll() []MessageData {
|
||||||
return b.messages
|
return b.messages
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ func (b *Bot) saveChatMessageToHistory(message *telego.Message) {
|
||||||
|
|
||||||
_, ok := b.history[chatId]
|
_, ok := b.history[chatId]
|
||||||
if !ok {
|
if !ok {
|
||||||
b.history[chatId] = NewMessageBuffer(HistoryLength)
|
b.history[chatId] = NewMessageHistory(HistoryLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
msgData := tgUserMessageToMessageData(message)
|
msgData := tgUserMessageToMessageData(message)
|
||||||
|
@ -74,7 +74,7 @@ func (b *Bot) saveBotReplyToHistory(message *telego.Message, text string) {
|
||||||
|
|
||||||
_, ok := b.history[chatId]
|
_, ok := b.history[chatId]
|
||||||
if !ok {
|
if !ok {
|
||||||
b.history[chatId] = NewMessageBuffer(HistoryLength)
|
b.history[chatId] = NewMessageHistory(HistoryLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
msgData := MessageData{
|
msgData := MessageData{
|
||||||
|
|
Loading…
Reference in a new issue