Skip to content

Commit

Permalink
Some lint clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Arnott committed Oct 23, 2024
1 parent 839a42d commit 4e684ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 52 deletions.
2 changes: 2 additions & 0 deletions core/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ func handleNoMatch(outputMsgs chan<- models.Message, message models.Message, hit
}

// isValidHitChatRule does additional checks on a successfully hit rule that came from the chat or CLI service.
//
//nolint:gocyclo // refactor
func isValidHitChatRule(message *models.Message, rule models.Rule, processedInput string, bot *models.Bot) bool {
// Check to honor allow_users or allow_usergroups
canRunRule := utils.CanTrigger(message.Vars["_user.name"], message.Vars["_user.id"], rule, bot)
Expand Down
56 changes: 4 additions & 52 deletions remote/slack/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,69 +449,21 @@ func populateMessage(message models.Message, msgType models.MessageType, channel
func populateReaction(message models.Message, msgType models.MessageType, channel, action, reaction, timeStamp, link string, user *slack.User, bot *models.Bot) models.Message {
switch msgType {
case models.MsgTypeDirect, models.MsgTypeChannel, models.MsgTypePrivateChannel:
// Populate message attributes
message.Type = msgType
message.Service = models.MsgServiceChat
message.ChannelID = channel
message.ReactionAction = action
message.Reaction = reaction
message.Input = ""
message.Output = ""
message.Timestamp = timeStamp
message.SourceLink = link

// If the message read was not a dm, get the name of the channel it came from
if msgType != models.MsgTypeDirect {
name, ok := findKey(bot.Rooms, channel)
if !ok {
log.Error().Msgf("could not find name of channel %#q", channel)
}

message.ChannelName = name
}

message.Vars["_reaction.action"] = action
message.Vars["_reaction"] = reaction
// make channel variables available
message.Vars["_channel.id"] = message.ChannelID
message.Vars["_channel.name"] = message.ChannelName // will be empty if it came via DM

// make link to trigger message available
message.Vars["_source.link"] = message.SourceLink

// make timestamp information available
message.Vars["_source.timestamp"] = timeStamp

// Populate message with user information (i.e. who sent the message)
// These will be accessible on rules via ${_user.email}, ${_user.id}, etc.
if user != nil { // nil user implies a message from an api/bot (i.e. not an actual user)
message.Vars["_user.id"] = user.ID
message.Vars["_user.teamid"] = user.TeamID
message.Vars["_user.name"] = user.Name
message.Vars["_user.color"] = user.Color
message.Vars["_user.realname"] = user.RealName
message.Vars["_user.tz"] = user.TZ
message.Vars["_user.tzlabel"] = user.TZLabel
message.Vars["_user.tzoffset"] = strconv.Itoa(user.TZOffset)
message.Vars["_user.firstname"] = user.Profile.FirstName
message.Vars["_user.lastname"] = user.Profile.LastName
message.Vars["_user.realnamenormalized"] = user.Profile.RealNameNormalized
message.Vars["_user.displayname"] = user.Profile.DisplayName
message.Vars["_user.displaynamenormalized"] = user.Profile.DisplayNameNormalized
message.Vars["_user.email"] = user.Profile.Email
message.Vars["_user.skype"] = user.Profile.Skype
message.Vars["_user.phone"] = user.Profile.Phone
message.Vars["_user.title"] = user.Profile.Title
message.Vars["_user.statustext"] = user.Profile.StatusText
message.Vars["_user.statusemoji"] = user.Profile.StatusEmoji
message.Vars["_user.team"] = user.Profile.Team
}

return message
message = populateMessage(message, msgType, channel, "", timeStamp, "", link, false, user, bot)
default:
log.Debug().Msgf("read message of unsupported type '%T' - unable to populate message attributes", msgType)
return message
}

return message
}

// readFromEventsAPI utilizes the Slack API client to read event-based messages.
Expand Down Expand Up @@ -548,7 +500,7 @@ func readFromEventsAPI(api *slack.Client, vToken string, inputMsgs chan<- models
//
// https://api.slack.com/apis/connections/socket
//
//nolint:gocyclo // needs refactor
//nolint:gocyclo,funlen // needs refactor
func readFromSocketMode(sm *slack.Client, inputMsgs chan<- models.Message, bot *models.Bot) {
// setup the client
client := socketmode.New(sm)
Expand Down

0 comments on commit 4e684ee

Please sign in to comment.