diff options
author | Patrick Connolly <patrick.c.connolly@gmail.com> | 2018-11-26 17:47:04 +0800 |
---|---|---|
committer | Duco van Amstel <duco.vanamstel@gmail.com> | 2018-11-26 09:47:04 +0000 |
commit | f5659d455d2c28a6f2fe4c40f4dc344419ff523a (patch) | |
tree | 76447e104bfafeea83f3df6cf7f540d7c0bf048c /bridge/slack/helpers.go | |
parent | 5ed7abdbeb8a81599b3516583e15df75651fb9bc (diff) | |
download | matterbridge-msglm-f5659d455d2c28a6f2fe4c40f4dc344419ff523a.tar.gz matterbridge-msglm-f5659d455d2c28a6f2fe4c40f4dc344419ff523a.tar.bz2 matterbridge-msglm-f5659d455d2c28a6f2fe4c40f4dc344419ff523a.zip |
Sync channel topics between Slack bridges (#585)
Added logic to allow for configurable synchronisation of topics and purposes of channels between Slack bridges.
Diffstat (limited to 'bridge/slack/helpers.go')
-rw-r--r-- | bridge/slack/helpers.go | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/bridge/slack/helpers.go b/bridge/slack/helpers.go index b0fdaba1..39fbcea7 100644 --- a/bridge/slack/helpers.go +++ b/bridge/slack/helpers.go @@ -262,12 +262,28 @@ func (b *Bslack) populateMessageWithBotInfo(ev *slack.MessageEvent, rmsg *config } var ( - mentionRE = regexp.MustCompile(`<@([a-zA-Z0-9]+)>`) - channelRE = regexp.MustCompile(`<#[a-zA-Z0-9]+\|(.+?)>`) - variableRE = regexp.MustCompile(`<!((?:subteam\^)?[a-zA-Z0-9]+)(?:\|@?(.+?))?>`) - urlRE = regexp.MustCompile(`<(.*?)(\|.*?)?>`) + mentionRE = regexp.MustCompile(`<@([a-zA-Z0-9]+)>`) + channelRE = regexp.MustCompile(`<#[a-zA-Z0-9]+\|(.+?)>`) + variableRE = regexp.MustCompile(`<!((?:subteam\^)?[a-zA-Z0-9]+)(?:\|@?(.+?))?>`) + urlRE = regexp.MustCompile(`<(.*?)(\|.*?)?>`) + topicOrPurposeRE = regexp.MustCompile(`(?s)(@.+) (cleared|set)(?: the)? channel (topic|purpose)(?:: (.*))?`) ) +func (b *Bslack) extractTopicOrPurpose(text string) (string, string) { + r := topicOrPurposeRE.FindStringSubmatch(text) + if len(r) == 5 { + action, updateType, extracted := r[2], r[3], r[4] + switch action { + case "set": + return updateType, extracted + case "cleared": + return updateType, "" + } + } + b.Log.Warnf("Encountered channel topic or purpose change message with unexpected format: %s", text) + return "unknown", "" +} + // @see https://api.slack.com/docs/message-formatting#linking_to_channels_and_users func (b *Bslack) replaceMention(text string) string { replaceFunc := func(match string) string { |