State: Separated DiffMessage for reusability
This commit is contained in:
parent
cb525ca5c0
commit
ea7e0d6229
|
@ -90,3 +90,32 @@ type StoreModifier interface {
|
|||
// isn't in the storage. There is no strict restrictions on what uses this (the
|
||||
// default one does, though), so be advised.
|
||||
var ErrStoreNotFound = errors.New("item not found in store")
|
||||
|
||||
// DiffMessage fills non-empty fields from src to dst.
|
||||
func DiffMessage(src discord.Message, dst *discord.Message) {
|
||||
// Thanks, Discord.
|
||||
if src.Content != "" {
|
||||
dst.Content = src.Content
|
||||
}
|
||||
if src.EditedTimestamp.Valid() {
|
||||
dst.EditedTimestamp = src.EditedTimestamp
|
||||
}
|
||||
if src.Mentions != nil {
|
||||
dst.Mentions = src.Mentions
|
||||
}
|
||||
if src.Embeds != nil {
|
||||
dst.Embeds = src.Embeds
|
||||
}
|
||||
if src.Attachments != nil {
|
||||
dst.Attachments = src.Attachments
|
||||
}
|
||||
if src.Timestamp.Valid() {
|
||||
dst.Timestamp = src.Timestamp
|
||||
}
|
||||
if src.Author.ID.Valid() {
|
||||
dst.Author = src.Author
|
||||
}
|
||||
if src.Reactions != nil {
|
||||
dst.Reactions = src.Reactions
|
||||
}
|
||||
}
|
||||
|
|
|
@ -436,7 +436,7 @@ func (s *DefaultStore) Messages(channelID discord.Snowflake) ([]discord.Message,
|
|||
return nil, ErrStoreNotFound
|
||||
}
|
||||
|
||||
return append([]discord.Message{}, ms...), nil
|
||||
return ms, nil
|
||||
}
|
||||
|
||||
func (s *DefaultStore) MaxMessages() int {
|
||||
|
@ -455,32 +455,7 @@ func (s *DefaultStore) MessageSet(message *discord.Message) error {
|
|||
// Check if we already have the message.
|
||||
for i, m := range ms {
|
||||
if m.ID == message.ID {
|
||||
// Thanks, Discord.
|
||||
if message.Content != "" {
|
||||
m.Content = message.Content
|
||||
}
|
||||
if message.EditedTimestamp.Valid() {
|
||||
m.EditedTimestamp = message.EditedTimestamp
|
||||
}
|
||||
if message.Mentions != nil {
|
||||
m.Mentions = message.Mentions
|
||||
}
|
||||
if message.Embeds != nil {
|
||||
m.Embeds = message.Embeds
|
||||
}
|
||||
if message.Attachments != nil {
|
||||
m.Attachments = message.Attachments
|
||||
}
|
||||
if message.Timestamp.Valid() {
|
||||
m.Timestamp = message.Timestamp
|
||||
}
|
||||
if message.Author.ID.Valid() {
|
||||
m.Author = message.Author
|
||||
}
|
||||
if message.Reactions != nil {
|
||||
m.Reactions = message.Reactions
|
||||
}
|
||||
|
||||
DiffMessage(*message, &m)
|
||||
ms[i] = m
|
||||
return nil
|
||||
}
|
||||
|
@ -552,7 +527,7 @@ func (s *DefaultStore) Presences(guildID discord.Snowflake) ([]discord.Presence,
|
|||
return nil, ErrStoreNotFound
|
||||
}
|
||||
|
||||
return append([]discord.Presence{}, ps...), nil
|
||||
return ps, nil
|
||||
}
|
||||
|
||||
func (s *DefaultStore) PresenceSet(guildID discord.Snowflake, presence *discord.Presence) error {
|
||||
|
|
Loading…
Reference in New Issue