From 1c74aa6cbe654b02132f7d9a766476d23c668640 Mon Sep 17 00:00:00 2001 From: Alexander Korelskiy Date: Thu, 31 Mar 2022 17:31:39 +0300 Subject: [PATCH] Ignore sending file with comment, if comment contains message to ignore --- gateway/gateway.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gateway/gateway.go b/gateway/gateway.go index fc75916c..6b20fdf7 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -299,13 +299,27 @@ 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 := f.(config.FileInfo) + 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]+")