Added feature to sync channel topic/purpose between Slack bridges. [#585]
This commit is contained in:
parent
0c382b081d
commit
fa2e31ce51
@ -117,6 +117,7 @@ type Protocol struct {
|
|||||||
ShowEmbeds bool // discord
|
ShowEmbeds bool // discord
|
||||||
SkipTLSVerify bool // IRC, mattermost
|
SkipTLSVerify bool // IRC, mattermost
|
||||||
StripNick bool // all protocols
|
StripNick bool // all protocols
|
||||||
|
SyncTopicChange bool // slack
|
||||||
Team string // mattermost
|
Team string // mattermost
|
||||||
Token string // gitter, slack, discord, api
|
Token string // gitter, slack, discord, api
|
||||||
Topic string // zulip
|
Topic string // zulip
|
||||||
|
@ -116,6 +116,11 @@ func (b *Bslack) skipMessageEvent(ev *slack.MessageEvent) bool {
|
|||||||
return b.GetBool(noSendJoinConfig)
|
return b.GetBool(noSendJoinConfig)
|
||||||
case sPinnedItem, sUnpinnedItem:
|
case sPinnedItem, sUnpinnedItem:
|
||||||
return true
|
return true
|
||||||
|
case sChannelTopic, sChannelPurpose:
|
||||||
|
// Skip the event if our bot/user account changed the topic/purpose
|
||||||
|
if ev.User == b.si.User.ID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip any messages that we made ourselves or from 'slackbot' (see #527).
|
// Skip any messages that we made ourselves or from 'slackbot' (see #527).
|
||||||
@ -201,6 +206,7 @@ func (b *Bslack) handleStatusEvent(ev *slack.MessageEvent, rmsg *config.Message)
|
|||||||
rmsg.Username = sSystemUser
|
rmsg.Username = sSystemUser
|
||||||
rmsg.Event = config.EventJoinLeave
|
rmsg.Event = config.EventJoinLeave
|
||||||
case sChannelTopic, sChannelPurpose:
|
case sChannelTopic, sChannelPurpose:
|
||||||
|
b.populateChannels()
|
||||||
rmsg.Event = config.EventTopicChange
|
rmsg.Event = config.EventTopicChange
|
||||||
case sMessageChanged:
|
case sMessageChanged:
|
||||||
rmsg.Text = ev.SubMessage.Text
|
rmsg.Text = ev.SubMessage.Text
|
||||||
|
@ -266,8 +266,18 @@ var (
|
|||||||
channelRE = regexp.MustCompile(`<#[a-zA-Z0-9]+\|(.+?)>`)
|
channelRE = regexp.MustCompile(`<#[a-zA-Z0-9]+\|(.+?)>`)
|
||||||
variableRE = regexp.MustCompile(`<!((?:subteam\^)?[a-zA-Z0-9]+)(?:\|@?(.+?))?>`)
|
variableRE = regexp.MustCompile(`<!((?:subteam\^)?[a-zA-Z0-9]+)(?:\|@?(.+?))?>`)
|
||||||
urlRE = regexp.MustCompile(`<(.*?)(\|.*?)?>`)
|
urlRE = regexp.MustCompile(`<(.*?)(\|.*?)?>`)
|
||||||
|
topicOrPurposeRE = regexp.MustCompile(`(?s)^@.+ set the channel (topic|purpose): (.+?)(\[nosync\])?$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (b *Bslack) extractTopicOrPurpose(text string) (updateType string, extracted string) {
|
||||||
|
r := topicOrPurposeRE.FindStringSubmatch(text)
|
||||||
|
updateType, extracted, noSync := r[1], r[2], r[3]
|
||||||
|
if noSync != "" {
|
||||||
|
return "nosync", ""
|
||||||
|
}
|
||||||
|
return updateType, extracted
|
||||||
|
}
|
||||||
|
|
||||||
// @see https://api.slack.com/docs/message-formatting#linking_to_channels_and_users
|
// @see https://api.slack.com/docs/message-formatting#linking_to_channels_and_users
|
||||||
func (b *Bslack) replaceMention(text string) string {
|
func (b *Bslack) replaceMention(text string) string {
|
||||||
replaceFunc := func(match string) string {
|
replaceFunc := func(match string) string {
|
||||||
|
@ -280,6 +280,24 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
if (msg.Event == config.EVENT_TOPIC_CHANGE) && b.GetBool("SyncTopicChange") {
|
||||||
|
incomingChangeType, text := b.extractTopicOrPurpose(msg.Text)
|
||||||
|
switch incomingChangeType {
|
||||||
|
case "topic":
|
||||||
|
if strings.HasSuffix(channelInfo.Topic.Value, "[nosync]") {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
b.rtm.SetTopicOfConversation(channelInfo.ID, text)
|
||||||
|
case "purpose":
|
||||||
|
if strings.HasSuffix(channelInfo.Purpose.Value, "[nosync]") {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
b.rtm.SetPurposeOfConversation(channelInfo.ID, text)
|
||||||
|
case "nosync":
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
// Handle message deletions.
|
// Handle message deletions.
|
||||||
var handled bool
|
var handled bool
|
||||||
|
@ -765,11 +765,17 @@ ShowJoinPart=false
|
|||||||
#OPTIONAL (default false)
|
#OPTIONAL (default false)
|
||||||
StripNick=false
|
StripNick=false
|
||||||
|
|
||||||
#Enable to show topic changes from other bridges
|
#Enable to show topic/purpose changes from other bridges
|
||||||
#Only works hiding/show topic changes from slack bridge for now
|
#Only works hiding/show topic changes from slack bridge for now
|
||||||
#OPTIONAL (default false)
|
#OPTIONAL (default false)
|
||||||
ShowTopicChange=false
|
ShowTopicChange=false
|
||||||
|
|
||||||
|
#Enable to sync topic/purpose changes from other bridges
|
||||||
|
#Only works syncing topic changes from slack bridge for now
|
||||||
|
#Appending "[nosync]" to the topic/purpose will protect it from being synced
|
||||||
|
#OPTIONAL (default false)
|
||||||
|
SyncTopicChange=false
|
||||||
|
|
||||||
###################################################################
|
###################################################################
|
||||||
#telegram section
|
#telegram section
|
||||||
###################################################################
|
###################################################################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user