Add channel key support (irc). Closes #27

This commit is contained in:
Wim 2017-01-04 14:10:35 +01:00
parent 01afe03a3f
commit 7685fe1724
3 changed files with 37 additions and 7 deletions

View File

@ -52,9 +52,14 @@ type Protocol struct {
UseTLS bool // IRC UseTLS bool // IRC
} }
type ChannelOptions struct {
Key string // irc
}
type Bridge struct { type Bridge struct {
Account string Account string
Channel string Channel string
Options ChannelOptions
} }
type Gateway struct { type Gateway struct {

View File

@ -13,12 +13,13 @@ type Gateway struct {
*config.Config *config.Config
MyConfig *config.Gateway MyConfig *config.Gateway
//Bridges []*bridge.Bridge //Bridges []*bridge.Bridge
Bridges map[string]*bridge.Bridge Bridges map[string]*bridge.Bridge
ChannelsOut map[string][]string ChannelsOut map[string][]string
ChannelsIn map[string][]string ChannelsIn map[string][]string
ignoreNicks map[string][]string ignoreNicks map[string][]string
Name string ChannelOptions map[string]config.ChannelOptions
Message chan config.Message Name string
Message chan config.Message
} }
func New(cfg *config.Config, gateway *config.Gateway) *Gateway { func New(cfg *config.Config, gateway *config.Gateway) *Gateway {
@ -47,8 +48,13 @@ func (gw *Gateway) AddBridge(cfg *config.Bridge) error {
exists := make(map[string]bool) exists := make(map[string]bool)
for _, channel := range append(gw.ChannelsOut[br.Account], gw.ChannelsIn[br.Account]...) { for _, channel := range append(gw.ChannelsOut[br.Account], gw.ChannelsIn[br.Account]...) {
if !exists[br.Account+channel] { if !exists[br.Account+channel] {
mychannel := channel
log.Infof("%s: joining %s", br.Account, channel) log.Infof("%s: joining %s", br.Account, channel)
br.JoinChannel(channel) if br.Protocol == "irc" && gw.ChannelOptions[br.Account+channel].Key != "" {
log.Debugf("using key %s for channel %s", gw.ChannelOptions[br.Account+channel].Key, channel)
mychannel = mychannel + " " + gw.ChannelOptions[br.Account+channel].Key
}
br.JoinChannel(mychannel)
exists[br.Account+channel] = true exists[br.Account+channel] = true
} }
} }
@ -81,21 +87,26 @@ func (gw *Gateway) handleReceive() {
} }
func (gw *Gateway) mapChannels() error { func (gw *Gateway) mapChannels() error {
options := make(map[string]config.ChannelOptions)
m := make(map[string][]string) m := make(map[string][]string)
for _, br := range gw.MyConfig.Out { for _, br := range gw.MyConfig.Out {
m[br.Account] = append(m[br.Account], br.Channel) m[br.Account] = append(m[br.Account], br.Channel)
options[br.Account+br.Channel] = br.Options
} }
gw.ChannelsOut = m gw.ChannelsOut = m
m = nil m = nil
m = make(map[string][]string) m = make(map[string][]string)
for _, br := range gw.MyConfig.In { for _, br := range gw.MyConfig.In {
m[br.Account] = append(m[br.Account], br.Channel) m[br.Account] = append(m[br.Account], br.Channel)
options[br.Account+br.Channel] = br.Options
} }
gw.ChannelsIn = m gw.ChannelsIn = m
for _, br := range gw.MyConfig.InOut { for _, br := range gw.MyConfig.InOut {
gw.ChannelsIn[br.Account] = append(gw.ChannelsIn[br.Account], br.Channel) gw.ChannelsIn[br.Account] = append(gw.ChannelsIn[br.Account], br.Channel)
gw.ChannelsOut[br.Account] = append(gw.ChannelsOut[br.Account], br.Channel) gw.ChannelsOut[br.Account] = append(gw.ChannelsOut[br.Account], br.Channel)
options[br.Account+br.Channel] = br.Options
} }
gw.ChannelOptions = options
return nil return nil
} }

View File

@ -534,18 +534,32 @@ enable=true
#REQUIRED #REQUIRED
channel="#testing" channel="#testing"
#OPTIONAL - only used for IRC protocol at the moment
[gateway.in.options]
#OPTIONAL - your irc channel key
key="yourkey"
#[[gateway.out]] specifies the account and channels we will sent messages to. #[[gateway.out]] specifies the account and channels we will sent messages to.
[[gateway.out]] [[gateway.out]]
account="irc.freenode" account="irc.freenode"
channel="#testing" channel="#testing"
#OPTIONAL - only used for IRC protocol at the moment
[gateway.out.options]
#OPTIONAL - your irc channel key
key="yourkey"
#[[gateway.inout]] can be used when then channel will be used to receive from #[[gateway.inout]] can be used when then channel will be used to receive from
#and send messages to #and send messages to
[[gateway.inout]] [[gateway.inout]]
account="mattermost.work" account="mattermost.work"
channel="off-topic" channel="off-topic"
#OPTIONAL - only used for IRC protocol at the moment
[gateway.inout.options]
#OPTIONAL - your irc channel key
key="yourkey"
#If you want to do a 1:1 mapping between protocols where the channelnames are the same #If you want to do a 1:1 mapping between protocols where the channelnames are the same
#e.g. slack and mattermost you can use the samechannelgateway configuration #e.g. slack and mattermost you can use the samechannelgateway configuration