diff options
author | Wim <wim@42.be> | 2016-11-13 23:06:37 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2016-11-13 23:06:37 +0100 |
commit | 99d130d1ed4c389a76d4fe7f5ea8fccb78bad444 (patch) | |
tree | 8799742a6713d28050f5af14ba8d2b1d62cd766a /bridge/slack/slack.go | |
parent | 14830d9f1c4e9435ee7a15e0839876ad1f4d1a9f (diff) | |
download | matterbridge-msglm-99d130d1ed4c389a76d4fe7f5ea8fccb78bad444.tar.gz matterbridge-msglm-99d130d1ed4c389a76d4fe7f5ea8fccb78bad444.tar.bz2 matterbridge-msglm-99d130d1ed4c389a76d4fe7f5ea8fccb78bad444.zip |
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)} } } } |