diff options
author | Alexander <korelskiy@uteka.ru> | 2022-04-01 00:50:38 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-31 23:50:38 +0200 |
commit | 4ab72acec656dafd304f88359b509b1f27c06604 (patch) | |
tree | 746423526c635fdda023b7fed7f7558eb354a006 /gateway | |
parent | 30aae8e257007adde40a522a0ac29cfdc39b80da (diff) | |
download | matterbridge-msglm-4ab72acec656dafd304f88359b509b1f27c06604.tar.gz matterbridge-msglm-4ab72acec656dafd304f88359b509b1f27c06604.tar.bz2 matterbridge-msglm-4ab72acec656dafd304f88359b509b1f27c06604.zip |
Ignore sending file with comment, if comment contains IgnoreMessages value (#1783)
* Ignore sending file with comment, if comment contains message to ignore
* Fix linter issue
Diffstat (limited to 'gateway')
-rw-r--r-- | gateway/gateway.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/gateway/gateway.go b/gateway/gateway.go index fc75916c..a2d572be 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -299,13 +299,30 @@ func (gw *Gateway) ignoreMessage(msg *config.Message) bool { igNicks := strings.Fields(gw.Bridges[msg.Account].GetString("IgnoreNicks")) igMessages := strings.Fields(gw.Bridges[msg.Account].GetString("IgnoreMessages")) - if gw.ignoreTextEmpty(msg) || gw.ignoreText(msg.Username, igNicks) || gw.ignoreText(msg.Text, igMessages) { + if gw.ignoreTextEmpty(msg) || gw.ignoreText(msg.Username, igNicks) || gw.ignoreText(msg.Text, igMessages) || gw.ignoreFilesComment(msg.Extra, igMessages) { return true } return false } +// ignoreFilesComment returns true if we need to ignore a file with matched comment. +func (gw *Gateway) ignoreFilesComment(extra map[string][]interface{}, igMessages []string) bool { + if extra == nil { + return false + } + for _, f := range extra["file"] { + fi, ok := f.(config.FileInfo) + if !ok { + continue + } + if gw.ignoreText(fi.Comment, igMessages) { + return true + } + } + return false +} + func (gw *Gateway) modifyUsername(msg *config.Message, dest *bridge.Bridge) string { if dest.GetBool("StripNick") { re := regexp.MustCompile("[^a-zA-Z0-9]+") |