From ef4cb5318534395f1dcbbf04b41a7ed5e60ab74d Mon Sep 17 00:00:00 2001 From: diamondburned Date: Fri, 1 Jan 2021 14:35:35 -0800 Subject: [PATCH] bumped cchat; added replier; minor fixes --- go.mod | 2 +- go.sum | 4 ++++ .../discord/channel/message/nickname/nicknamer.go | 8 ++++---- internal/discord/channel/message/send/sender.go | 13 ++++++++++++- internal/discord/message/message.go | 3 ++- internal/discord/session/session.go | 3 ++- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index a9147ef..b9f12e5 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.14 require ( github.com/diamondburned/arikawa/v2 v2.0.0-20210101083335-169b36126239 - github.com/diamondburned/cchat v0.3.15 + github.com/diamondburned/cchat v0.3.17 github.com/diamondburned/ningen/v2 v2.0.0-20210101084041-d9a5058b63b5 github.com/dustin/go-humanize v1.0.0 github.com/go-test/deep v1.0.7 diff --git a/go.sum b/go.sum index 9fe0110..ea6b3c9 100644 --- a/go.sum +++ b/go.sum @@ -132,6 +132,10 @@ github.com/diamondburned/cchat v0.3.14 h1:nDr9DJ1EW3kab4gieE+DLhpvHRws+umWpw5XrO github.com/diamondburned/cchat v0.3.14/go.mod h1:IlMtF+XIvAJh0GL/2yFdf0/34w+Hdy5A1GgvSwAXtQI= github.com/diamondburned/cchat v0.3.15 h1:BJf8ZiRtDWTGMtQ3QqjNU0H+784WSrkJEpFGkKY5gEw= github.com/diamondburned/cchat v0.3.15/go.mod h1:IlMtF+XIvAJh0GL/2yFdf0/34w+Hdy5A1GgvSwAXtQI= +github.com/diamondburned/cchat v0.3.16 h1:vRF8BeypyQ6yr0wK/odGStrmrbB+1WkNcjIwP+SMZeo= +github.com/diamondburned/cchat v0.3.16/go.mod h1:IlMtF+XIvAJh0GL/2yFdf0/34w+Hdy5A1GgvSwAXtQI= +github.com/diamondburned/cchat v0.3.17 h1:pGwas8Y0SBU7yg4EQ/MvrbqZhrnRhPBYm1AiRsL147s= +github.com/diamondburned/cchat v0.3.17/go.mod h1:IlMtF+XIvAJh0GL/2yFdf0/34w+Hdy5A1GgvSwAXtQI= 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.20200708085949-b64e350f3b8c h1:3h/kyk6HplYZF3zLi106itjYJWjbuMK/twijeGLEy2M= diff --git a/internal/discord/channel/message/nickname/nicknamer.go b/internal/discord/channel/message/nickname/nicknamer.go index bf10a24..6a0b61a 100644 --- a/internal/discord/channel/message/nickname/nicknamer.go +++ b/internal/discord/channel/message/nickname/nicknamer.go @@ -38,6 +38,8 @@ func (nn Nicknamer) Nickname(ctx context.Context, labeler cchat.LabelContainer) return func() {}, nil } + nn.tryNicknameLabel(ctx, labeler) + return funcutil.JoinCancels( nn.State.AddHandler(func(chunks *gateway.GuildMembersChunkEvent) { if chunks.GuildID != nn.GuildID { @@ -66,11 +68,9 @@ func (nn Nicknamer) tryNicknameLabel(ctx context.Context, labeler cchat.LabelCon state := nn.State.WithContext(ctx) m, err := state.Cabinet.Member(nn.GuildID, nn.userID) - if err != nil { - return + if err == nil { + nn.setMember(labeler, *m) } - - nn.setMember(labeler, *m) } func (nn Nicknamer) setMember(labeler cchat.LabelContainer, m discord.Member) { diff --git a/internal/discord/channel/message/send/sender.go b/internal/discord/channel/message/send/sender.go index 1ee8ef0..da35363 100644 --- a/internal/discord/channel/message/send/sender.go +++ b/internal/discord/channel/message/send/sender.go @@ -12,13 +12,24 @@ import ( func WrapMessage(s *state.Instance, msg cchat.SendableMessage) api.SendMessageData { var send = api.SendMessageData{Content: msg.Content()} - if attacher := msg.AsAttachments(); attacher != nil { + + if attacher := msg.AsAttacher(); attacher != nil { send.Files = addAttachments(attacher.Attachments()) } + if noncer := msg.AsNoncer(); noncer != nil { send.Nonce = s.Nonces.Generate(noncer.Nonce()) } + if replier := msg.AsReplier(); replier != nil { + id, err := discord.ParseSnowflake(replier.ReplyingTo()) + if err == nil { + send.Reference = &discord.MessageReference{ + MessageID: discord.MessageID(id), + } + } + } + return send } diff --git a/internal/discord/message/message.go b/internal/discord/message/message.go index c61d409..4c9ddfc 100644 --- a/internal/discord/message/message.go +++ b/internal/discord/message/message.go @@ -1,6 +1,7 @@ package message import ( + "strings" "time" "github.com/diamondburned/arikawa/v2/discord" @@ -171,7 +172,7 @@ func NewMessage(m discord.Message, s *state.Instance, author Author) Message { refmsg = refmsg[:120] + "..." } - content.Content = refmsg + "\n" + content.Content = strings.ReplaceAll(refmsg, "\n", " ") + "\n" content.Segments = []text.Segment{ reference.NewMessageSegment(0, len(refmsg), ref.ID), } diff --git a/internal/discord/session/session.go b/internal/discord/session/session.go index ccd1183..fe38adb 100644 --- a/internal/discord/session/session.go +++ b/internal/discord/session/session.go @@ -2,6 +2,7 @@ package session import ( "context" + "log" "github.com/diamondburned/arikawa/v2/gateway" "github.com/diamondburned/arikawa/v2/session" @@ -84,7 +85,7 @@ func (s *Session) Servers(container cchat.ServersContainer) error { // Set the entire container again once reconnected. s.state.AddHandler(func(*ningen.Connected) { - s.servers(container) + log.Println("[Discord] ningen.Connected received, error:", s.servers(container)) }) return s.servers(container)