Class: Splam::Rules::BadWords
- Inherits:
-
Splam::Rule
- Object
- Splam::Rule
- Splam::Rules::BadWords
- Defined in:
- lib/splam/rules/bad_words.rb
Class Attribute Summary collapse
-
.bad_word_score ⇒ Object
Returns the value of attribute bad_word_score.
-
.suspicious_word_score ⇒ Object
Returns the value of attribute suspicious_word_score.
Attributes inherited from Splam::Rule
#body, #reasons, #score, #suite, #weight
Instance Method Summary collapse
Methods inherited from Splam::Rule
#add_score, inherited, #initialize, #name, run
Constructor Details
This class inherits a constructor from Splam::Rule
Class Attribute Details
.bad_word_score ⇒ Object
Returns the value of attribute bad_word_score.
3 4 5 |
# File 'lib/splam/rules/bad_words.rb', line 3 def bad_word_score @bad_word_score end |
.suspicious_word_score ⇒ Object
Returns the value of attribute suspicious_word_score.
3 4 5 |
# File 'lib/splam/rules/bad_words.rb', line 3 def suspicious_word_score @suspicious_word_score end |
Instance Method Details
#run ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/splam/rules/bad_words.rb', line 9 def run bad_words = %w( sex sexy porn gay erotica viagra erotismo porno porn lesbian amateur tit\b) bad_words |= %w( gratis erotismo porno torrent bittorrent adulto ) bad_words |= %w( cialis viagra payday loan jihad ) bad_words |= %w( webcam free-web-host rapidshare muslim) bad_words << /pel?cula/ << /pornogr?fica/ << "portal porno" # srsly, spamming in spanish? suspicious_words = %w( free buy galleries dating gallery hard hardcore video homemade celebrity ) << "credit card" << "my friend" << "friend sent me" suspicious_words |= %w( adult pharmacy overnight shipping free hot movie nylon arab ?????? xxx) << "sent me a link" suspicious_words << "forums/member.php?u=" << "chat room" << "free chat" << "yahoo chat" << "page.php" bad_words.each do |word| results = @body.downcase.scan(word) if results && results.size > 0 add_score((self.class.bad_word_score ** results.size), "nasty word: '#{word}'") # Add more points if the bad word is INSIDE a link @body.scan(/<a[^>]+>(.*?)<\/a>/).each do |match| add_score self.class.bad_word_score * 4 * match[0].scan(word).size, "nasty word inside a link: #{word}" end @body.scan(/\nhttp:\/\/(.*?#{word})/).each do |match| add_score self.class.bad_word_score ** 4 * match[0].scan(word).size, "nasty word inside a straight-up link: #{word}" end @body.scan(/<a(.*?)>/).each do |match| add_score self.class.bad_word_score * 4 * match[0].scan(word).size, "nasty word inside a URL: #{word}" end end end suspicious_words.each do |word| results = @body.downcase.scan(word) if results && results.size > 0 add_score (self.class.suspicious_word_score * results.size), "suspicious word: #{word}" # Add more points if the bad word is INSIDE a link @body.scan(/<a[^>]+>(.*?)<\/a>/).each do |match| add_score((self.class.suspicious_word_score * match[0].scan(word).size), "suspicious word inside a link: #{word}") end end end end |