5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-26 13:31:38 +00:00

Swap token/id. Also check for default webhookURL in isWebhookID (discord)

This commit is contained in:
Wim 2017-08-12 16:30:00 +02:00
parent 59b2a5f8d0
commit e77c3eb20a

View File

@ -41,7 +41,7 @@ func New(cfg config.Protocol, account string, c chan config.Message) *bdiscord {
b.channelInfoMap = make(map[string]*config.ChannelInfo) b.channelInfoMap = make(map[string]*config.ChannelInfo)
if b.Config.WebhookURL != "" { if b.Config.WebhookURL != "" {
flog.Debug("Configuring Discord Incoming Webhook") flog.Debug("Configuring Discord Incoming Webhook")
b.webhookToken, b.webhookID = b.splitURL(b.Config.WebhookURL) b.webhookID, b.webhookToken = b.splitURL(b.Config.WebhookURL)
} }
return b return b
} }
@ -121,7 +121,7 @@ func (b *bdiscord) Send(msg config.Message) error {
wID := b.webhookID wID := b.webhookID
wToken := b.webhookToken wToken := b.webhookToken
if ci, ok := b.channelInfoMap[msg.Channel+msg.Account]; ok { if ci, ok := b.channelInfoMap[msg.Channel+b.Account]; ok {
if ci.Options.WebhookURL != "" { if ci.Options.WebhookURL != "" {
wID, wToken = b.splitURL(ci.Options.WebhookURL) wID, wToken = b.splitURL(ci.Options.WebhookURL)
} }
@ -131,7 +131,7 @@ func (b *bdiscord) Send(msg config.Message) error {
flog.Debugf("Broadcasting using token (API)") flog.Debugf("Broadcasting using token (API)")
b.c.ChannelMessageSend(channelID, msg.Username+msg.Text) b.c.ChannelMessageSend(channelID, msg.Username+msg.Text)
} else { } else {
flog.Debugf("Broadcasting using Webhook %#v %#v", wID, wToken) flog.Debugf("Broadcasting using Webhook")
b.c.WebhookExecute( b.c.WebhookExecute(
wID, wID,
wToken, wToken,
@ -342,6 +342,12 @@ func (b *bdiscord) useWebhook() bool {
// isWebhookID returns true if the specified id is used in a defined webhook // isWebhookID returns true if the specified id is used in a defined webhook
func (b *bdiscord) isWebhookID(id string) bool { func (b *bdiscord) isWebhookID(id string) bool {
if b.Config.WebhookURL != "" {
wID, _ := b.splitURL(b.Config.WebhookURL)
if wID == id {
return true
}
}
for _, channel := range b.channelInfoMap { for _, channel := range b.channelInfoMap {
if channel.Options.WebhookURL != "" { if channel.Options.WebhookURL != "" {
wID, _ := b.splitURL(channel.Options.WebhookURL) wID, _ := b.splitURL(channel.Options.WebhookURL)