2020-11-30 00:57:58 +00:00
|
|
|
package defaultstore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
2021-06-02 02:53:19 +00:00
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
|
|
|
"github.com/diamondburned/arikawa/v3/state/store"
|
2020-11-30 00:57:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-06-03 19:39:49 +00:00
|
|
|
func (m *Me) MyselfSet(me discord.User, update bool) error {
|
2020-11-30 00:57:58 +00:00
|
|
|
m.mut.Lock()
|
2021-06-03 19:39:49 +00:00
|
|
|
if !m.self.ID.IsValid() || update {
|
|
|
|
m.self = me
|
|
|
|
}
|
2020-11-30 00:57:58 +00:00
|
|
|
m.mut.Unlock()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|