Class: Ayadn::BlacklistWorkers
Instance Method Summary collapse
- #add(args) ⇒ Object
-
#clear ⇒ Object
def import(database) begin new_db = File.realpath(database) if File.exist?(new_db) Databases.import_blacklist(new_db) Logs.rec.info “Imported ‘#new_db’ values in blacklist database.” else puts “nFile ‘#new_db’ doesn’t exist.nn”.color(:red) Logs.rec.warn “File ‘#new_db’ doesn’t exist.” end end end.
-
#initialize ⇒ BlacklistWorkers
constructor
A new instance of BlacklistWorkers.
- #list(options) ⇒ Object
- #remove(args) ⇒ Object
Constructor Details
#initialize ⇒ BlacklistWorkers
Returns a new instance of BlacklistWorkers.
51 52 53 54 55 56 57 58 |
# File 'lib/ayadn/blacklist.rb', line 51 def initialize Settings.load_config Settings.get_token Settings.init_config Logs.create_logger Databases.open_databases @workers = Workers.new end |
Instance Method Details
#add(args) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ayadn/blacklist.rb', line 84 def add(args) begin type = args.shift case type when 'user', 'username', 'account' target = @workers.remove_arobase_if_present(args) Databases.add_to_blacklist('user', target) target = @workers.add_arobases_to_usernames args Logs.rec.info "Added '#{target}' to blacklist of users." when 'mention', 'mentions' target = @workers.remove_arobase_if_present(args) Databases.add_to_blacklist('mention', target) target = @workers.add_arobases_to_usernames args Logs.rec.info "Added '#{target}' to blacklist of mentions." when 'client', 'source' Databases.add_to_blacklist('client', args) Logs.rec.info "Added '#{args}' to blacklist of clients." when 'hashtag', 'tag' Databases.add_to_blacklist('hashtag', args) Logs.rec.info "Added '#{args}' to blacklist of hashtags." when 'word', 'keyword' args = args.map { |w| w.gsub(/[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/, "") } Databases.add_to_blacklist('word', args) Logs.rec.info "Added '#{args}' to blacklist of words." else Status.new.wrong_arguments end end end |
#clear ⇒ Object
def import(database)
begin
new_db = File.realpath(database)
if File.exist?(new_db)
Databases.import_blacklist(new_db)
Logs.rec.info "Imported '#{new_db}' values in blacklist database."
else
puts "\nFile '#{new_db}' doesn't exist.\n\n".color(:red)
Logs.rec.warn "File '#{new_db}' doesn't exist."
end
end
end
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ayadn/blacklist.rb', line 71 def clear begin Status.new.ask_clear_blacklist input = STDIN.getch if input == 'y' || input == 'Y' Databases.clear_blacklist Logs.rec.info "Cleared the blacklist database." else Status.new.canceled exit end end end |
#list(options) ⇒ Object
140 141 142 143 144 145 |
# File 'lib/ayadn/blacklist.rb', line 140 def list() begin Settings.[:timeline][:compact] = true if [:compact] == true show_list() end end |
#remove(args) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ayadn/blacklist.rb', line 113 def remove(args) begin type = args.shift case type when 'user', 'username', 'account' Databases.remove_from_blacklist('user', args) target = @workers.add_arobases_to_usernames(args) Logs.rec.info "Removed '#{type}:#{target}' from blacklist of users." when 'mention', 'mentions' Databases.remove_from_blacklist('mention', args) target = @workers.add_arobases_to_usernames(args) Logs.rec.info "Removed '#{target}' from blacklist of mentions." when 'client', 'source' Databases.remove_from_blacklist('client', args) Logs.rec.info "Removed '#{type}:#{args}' from blacklist." when 'hashtag', 'tag' Databases.remove_from_blacklist('hashtag', args) Logs.rec.info "Removed '#{type}:#{args}' from blacklist." when 'word', 'keyword' args = args.map { |w| w.gsub(/[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/, "") } Databases.remove_from_blacklist('word', args) Logs.rec.info "Removed '#{type}:#{args}' from blacklist." else Status.new.wrong_arguments end end end |