From ba6759010bc3c1c6b2793b3fdf92f8dadf481117 Mon Sep 17 00:00:00 2001 From: Qais Patankar Date: Thu, 3 Oct 2019 23:18:56 +0100 Subject: [PATCH] Add UserTypingSupport (discord) (#914) * Add Discord to UserTypingSupport * discord: start typing in a channel on EventUserTyping receive * discord: emit EventUserTyping to gateway --- bridge/discord/discord.go | 9 +++++++++ bridge/discord/handlers.go | 13 +++++++++++++ gateway/bridgemap/bridgemap.go | 3 ++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index 84171fa5..1c6c40d9 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -72,6 +72,7 @@ func (b *Bdiscord) Connect() error { } b.Log.Info("Connection succeeded") b.c.AddHandler(b.messageCreate) + b.c.AddHandler(b.messageTyping) b.c.AddHandler(b.memberUpdate) b.c.AddHandler(b.messageUpdate) b.c.AddHandler(b.messageDelete) @@ -188,6 +189,14 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) { return "", fmt.Errorf("Could not find channelID for %v", msg.Channel) } + if msg.Event == config.EventUserTyping { + if b.GetBool("ShowUserTyping") { + err := b.c.ChannelTyping(channelID) + return "", err + } + return "", nil + } + // Make a action /me of the message if msg.Event == config.EventUserAction { msg.Text = "_" + msg.Text + "_" diff --git a/bridge/discord/handlers.go b/bridge/discord/handlers.go index cfda2de9..9260427d 100644 --- a/bridge/discord/handlers.go +++ b/bridge/discord/handlers.go @@ -37,6 +37,19 @@ func (b *Bdiscord) messageDeleteBulk(s *discordgo.Session, m *discordgo.MessageD } } +func (b *Bdiscord) messageTyping(s *discordgo.Session, m *discordgo.TypingStart) { + if !b.GetBool("ShowUserTyping") { + return + } + + rmsg := config.Message{Account: b.Account, Event: config.EventUserTyping} + rmsg.Channel = b.getChannelName(m.ChannelID) + if b.useChannelID { + rmsg.Channel = "ID:" + m.ChannelID + } + b.Remote <- rmsg +} + func (b *Bdiscord) messageUpdate(s *discordgo.Session, m *discordgo.MessageUpdate) { //nolint:unparam if b.GetBool("EditDisable") { return diff --git a/gateway/bridgemap/bridgemap.go b/gateway/bridgemap/bridgemap.go index 599df7b2..cb9a3932 100644 --- a/gateway/bridgemap/bridgemap.go +++ b/gateway/bridgemap/bridgemap.go @@ -40,6 +40,7 @@ var ( } UserTypingSupport = map[string]struct{}{ - "slack": {}, + "slack": {}, + "discord": {}, } )