diff options
author | Wim <wim@42.be> | 2016-11-13 23:09:06 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2016-11-13 23:09:06 +0100 |
commit | 497633867759601d658233257447b5b86aa1b01e (patch) | |
tree | bc732d5333ddcd0343e1c2d7fd0a025c23822196 /bridge/slack/slack.go | |
parent | 4fb0544b0e25bf6409811fc3e574bf45efea369d (diff) | |
parent | 99d130d1ed4c389a76d4fe7f5ea8fccb78bad444 (diff) | |
download | matterbridge-msglm-497633867759601d658233257447b5b86aa1b01e.tar.gz matterbridge-msglm-497633867759601d658233257447b5b86aa1b01e.tar.bz2 matterbridge-msglm-497633867759601d658233257447b5b86aa1b01e.zip |
Merge branch 'refactor'
Diffstat (limited to 'bridge/slack/slack.go')
-rw-r--r-- | bridge/slack/slack.go | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index f700aee8..159204d0 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -25,8 +25,7 @@ type Bslack struct { Plus bool Remote chan config.Message Users []slack.User - protocol string - origin string + Account string si *slack.Info channels []slack.Channel } @@ -38,12 +37,11 @@ func init() { flog = log.WithFields(log.Fields{"module": protocol}) } -func New(cfg config.Protocol, origin string, c chan config.Message) *Bslack { +func New(cfg config.Protocol, account string, c chan config.Message) *Bslack { b := &Bslack{} b.Config = &cfg b.Remote = c - b.protocol = protocol - b.origin = origin + b.Account = account return b } @@ -66,10 +64,6 @@ func (b *Bslack) Connect() error { return nil } -func (b *Bslack) FullOrigin() string { - return b.protocol + "." + b.origin -} - func (b *Bslack) JoinChannel(channel string) error { // we can only join channels using the API if b.Config.UseAPI { @@ -81,24 +75,12 @@ func (b *Bslack) JoinChannel(channel string) error { return nil } -func (b *Bslack) Name() string { - return b.protocol + "." + b.origin -} - -func (b *Bslack) Protocol() string { - return b.protocol -} - -func (b *Bslack) Origin() string { - return b.origin -} - func (b *Bslack) Send(msg config.Message) error { flog.Debugf("Receiving %#v", msg) - if msg.FullOrigin == b.FullOrigin() { + if msg.Account == b.Account { return nil } - nick := config.GetNick(&msg, b.Config) + nick := msg.Username message := msg.Text channel := msg.Channel if b.Config.PrefixMessagesWithNick { @@ -154,14 +136,14 @@ func (b *Bslack) getAvatar(user string) string { func (b *Bslack) getChannelByName(name string) (*slack.Channel, error) { if b.channels == nil { - return nil, fmt.Errorf("%s: channel %s not found (no channels found)", b.FullOrigin(), name) + return nil, fmt.Errorf("%s: channel %s not found (no channels found)", b.Account, name) } for _, channel := range b.channels { if channel.Name == name { return &channel, nil } } - return nil, fmt.Errorf("%s: channel %s not found", b.FullOrigin(), name) + return nil, fmt.Errorf("%s: channel %s not found", b.Account, name) } func (b *Bslack) handleSlack() { @@ -181,8 +163,8 @@ func (b *Bslack) handleSlack() { } texts := strings.Split(message.Text, "\n") for _, text := range texts { - flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.FullOrigin()) - b.Remote <- config.Message{Text: text, Username: message.Username, Channel: message.Channel, Origin: b.origin, Protocol: b.protocol, FullOrigin: b.FullOrigin(), Avatar: b.getAvatar(message.Username)} + flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account) + b.Remote <- config.Message{Text: text, Username: message.Username, Channel: message.Channel, Account: b.Account, Avatar: b.getAvatar(message.Username)} } } } |