Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit f311f95f9f15d38d4afbac96ca2a5b4455e9de57 Author: Wim <wim@42.be> Date: Wed Oct 26 01:01:36 2016 +0000 Add support for discord channel ID. See #57 diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index 7cf7e89..903c80c 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -416 +418 @@ import (   "github.com/42wim/matterbridge/bridge/config"   log "github.com/Sirupsen/logrus"   "github.com/bwmarrin/discordgo" + "strings"  )    type bdiscord struct { - c *discordgo.Session - Config *config.Protocol - Remote chan config.Message - protocol string - origin string - Channels []*discordgo.Channel - Nick string + c *discordgo.Session + Config *config.Protocol + Remote chan config.Message + protocol string + origin string + Channels []*discordgo.Channel + Nick string + UseChannelID bool  }    var flog *log.Entry @@ -756 +7710 @@ func (b *bdiscord) FullOrigin() string {  }    func (b *bdiscord) JoinChannel(channel string) error { + idcheck := strings.Split(channel, "ID:") + if len(idcheck) > 1 { + b.UseChannelID = true + }   return nil  }   @@ -11511 +12119 @@ func (b *bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat   return   }   flog.Debugf("Sending message from %s on %s to gateway", m.Author.Username, b.FullOrigin()) - b.Remote <- config.Message{Username: m.Author.Username, Text: m.Content, Channel: b.getChannelName(m.ChannelID), + channelName := b.getChannelName(m.ChannelID) + if b.UseChannelID { + channelName = "ID:" + m.ChannelID + } + b.Remote <- config.Message{Username: m.Author.Username, Text: m.Content, Channel: channelName,   Origin: b.origin, Protocol: b.protocol, FullOrigin: b.FullOrigin()}  }    func (b *bdiscord) getChannelID(name string) string { + idcheck := strings.Split(name, "ID:") + if len(idcheck) > 1 { + return idcheck[1] + }   for _, channel := range b.Channels {   if channel.Name == name {   return channel.ID