mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-10 22:19:26 +01:00
Remove multiple Token config. Use same channel setup as from matterbridge-plus
This commit is contained in:
parent
8fb5c7afa6
commit
a87cac1982
22
README.md
22
README.md
@ -51,11 +51,11 @@ Look at matterbridge.conf.sample for an example
|
|||||||
[IRC]
|
[IRC]
|
||||||
server="irc.freenode.net"
|
server="irc.freenode.net"
|
||||||
port=6667
|
port=6667
|
||||||
|
#default no TLS connection to irc server
|
||||||
UseTLS=false
|
UseTLS=false
|
||||||
|
#do not check the certificate if we use TLS (allows for selfsigned certificates)
|
||||||
SkipTLSVerify=true
|
SkipTLSVerify=true
|
||||||
nick="matterbot"
|
nick="matterbot"
|
||||||
channel="#matterbridge"
|
|
||||||
UseSlackCircumfix=false
|
|
||||||
#Freenode nickserv
|
#Freenode nickserv
|
||||||
NickServNick="nickserv"
|
NickServNick="nickserv"
|
||||||
#Password for nickserv
|
#Password for nickserv
|
||||||
@ -71,9 +71,8 @@ port=9999
|
|||||||
#address the webserver will bind to
|
#address the webserver will bind to
|
||||||
BindAddress="0.0.0.0"
|
BindAddress="0.0.0.0"
|
||||||
showjoinpart=true #show irc users joining and parting
|
showjoinpart=true #show irc users joining and parting
|
||||||
#the token you get from the outgoing webhook in mattermost. If empty no token check will be done.
|
#the token you get from the outgoing webhook in mattermost.
|
||||||
#if you use multiple IRC channel (see below, this must be empty!)
|
Token="outgoingwebhooktoken1"
|
||||||
token=yourtokenfrommattermost
|
|
||||||
#disable certificate checking (selfsigned certificates)
|
#disable certificate checking (selfsigned certificates)
|
||||||
#SkipTLSVerify=true
|
#SkipTLSVerify=true
|
||||||
#whether to prefix messages from IRC to mattermost with the sender's nick. Useful if username overrides for incoming webhooks isn't enabled on the mattermost server
|
#whether to prefix messages from IRC to mattermost with the sender's nick. Useful if username overrides for incoming webhooks isn't enabled on the mattermost server
|
||||||
@ -86,14 +85,13 @@ NicksPerRow=4
|
|||||||
IgnoreNicks="mmbot spammer2"
|
IgnoreNicks="mmbot spammer2"
|
||||||
|
|
||||||
#multiple channel config
|
#multiple channel config
|
||||||
#token you can find in your outgoing webhook
|
[Channel "channel1"]
|
||||||
[Token "outgoingwebhooktoken1"]
|
IRC="#off-topic"
|
||||||
IRCChannel="#off-topic"
|
mattermost="off-topic"
|
||||||
MMChannel="off-topic"
|
|
||||||
|
|
||||||
[Token "outgoingwebhooktoken2"]
|
[Channel "testchannel"]
|
||||||
IRCChannel="#testing"
|
IRC="#testing"
|
||||||
MMChannel="testing"
|
mattermost="testing"
|
||||||
|
|
||||||
[general]
|
[general]
|
||||||
#request your API key on https://github.com/giphy/GiphyAPI. This is a public beta key
|
#request your API key on https://github.com/giphy/GiphyAPI. This is a public beta key
|
||||||
|
@ -69,28 +69,20 @@ func NewBridge(name string, config *Config, kind string) *Bridge {
|
|||||||
b.kind = kind
|
b.kind = kind
|
||||||
b.ircNick = b.Config.IRC.Nick
|
b.ircNick = b.Config.IRC.Nick
|
||||||
b.ircMap = make(map[string]string)
|
b.ircMap = make(map[string]string)
|
||||||
|
b.mmMap = make(map[string]string)
|
||||||
b.MMirc.names = make(map[string][]string)
|
b.MMirc.names = make(map[string][]string)
|
||||||
b.ircIgnoreNicks = strings.Fields(b.Config.IRC.IgnoreNicks)
|
b.ircIgnoreNicks = strings.Fields(b.Config.IRC.IgnoreNicks)
|
||||||
b.mmIgnoreNicks = strings.Fields(b.Config.Mattermost.IgnoreNicks)
|
b.mmIgnoreNicks = strings.Fields(b.Config.Mattermost.IgnoreNicks)
|
||||||
|
for _, val := range b.Config.Channel {
|
||||||
|
b.ircMap[val.IRC] = val.Mattermost
|
||||||
|
b.mmMap[val.Mattermost] = val.IRC
|
||||||
|
}
|
||||||
if kind == Legacy {
|
if kind == Legacy {
|
||||||
if len(b.Config.Token) > 0 {
|
|
||||||
for _, val := range b.Config.Token {
|
|
||||||
b.ircMap[val.IRCChannel] = val.MMChannel
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
b.mh = matterhook.New(b.Config.Mattermost.URL,
|
b.mh = matterhook.New(b.Config.Mattermost.URL,
|
||||||
matterhook.Config{Port: b.Config.Mattermost.Port, Token: b.Config.Mattermost.Token,
|
matterhook.Config{Port: b.Config.Mattermost.Port, Token: b.Config.Mattermost.Token,
|
||||||
InsecureSkipVerify: b.Config.Mattermost.SkipTLSVerify,
|
InsecureSkipVerify: b.Config.Mattermost.SkipTLSVerify,
|
||||||
BindAddress: b.Config.Mattermost.BindAddress})
|
BindAddress: b.Config.Mattermost.BindAddress})
|
||||||
} else {
|
} else {
|
||||||
b.mmMap = make(map[string]string)
|
|
||||||
if len(b.Config.Channel) > 0 {
|
|
||||||
for _, val := range b.Config.Channel {
|
|
||||||
b.ircMap[val.IRC] = val.Mattermost
|
|
||||||
b.mmMap[val.Mattermost] = val.IRC
|
|
||||||
}
|
|
||||||
}
|
|
||||||
b.mc = matterclient.New(b.Config.Mattermost.Login, b.Config.Mattermost.Password,
|
b.mc = matterclient.New(b.Config.Mattermost.Login, b.Config.Mattermost.Password,
|
||||||
b.Config.Mattermost.Team, b.Config.Mattermost.Server)
|
b.Config.Mattermost.Team, b.Config.Mattermost.Server)
|
||||||
b.mc.SkipTLSVerify = b.Config.Mattermost.SkipTLSVerify
|
b.mc.SkipTLSVerify = b.Config.Mattermost.SkipTLSVerify
|
||||||
@ -102,10 +94,8 @@ func NewBridge(name string, config *Config, kind string) *Bridge {
|
|||||||
}
|
}
|
||||||
flog.mm.Info("Login ok")
|
flog.mm.Info("Login ok")
|
||||||
b.mc.JoinChannel(b.Config.Mattermost.Channel)
|
b.mc.JoinChannel(b.Config.Mattermost.Channel)
|
||||||
if len(b.Config.Channel) > 0 {
|
for _, val := range b.Config.Channel {
|
||||||
for _, val := range b.Config.Channel {
|
b.mc.JoinChannel(val.Mattermost)
|
||||||
b.mc.JoinChannel(val.Mattermost)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
go b.mc.WsReceiver()
|
go b.mc.WsReceiver()
|
||||||
}
|
}
|
||||||
@ -153,20 +143,9 @@ func (b *Bridge) handleNewConnection(event *irc.Event) {
|
|||||||
|
|
||||||
func (b *Bridge) setupChannels() {
|
func (b *Bridge) setupChannels() {
|
||||||
i := b.i
|
i := b.i
|
||||||
if b.Config.IRC.Channel != "" {
|
for _, val := range b.Config.Channel {
|
||||||
flog.irc.Infof("Joining %s as %s", b.Config.IRC.Channel, b.ircNick)
|
flog.irc.Infof("Joining %s as %s", val.IRC, b.ircNick)
|
||||||
i.Join(b.Config.IRC.Channel)
|
i.Join(val.IRC)
|
||||||
}
|
|
||||||
if b.kind == Legacy {
|
|
||||||
for _, val := range b.Config.Token {
|
|
||||||
flog.irc.Infof("Joining %s as %s", val.IRCChannel, b.ircNick)
|
|
||||||
i.Join(val.IRCChannel)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for _, val := range b.Config.Channel {
|
|
||||||
flog.irc.Infof("Joining %s as %s", val.IRC, b.ircNick)
|
|
||||||
i.Join(val.IRC)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,6 +182,7 @@ func (b *Bridge) ircNickFormat(nick string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bridge) handlePrivMsg(event *irc.Event) {
|
func (b *Bridge) handlePrivMsg(event *irc.Event) {
|
||||||
|
flog.irc.Debugf("handlePrivMsg() %s %s", event.Nick, event.Message)
|
||||||
if b.ignoreMessage(event.Nick, event.Message(), "irc") {
|
if b.ignoreMessage(event.Nick, event.Message(), "irc") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -307,6 +287,7 @@ func (b *Bridge) SendType(nick string, message string, channel string, mtype str
|
|||||||
flog.mm.Info(err)
|
flog.mm.Info(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
flog.mm.Debug("->mattermost channel: ", channel, " ", message)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
flog.mm.Debug("->mattermost channel: ", channel, " ", message)
|
flog.mm.Debug("->mattermost channel: ", channel, " ", message)
|
||||||
@ -317,10 +298,11 @@ func (b *Bridge) SendType(nick string, message string, channel string, mtype str
|
|||||||
func (b *Bridge) handleMatterHook(mchan chan *MMMessage) {
|
func (b *Bridge) handleMatterHook(mchan chan *MMMessage) {
|
||||||
for {
|
for {
|
||||||
message := b.mh.Receive()
|
message := b.mh.Receive()
|
||||||
|
flog.mm.Debugf("receiving from matterhook %#v", message)
|
||||||
m := &MMMessage{}
|
m := &MMMessage{}
|
||||||
m.Username = message.UserName
|
m.Username = message.UserName
|
||||||
m.Text = message.Text
|
m.Text = message.Text
|
||||||
m.Channel = message.Token
|
m.Channel = message.ChannelName
|
||||||
mchan <- m
|
mchan <- m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -329,11 +311,11 @@ func (b *Bridge) handleMatterClient(mchan chan *MMMessage) {
|
|||||||
for message := range b.mc.MessageChan {
|
for message := range b.mc.MessageChan {
|
||||||
// do not post our own messages back to irc
|
// do not post our own messages back to irc
|
||||||
if message.Raw.Action == "posted" && b.mc.User.Username != message.Username {
|
if message.Raw.Action == "posted" && b.mc.User.Username != message.Username {
|
||||||
|
flog.mm.Debugf("receiving from matterclient %#v", message)
|
||||||
m := &MMMessage{}
|
m := &MMMessage{}
|
||||||
m.Username = message.Username
|
m.Username = message.Username
|
||||||
m.Channel = message.Channel
|
m.Channel = message.Channel
|
||||||
m.Text = message.Text
|
m.Text = message.Text
|
||||||
flog.mm.Debugf("<-mattermost channel: %s %#v %#v", message.Channel, message.Post, message.Raw)
|
|
||||||
mchan <- m
|
mchan <- m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -394,30 +376,15 @@ func (b *Bridge) giphyRandom(query []string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bridge) getMMChannel(ircChannel string) string {
|
func (b *Bridge) getMMChannel(ircChannel string) string {
|
||||||
mmchannel, ok := b.ircMap[ircChannel]
|
mmChannel := b.ircMap[ircChannel]
|
||||||
if !ok {
|
|
||||||
mmchannel = b.Config.Mattermost.Channel
|
|
||||||
}
|
|
||||||
if b.kind == Legacy {
|
if b.kind == Legacy {
|
||||||
return mmchannel
|
return mmChannel
|
||||||
}
|
}
|
||||||
return b.mc.GetChannelId(mmchannel, "")
|
return b.mc.GetChannelId(mmChannel, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bridge) getIRCChannel(channel string) string {
|
func (b *Bridge) getIRCChannel(mmChannel string) string {
|
||||||
if b.kind == Legacy {
|
return b.mmMap[mmChannel]
|
||||||
ircchannel := b.Config.IRC.Channel
|
|
||||||
_, ok := b.Config.Token[channel]
|
|
||||||
if ok {
|
|
||||||
ircchannel = b.Config.Token[channel].IRCChannel
|
|
||||||
}
|
|
||||||
return ircchannel
|
|
||||||
}
|
|
||||||
ircchannel, ok := b.mmMap[channel]
|
|
||||||
if !ok {
|
|
||||||
ircchannel = b.Config.IRC.Channel
|
|
||||||
}
|
|
||||||
return ircchannel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bridge) ignoreMessage(nick string, message string, protocol string) bool {
|
func (b *Bridge) ignoreMessage(nick string, message string, protocol string) bool {
|
||||||
|
@ -40,10 +40,6 @@ type Config struct {
|
|||||||
IgnoreNicks string
|
IgnoreNicks string
|
||||||
NoTLS bool
|
NoTLS bool
|
||||||
}
|
}
|
||||||
Token map[string]*struct {
|
|
||||||
IRCChannel string
|
|
||||||
MMChannel string
|
|
||||||
}
|
|
||||||
Channel map[string]*struct {
|
Channel map[string]*struct {
|
||||||
IRC string
|
IRC string
|
||||||
Mattermost string
|
Mattermost string
|
||||||
|
Loading…
Reference in New Issue
Block a user