mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-07-07 05:24:03 +00:00
Sync channel topics between Slack bridges (#585)
Added logic to allow for configurable synchronisation of topics and purposes of channels between Slack bridges.
This commit is contained in:

committed by
Duco van Amstel

parent
5ed7abdbeb
commit
f5659d455d
@ -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 {
|
||||
|
Reference in New Issue
Block a user