コード例 #1
0
ファイル: rocketchat.go プロジェクト: 42wim/matterbridge
func (b *Brocketchat) Connect() error {
	flog.Info("Connecting webhooks")
	b.mh = matterhook.New(b.Config.URL,
		matterhook.Config{InsecureSkipVerify: b.Config.SkipTLSVerify,
			DisableServer: true})
	b.rh = rockethook.New(b.Config.URL, rockethook.Config{BindAddress: b.Config.BindAddress})
	go b.handleRocketHook()
	return nil
}
コード例 #2
0
ファイル: matterbridge.go プロジェクト: Rotwang/matterbridge
func NewBridge(name string, config *Config) *Bridge {
	b := &Bridge{}
	b.Config = config
	b.m = matterhook.New(b.Config.Mattermost.URL,
		matterhook.Config{Port: b.Config.Mattermost.Port, Token: b.Config.Mattermost.Token,
			InsecureSkipVerify: b.Config.Mattermost.SkipTLSVerify})
	b.i = b.createIRC(name)
	go b.handleMatter()
	return b
}
コード例 #3
0
ファイル: bridge.go プロジェクト: 42wim/matterbridge
func NewBridge(name string, config *Config, kind string) *Bridge {
	initFLog()
	b := &Bridge{}
	b.Config = config
	b.kind = kind
	b.ircNick = b.Config.IRC.Nick
	b.ircMap = make(map[string]string)
	b.MMirc.names = make(map[string][]string)
	b.ircIgnoreNicks = strings.Fields(b.Config.IRC.IgnoreNicks)
	b.mmIgnoreNicks = strings.Fields(b.Config.Mattermost.IgnoreNicks)
	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,
			matterhook.Config{Port: b.Config.Mattermost.Port, Token: b.Config.Mattermost.Token,
				InsecureSkipVerify: b.Config.Mattermost.SkipTLSVerify,
				BindAddress:        b.Config.Mattermost.BindAddress})
	} 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.Config.Mattermost.Team, b.Config.Mattermost.Server)
		b.mc.SkipTLSVerify = b.Config.Mattermost.SkipTLSVerify
		b.mc.NoTLS = b.Config.Mattermost.NoTLS
		flog.mm.Infof("Trying login %s (team: %s) on %s", b.Config.Mattermost.Login, b.Config.Mattermost.Team, b.Config.Mattermost.Server)
		err := b.mc.Login()
		if err != nil {
			flog.mm.Fatal("Can not connect", err)
		}
		flog.mm.Info("Login ok")
		b.mc.JoinChannel(b.Config.Mattermost.Channel)
		if len(b.Config.Channel) > 0 {
			for _, val := range b.Config.Channel {
				b.mc.JoinChannel(val.Mattermost)
			}
		}
		go b.mc.WsReceiver()
	}
	flog.irc.Info("Trying IRC connection")
	b.i = b.createIRC(name)
	flog.irc.Info("Connection succeeded")
	go b.handleMatter()
	return b
}
コード例 #4
0
ファイル: slack.go プロジェクト: 42wim/matterbridge
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})
	} else {
		b.sc = slack.New(b.Config.Token)
		b.rtm = b.sc.NewRTM()
		go b.rtm.ManageConnection()
	}
	flog.Info("Connection succeeded")
	go b.handleSlack()
	return nil
}
コード例 #5
0
func NewBridge(name string, config *Config) *Bridge {
	b := &Bridge{}
	b.Config = config
	b.cmap = make(map[string]string)
	if len(b.Config.Token) > 0 {
		for _, val := range b.Config.Token {
			b.cmap[val.IRCChannel] = val.MMChannel
		}
	}
	b.m = matterhook.New(b.Config.Mattermost.URL,
		matterhook.Config{Port: b.Config.Mattermost.Port, Token: b.Config.Mattermost.Token,
			InsecureSkipVerify: b.Config.Mattermost.SkipTLSVerify,
			BindAddress:        b.Config.Mattermost.BindAddress})
	b.i = b.createIRC(name)
	go b.handleMatter()
	return b
}
コード例 #6
0
ファイル: main.go プロジェクト: 42wim/matterstuff
func main() {
	if flagVersion {
		fmt.Println("version:", version)
		return
	}
	url := os.Getenv("MM_HOOK")
	if cfg.MatterURL != "" {
		url = cfg.MatterURL
	}
	m := matterhook.New(url, matterhook.Config{DisableServer: true})
	msg := matterhook.OMessage{}
	msg.UserName = cfg.Username
	msg.Channel = cfg.Channel
	msg.IconURL = cfg.IconURL
	if cfg.NoBuffer {
		scanner := bufio.NewScanner(os.Stdin)
		for scanner.Scan() {
			line := scanner.Text()
			fmt.Println(line)
			msg.Text = md(line)
			if cfg.PlainText {
				msg.Text = line
			}
			m.Send(msg)
		}
	} else {
		buf := new(bytes.Buffer)
		io.Copy(buf, os.Stdin)
		text := buf.String()
		fmt.Print(text)
		msg.Text = md(text)
		if cfg.PlainText {
			msg.Text = text
		}
		if cfg.Extra {
			msg.Text += extraInfo()
		}
		if cfg.Title != "" {
			msg.Text = cfg.Title + "\n" + msg.Text
		}
		m.Send(msg)
	}
}