mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-06-26 18:59:24 +00:00
Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
e99532fb89 | |||
4aa646f6b0 | |||
9dcd51fb80 | |||
6dee988b76 | |||
5af40db396 | |||
b3553bee7a | |||
ac19c94b9f | |||
845f7dc331 | |||
2adeae37e1 | |||
16eb12b2a0 | |||
8411f2aa32 | |||
e8acc49cbd |
34
.travis.yml
Normal file
34
.travis.yml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
language: go
|
||||||
|
go:
|
||||||
|
- 1.7.x
|
||||||
|
- 1.8.x
|
||||||
|
- tip
|
||||||
|
install: true
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
# It's ok if our code fails on unstable development versions of Go.
|
||||||
|
allow_failures:
|
||||||
|
- go: tip
|
||||||
|
# Don't wait for tip tests to finish. Mark the test run green if the
|
||||||
|
# tests pass on the stable versions of Go.
|
||||||
|
fast_finish: true
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
email: false
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- GO_FILES=$(find . -iname '*.go' | grep -v /vendor/) # All the .go files, excluding vendor/
|
||||||
|
- PKGS=$(go list ./... | grep -v /vendor/) # All the import paths, excluding vendor/
|
||||||
|
# - go get github.com/golang/lint/golint # Linter
|
||||||
|
- go get honnef.co/go/tools/cmd/megacheck # Badass static analyzer/linter
|
||||||
|
|
||||||
|
# Anything in before_script: that returns a nonzero exit code will
|
||||||
|
# flunk the build and immediately stop. It's sorta like having
|
||||||
|
# set -e enabled in bash.
|
||||||
|
script:
|
||||||
|
script:
|
||||||
|
- test -z $(gofmt -s -l $GO_FILES) # Fail if a .go file hasn't been formatted with gofmt
|
||||||
|
#- go test -v -race $PKGS # Run all the tests with the race detector enabled
|
||||||
|
- go vet $PKGS # go vet is the official Go static analyzer
|
||||||
|
- megacheck $PKGS # "go vet on steroids" + linter
|
||||||
|
#- golint -set_exit_status $PKGS # one last linter
|
15
README.md
15
README.md
@ -1,5 +1,7 @@
|
|||||||
# matterbridge
|
# matterbridge
|
||||||
[](https://gitter.im/42wim/matterbridge) [](https://webchat.freenode.net/?channels=matterbridgechat) [](https://discord.gg/AkKPtrQ) [](https://riot.im/app/#/room/#matterbridge:matrix.org)
|
Click on one of the badges below to join the chat
|
||||||
|
|
||||||
|
[](https://gitter.im/42wim/matterbridge) [](https://webchat.freenode.net/?channels=matterbridgechat) [](https://discord.gg/AkKPtrQ) [](https://riot.im/app/#/room/#matterbridge:matrix.org) [](https://join.slack.com/matterbridgechat/shared_invite/MjEwODMxNjU1NDMwLTE0OTk2MTU3NTMtMzZkZmRiNDZhOA)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@ -13,6 +15,7 @@ Has a REST API.
|
|||||||
* [Binaries](#binaries)
|
* [Binaries](#binaries)
|
||||||
* [Building](#building)
|
* [Building](#building)
|
||||||
* [Configuration](#configuration)
|
* [Configuration](#configuration)
|
||||||
|
* [Howto](https://github.com/42wim/matterbridge/wiki/How-to-create-your-config)
|
||||||
* [Examples](#examples)
|
* [Examples](#examples)
|
||||||
* [Running](#running)
|
* [Running](#running)
|
||||||
* [Docker](#docker)
|
* [Docker](#docker)
|
||||||
@ -45,7 +48,7 @@ Accounts to one of the supported bridges
|
|||||||
# Installing
|
# Installing
|
||||||
## Binaries
|
## Binaries
|
||||||
Binaries can be found [here] (https://github.com/42wim/matterbridge/releases/)
|
Binaries can be found [here] (https://github.com/42wim/matterbridge/releases/)
|
||||||
* Latest stable release [v0.16.0](https://github.com/42wim/matterbridge/releases/tag/v0.16.0)
|
* Latest stable release [v0.16.1](https://github.com/42wim/matterbridge/releases/tag/v0.16.1)
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
Go 1.6+ is required. Make sure you have [Go](https://golang.org/doc/install) properly installed, including setting up your [GOPATH] (https://golang.org/doc/code.html#GOPATH)
|
Go 1.6+ is required. Make sure you have [Go](https://golang.org/doc/install) properly installed, including setting up your [GOPATH] (https://golang.org/doc/code.html#GOPATH)
|
||||||
@ -63,12 +66,12 @@ matterbridge
|
|||||||
```
|
```
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
* [matterbridge.toml.sample](https://github.com/42wim/matterbridge/blob/master/matterbridge.toml.sample) for documentation and an example.
|
## Basic configuration
|
||||||
* [matterbridge.toml.simple](https://github.com/42wim/matterbridge/blob/master/matterbridge.toml.simple) for a simple example.
|
|
||||||
|
|
||||||
## Create a configuration.
|
|
||||||
See [howto](https://github.com/42wim/matterbridge/wiki/How-to-create-your-config) for a step by step walkthrough for creating your configuration.
|
See [howto](https://github.com/42wim/matterbridge/wiki/How-to-create-your-config) for a step by step walkthrough for creating your configuration.
|
||||||
|
|
||||||
|
## Advanced configuration
|
||||||
|
* [matterbridge.toml.sample](https://github.com/42wim/matterbridge/blob/master/matterbridge.toml.sample) for documentation and an example.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
### Bridge mattermost (off-topic) - irc (#testing)
|
### Bridge mattermost (off-topic) - irc (#testing)
|
||||||
```
|
```
|
||||||
|
@ -88,10 +88,7 @@ func New(cfg *config.Config, bridge *config.Bridge, c chan config.Message) *Brid
|
|||||||
|
|
||||||
func (b *Bridge) JoinChannels() error {
|
func (b *Bridge) JoinChannels() error {
|
||||||
err := b.joinChannels(b.Channels, b.Joined)
|
err := b.joinChannels(b.Channels, b.Joined)
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bridge) joinChannels(channels map[string]config.ChannelInfo, exists map[string]bool) error {
|
func (b *Bridge) joinChannels(channels map[string]config.ChannelInfo, exists map[string]bool) error {
|
||||||
|
@ -209,7 +209,7 @@ func Deprecated(cfg Protocol, account string) bool {
|
|||||||
log.Printf("ERROR: %s BindAddress is deprecated, you need to change it to WebhookBindAddress.", account)
|
log.Printf("ERROR: %s BindAddress is deprecated, you need to change it to WebhookBindAddress.", account)
|
||||||
} else if cfg.URL != "" {
|
} else if cfg.URL != "" {
|
||||||
log.Printf("ERROR: %s URL is deprecated, you need to change it to WebhookURL.", account)
|
log.Printf("ERROR: %s URL is deprecated, you need to change it to WebhookURL.", account)
|
||||||
} else if cfg.UseAPI == true {
|
} else if cfg.UseAPI {
|
||||||
log.Printf("ERROR: %s UseAPI is deprecated, it's enabled by default, please remove it from your config file.", account)
|
log.Printf("ERROR: %s UseAPI is deprecated, it's enabled by default, please remove it from your config file.", account)
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
func tableformatter(nicks []string, nicksPerRow int, continued bool) string {
|
func tableformatter(nicks []string, nicksPerRow int, continued bool) string {
|
||||||
result := "|IRC users"
|
result := "|IRC users"
|
||||||
if continued {
|
if continued {
|
||||||
@ -29,6 +30,7 @@ func tableformatter(nicks []string, nicksPerRow int, continued bool) string {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
func plainformatter(nicks []string, nicksPerRow int) string {
|
func plainformatter(nicks []string, nicksPerRow int) string {
|
||||||
return strings.Join(nicks, ", ") + " currently on IRC"
|
return strings.Join(nicks, ", ") + " currently on IRC"
|
||||||
|
@ -148,9 +148,9 @@ func (b *Birc) Send(msg config.Message) error {
|
|||||||
|
|
||||||
func (b *Birc) doSend() {
|
func (b *Birc) doSend() {
|
||||||
rate := time.Millisecond * time.Duration(b.Config.MessageDelay)
|
rate := time.Millisecond * time.Duration(b.Config.MessageDelay)
|
||||||
throttle := time.Tick(rate)
|
throttle := time.NewTicker(rate)
|
||||||
for msg := range b.Local {
|
for msg := range b.Local {
|
||||||
<-throttle
|
<-throttle.C
|
||||||
b.i.Privmsg(msg.Channel, msg.Username+msg.Text)
|
b.i.Privmsg(msg.Channel, msg.Username+msg.Text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package bmattermost
|
package bmattermost
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
"github.com/42wim/matterbridge/matterclient"
|
"github.com/42wim/matterbridge/matterclient"
|
||||||
"github.com/42wim/matterbridge/matterhook"
|
"github.com/42wim/matterbridge/matterhook"
|
||||||
@ -12,9 +13,8 @@ type MMhook struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MMapi struct {
|
type MMapi struct {
|
||||||
mc *matterclient.MMClient
|
mc *matterclient.MMClient
|
||||||
mmMap map[string]string
|
mmMap map[string]string
|
||||||
mmIgnoreNicks []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MMMessage struct {
|
type MMMessage struct {
|
||||||
@ -29,7 +29,6 @@ type Bmattermost struct {
|
|||||||
MMapi
|
MMapi
|
||||||
Config *config.Protocol
|
Config *config.Protocol
|
||||||
Remote chan config.Message
|
Remote chan config.Message
|
||||||
name string
|
|
||||||
TeamId string
|
TeamId string
|
||||||
Account string
|
Account string
|
||||||
}
|
}
|
||||||
@ -55,33 +54,49 @@ func (b *Bmattermost) Command(cmd string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bmattermost) Connect() error {
|
func (b *Bmattermost) Connect() error {
|
||||||
if b.Config.WebhookURL != "" && b.Config.WebhookBindAddress != "" {
|
if b.Config.WebhookBindAddress != "" {
|
||||||
flog.Info("Connecting using webhookurl and webhookbindaddress")
|
if b.Config.WebhookURL != "" {
|
||||||
b.mh = matterhook.New(b.Config.WebhookURL,
|
flog.Info("Connecting using webhookurl (sending) and webhookbindaddress (receiving)")
|
||||||
matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
|
} else if b.Config.Login != "" {
|
||||||
BindAddress: b.Config.WebhookBindAddress})
|
flog.Info("Connecting using login/password (sending)")
|
||||||
} else if b.Config.WebhookURL != "" {
|
err := b.apiLogin()
|
||||||
flog.Info("Connecting using webhookurl (for posting) and token")
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
flog.Info("Connecting using webhookbindaddress (receiving)")
|
||||||
|
b.mh = matterhook.New(b.Config.WebhookURL,
|
||||||
|
matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
|
||||||
|
BindAddress: b.Config.WebhookBindAddress})
|
||||||
|
}
|
||||||
|
go b.handleMatter()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if b.Config.WebhookURL != "" {
|
||||||
|
flog.Info("Connecting using webhookurl (sending)")
|
||||||
b.mh = matterhook.New(b.Config.WebhookURL,
|
b.mh = matterhook.New(b.Config.WebhookURL,
|
||||||
matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
|
matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
|
||||||
DisableServer: true})
|
DisableServer: true})
|
||||||
} else {
|
if b.Config.Login != "" {
|
||||||
flog.Info("Connecting using token")
|
flog.Info("Connecting using login/password (receiving)")
|
||||||
b.mc = matterclient.New(b.Config.Login, b.Config.Password,
|
err := b.apiLogin()
|
||||||
b.Config.Team, b.Config.Server)
|
if err != nil {
|
||||||
b.mc.SkipTLSVerify = b.Config.SkipTLSVerify
|
return err
|
||||||
b.mc.NoTLS = b.Config.NoTLS
|
}
|
||||||
flog.Infof("Connecting %s (team: %s) on %s", b.Config.Login, b.Config.Team, b.Config.Server)
|
go b.handleMatter()
|
||||||
err := b.mc.Login()
|
}
|
||||||
|
return nil
|
||||||
|
} else if b.Config.Login != "" {
|
||||||
|
flog.Info("Connecting using login/password (sending and receiving)")
|
||||||
|
err := b.apiLogin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
flog.Info("Connection succeeded")
|
go b.handleMatter()
|
||||||
b.TeamId = b.mc.GetTeamId()
|
}
|
||||||
go b.mc.WsReceiver()
|
if b.Config.WebhookBindAddress == "" && b.Config.WebhookURL == "" && b.Config.Login == "" {
|
||||||
go b.mc.StatusLoop()
|
return errors.New("No connection method found. See that you have WebhookBindAddress, WebhookURL or Login/Password/Server/Team configured.")
|
||||||
}
|
}
|
||||||
go b.handleMatter()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,11 +141,11 @@ func (b *Bmattermost) Send(msg config.Message) error {
|
|||||||
|
|
||||||
func (b *Bmattermost) handleMatter() {
|
func (b *Bmattermost) handleMatter() {
|
||||||
mchan := make(chan *MMMessage)
|
mchan := make(chan *MMMessage)
|
||||||
if b.Config.WebhookBindAddress != "" && b.Config.WebhookURL != "" {
|
if b.Config.WebhookBindAddress != "" {
|
||||||
flog.Debugf("Choosing webhooks based receiving")
|
flog.Debugf("Choosing webhooks based receiving")
|
||||||
go b.handleMatterHook(mchan)
|
go b.handleMatterHook(mchan)
|
||||||
} else {
|
} else {
|
||||||
flog.Debugf("Choosing login (api) based receiving")
|
flog.Debugf("Choosing login/password based receiving")
|
||||||
go b.handleMatterClient(mchan)
|
go b.handleMatterClient(mchan)
|
||||||
}
|
}
|
||||||
for message := range mchan {
|
for message := range mchan {
|
||||||
@ -166,7 +181,7 @@ func (b *Bmattermost) handleMatterClient(mchan chan *MMMessage) {
|
|||||||
m.Text = message.Text + b.Config.EditSuffix
|
m.Text = message.Text + b.Config.EditSuffix
|
||||||
}
|
}
|
||||||
if len(message.Post.FileIds) > 0 {
|
if len(message.Post.FileIds) > 0 {
|
||||||
for _, link := range b.mc.GetPublicLinks(message.Post.FileIds) {
|
for _, link := range b.mc.GetFileLinks(message.Post.FileIds) {
|
||||||
m.Text = m.Text + "\n" + link
|
m.Text = m.Text + "\n" + link
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -187,3 +202,20 @@ func (b *Bmattermost) handleMatterHook(mchan chan *MMMessage) {
|
|||||||
mchan <- m
|
mchan <- m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Bmattermost) apiLogin() error {
|
||||||
|
b.mc = matterclient.New(b.Config.Login, b.Config.Password,
|
||||||
|
b.Config.Team, b.Config.Server)
|
||||||
|
b.mc.SkipTLSVerify = b.Config.SkipTLSVerify
|
||||||
|
b.mc.NoTLS = b.Config.NoTLS
|
||||||
|
flog.Infof("Connecting %s (team: %s) on %s", b.Config.Login, b.Config.Team, b.Config.Server)
|
||||||
|
err := b.mc.Login()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
flog.Info("Connection succeeded")
|
||||||
|
b.TeamId = b.mc.GetTeamId()
|
||||||
|
go b.mc.WsReceiver()
|
||||||
|
go b.mc.StatusLoop()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -16,7 +16,6 @@ type Brocketchat struct {
|
|||||||
MMhook
|
MMhook
|
||||||
Config *config.Protocol
|
Config *config.Protocol
|
||||||
Remote chan config.Message
|
Remote chan config.Message
|
||||||
name string
|
|
||||||
Account string
|
Account string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package bslack
|
package bslack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
"github.com/42wim/matterbridge/matterhook"
|
"github.com/42wim/matterbridge/matterhook"
|
||||||
@ -53,22 +54,52 @@ func (b *Bslack) Command(cmd string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bslack) Connect() error {
|
func (b *Bslack) Connect() error {
|
||||||
if b.Config.WebhookURL != "" && b.Config.WebhookBindAddress != "" {
|
if b.Config.WebhookBindAddress != "" {
|
||||||
flog.Info("Connecting using webhookurl and webhookbindaddress")
|
if b.Config.WebhookURL != "" {
|
||||||
|
flog.Info("Connecting using webhookurl (sending) and webhookbindaddress (receiving)")
|
||||||
|
b.mh = matterhook.New(b.Config.WebhookURL,
|
||||||
|
matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
|
||||||
|
BindAddress: b.Config.WebhookBindAddress})
|
||||||
|
} else if b.Config.Token != "" {
|
||||||
|
flog.Info("Connecting using token (sending)")
|
||||||
|
b.sc = slack.New(b.Config.Token)
|
||||||
|
b.rtm = b.sc.NewRTM()
|
||||||
|
go b.rtm.ManageConnection()
|
||||||
|
flog.Info("Connecting using webhookbindaddress (receiving)")
|
||||||
|
b.mh = matterhook.New(b.Config.WebhookURL,
|
||||||
|
matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
|
||||||
|
BindAddress: b.Config.WebhookBindAddress})
|
||||||
|
} else {
|
||||||
|
flog.Info("Connecting using webhookbindaddress (receiving)")
|
||||||
|
b.mh = matterhook.New(b.Config.WebhookURL,
|
||||||
|
matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
|
||||||
|
BindAddress: b.Config.WebhookBindAddress})
|
||||||
|
}
|
||||||
|
go b.handleSlack()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if b.Config.WebhookURL != "" {
|
||||||
|
flog.Info("Connecting using webhookurl (sending)")
|
||||||
b.mh = matterhook.New(b.Config.WebhookURL,
|
b.mh = matterhook.New(b.Config.WebhookURL,
|
||||||
matterhook.Config{BindAddress: b.Config.WebhookBindAddress})
|
matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
|
||||||
} else if b.Config.WebhookURL != "" {
|
DisableServer: true})
|
||||||
flog.Info("Connecting using webhookurl (for posting) and token")
|
if b.Config.Token != "" {
|
||||||
b.mh = matterhook.New(b.Config.WebhookURL,
|
flog.Info("Connecting using token (receiving)")
|
||||||
matterhook.Config{DisableServer: true})
|
b.sc = slack.New(b.Config.Token)
|
||||||
} else {
|
b.rtm = b.sc.NewRTM()
|
||||||
flog.Info("Connecting using token")
|
go b.rtm.ManageConnection()
|
||||||
|
go b.handleSlack()
|
||||||
|
}
|
||||||
|
} else if b.Config.Token != "" {
|
||||||
|
flog.Info("Connecting using token (sending and receiving)")
|
||||||
b.sc = slack.New(b.Config.Token)
|
b.sc = slack.New(b.Config.Token)
|
||||||
b.rtm = b.sc.NewRTM()
|
b.rtm = b.sc.NewRTM()
|
||||||
go b.rtm.ManageConnection()
|
go b.rtm.ManageConnection()
|
||||||
|
go b.handleSlack()
|
||||||
|
}
|
||||||
|
if b.Config.WebhookBindAddress == "" && b.Config.WebhookURL == "" && b.Config.Token == "" {
|
||||||
|
return errors.New("No connection method found. See that you have WebhookBindAddress, WebhookURL or Token configured.")
|
||||||
}
|
}
|
||||||
flog.Info("Connection succeeded")
|
|
||||||
go b.handleSlack()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +110,7 @@ func (b *Bslack) Disconnect() error {
|
|||||||
|
|
||||||
func (b *Bslack) JoinChannel(channel string) error {
|
func (b *Bslack) JoinChannel(channel string) error {
|
||||||
// we can only join channels using the API
|
// we can only join channels using the API
|
||||||
if b.Config.WebhookURL == "" || b.Config.WebhookBindAddress == "" {
|
if b.Config.WebhookURL == "" && b.Config.WebhookBindAddress == "" {
|
||||||
if strings.HasPrefix(b.Config.Token, "xoxb") {
|
if strings.HasPrefix(b.Config.Token, "xoxb") {
|
||||||
// TODO check if bot has already joined channel
|
// TODO check if bot has already joined channel
|
||||||
return nil
|
return nil
|
||||||
@ -120,7 +151,7 @@ func (b *Bslack) Send(msg config.Message) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
np := slack.NewPostMessageParameters()
|
np := slack.NewPostMessageParameters()
|
||||||
if b.Config.PrefixMessagesWithNick == true {
|
if b.Config.PrefixMessagesWithNick {
|
||||||
np.AsUser = true
|
np.AsUser = true
|
||||||
}
|
}
|
||||||
np.Username = nick
|
np.Username = nick
|
||||||
@ -176,7 +207,7 @@ func (b *Bslack) getChannelByID(ID string) (*slack.Channel, error) {
|
|||||||
|
|
||||||
func (b *Bslack) handleSlack() {
|
func (b *Bslack) handleSlack() {
|
||||||
mchan := make(chan *MMMessage)
|
mchan := make(chan *MMMessage)
|
||||||
if b.Config.WebhookBindAddress != "" && b.Config.WebhookURL != "" {
|
if b.Config.WebhookBindAddress != "" {
|
||||||
flog.Debugf("Choosing webhooks based receiving")
|
flog.Debugf("Choosing webhooks based receiving")
|
||||||
go b.handleMatterHook(mchan)
|
go b.handleMatterHook(mchan)
|
||||||
} else {
|
} else {
|
||||||
@ -229,6 +260,15 @@ func (b *Bslack) handleSlackClient(mchan chan *MMMessage) {
|
|||||||
m.Text = ev.Text
|
m.Text = ev.Text
|
||||||
m.Raw = ev
|
m.Raw = ev
|
||||||
m.Text = b.replaceMention(m.Text)
|
m.Text = b.replaceMention(m.Text)
|
||||||
|
if ev.BotID != "" && user.Name == "" {
|
||||||
|
bot, err := b.rtm.GetBotInfo(ev.BotID)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if bot.Name != "" {
|
||||||
|
m.Username = bot.Name
|
||||||
|
}
|
||||||
|
}
|
||||||
mchan <- m
|
mchan <- m
|
||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
|
@ -136,7 +136,7 @@ func (b *Bsteam) handleEvents() {
|
|||||||
myLoginInfo.AuthCode = code
|
myLoginInfo.AuthCode = code
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log.Errorf("LogOnFailedEvent: ", e.Result)
|
log.Errorf("LogOnFailedEvent: %#v ", e.Result)
|
||||||
// TODO: Handle EResult_InvalidLoginAuthCode
|
// TODO: Handle EResult_InvalidLoginAuthCode
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
# v0.16.1
|
||||||
|
## New features
|
||||||
|
* slack: also relay messages of other bots #213
|
||||||
|
* mattermost: show also links if public links have not been enabled.
|
||||||
|
|
||||||
|
## Bugfix
|
||||||
|
* mattermost, slack: fix connecting logic #216
|
||||||
|
|
||||||
# v0.16.0
|
# v0.16.0
|
||||||
## Breaking Changes
|
## Breaking Changes
|
||||||
* URL,UseAPI,BindAddress is deprecated. Your config has to be updated.
|
* URL,UseAPI,BindAddress is deprecated. Your config has to be updated.
|
||||||
|
@ -96,31 +96,28 @@ func (gw *Gateway) Start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gw *Gateway) handleReceive() {
|
func (gw *Gateway) handleReceive() {
|
||||||
for {
|
for msg := range gw.Message {
|
||||||
select {
|
if msg.Event == config.EVENT_FAILURE {
|
||||||
case msg := <-gw.Message:
|
for _, br := range gw.Bridges {
|
||||||
if msg.Event == config.EVENT_FAILURE {
|
if msg.Account == br.Account {
|
||||||
for _, br := range gw.Bridges {
|
go gw.reconnectBridge(br)
|
||||||
if msg.Account == br.Account {
|
|
||||||
go gw.reconnectBridge(br)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if msg.Event == config.EVENT_REJOIN_CHANNELS {
|
}
|
||||||
for _, br := range gw.Bridges {
|
if msg.Event == config.EVENT_REJOIN_CHANNELS {
|
||||||
if msg.Account == br.Account {
|
for _, br := range gw.Bridges {
|
||||||
br.Joined = make(map[string]bool)
|
if msg.Account == br.Account {
|
||||||
br.JoinChannels()
|
br.Joined = make(map[string]bool)
|
||||||
}
|
br.JoinChannels()
|
||||||
}
|
}
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
if !gw.ignoreMessage(&msg) {
|
continue
|
||||||
msg.Timestamp = time.Now()
|
}
|
||||||
gw.modifyMessage(&msg)
|
if !gw.ignoreMessage(&msg) {
|
||||||
for _, br := range gw.Bridges {
|
msg.Timestamp = time.Now()
|
||||||
gw.handleMessage(msg, br)
|
gw.modifyMessage(&msg)
|
||||||
}
|
for _, br := range gw.Bridges {
|
||||||
|
gw.handleMessage(msg, br)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -317,8 +314,8 @@ func (gw *Gateway) validGatewayDest(msg *config.Message, channel *config.Channel
|
|||||||
|
|
||||||
// check if we are running a samechannelgateway.
|
// check if we are running a samechannelgateway.
|
||||||
// if it is and the channel name matches it's ok, otherwise we shouldn't use this channel.
|
// if it is and the channel name matches it's ok, otherwise we shouldn't use this channel.
|
||||||
for k, _ := range GIDmap {
|
for k := range GIDmap {
|
||||||
if channel.SameChannel[k] == true {
|
if channel.SameChannel[k] {
|
||||||
if msg.Channel == channel.Name {
|
if msg.Channel == channel.Name {
|
||||||
// add the gateway to our message
|
// add the gateway to our message
|
||||||
msg.Gateway = k
|
msg.Gateway = k
|
||||||
@ -329,8 +326,8 @@ func (gw *Gateway) validGatewayDest(msg *config.Message, channel *config.Channel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check if we are in the correct gateway
|
// check if we are in the correct gateway
|
||||||
for k, _ := range GIDmap {
|
for k := range GIDmap {
|
||||||
if channel.GID[k] == true {
|
if channel.GID[k] {
|
||||||
// add the gateway to our message
|
// add the gateway to our message
|
||||||
msg.Gateway = k
|
msg.Gateway = k
|
||||||
return true
|
return true
|
||||||
@ -340,8 +337,5 @@ func (gw *Gateway) validGatewayDest(msg *config.Message, channel *config.Channel
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isApi(account string) bool {
|
func isApi(account string) bool {
|
||||||
if strings.HasPrefix(account, "api.") {
|
return strings.HasPrefix(account, "api.")
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
@ -99,10 +99,9 @@ func (c *Client) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Receive returns an incoming message from mattermost outgoing webhooks URL.
|
// Receive returns an incoming message from mattermost outgoing webhooks URL.
|
||||||
func (c *Client) Receive() Message {
|
func (c *Client) Receive() Message {
|
||||||
for {
|
var msg Message
|
||||||
select {
|
for msg = range c.In {
|
||||||
case msg := <-c.In:
|
return msg
|
||||||
return msg
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return msg
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version = "0.16.0"
|
version = "0.16.1"
|
||||||
githash string
|
githash string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ func (m *MMClient) SetLogLevel(level string) {
|
|||||||
func (m *MMClient) Login() error {
|
func (m *MMClient) Login() error {
|
||||||
// check if this is a first connect or a reconnection
|
// check if this is a first connect or a reconnection
|
||||||
firstConnection := true
|
firstConnection := true
|
||||||
if m.WsConnected == true {
|
if m.WsConnected {
|
||||||
firstConnection = false
|
firstConnection = false
|
||||||
}
|
}
|
||||||
m.WsConnected = false
|
m.WsConnected = false
|
||||||
@ -149,7 +149,7 @@ func (m *MMClient) Login() error {
|
|||||||
return errors.New("invalid " + model.SESSION_COOKIE_TOKEN)
|
return errors.New("invalid " + model.SESSION_COOKIE_TOKEN)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
myinfo, appErr = m.Client.Login(m.Credentials.Login, m.Credentials.Pass)
|
_, appErr = m.Client.Login(m.Credentials.Login, m.Credentials.Pass)
|
||||||
}
|
}
|
||||||
if appErr != nil {
|
if appErr != nil {
|
||||||
d := b.Duration()
|
d := b.Duration()
|
||||||
@ -329,7 +329,6 @@ func (m *MMClient) parseActionPost(rmsg *Message) {
|
|||||||
}
|
}
|
||||||
rmsg.Text = data.Message
|
rmsg.Text = data.Message
|
||||||
rmsg.Post = data
|
rmsg.Post = data
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) UpdateUsers() error {
|
func (m *MMClient) UpdateUsers() error {
|
||||||
@ -500,6 +499,25 @@ func (m *MMClient) GetPublicLinks(filenames []string) []string {
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MMClient) GetFileLinks(filenames []string) []string {
|
||||||
|
uriScheme := "https://"
|
||||||
|
if m.NoTLS {
|
||||||
|
uriScheme = "http://"
|
||||||
|
}
|
||||||
|
|
||||||
|
var output []string
|
||||||
|
for _, f := range filenames {
|
||||||
|
res, err := m.Client.GetPublicLink(f)
|
||||||
|
if err != nil {
|
||||||
|
// public links is probably disabled, create the link ourselves
|
||||||
|
output = append(output, uriScheme+m.Credentials.Server+model.API_URL_SUFFIX_V3+"/files/"+f+"/get")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
output = append(output, res)
|
||||||
|
}
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
func (m *MMClient) UpdateChannelHeader(channelId string, header string) {
|
func (m *MMClient) UpdateChannelHeader(channelId string, header string) {
|
||||||
data := make(map[string]string)
|
data := make(map[string]string)
|
||||||
data["channel_id"] = channelId
|
data["channel_id"] = channelId
|
||||||
@ -516,7 +534,7 @@ func (m *MMClient) UpdateLastViewed(channelId string) {
|
|||||||
if m.mmVersion() >= 3.08 {
|
if m.mmVersion() >= 3.08 {
|
||||||
view := model.ChannelView{ChannelId: channelId}
|
view := model.ChannelView{ChannelId: channelId}
|
||||||
res, _ := m.Client.ViewChannel(view)
|
res, _ := m.Client.ViewChannel(view)
|
||||||
if res == false {
|
if !res {
|
||||||
m.log.Errorf("ChannelView update for %s failed", channelId)
|
m.log.Errorf("ChannelView update for %s failed", channelId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -664,13 +682,13 @@ func (m *MMClient) GetUsers() map[string]*model.User {
|
|||||||
func (m *MMClient) GetUser(userId string) *model.User {
|
func (m *MMClient) GetUser(userId string) *model.User {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
u, ok := m.Users[userId]
|
_, ok := m.Users[userId]
|
||||||
if !ok {
|
if !ok {
|
||||||
res, err := m.Client.GetProfilesByIds([]string{userId})
|
res, err := m.Client.GetProfilesByIds([]string{userId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
u = res.Data.(map[string]*model.User)[userId]
|
u := res.Data.(map[string]*model.User)[userId]
|
||||||
m.Users[userId] = u
|
m.Users[userId] = u
|
||||||
}
|
}
|
||||||
return m.Users[userId]
|
return m.Users[userId]
|
||||||
|
@ -134,12 +134,11 @@ func (c *Client) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Receive returns an incoming message from mattermost outgoing webhooks URL.
|
// Receive returns an incoming message from mattermost outgoing webhooks URL.
|
||||||
func (c *Client) Receive() IMessage {
|
func (c *Client) Receive() IMessage {
|
||||||
for {
|
var msg IMessage
|
||||||
select {
|
for msg := range c.In {
|
||||||
case msg := <-c.In:
|
return msg
|
||||||
return msg
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send sends a msg to mattermost incoming webhooks URL.
|
// Send sends a msg to mattermost incoming webhooks URL.
|
||||||
|
Reference in New Issue
Block a user