Skip to content

Commit

Permalink
Merge 509927c into 74a5bbf
Browse files Browse the repository at this point in the history
  • Loading branch information
wass3r committed Apr 8, 2021
2 parents 74a5bbf + 509927c commit 82c9db5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 37 deletions.
2 changes: 2 additions & 0 deletions remote/discord/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func populateMessage(message models.Message, msgType models.MessageType, channel
message.Vars["_channel.id"] = channel
message.Vars["_channel.name"] = message.ChannelName

message.Vars["_source.timestamp"] = timeStamp

// Populate message user sender
// These will be accessible on rules via ${_user.email}, etc
if user != nil { // nil user implies a message from an api/bot (i.e. not an actual user)
Expand Down
6 changes: 6 additions & 0 deletions remote/discord/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (c *Client) Read(inputMsgs chan<- models.Message, rules map[string]models.R
}

bot.Name = botuser.Username
bot.ID = botuser.ID

foundGuild := false

Expand Down Expand Up @@ -177,6 +178,11 @@ func handleDiscordMessage(bot *models.Bot, inputMsgs chan<- models.Message) inte
return
}

// ignore messages from self
if m.Author.ID == bot.ID {
return
}

// Process message
message := models.NewMessage()
switch m.Type {
Expand Down
6 changes: 6 additions & 0 deletions remote/slack/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func handleCallBack(api *slack.Client, event slackevents.EventsAPIInnerEvent, bo

link, err := api.GetPermalink(&slack.PermalinkParameters{Channel: channel, Ts: timestamp})
if err != nil {
bot.Log.Errorf("unable to retrieve link to message: %s", err.Error())
link = ""
}

Expand Down Expand Up @@ -503,6 +504,10 @@ func populateMessage(message models.Message, msgType models.MessageType, channel
// make link to trigger message available
message.Vars["_source.link"] = message.SourceLink

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

// 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)
Expand Down Expand Up @@ -638,6 +643,7 @@ func readFromRTM(rtm *slack.RTM, inputMsgs chan<- models.Message, bot *models.Bo

link, err := rtm.GetPermalink(&slack.PermalinkParameters{Channel: channel, Ts: timestamp})
if err != nil {
bot.Log.Errorf("unable to retrieve link to message: %s", err.Error())
link = ""
}

Expand Down
79 changes: 42 additions & 37 deletions remote/telegram/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,47 +69,52 @@ func (c *Client) Read(inputMsgs chan<- models.Message, rules map[string]models.R
}

// check if we should respond to other bot messages
if m.From.IsBot && !bot.RespondToBots {
if m.From != nil && m.From.IsBot && !bot.RespondToBots {
continue
}

// only process messages not from out bot
if m.From.ID != botuser.ID {
msg, mentioned := processMessageText(m.Text, bot.Name)

// support slash commands
if len(m.Command()) > 0 {
fullCmd := fmt.Sprintf("%s %s", m.Command(), m.CommandArguments())
mentioned = true
msg = strings.TrimSpace(fullCmd)
}

message := models.NewMessage()
message.Timestamp = strconv.FormatInt(m.Time().Unix(), 10)
message.Type = mapMessageType(*m)
message.Input = msg
message.Output = ""
message.ID = strconv.Itoa(m.MessageID)
message.Service = models.MsgServiceChat
message.BotMentioned = mentioned
message.ChannelID = strconv.FormatInt(m.Chat.ID, 10)

// populate message with metadata
if m.From != nil {
message.Vars["_user.name"] = m.From.UserName
message.Vars["_user.firstname"] = m.From.FirstName
message.Vars["_user.lastname"] = m.From.LastName
message.Vars["_user.id"] = strconv.Itoa(m.From.ID)
message.Vars["_user.realnamenormalized"] = fmt.Sprintf("%s %s", m.From.FirstName, m.From.LastName)
message.Vars["_user.displayname"] = m.From.UserName
message.Vars["_user.displaynamenormalized"] = m.From.UserName
}

message.Vars["_channel.id"] = message.ChannelID
message.Vars["_channel.name"] = m.Chat.Title

inputMsgs <- message
// only process messages not from our bot
// Note: it looks like "From" is not being populated currently
if m.From != nil && m.From.ID == botuser.ID {
continue
}

msg, mentioned := processMessageText(m.Text, bot.Name)

// support slash commands
if len(m.Command()) > 0 {
fullCmd := fmt.Sprintf("%s %s", m.Command(), m.CommandArguments())
mentioned = true
msg = strings.TrimSpace(fullCmd)
}

message := models.NewMessage()
message.Timestamp = strconv.FormatInt(m.Time().Unix(), 10)
message.Type = mapMessageType(*m)
message.Input = msg
message.Output = ""
message.ID = strconv.Itoa(m.MessageID)
message.Service = models.MsgServiceChat
message.BotMentioned = mentioned
message.ChannelID = strconv.FormatInt(m.Chat.ID, 10)

// populate message with metadata
if m.From != nil {
message.Vars["_user.name"] = m.From.UserName
message.Vars["_user.firstname"] = m.From.FirstName
message.Vars["_user.lastname"] = m.From.LastName
message.Vars["_user.id"] = strconv.Itoa(m.From.ID)
message.Vars["_user.realnamenormalized"] = fmt.Sprintf("%s %s", m.From.FirstName, m.From.LastName)
message.Vars["_user.displayname"] = m.From.UserName
message.Vars["_user.displaynamenormalized"] = m.From.UserName
}

message.Vars["_channel.id"] = message.ChannelID
message.Vars["_channel.name"] = m.Chat.Title

message.Vars["_source.timestamp"] = strconv.Itoa(m.Date)

inputMsgs <- message
}
}

Expand Down

0 comments on commit 82c9db5

Please sign in to comment.