Class: Wiki2Go::SpamFilter
- Inherits:
-
Object
- Object
- Wiki2Go::SpamFilter
- Defined in:
- lib/Wiki2Go/SpamFilter.rb
Instance Method Summary collapse
- #added_urls(original_content, modified_content) ⇒ Object
- #blacklist_url(url) ⇒ Object
- #blacklist_urls(urls) ⇒ Object
- #blacklist_user(author) ⇒ Object
- #blacklist_user_and_urls_added(author, original, new_content) ⇒ Object
- #edit_by_banned_user?(author) ⇒ Boolean
- #edit_contains_banned_url?(content) ⇒ Boolean
- #greylist_new_urls(author, original, new_content) ⇒ Object
- #greylist_suspects ⇒ Object
- #greylist_urls(author, new_urls) ⇒ Object
- #greylisted_url?(url) ⇒ Boolean
-
#initialize(config) ⇒ SpamFilter
constructor
A new instance of SpamFilter.
- #remove_from_greylist(author, url) ⇒ Object
- #too_many_new_urls?(original_content, modified_content, max_new_urls) ⇒ Boolean
- #update_chongqed ⇒ Object
Constructor Details
#initialize(config) ⇒ SpamFilter
Returns a new instance of SpamFilter.
9 10 11 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 9 def initialize(config) @config = config end |
Instance Method Details
#added_urls(original_content, modified_content) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 31 def added_urls(original_content, modified_content) url_finder = Wiki2Go::UrlFinder.new old_urls = url_finder.urls_in(original_content) new_urls = url_finder.urls_in(modified_content) urls = new_urls - old_urls urls end |
#blacklist_url(url) ⇒ Object
46 47 48 49 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 46 def blacklist_url(url) banned_urls.add(url) @config.storage.save_list(banned_urls) end |
#blacklist_urls(urls) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 51 def blacklist_urls(urls) urls.each do |url| banned_urls.add(url) end @config.storage.save_list(banned_urls) end |
#blacklist_user(author) ⇒ Object
40 41 42 43 44 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 40 def blacklist_user() bad_users = banned_users bad_users.add() @config.storage.save_list(bad_users) end |
#blacklist_user_and_urls_added(author, original, new_content) ⇒ Object
58 59 60 61 62 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 58 def blacklist_user_and_urls_added(,original,new_content) blacklist_user() new_urls = added_urls(original,new_content) blacklist_urls(new_urls) end |
#edit_by_banned_user?(author) ⇒ Boolean
13 14 15 16 17 18 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 13 def edit_by_banned_user?() @config.log("Checking if '#{}' is banned") banned = banned_users.contains() @config.log("Checking if '#{}' is banned. Done.") banned end |
#edit_contains_banned_url?(content) ⇒ Boolean
20 21 22 23 24 25 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 20 def edit_contains_banned_url?(content) @config.log("Checking if '#{content}' is banned") banned = banned_urls.found_in(content) || chonqed_urls.found_in(content) @config.log("Checking if '#{content}' is banned. Done") banned end |
#greylist_new_urls(author, original, new_content) ⇒ Object
64 65 66 67 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 64 def greylist_new_urls(,original,new_content) new_urls = added_urls(original,new_content) greylist_urls(,new_urls) end |
#greylist_suspects ⇒ Object
83 84 85 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 83 def greylist_suspects greylist.suspects end |
#greylist_urls(author, new_urls) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 69 def greylist_urls(,new_urls) if new_urls.length > 0 then list = greylist new_urls.each do |url| list.add(,url) end @config.storage.save_list(list) end end |
#greylisted_url?(url) ⇒ Boolean
79 80 81 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 79 def greylisted_url?(url) greylist.contains_url?(url) end |
#remove_from_greylist(author, url) ⇒ Object
87 88 89 90 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 87 def remove_from_greylist(,url) greylist.remove(,url) @config.storage.save_list(greylist) end |
#too_many_new_urls?(original_content, modified_content, max_new_urls) ⇒ Boolean
27 28 29 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 27 def too_many_new_urls?(original_content, modified_content,max_new_urls) return added_urls(original_content,modified_content).size > max_new_urls end |
#update_chongqed ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 92 def update_chongqed output = 'Updating blacklist' response = Net::HTTP.get_response('blacklist.chongqed.org','/index.html') if response.code == '200' then output = response.body @config.storage.update_chongqed_spamlist(output) else output = "Error code #{response.code}: #{response.}" end output end |