From ed018207226912ee57ecaae06c539aea37e7bb96 Mon Sep 17 00:00:00 2001 From: Wim Date: Mon, 11 Sep 2017 22:45:15 +0200 Subject: Add support for deleting messages across bridges. Currently fully support mattermost,slack and discord. Message deleted on the bridge or received from other bridges will be deleted. Partially support for Gitter. Gitter bridge will delete messages received from other bridges. But if you delete a message on gitter, this deletion will not be sent to other bridges (this is a gitter API limitation, it doesn't propogate edits or deletes via the API) --- bridge/discord/discord.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'bridge/discord') diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index ffbada40..d8320c76 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -66,6 +66,7 @@ func (b *bdiscord) Connect() error { b.c.AddHandler(b.messageCreate) b.c.AddHandler(b.memberUpdate) b.c.AddHandler(b.messageUpdate) + b.c.AddHandler(b.messageDelete) err = b.c.Open() if err != nil { flog.Debugf("%#v", err) @@ -129,6 +130,13 @@ func (b *bdiscord) Send(msg config.Message) (string, error) { if wID == "" { flog.Debugf("Broadcasting using token (API)") + if msg.Event == config.EVENT_MSG_DELETE { + if msg.ID == "" { + return "", nil + } + err := b.c.ChannelMessageDelete(channelID, msg.ID) + return "", err + } if msg.ID != "" { _, err := b.c.ChannelMessageEdit(channelID, msg.ID, msg.Username+msg.Text) return msg.ID, err @@ -152,6 +160,17 @@ func (b *bdiscord) Send(msg config.Message) (string, error) { return "", err } +func (b *bdiscord) messageDelete(s *discordgo.Session, m *discordgo.MessageDelete) { + rmsg := config.Message{Account: b.Account, ID: m.ID, Event: config.EVENT_MSG_DELETE, Text: config.EVENT_MSG_DELETE} + rmsg.Channel = b.getChannelName(m.ChannelID) + if b.UseChannelID { + rmsg.Channel = "ID:" + m.ChannelID + } + flog.Debugf("Sending message from %s to gateway", b.Account) + flog.Debugf("Message is %#v", rmsg) + b.Remote <- rmsg +} + func (b *bdiscord) messageUpdate(s *discordgo.Session, m *discordgo.MessageUpdate) { if b.Config.EditDisable { return @@ -223,6 +242,7 @@ func (b *bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat rmsg.Text = text flog.Debugf("Sending message from %s on %s to gateway", m.Author.Username, b.Account) + flog.Debugf("Message is %#v", rmsg) b.Remote <- rmsg } -- cgit v1.2.3