mirror of
https://github.com/diamondburned/cchat-discord.git
synced 2024-11-01 12:24:15 +00:00
Implemented better typing
This commit is contained in:
parent
73a7393e78
commit
fef47e3574
|
@ -445,7 +445,7 @@ func (ch *Channel) TypingSubscribe(ti cchat.TypingIndicator) (func(), error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ti.AddTyper(NewGuildMember(*t.Member, *g))
|
ti.AddTyper(NewTyper(NewGuildMember(*t.Member, *g), t))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,7 +456,7 @@ func (ch *Channel) TypingSubscribe(ti cchat.TypingIndicator) (func(), error) {
|
||||||
|
|
||||||
for _, user := range c.DMRecipients {
|
for _, user := range c.DMRecipients {
|
||||||
if user.ID == t.UserID {
|
if user.ID == t.UserID {
|
||||||
ti.AddTyper(NewUser(user))
|
ti.AddTyper(NewTyper(NewUser(user), t))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/diamondburned/arikawa v0.9.5
|
github.com/diamondburned/arikawa v0.9.5
|
||||||
github.com/diamondburned/cchat v0.0.39
|
github.com/diamondburned/cchat v0.0.40
|
||||||
github.com/diamondburned/ningen v0.1.1-0.20200621014632-6babb812b249
|
github.com/diamondburned/ningen v0.1.1-0.20200621014632-6babb812b249
|
||||||
github.com/go-test/deep v1.0.6
|
github.com/go-test/deep v1.0.6
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -35,6 +35,8 @@ github.com/diamondburned/cchat v0.0.37 h1:yGz9yls5Lb/vLkU/DU53GjC80WOqoRe229DXsu
|
||||||
github.com/diamondburned/cchat v0.0.37/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
github.com/diamondburned/cchat v0.0.37/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
||||||
github.com/diamondburned/cchat v0.0.39 h1:Hxd7swmAIECm0MBd5wb1IFvreChwDFwnAshqgAstWGA=
|
github.com/diamondburned/cchat v0.0.39 h1:Hxd7swmAIECm0MBd5wb1IFvreChwDFwnAshqgAstWGA=
|
||||||
github.com/diamondburned/cchat v0.0.39/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
github.com/diamondburned/cchat v0.0.39/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
||||||
|
github.com/diamondburned/cchat v0.0.40 h1:38gPyJnnDoNDHrXcV8Qchfv3y6jlS3Fzz/6FY0BPH6I=
|
||||||
|
github.com/diamondburned/cchat v0.0.40/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
||||||
github.com/diamondburned/ningen v0.1.1-0.20200621014632-6babb812b249 h1:yP7kJ+xCGpDz6XbcfACJcju4SH1XDPwlrvbofz3lP8I=
|
github.com/diamondburned/ningen v0.1.1-0.20200621014632-6babb812b249 h1:yP7kJ+xCGpDz6XbcfACJcju4SH1XDPwlrvbofz3lP8I=
|
||||||
github.com/diamondburned/ningen v0.1.1-0.20200621014632-6babb812b249/go.mod h1:xW9hpBZsGi8KpAh10TyP+YQlYBo+Xc+2w4TR6N0951A=
|
github.com/diamondburned/ningen v0.1.1-0.20200621014632-6babb812b249/go.mod h1:xW9hpBZsGi8KpAh10TyP+YQlYBo+Xc+2w4TR6N0951A=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
|
|
63
typer.go
Normal file
63
typer.go
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
package discord
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/diamondburned/arikawa/discord"
|
||||||
|
"github.com/diamondburned/arikawa/gateway"
|
||||||
|
"github.com/diamondburned/arikawa/state"
|
||||||
|
"github.com/diamondburned/cchat"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Typer struct {
|
||||||
|
Author
|
||||||
|
time discord.UnixTimestamp
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ cchat.Typer = (*Typer)(nil)
|
||||||
|
|
||||||
|
func NewTyperAuthor(author Author, ev *gateway.TypingStartEvent) Typer {
|
||||||
|
return Typer{
|
||||||
|
Author: author,
|
||||||
|
time: ev.Timestamp,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if t.Member == nil {
|
||||||
|
t.Member, err = ch.session.Store.Member(t.GuildID, t.UserID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ti.AddTyper(NewTyper(NewGuildMember(*t.Member, *g), t))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c, err := ch.self()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, user := range c.DMRecipients {
|
||||||
|
if user.ID == t.UserID {
|
||||||
|
ti.AddTyper(NewTyper(NewUser(user), t))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t Typer) Time() time.Time {
|
||||||
|
return t.time.Time()
|
||||||
|
}
|
Loading…
Reference in a new issue