summaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
Diffstat (limited to 'bridge')
-rw-r--r--bridge/config/config.go44
-rw-r--r--bridge/discord/discord.go7
-rw-r--r--bridge/mattermost/mattermost.go27
-rw-r--r--bridge/rocketchat/rocketchat.go4
-rw-r--r--bridge/slack/slack.go28
5 files changed, 83 insertions, 27 deletions
diff --git a/bridge/config/config.go b/bridge/config/config.go
index 6244dd6a..fc41fe02 100644
--- a/bridge/config/config.go
+++ b/bridge/config/config.go
@@ -40,7 +40,7 @@ type ChannelInfo struct {
type Protocol struct {
AuthCode string // steam
- BindAddress string // mattermost, slack
+ BindAddress string // mattermost, slack // DEPRECATED
Buffer int // api
EditSuffix string // mattermost, slack, discord, telegram, gitter
EditDisable bool // mattermost, slack, discord, telegram, gitter
@@ -72,12 +72,14 @@ type Protocol struct {
SkipTLSVerify bool // IRC, mattermost
Team string // mattermost
Token string // gitter, slack, discord, api
- URL string // mattermost, slack, matrix
+ URL string // mattermost, slack // DEPRECATED
UseAPI bool // mattermost, slack
UseSASL bool // IRC
UseTLS bool // IRC
UseFirstName bool // telegram
- WebhookURL string // discord
+ WebhookBindAddress string // mattermost, slack
+ WebhookURL string // mattermost, slack
+ WebhookUse string // mattermost, slack, discord
}
type ChannelOptions struct {
@@ -128,6 +130,28 @@ func NewConfig(cfgfile string) *Config {
if _, err := toml.DecodeFile(cfgfile, &cfg); err != nil {
log.Fatal(err)
}
+ fail := false
+ for k, v := range cfg.Mattermost {
+ res := Deprecated(v, "mattermost."+k)
+ if res {
+ fail = res
+ }
+ }
+ for k, v := range cfg.Slack {
+ res := Deprecated(v, "slack."+k)
+ if res {
+ fail = res
+ }
+ }
+ for k, v := range cfg.Rocketchat {
+ res := Deprecated(v, "rocketchat."+k)
+ if res {
+ fail = res
+ }
+ }
+ if fail {
+ log.Fatalf("Fix your config. Please see changelog for more information")
+ }
return &cfg
}
@@ -178,3 +202,17 @@ func GetIconURL(msg *Message, cfg *Protocol) string {
iconURL = strings.Replace(iconURL, "{PROTOCOL}", protocol, -1)
return iconURL
}
+
+func Deprecated(cfg Protocol, account string) bool {
+ if cfg.BindAddress != "" {
+ log.Printf("ERROR: %s BindAddress is deprecated, you need to change it to WebhookBindAddress.", account)
+ } else if cfg.URL != "" {
+ log.Printf("ERROR: %s URL is deprecated, you need to change it to WebhookURL.", account)
+ } else if cfg.UseAPI == true {
+ log.Printf("ERROR: %s UseAPI is deprecated, it's enabled by default, please remove it from your config file.", account)
+ } else {
+ return false
+ }
+ return true
+ //log.Fatalf("ERROR: Fix your config: %s", account)
+}
diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go
index 1acbb19b..e3ea9f9b 100644
--- a/bridge/discord/discord.go
+++ b/bridge/discord/discord.go
@@ -49,6 +49,11 @@ func New(cfg config.Protocol, account string, c chan config.Message) *bdiscord {
func (b *bdiscord) Connect() error {
var err error
flog.Info("Connecting")
+ if b.Config.WebhookURL == "" {
+ flog.Info("Connecting using token")
+ } else {
+ flog.Info("Connecting using webhookurl (for posting) and token")
+ }
if !strings.HasPrefix(b.Config.Token, "Bot ") {
b.Config.Token = "Bot " + b.Config.Token
}
@@ -110,7 +115,7 @@ func (b *bdiscord) Send(msg config.Message) error {
return nil
}
if b.Config.WebhookURL == "" {
- flog.Debugf("Broadcasting using API")
+ flog.Debugf("Broadcasting using token (API)")
b.c.ChannelMessageSend(channelID, msg.Username+msg.Text)
} else {
flog.Debugf("Broadcasting using Webhook")
diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go
index e88bf838..222522ee 100644
--- a/bridge/mattermost/mattermost.go
+++ b/bridge/mattermost/mattermost.go
@@ -55,12 +55,18 @@ func (b *Bmattermost) Command(cmd string) string {
}
func (b *Bmattermost) Connect() error {
- if !b.Config.UseAPI {
- flog.Info("Connecting webhooks")
- b.mh = matterhook.New(b.Config.URL,
+ if b.Config.WebhookURL != "" && b.Config.WebhookBindAddress != "" {
+ flog.Info("Connecting using webhookurl and webhookbindaddress")
+ b.mh = matterhook.New(b.Config.WebhookURL,
matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
- BindAddress: b.Config.BindAddress})
+ BindAddress: b.Config.WebhookBindAddress})
+ } else if b.Config.WebhookURL != "" {
+ flog.Info("Connecting using webhookurl (for posting) and token")
+ b.mh = matterhook.New(b.Config.WebhookURL,
+ matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
+ DisableServer: true})
} else {
+ flog.Info("Connecting using token")
b.mc = matterclient.New(b.Config.Login, b.Config.Password,
b.Config.Team, b.Config.Server)
b.mc.SkipTLSVerify = b.Config.SkipTLSVerify
@@ -85,7 +91,7 @@ func (b *Bmattermost) Disconnect() error {
func (b *Bmattermost) JoinChannel(channel string) error {
// we can only join channels using the API
- if b.Config.UseAPI {
+ if b.Config.WebhookURL == "" && b.Config.WebhookBindAddress == "" {
return b.mc.JoinChannel(b.mc.GetChannelId(channel, ""))
}
return nil
@@ -100,7 +106,7 @@ func (b *Bmattermost) Send(msg config.Message) error {
if b.Config.PrefixMessagesWithNick {
message = nick + message
}
- if !b.Config.UseAPI {
+ if b.Config.WebhookURL != "" {
matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL}
matterMessage.IconURL = msg.Avatar
matterMessage.Channel = channel
@@ -119,12 +125,13 @@ func (b *Bmattermost) Send(msg config.Message) error {
}
func (b *Bmattermost) handleMatter() {
- flog.Debugf("Choosing API based Mattermost connection: %t", b.Config.UseAPI)
mchan := make(chan *MMMessage)
- if b.Config.UseAPI {
- go b.handleMatterClient(mchan)
- } else {
+ if b.Config.WebhookBindAddress != "" && b.Config.WebhookURL != "" {
+ flog.Debugf("Choosing webhooks based receiving")
go b.handleMatterHook(mchan)
+ } else {
+ flog.Debugf("Choosing login (api) based receiving")
+ go b.handleMatterClient(mchan)
}
for message := range mchan {
flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account)
diff --git a/bridge/rocketchat/rocketchat.go b/bridge/rocketchat/rocketchat.go
index 15cac553..8eb788f9 100644
--- a/bridge/rocketchat/rocketchat.go
+++ b/bridge/rocketchat/rocketchat.go
@@ -41,10 +41,10 @@ func (b *Brocketchat) Command(cmd string) string {
func (b *Brocketchat) Connect() error {
flog.Info("Connecting webhooks")
- b.mh = matterhook.New(b.Config.URL,
+ b.mh = matterhook.New(b.Config.WebhookURL,
matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
DisableServer: true})
- b.rh = rockethook.New(b.Config.URL, rockethook.Config{BindAddress: b.Config.BindAddress})
+ b.rh = rockethook.New(b.Config.WebhookURL, rockethook.Config{BindAddress: b.Config.WebhookBindAddress})
go b.handleRocketHook()
return nil
}
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go
index ad6a2b60..94f74d73 100644
--- a/bridge/slack/slack.go
+++ b/bridge/slack/slack.go
@@ -52,11 +52,16 @@ func (b *Bslack) Command(cmd string) string {
}
func (b *Bslack) Connect() error {
- flog.Info("Connecting")
- if !b.Config.UseAPI {
- b.mh = matterhook.New(b.Config.URL,
- matterhook.Config{BindAddress: b.Config.BindAddress})
+ if b.Config.WebhookURL != "" && b.Config.WebhookBindAddress != "" {
+ flog.Info("Connecting using webhookurl and webhookbindaddress")
+ b.mh = matterhook.New(b.Config.WebhookURL,
+ matterhook.Config{BindAddress: b.Config.WebhookBindAddress})
+ } else if b.Config.WebhookURL != "" {
+ flog.Info("Connecting using webhookurl (for posting) and token")
+ b.mh = matterhook.New(b.Config.WebhookURL,
+ matterhook.Config{DisableServer: true})
} else {
+ flog.Info("Connecting using token")
b.sc = slack.New(b.Config.Token)
b.rtm = b.sc.NewRTM()
go b.rtm.ManageConnection()
@@ -73,7 +78,7 @@ func (b *Bslack) Disconnect() error {
func (b *Bslack) JoinChannel(channel string) error {
// we can only join channels using the API
- if b.Config.UseAPI {
+ if b.Config.WebhookURL == "" || b.Config.WebhookBindAddress == "" {
if strings.HasPrefix(b.Config.Token, "xoxb") {
// TODO check if bot has already joined channel
return nil
@@ -96,7 +101,7 @@ func (b *Bslack) Send(msg config.Message) error {
if b.Config.PrefixMessagesWithNick {
message = nick + " " + message
}
- if !b.Config.UseAPI {
+ if b.Config.WebhookURL != "" {
matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL}
matterMessage.Channel = channel
matterMessage.UserName = nick
@@ -169,18 +174,19 @@ func (b *Bslack) getChannelByID(ID string) (*slack.Channel, error) {
}
func (b *Bslack) handleSlack() {
- flog.Debugf("Choosing API based slack connection: %t", b.Config.UseAPI)
mchan := make(chan *MMMessage)
- if b.Config.UseAPI {
- go b.handleSlackClient(mchan)
- } else {
+ if b.Config.WebhookBindAddress != "" && b.Config.WebhookURL != "" {
+ flog.Debugf("Choosing webhooks based receiving")
go b.handleMatterHook(mchan)
+ } else {
+ flog.Debugf("Choosing token based receiving")
+ go b.handleSlackClient(mchan)
}
time.Sleep(time.Second)
flog.Debug("Start listening for Slack messages")
for message := range mchan {
// do not send messages from ourself
- if b.Config.UseAPI && message.Username == b.si.User.Name {
+ if b.Config.WebhookURL == "" && b.Config.WebhookBindAddress == "" && message.Username == b.si.User.Name {
continue
}
texts := strings.Split(message.Text, "\n")