mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-01 12:34:28 +00:00
a808b52f00
* Store,State: Add update param to all store.XXXStore.XXXSet methods * State: add paginating Messages * Store: Fix test error * store: merge shouldPrependMessage and shouldAppendMessage into single messageInsertPosition
50 lines
704 B
Go
50 lines
704 B
Go
package defaultstore
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
|
"github.com/diamondburned/arikawa/v3/state/store"
|
|
)
|
|
|
|
type Me struct {
|
|
mut sync.RWMutex
|
|
self discord.User
|
|
}
|
|
|
|
var _ store.MeStore = (*Me)(nil)
|
|
|
|
func NewMe() *Me {
|
|
return &Me{}
|
|
}
|
|
|
|
func (m *Me) Reset() error {
|
|
m.mut.Lock()
|
|
m.self = discord.User{}
|
|
m.mut.Unlock()
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *Me) Me() (*discord.User, error) {
|
|
m.mut.RLock()
|
|
self := m.self
|
|
m.mut.RUnlock()
|
|
|
|
if !self.ID.IsValid() {
|
|
return nil, store.ErrNotFound
|
|
}
|
|
|
|
return &self, nil
|
|
}
|
|
|
|
func (m *Me) MyselfSet(me discord.User, update bool) error {
|
|
m.mut.Lock()
|
|
if !m.self.ID.IsValid() || update {
|
|
m.self = me
|
|
}
|
|
m.mut.Unlock()
|
|
|
|
return nil
|
|
}
|