mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-25 04:02:03 -08:00
Add support for ReplaceMessages using regexp to replace messages. #269
This commit is contained in:
parent
2778580397
commit
aff3964078
@ -48,52 +48,53 @@ type ChannelInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Protocol struct {
|
type Protocol struct {
|
||||||
AuthCode string // steam
|
AuthCode string // steam
|
||||||
BindAddress string // mattermost, slack // DEPRECATED
|
BindAddress string // mattermost, slack // DEPRECATED
|
||||||
Buffer int // api
|
Buffer int // api
|
||||||
Charset string // irc
|
Charset string // irc
|
||||||
EditSuffix string // mattermost, slack, discord, telegram, gitter
|
EditSuffix string // mattermost, slack, discord, telegram, gitter
|
||||||
EditDisable bool // mattermost, slack, discord, telegram, gitter
|
EditDisable bool // mattermost, slack, discord, telegram, gitter
|
||||||
IconURL string // mattermost, slack
|
IconURL string // mattermost, slack
|
||||||
IgnoreNicks string // all protocols
|
IgnoreNicks string // all protocols
|
||||||
IgnoreMessages string // all protocols
|
IgnoreMessages string // all protocols
|
||||||
Jid string // xmpp
|
Jid string // xmpp
|
||||||
Login string // mattermost, matrix
|
Login string // mattermost, matrix
|
||||||
Muc string // xmpp
|
Muc string // xmpp
|
||||||
Name string // all protocols
|
Name string // all protocols
|
||||||
Nick string // all protocols
|
Nick string // all protocols
|
||||||
NickFormatter string // mattermost, slack
|
NickFormatter string // mattermost, slack
|
||||||
NickServNick string // IRC
|
NickServNick string // IRC
|
||||||
NickServUsername string // IRC
|
NickServUsername string // IRC
|
||||||
NickServPassword string // IRC
|
NickServPassword string // IRC
|
||||||
NicksPerRow int // mattermost, slack
|
NicksPerRow int // mattermost, slack
|
||||||
NoHomeServerSuffix bool // matrix
|
NoHomeServerSuffix bool // matrix
|
||||||
NoTLS bool // mattermost
|
NoTLS bool // mattermost
|
||||||
Password string // IRC,mattermost,XMPP,matrix
|
Password string // IRC,mattermost,XMPP,matrix
|
||||||
PrefixMessagesWithNick bool // mattemost, slack
|
PrefixMessagesWithNick bool // mattemost, slack
|
||||||
Protocol string //all protocols
|
Protocol string //all protocols
|
||||||
MessageQueue int // IRC, size of message queue for flood control
|
ReplaceMessages [][]string // all messages
|
||||||
MessageDelay int // IRC, time in millisecond to wait between messages
|
MessageQueue int // IRC, size of message queue for flood control
|
||||||
MessageLength int // IRC, max length of a message allowed
|
MessageDelay int // IRC, time in millisecond to wait between messages
|
||||||
MessageFormat string // telegram
|
MessageLength int // IRC, max length of a message allowed
|
||||||
RemoteNickFormat string // all protocols
|
MessageFormat string // telegram
|
||||||
Server string // IRC,mattermost,XMPP,discord
|
RemoteNickFormat string // all protocols
|
||||||
ShowJoinPart bool // all protocols
|
Server string // IRC,mattermost,XMPP,discord
|
||||||
ShowEmbeds bool // discord
|
ShowJoinPart bool // all protocols
|
||||||
SkipTLSVerify bool // IRC, mattermost
|
ShowEmbeds bool // discord
|
||||||
StripNick bool // all protocols
|
SkipTLSVerify bool // IRC, mattermost
|
||||||
Team string // mattermost
|
StripNick bool // all protocols
|
||||||
Token string // gitter, slack, discord, api
|
Team string // mattermost
|
||||||
URL string // mattermost, slack // DEPRECATED
|
Token string // gitter, slack, discord, api
|
||||||
UseAPI bool // mattermost, slack
|
URL string // mattermost, slack // DEPRECATED
|
||||||
UseSASL bool // IRC
|
UseAPI bool // mattermost, slack
|
||||||
UseTLS bool // IRC
|
UseSASL bool // IRC
|
||||||
UseFirstName bool // telegram
|
UseTLS bool // IRC
|
||||||
UseUserName bool // discord
|
UseFirstName bool // telegram
|
||||||
UseInsecureURL bool // telegram
|
UseUserName bool // discord
|
||||||
WebhookBindAddress string // mattermost, slack
|
UseInsecureURL bool // telegram
|
||||||
WebhookURL string // mattermost, slack
|
WebhookBindAddress string // mattermost, slack
|
||||||
WebhookUse string // mattermost, slack, discord
|
WebhookURL string // mattermost, slack
|
||||||
|
WebhookUse string // mattermost, slack, discord
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChannelOptions struct {
|
type ChannelOptions struct {
|
||||||
|
@ -287,6 +287,19 @@ func (gw *Gateway) modifyAvatar(msg config.Message, dest *bridge.Bridge) string
|
|||||||
func (gw *Gateway) modifyMessage(msg *config.Message) {
|
func (gw *Gateway) modifyMessage(msg *config.Message) {
|
||||||
// replace :emoji: to unicode
|
// replace :emoji: to unicode
|
||||||
msg.Text = emojilib.Replace(msg.Text)
|
msg.Text = emojilib.Replace(msg.Text)
|
||||||
|
br := gw.Bridges[msg.Account]
|
||||||
|
// loop to replace messages
|
||||||
|
for _, outer := range br.Config.ReplaceMessages {
|
||||||
|
search := outer[0]
|
||||||
|
replace := outer[1]
|
||||||
|
// TODO move compile to bridge init somewhere
|
||||||
|
re, err := regexp.Compile(search)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("regexp in %s failed: %s", msg.Account, err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
msg.Text = re.ReplaceAllString(msg.Text, replace)
|
||||||
|
}
|
||||||
msg.Gateway = gw.Name
|
msg.Gateway = gw.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user