diff options
author | Wim <wim@42.be> | 2019-02-23 16:35:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-23 16:35:54 +0100 |
commit | 3190703dc8618896c932a23d8ca155fbbf6fab13 (patch) | |
tree | ab49eb5adbe6b59945dd2b21cb378ffb7538add9 /gateway/handlers_test.go | |
parent | 5095db8a43491fd2c5859f25cbb89a3be40bef6d (diff) | |
download | matterbridge-msglm-3190703dc8618896c932a23d8ca155fbbf6fab13.tar.gz matterbridge-msglm-3190703dc8618896c932a23d8ca155fbbf6fab13.tar.bz2 matterbridge-msglm-3190703dc8618896c932a23d8ca155fbbf6fab13.zip |
Support rewriting messages from relaybots using ExtractNicks. Fixes #466 (#730)
some examples:
this replaces a message like "Relaybot: <relayeduser> something interesting" to "relayeduser: something interesting"
ExtractNicks=[ [ "Relaybot", "<(.*?)>\\s+" ] ]
you can use multiple entries for multiplebots
this also replaces a message like "otherbot: (relayeduser) something else" to "relayeduser: something else"
ExtractNicks=[ [ "Relaybot", "<(.*?)>\\s+" ],[ "otherbot","\\((.*?)\\)\\s+" ]
OPTIONAL (default empty)
ExtractNicks=[ ["otherbot","<(.*?)>\\s+" ] ]
Diffstat (limited to 'gateway/handlers_test.go')
-rw-r--r-- | gateway/handlers_test.go | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/gateway/handlers_test.go b/gateway/handlers_test.go new file mode 100644 index 00000000..db7988a9 --- /dev/null +++ b/gateway/handlers_test.go @@ -0,0 +1,75 @@ +package gateway + +import ( + "github.com/42wim/matterbridge/bridge" + "github.com/42wim/matterbridge/bridge/config" + "github.com/stretchr/testify/assert" + + "testing" +) + +func TestIgnoreEvent(t *testing.T) { + eventTests := map[string]struct { + input string + dest *bridge.Bridge + output bool + }{ + "avatar mattermost": { + input: config.EventAvatarDownload, + dest: &bridge.Bridge{Protocol: "mattermost"}, + output: false, + }, + "avatar slack": { + input: config.EventAvatarDownload, + dest: &bridge.Bridge{Protocol: "slack"}, + output: true, + }, + "avatar telegram": { + input: config.EventAvatarDownload, + dest: &bridge.Bridge{Protocol: "telegram"}, + output: false, + }, + } + gw := &Gateway{} + for testname, testcase := range eventTests { + output := gw.ignoreEvent(testcase.input, testcase.dest) + assert.Equalf(t, testcase.output, output, "case '%s' failed", testname) + } + +} + +func TestExtractNick(t *testing.T) { + eventTests := map[string]struct { + search string + extract string + username string + text string + resultUsername string + resultText string + }{ + "test1": { + search: "fromgitter", + extract: "<(.*?)>\\s+", + username: "fromgitter", + text: "<userx> blahblah", + resultUsername: "userx", + resultText: "blahblah", + }, + "test2": { + search: "<.*?bot>", + //extract: `\((.*?)\)\s+`, + extract: "\\((.*?)\\)\\s+", + username: "<matterbot>", + text: "(userx) blahblah (abc) test", + resultUsername: "userx", + resultText: "blahblah (abc) test", + }, + } + // gw := &Gateway{} + for testname, testcase := range eventTests { + resultUsername, resultText, _ := extractNick(testcase.search, testcase.extract, testcase.username, testcase.text) + assert.Equalf(t, testcase.resultUsername, resultUsername, "case '%s' failed", testname) + assert.Equalf(t, testcase.resultText, resultText, "case '%s' failed", testname) + } + +} |