mirror of
https://github.com/diamondburned/cchat-discord.git
synced 2025-01-24 02:56:49 +00:00
Fixed Typer
This commit is contained in:
parent
4ecbbbe114
commit
fbf95b9b6c
37
typer.go
37
typer.go
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/diamondburned/arikawa/gateway"
|
||||
"github.com/diamondburned/arikawa/state"
|
||||
"github.com/diamondburned/cchat"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Typer struct {
|
||||
|
@ -24,38 +25,40 @@ func NewTyperAuthor(author Author, ev *gateway.TypingStartEvent) Typer {
|
|||
}
|
||||
|
||||
func NewTyper(store state.Store, ev *gateway.TypingStartEvent) (*Typer, error) {
|
||||
if t.ChannelID != ch.id {
|
||||
return
|
||||
}
|
||||
|
||||
if ch.guildID.Valid() {
|
||||
g, err := ch.session.Store.Guild(t.GuildID)
|
||||
if ev.GuildID.Valid() {
|
||||
g, err := store.Guild(ev.GuildID)
|
||||
if err != nil {
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if t.Member == nil {
|
||||
t.Member, err = ch.session.Store.Member(t.GuildID, t.UserID)
|
||||
if ev.Member == nil {
|
||||
ev.Member, err = store.Member(ev.GuildID, ev.UserID)
|
||||
if err != nil {
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
ti.AddTyper(NewTyper(NewGuildMember(*t.Member, *g), t))
|
||||
return
|
||||
return &Typer{
|
||||
Author: NewGuildMember(*ev.Member, *g),
|
||||
time: ev.Timestamp,
|
||||
}, nil
|
||||
}
|
||||
|
||||
c, err := ch.self()
|
||||
c, err := store.Channel(ev.ChannelID)
|
||||
if err != nil {
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, user := range c.DMRecipients {
|
||||
if user.ID == t.UserID {
|
||||
ti.AddTyper(NewTyper(NewUser(user), t))
|
||||
return
|
||||
if user.ID == ev.UserID {
|
||||
return &Typer{
|
||||
Author: NewUser(user),
|
||||
time: ev.Timestamp,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, errors.New("typer not found in state")
|
||||
}
|
||||
|
||||
func (t Typer) Time() time.Time {
|
||||
|
|
Loading…
Reference in a new issue