diff --git a/site-configs/patterns.toml b/site-configs/patterns.toml index aaed326..2f00a05 100644 Binary files a/site-configs/patterns.toml and b/site-configs/patterns.toml differ diff --git a/src/patterns.go b/src/patterns.go index fa5582f..5258060 100644 --- a/src/patterns.go +++ b/src/patterns.go @@ -41,6 +41,7 @@ type opPatterns struct { Username []opPatternAction `toml:"username"` Bio []opPatternAction `toml:"bio"` Message []opPatternAction `toml:"message"` + Sticker []opPatternAction `toml:"sticker"` } // opMatchPattern contains the data we will use when matching. @@ -51,8 +52,9 @@ type opMatchPattern struct { Nickname string // This is the first + last name. Username string Bio string - // This will be matched in regular messages. + // These will be matched in regular messages. Message string + Sticker string } // This is a way to obtain specific information not available with the current @@ -134,6 +136,9 @@ func getMatchPattern(bot *tgbotapi.BotAPI, update tgbotapi.Update) (opMatchPatte // Media messages won't have a "Text" attribute, but may have a // "Caption", so let's match against it. matchPattern.Message = update.Message.Caption + case update.Message.Sticker != nil && len(update.Message.Sticker.SetName) > 0: + // Let's match against the name of the sticker set. + matchPattern.Sticker = update.Message.Sticker.SetName default: // By default, we only get the actual message to match against. matchPattern.Message = update.Message.Text @@ -142,7 +147,7 @@ func getMatchPattern(bot *tgbotapi.BotAPI, update tgbotapi.Update) (opMatchPatte } // stringTomlToPatterns() converts the toml patterns from string to the Patterns -// type, that ca be used for the matching. +// type, that can be used for the matching. func stringTomlToPatterns(sp string) (opPatterns, error) { newPatterns := opPatterns{} if _, err := toml.Decode(sp, &newPatterns); err != nil { @@ -205,6 +210,10 @@ func (p *opPatterns) matchPattern(m opMatchPattern) (bool, opMatchAction) { // Common case; match against actual message. return performGroupMatch(p.Message, m.Message) } + if len(m.Sticker) > 0 { + // Let's check whether this sticker set is allowed. + return performGroupMatch(p.Sticker, m.Sticker) + } // We are matching against the data from a new user who just joined. diff --git a/src/patterns_test.go b/src/patterns_test.go index 70f0f23..aaaeacc 100644 --- a/src/patterns_test.go +++ b/src/patterns_test.go @@ -24,6 +24,10 @@ action = "ban" [[message]] pattern = "foobar.example.com" +action = "ban" + +[[sticker]] +pattern = "(foobar|nsfw)" action = "ban"` ) @@ -100,6 +104,27 @@ func TestPatternMatch(t *testing.T) { expected: true, expectedAction: opKick, }, + { + mp: opMatchPattern{ + Sticker: "bar", + }, + expected: false, + expectedAction: opNoAction, + }, + { + mp: opMatchPattern{ + Sticker: "foobar", + }, + expected: true, + expectedAction: opBan, + }, + { + mp: opMatchPattern{ + Sticker: "nsfw_sticker_set", + }, + expected: true, + expectedAction: opBan, + }, } p, _ := stringTomlToPatterns(patterns)