Skip to content

Commit

Permalink
chore: go 1.13; bump slack lib; fix deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
wass3r committed Oct 14, 2019
1 parent 1fb3a63 commit 0647a4c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- "1.12"
- "1.13"
before_install:
- go get github.com/mattn/goveralls
- go get github.com/fzipp/gocyclo
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ require (
github.com/gorilla/mux v1.7.0
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/leekchan/gtf v0.0.0-20190214083521-5fba33c5b00b
github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5 // indirect
github.com/lusis/slack-test v0.0.0-20190426140909-c40012f20018 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/nlopes/slack v0.4.0
github.com/nlopes/slack v0.6.0
github.com/pkg/errors v0.8.1 // indirect
github.com/prometheus/client_golang v0.9.1
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 // indirect
Expand All @@ -26,3 +24,5 @@ require (
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c // indirect
golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc // indirect
)

go 1.13
9 changes: 3 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/gorilla/mux v1.7.0 h1:tOSd0UKHQd6urX6ApfOn4XdBMY6Sh1MfxV3kmaazO+U=
github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
Expand All @@ -37,10 +38,6 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxv
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/leekchan/gtf v0.0.0-20190214083521-5fba33c5b00b h1:ozQQA/k08pNmaav0AxE/EYzN4jvzvhD2idtcHcSAOSA=
github.com/leekchan/gtf v0.0.0-20190214083521-5fba33c5b00b/go.mod h1:thNruaSwydMhkQ8dXzapABF9Sc1Tz08ZBcDdgott9RA=
github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5 h1:AsEBgzv3DhuYHI/GiQh2HxvTP71HCCE9E/tzGUzGdtU=
github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5/go.mod h1:c2mYKRyMb1BPkO5St0c/ps62L4S0W2NAkaTXj9qEI+0=
github.com/lusis/slack-test v0.0.0-20190426140909-c40012f20018 h1:MNApn+Z+fIT4NPZopPfCc1obT6aY3SVM6DOctz1A9ZU=
github.com/lusis/slack-test v0.0.0-20190426140909-c40012f20018/go.mod h1:sFlOUpQL1YcjhFVXhg1CG8ZASEs/Mf1oVb6H75JL/zg=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
Expand All @@ -50,8 +47,8 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
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.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA=
github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
58 changes: 18 additions & 40 deletions remote/slack/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Slack helper functions (anything that uses the 'nlopes/slack' package)
// constructInteractiveComponentMessage creates a message specifically for a matched rule from the Interactive Components server
func constructInteractiveComponentMessage(callback slack.AttachmentActionCallback, bot *models.Bot) models.Message {
text := ""
if len(callback.Actions) > 0 {
for _, action := range callback.Actions {
if len(callback.ActionCallback.AttachmentActions) > 0 {
for _, action := range callback.ActionCallback.AttachmentActions {
if action.Value != "" {
text = fmt.Sprintf("<@%s> %s", bot.ID, action.Value)
break
Expand Down Expand Up @@ -499,7 +499,11 @@ func readFromRTM(rtm *slack.RTM, inputMsgs chan<- models.Message, bot *models.Bo
}
case *slack.ConnectedEvent:
// populate users
populateBotUsers(ev.Info.Users, bot)
users, err := rtm.GetUsers()
if err != nil {
bot.Log.Errorf("Unable to get users: %v", err)
}
populateBotUsers(users, bot)
// populate user groups
populateUserGroups(bot)
bot.Log.Debugf("RTM connection established!")
Expand Down Expand Up @@ -568,43 +572,17 @@ func sendDirectMessage(api *slack.Client, userID string, message models.Message)
func sendMessage(api *slack.Client, ephemeral bool, channel, userID, text, threadTimeStamp, wsToken string, attachments []slack.Attachment) error {
// send ephemeral message is indicated
if ephemeral {
var opt slack.MsgOption
if len(attachments) > 0 {
opt = slack.MsgOptionAttachments(attachments[0]) // only handling attachments messages with single attachments
_, err := api.PostEphemeral(channel, userID, opt)
if err != nil {
return err
}
}
return nil
}
// send standard message
pmp := slack.PostMessageParameters{
AsUser: true,
ThreadTimestamp: threadTimeStamp,
}
// check if message was a link to set link attachment
if text != "" && strings.Contains(text, "http") {
if isValidURL(text) {
if len(attachments) > 0 {
attachments[0].ImageURL = text
} else {
attachments = []slack.Attachment{
{
ImageURL: text,
},
}
attachments[0].ImageURL = text
}
}
}
// include attachments if any
if len(attachments) > 0 {
pmp.Attachments = attachments
}
_, _, err := api.PostMessage(channel, text, pmp)
if err != nil {
opt := slack.MsgOptionAttachments(attachments...)
_, err := api.PostEphemeral(channel, userID, opt)
return err
}
return nil

opts := []slack.MsgOption{
slack.MsgOptionText(text, false),
slack.MsgOptionAsUser(true),
slack.MsgOptionAttachments(attachments...),
slack.MsgOptionTS(threadTimeStamp),
}
_, _, err := api.PostMessage(channel, opts...)
return err
}
12 changes: 0 additions & 12 deletions remote/slack/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,6 @@ func isValidPath(path string) bool {
return false
}

// isValidURL - regex matches a URL string to check if it is a correct URL
func isValidURL(url string) bool {
urlPattern := regexp.MustCompile(`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)`)
matches := urlPattern.FindAllString(url, -1)
if matches != nil {
if matches[0] == url {
return true
}
}
return false
}

// removeBotMention - parse out the prepended bot mention in a message
func removeBotMention(contents, botID string) (string, bool) {
mention := fmt.Sprintf("<@%s> ", botID)
Expand Down

0 comments on commit 0647a4c

Please sign in to comment.