From 1fd64db52344468ff24e7dd3213f540650e454af Mon Sep 17 00:00:00 2001 From: Igor Mandrigin Date: Thu, 22 Feb 2018 17:53:19 +0100 Subject: [PATCH] Fixed for data storage and support for messages with nil username. --- bots/utils_messages.go | 2 +- cmd/chanreader/messages_store.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bots/utils_messages.go b/bots/utils_messages.go index dba768c..cf0061a 100644 --- a/bots/utils_messages.go +++ b/bots/utils_messages.go @@ -12,7 +12,7 @@ import ( ) const ( - messageRegexString = `{:message-id "(?P.+)",\s+:group-id "(?P.+)",\s+:content "(?P.+)",\s+:username "(?P.+)",\s+:type :public-group-message.+:timestamp (?P\d+)}` + messageRegexString = `{:message-id "(?P.+)",\s+:group-id "(?P.+)",\s+:content "(?P.+)",\s+:username ["]?(?P.+)["]?,\s+:type :public-group-message.+:timestamp (?P\d+)}` ) var messageRegex *regexp.Regexp = regexp.MustCompile(messageRegexString) diff --git a/cmd/chanreader/messages_store.go b/cmd/chanreader/messages_store.go index d2081e0..88eb9b2 100644 --- a/cmd/chanreader/messages_store.go +++ b/cmd/chanreader/messages_store.go @@ -69,7 +69,9 @@ func (ms *messagesStore) Add(message bots.StatusMessage) error { } func (ms *messagesStore) Messages(channel string) []bots.StatusMessage { - return messagesFromIterator(ms.db.NewIterator(util.BytesPrefix([]byte(channel)), nil)) + messages := messagesFromIterator(ms.db.NewIterator(util.BytesPrefix([]byte(channel)), nil)) + sort.Sort(ByTimestamp(messages)) + return messages } func (ms *messagesStore) Close() {