Add support for discord channel ID. See #57
This commit is contained in:
parent
40a967523c
commit
475bed5e19
|
@ -4,16 +4,18 @@ import (
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type bdiscord struct {
|
type bdiscord struct {
|
||||||
c *discordgo.Session
|
c *discordgo.Session
|
||||||
Config *config.Protocol
|
Config *config.Protocol
|
||||||
Remote chan config.Message
|
Remote chan config.Message
|
||||||
protocol string
|
protocol string
|
||||||
origin string
|
origin string
|
||||||
Channels []*discordgo.Channel
|
Channels []*discordgo.Channel
|
||||||
Nick string
|
Nick string
|
||||||
|
UseChannelID bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var flog *log.Entry
|
var flog *log.Entry
|
||||||
|
@ -75,6 +77,10 @@ func (b *bdiscord) FullOrigin() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bdiscord) JoinChannel(channel string) error {
|
func (b *bdiscord) JoinChannel(channel string) error {
|
||||||
|
idcheck := strings.Split(channel, "ID:")
|
||||||
|
if len(idcheck) > 1 {
|
||||||
|
b.UseChannelID = true
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,11 +121,19 @@ func (b *bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
flog.Debugf("Sending message from %s on %s to gateway", m.Author.Username, b.FullOrigin())
|
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()}
|
Origin: b.origin, Protocol: b.protocol, FullOrigin: b.FullOrigin()}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bdiscord) getChannelID(name string) string {
|
func (b *bdiscord) getChannelID(name string) string {
|
||||||
|
idcheck := strings.Split(name, "ID:")
|
||||||
|
if len(idcheck) > 1 {
|
||||||
|
return idcheck[1]
|
||||||
|
}
|
||||||
for _, channel := range b.Channels {
|
for _, channel := range b.Channels {
|
||||||
if channel.Name == name {
|
if channel.Name == name {
|
||||||
return channel.ID
|
return channel.ID
|
||||||
|
|
Loading…
Reference in New Issue