Class: Ayadn::BlacklistWorkers

Inherits:
Object
  • Object
show all
Defined in:
lib/ayadn/blacklist.rb

Instance Method Summary collapse

Constructor Details

#initializeBlacklistWorkers

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



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ayadn/blacklist.rb', line 94

def add(args)
  begin
    type = args.shift
    case type
    when 'user', 'username', 'account'
      target = @workers.add_arobases_to_usernames args
      Databases.add_user_to_blacklist(target)
      Logs.rec.info "Added '#{target}' to blacklist of users."
    when 'mention', 'mentions'
      target = @workers.add_arobases_to_usernames args
      Databases.add_mention_to_blacklist(target)
      Logs.rec.info "Added '#{target}' to blacklist of mentions."
    when 'client', 'source'
      Databases.add_client_to_blacklist(args)
      Logs.rec.info "Added '#{args}' to blacklist of clients."
    when 'hashtag', 'tag'
      Databases.add_hashtag_to_blacklist(args)
      Logs.rec.info "Added '#{args}' to blacklist of hashtags."
    else
      puts Status.wrong_arguments
    end
  ensure
    Databases.close_all
  end
end

#clearObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ayadn/blacklist.rb', line 80

def clear
  begin
    puts "\n\nAre you sure you want to erase all the content of your blacklist database?\n\n[y/N]\n".color(:red)
    input = STDIN.getch
    if input == 'y' || input == 'Y'
      Databases.clear_blacklist
      Logs.rec.info "Cleared the blacklist database."
    else
      abort Status.canceled
    end
  ensure
    Databases.close_all
  end
end

#convertObject



73
74
75
76
77
78
79
# File 'lib/ayadn/blacklist.rb', line 73

def convert
  begin
    Databases.convert_blacklist
  ensure
    Databases.close_all
  end
end

#import(database) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ayadn/blacklist.rb', line 59

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
  ensure
    Databases.close_all
  end
end

#list(options) ⇒ Object



142
143
144
145
146
147
148
# File 'lib/ayadn/blacklist.rb', line 142

def list(options)
  begin
    show_list(options)
  ensure
    Databases.close_all
  end
end

#remove(args) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/ayadn/blacklist.rb', line 119

def remove(args)
  begin
    type = args.shift
    case type
    when 'user', 'username', 'account'
      temp = @workers.add_arobases_to_usernames args
      target = temp.map {|u| "-#{u}"}
      Databases.remove_from_blacklist(target)
      Logs.rec.info "Removed '#{target}' from blacklist of users."
    when 'mention', 'mentions'
      target = @workers.add_arobases_to_usernames args
      Databases.remove_from_blacklist(target)
      Logs.rec.info "Removed '#{target}' from blacklist of mentions."
    when 'client', 'source', 'hashtag', 'tag'
      Databases.remove_from_blacklist(args)
      Logs.rec.info "Removed '#{type}:#{args}' from blacklist."
    else
      puts Status.wrong_arguments
    end
  ensure
    Databases.close_all
  end
end