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.



46
47
48
49
50
51
52
53
# File 'lib/ayadn/blacklist.rb', line 46

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



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ayadn/blacklist.rb', line 69

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

#clearObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ayadn/blacklist.rb', line 55

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



127
128
129
130
131
132
# File 'lib/ayadn/blacklist.rb', line 127

def list(options)
  begin
    Settings.options.timeline.compact = true if options[:compact]
    show_list(options)
  end
end

#remove(args) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/ayadn/blacklist.rb', line 99

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