mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-16 03:44:26 +00:00
diamondburned
c6679dc52c
This commit refactors the Store interface in State into smaller interfaces in package store. These interfaces are combined into one structure called a "Cabinet". The default implementation of those interfaces have been rewritten in package defaultstore, while the old no-op implementation stays with the store package. This commit also omitted several state handlers for user events, as it is unclear what they are actually structured like.
48 lines
650 B
Go
48 lines
650 B
Go
package defaultstore
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/diamondburned/arikawa/v2/discord"
|
|
"github.com/diamondburned/arikawa/v2/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) error {
|
|
m.mut.Lock()
|
|
m.self = me
|
|
m.mut.Unlock()
|
|
|
|
return nil
|
|
}
|