mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-27 09:12:53 +00:00
Bot: Refactored accordingly to State's new Store API
This commit is contained in:
parent
e0adbfab35
commit
afc87adbae
|
@ -75,7 +75,7 @@ func (ctx *Context) callCmd(ev interface{}) (bottomError error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the updated message.
|
// Query the updated message.
|
||||||
m, err := ctx.Store.Message(up.ChannelID, up.ID)
|
m, err := ctx.Cabinet.Message(up.ChannelID, up.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// It's probably safe to ignore this.
|
// It's probably safe to ignore this.
|
||||||
return nil
|
return nil
|
||||||
|
@ -87,7 +87,7 @@ func (ctx *Context) callCmd(ev interface{}) (bottomError error) {
|
||||||
|
|
||||||
// Fill up member, if available.
|
// Fill up member, if available.
|
||||||
if m.GuildID.IsValid() && up.Member == nil {
|
if m.GuildID.IsValid() && up.Member == nil {
|
||||||
if mem, err := ctx.Store.Member(m.GuildID, m.Author.ID); err == nil {
|
if mem, err := ctx.Cabinet.Member(m.GuildID, m.Author.ID); err == nil {
|
||||||
msc.Member = mem
|
msc.Member = mem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/diamondburned/arikawa/v2/discord"
|
"github.com/diamondburned/arikawa/v2/discord"
|
||||||
"github.com/diamondburned/arikawa/v2/gateway"
|
"github.com/diamondburned/arikawa/v2/gateway"
|
||||||
"github.com/diamondburned/arikawa/v2/state"
|
"github.com/diamondburned/arikawa/v2/state"
|
||||||
|
"github.com/diamondburned/arikawa/v2/state/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type hasPlumb struct {
|
type hasPlumb struct {
|
||||||
|
@ -31,7 +32,7 @@ func (h *hasPlumb) Plumber(_ *gateway.MessageCreateEvent, c RawArguments) error
|
||||||
|
|
||||||
func TestSubcommandPlumb(t *testing.T) {
|
func TestSubcommandPlumb(t *testing.T) {
|
||||||
var s = &state.State{
|
var s = &state.State{
|
||||||
Store: state.NewDefaultStore(nil),
|
Cabinet: store.NoopCabinet,
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := New(s, &testc{})
|
c, err := New(s, &testc{})
|
||||||
|
@ -79,7 +80,7 @@ func (h *onlyPlumb) Plumber(_ *gateway.MessageCreateEvent, c RawArguments) error
|
||||||
|
|
||||||
func TestSubcommandOnlyPlumb(t *testing.T) {
|
func TestSubcommandOnlyPlumb(t *testing.T) {
|
||||||
var s = &state.State{
|
var s = &state.State{
|
||||||
Store: state.NewDefaultStore(nil),
|
Cabinet: store.NoopCabinet,
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := New(s, &testc{})
|
c, err := New(s, &testc{})
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/diamondburned/arikawa/v2/discord"
|
"github.com/diamondburned/arikawa/v2/discord"
|
||||||
"github.com/diamondburned/arikawa/v2/gateway"
|
"github.com/diamondburned/arikawa/v2/gateway"
|
||||||
"github.com/diamondburned/arikawa/v2/state"
|
"github.com/diamondburned/arikawa/v2/state"
|
||||||
|
"github.com/diamondburned/arikawa/v2/state/store"
|
||||||
"github.com/diamondburned/arikawa/v2/utils/handler"
|
"github.com/diamondburned/arikawa/v2/utils/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ func (t *testc) OnTyping(*gateway.TypingStartEvent) {
|
||||||
|
|
||||||
func TestNewContext(t *testing.T) {
|
func TestNewContext(t *testing.T) {
|
||||||
var s = &state.State{
|
var s = &state.State{
|
||||||
Store: state.NewDefaultStore(nil),
|
Cabinet: store.NoopCabinet,
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := New(s, &testc{})
|
c, err := New(s, &testc{})
|
||||||
|
@ -81,7 +82,7 @@ func TestNewContext(t *testing.T) {
|
||||||
func TestContext(t *testing.T) {
|
func TestContext(t *testing.T) {
|
||||||
var given = &testc{}
|
var given = &testc{}
|
||||||
var s = &state.State{
|
var s = &state.State{
|
||||||
Store: state.NewDefaultStore(nil),
|
Cabinet: store.NoopCabinet,
|
||||||
Handler: handler.New(),
|
Handler: handler.New(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,12 +105,8 @@ func TestContext(t *testing.T) {
|
||||||
t.Fatal("Failed to init commands:", err)
|
t.Fatal("Failed to init commands:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if given.Ctx == nil {
|
if given.Ctx != ctx {
|
||||||
t.Fatal("given'sub Context field is nil")
|
t.Fatal("given Context field has invalid pointer")
|
||||||
}
|
|
||||||
|
|
||||||
if given.Ctx.State.Store == nil {
|
|
||||||
t.Fatal("given'sub State is nil")
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -379,7 +376,7 @@ func sendMsg(ctx *Context, given *testc, into interface{}, content string) (call
|
||||||
|
|
||||||
func BenchmarkConstructor(b *testing.B) {
|
func BenchmarkConstructor(b *testing.B) {
|
||||||
var s = &state.State{
|
var s = &state.State{
|
||||||
Store: state.NewDefaultStore(nil),
|
Cabinet: store.NoopCabinet,
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
|
@ -390,7 +387,7 @@ func BenchmarkConstructor(b *testing.B) {
|
||||||
func BenchmarkCall(b *testing.B) {
|
func BenchmarkCall(b *testing.B) {
|
||||||
var given = &testc{}
|
var given = &testc{}
|
||||||
var s = &state.State{
|
var s = &state.State{
|
||||||
Store: state.NewDefaultStore(nil),
|
Cabinet: store.NoopCabinet,
|
||||||
}
|
}
|
||||||
|
|
||||||
sub, _ := NewSubcommand(given)
|
sub, _ := NewSubcommand(given)
|
||||||
|
@ -418,7 +415,7 @@ func BenchmarkCall(b *testing.B) {
|
||||||
func BenchmarkHelp(b *testing.B) {
|
func BenchmarkHelp(b *testing.B) {
|
||||||
var given = &testc{}
|
var given = &testc{}
|
||||||
var s = &state.State{
|
var s = &state.State{
|
||||||
Store: state.NewDefaultStore(nil),
|
Cabinet: store.NoopCabinet,
|
||||||
}
|
}
|
||||||
|
|
||||||
sub, _ := NewSubcommand(given)
|
sub, _ := NewSubcommand(given)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/diamondburned/arikawa/v2/gateway"
|
"github.com/diamondburned/arikawa/v2/gateway"
|
||||||
"github.com/diamondburned/arikawa/v2/session"
|
"github.com/diamondburned/arikawa/v2/session"
|
||||||
"github.com/diamondburned/arikawa/v2/state"
|
"github.com/diamondburned/arikawa/v2/state"
|
||||||
|
"github.com/diamondburned/arikawa/v2/state/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAdminOnly(t *testing.T) {
|
func TestAdminOnly(t *testing.T) {
|
||||||
|
@ -23,7 +24,7 @@ func TestAdminOnly(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Store: &mockStore{},
|
Cabinet: mockCabinet(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var middleware = AdminOnly(ctx)
|
var middleware = AdminOnly(ctx)
|
||||||
|
@ -69,7 +70,7 @@ func TestGuildOnly(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Store: &mockStore{},
|
Cabinet: mockCabinet(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var middleware = GuildOnly(ctx)
|
var middleware = GuildOnly(ctx)
|
||||||
|
@ -131,7 +132,7 @@ func expectBreak(t *testing.T, err error) {
|
||||||
func BenchmarkGuildOnly(b *testing.B) {
|
func BenchmarkGuildOnly(b *testing.B) {
|
||||||
var ctx = &bot.Context{
|
var ctx = &bot.Context{
|
||||||
State: &state.State{
|
State: &state.State{
|
||||||
Store: &mockStore{},
|
Cabinet: mockCabinet(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var middleware = GuildOnly(ctx)
|
var middleware = GuildOnly(ctx)
|
||||||
|
@ -156,7 +157,7 @@ func BenchmarkGuildOnly(b *testing.B) {
|
||||||
func BenchmarkAdminOnly(b *testing.B) {
|
func BenchmarkAdminOnly(b *testing.B) {
|
||||||
var ctx = &bot.Context{
|
var ctx = &bot.Context{
|
||||||
State: &state.State{
|
State: &state.State{
|
||||||
Store: &mockStore{},
|
Cabinet: mockCabinet(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var middleware = AdminOnly(ctx)
|
var middleware = AdminOnly(ctx)
|
||||||
|
@ -178,7 +179,16 @@ func BenchmarkAdminOnly(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockStore struct {
|
type mockStore struct {
|
||||||
state.NoopStore
|
store.NoopStore
|
||||||
|
}
|
||||||
|
|
||||||
|
func mockCabinet() store.Cabinet {
|
||||||
|
c := store.NoopCabinet
|
||||||
|
c.GuildStore = &mockStore{}
|
||||||
|
c.MemberStore = &mockStore{}
|
||||||
|
c.ChannelStore = &mockStore{}
|
||||||
|
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *mockStore) Guild(id discord.GuildID) (*discord.Guild, error) {
|
func (s *mockStore) Guild(id discord.GuildID) (*discord.Guild, error) {
|
||||||
|
|
Loading…
Reference in a new issue