Updated nlopes/slack to 4.1-dev.

This commit is contained in:
Patrick Connolly
2018-11-17 05:19:02 +08:00
parent f94c2b40a3
commit 9eae93bf1e
3 changed files with 20 additions and 9 deletions

View File

@@ -303,12 +303,14 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) {
return msg.ID, err
}
messageParameters := b.prepareMessageParameters(&msg)
var messageOptions []slack.MsgOption
// Upload a file if it exists.
if msg.Extra != nil {
for _, rmsg := range helper.HandleExtra(&msg, b.General) {
_, _, err = b.rtm.PostMessage(channelInfo.ID, rmsg.Username+rmsg.Text, *messageParameters)
messageOptions = b.prepareMessageOptions(&rmsg)
messageOptions = append(messageOptions, slack.MsgOptionText(rmsg.Username+rmsg.Text, false))
_, _, err = b.rtm.PostMessage(channelInfo.ID, messageOptions...)
if err != nil {
b.Log.Error(err)
}
@@ -318,7 +320,9 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) {
}
// Post message.
return b.postMessage(&msg, messageParameters, channelInfo)
messageOptions = b.prepareMessageOptions(&msg)
messageOptions = append(messageOptions, slack.MsgOptionText(msg.Text, false))
return b.postMessage(&msg, messageOptions, channelInfo)
}
func (b *Bslack) updateTopicOrPurpose(msg *config.Message, channelInfo *slack.Channel) (bool, error) {
@@ -393,7 +397,9 @@ func (b *Bslack) editMessage(msg *config.Message, channelInfo *slack.Channel) (b
}
for {
_, _, _, err := b.rtm.UpdateMessage(channelInfo.ID, msg.ID, msg.Text)
messageOptions := b.prepareMessageOptions(msg)
messageOptions = append(messageOptions, slack.MsgOptionText(msg.Text, false))
_, _, _, err := b.rtm.UpdateMessage(channelInfo.ID, msg.ID, messageOptions...)
if err == nil {
return true, nil
}
@@ -405,13 +411,13 @@ func (b *Bslack) editMessage(msg *config.Message, channelInfo *slack.Channel) (b
}
}
func (b *Bslack) postMessage(msg *config.Message, messageParameters *slack.PostMessageParameters, channelInfo *slack.Channel) (string, error) {
func (b *Bslack) postMessage(msg *config.Message, messageOptions []slack.MsgOption, channelInfo *slack.Channel) (string, error) {
// don't post empty messages
if msg.Text == "" {
return "", nil
}
for {
_, id, err := b.rtm.PostMessage(channelInfo.ID, msg.Text, *messageParameters)
_, id, err := b.rtm.PostMessage(channelInfo.ID, messageOptions...)
if err == nil {
return id, nil
}
@@ -461,7 +467,7 @@ func (b *Bslack) uploadFile(msg *config.Message, channelID string) {
}
}
func (b *Bslack) prepareMessageParameters(msg *config.Message) *slack.PostMessageParameters {
func (b *Bslack) prepareMessageOptions(msg *config.Message) []slack.MsgOption {
params := slack.NewPostMessageParameters()
if b.GetBool(useNickPrefixConfig) {
params.AsUser = true
@@ -483,7 +489,10 @@ func (b *Bslack) prepareMessageParameters(msg *config.Message) *slack.PostMessag
params.Attachments = append(params.Attachments, attach.([]slack.Attachment)...)
}
}
return &params
var opts []slack.MsgOption
opts = append(opts, slack.MsgOptionAttachments(params.Attachments...))
opts = append(opts, slack.MsgOptionPostMessageParameters(params))
return opts
}
func (b *Bslack) createAttach(extra map[string][]interface{}) []slack.Attachment {

2
go.mod
View File

@@ -37,7 +37,7 @@ require (
github.com/mreiferson/go-httpclient v0.0.0-20160630210159-31f0106b4474 // indirect
github.com/mrexodia/wray v0.0.0-20160318003008-78a2c1f284ff // indirect
github.com/nicksnyder/go-i18n v1.4.0 // indirect
github.com/nlopes/slack v0.4.0
github.com/nlopes/slack v0.4.1-0.20181111125009-5963eafd777b
github.com/onsi/ginkgo v1.6.0 // indirect
github.com/onsi/gomega v1.4.1 // indirect
github.com/paulrosania/go-charset v0.0.0-20151028000031-621bb39fcc83

2
go.sum
View File

@@ -88,6 +88,8 @@ github.com/nicksnyder/go-i18n v1.4.0 h1:AgLl+Yq7kg5OYlzCgu9cKTZOyI4tD/NgukKqLqC8
github.com/nicksnyder/go-i18n v1.4.0/go.mod h1:HrK7VCrbOvQoUAQ7Vpy7i87N7JZZZ7R2xBGjv0j365Q=
github.com/nlopes/slack v0.4.0 h1:OVnHm7lv5gGT5gkcHsZAyw++oHVFihbjWbL3UceUpiA=
github.com/nlopes/slack v0.4.0/go.mod h1:jVI4BBK3lSktibKahxBF74txcK2vyvkza1z/+rRnVAM=
github.com/nlopes/slack v0.4.1-0.20181111125009-5963eafd777b h1:8ncrr7Xps0GafXIxBzrq1qSjy1zhiCDp/9C4cOrE+GU=
github.com/nlopes/slack v0.4.1-0.20181111125009-5963eafd777b/go.mod h1:jVI4BBK3lSktibKahxBF74txcK2vyvkza1z/+rRnVAM=
github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.1 h1:PZSj/UFNaVp3KxrzHOcS7oyuWA7LoOY/77yCTEFu21U=