diff options
author | Wim <wim@42.be> | 2017-09-11 22:45:15 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2017-09-11 22:45:15 +0200 |
commit | ed018207226912ee57ecaae06c539aea37e7bb96 (patch) | |
tree | 4426d2bfd3041c9110b9b2e4ad38c35e9e918bff /bridge/discord | |
parent | 90a61f15cc93ddca78f598dc6856c759a91bd96a (diff) | |
download | matterbridge-msglm-ed018207226912ee57ecaae06c539aea37e7bb96.tar.gz matterbridge-msglm-ed018207226912ee57ecaae06c539aea37e7bb96.tar.bz2 matterbridge-msglm-ed018207226912ee57ecaae06c539aea37e7bb96.zip |
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)
Diffstat (limited to 'bridge/discord')
-rw-r--r-- | bridge/discord/discord.go | 20 |
1 files changed, 20 insertions, 0 deletions
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 } |