lib/ayadn/workers.rb in ayadn-1.2.10 vs lib/ayadn/workers.rb in ayadn-1.3.0

- old
+ new

@@ -3,17 +3,20 @@ class Workers def build_aliases_list(list) table = init_table table.title = "List of your channel aliases".color(:cyan) + "".color(:white) + table.style = {border_x: '~', border_i: '+', border_y: ':'} list.each {|k,v| table << ["#{k}".color(:green), "#{v}".color(:red)]} table end def build_blacklist_list(list) table = init_table table.title = "Your blacklist".color(:cyan) + "".color(:white) + table.style = {border_x: '~', border_i: '+', border_y: ':'} + list = list.sort_by {|k,v| v} # no sort_by! for Daybreak dbs list.each {|k,v| table << ["#{v.capitalize}".color(:green), "#{k}".color(:red)]} table end def build_reposted_list(list, target) @@ -22,10 +25,11 @@ users_list = [] list.each do |obj| obj['name'].nil? ? name = "" : name = obj['name'] users_list << {:username => obj['username'], :name => name, :you_follow => obj['you_follow'], :follows_you => obj['follows_you']} end + table.style = {border_x: ' ', border_i: ' ', border_y: ' '} return users_list, table end def build_starred_list(list, target) table = init_table @@ -33,20 +37,22 @@ users_list = [] list.each do |obj| obj['name'].nil? ? name = "" : name = obj['name'] users_list << {:username => obj['username'], :name => name, :you_follow => obj['you_follow'], :follows_you => obj['follows_you']} end + table.style = {border_x: ' ', border_i: ' ', border_y: ' '} return users_list, table end def build_followings_list(list, target) #takes a hash of users with ayadn format table = init_table table.title = if target == "me" "List of users you're following".color(:cyan) + "".color(:white) else "List of users ".color(:cyan) + "#{target}".color(:red) + " is following ".color(:cyan) + "".color(:white) end + table.style = {border_x: ' ', border_i: ' ', border_y: ' '} users_list = build_users_array(list) build_users_list(users_list, table) end def build_followers_list(list, target) @@ -54,31 +60,36 @@ table.title = if target == "me" "List of your followers".color(:cyan) + "".color(:white) else "List of users following ".color(:cyan) + "#{target}".color(:red) + "".color(:white) end + table.style = {border_x: ' ', border_i: ' ', border_y: ' '} build_users_list(build_users_array(list), table) end def build_muted_list(list) table = init_table table.title = "List of users you muted".color(:cyan) + "".color(:white) + table.style = {border_x: ' ', border_i: ' ', border_y: ' '} build_users_list(build_users_array(list), table) end def build_blocked_list(list) table = init_table table.title = "List of users you blocked".color(:cyan) + "".color(:white) + table.style = {border_x: ' ', border_i: ' ', border_y: ' '} build_users_list(build_users_array(list), table) end def build_users_list(list, table) list.each_with_index do |obj, index| + obj[:username].length > 35 ? username = "#{obj[:username][0...32]}..." : username = obj[:username] unless obj[:name].nil? - table << [ "@#{obj[:username]} ".color(Settings.options[:colors][:username]), "#{obj[:name]}" ] + obj[:name].length > 35 ? name = "#{obj[:name][0...32]}..." : name = obj[:name] + table << [ "@#{username} ".color(Settings.options[:colors][:username]), "#{name}" ] else - table << [ "@#{obj[:username]} ".color(Settings.options[:colors][:username]), "" ] + table << [ "@#{username} ".color(Settings.options[:colors][:username]), "" ] end table << :separator unless index + 1 == list.length end table end @@ -87,10 +98,11 @@ # builds a hash of hashes, each hash is a normalized post with post id as a key posts = {} data.each.with_index(1) do |post, index| next if Databases.blacklist[post['source']['name'].downcase] + next if Databases.blacklist["-@#{post['user']['username'].downcase}"] hashtags = extract_hashtags(post) @skip = false hashtags.each do |h| if Databases.blacklist[h.downcase] @skip = true @@ -99,23 +111,25 @@ end next if @skip mentions= [] post['entities']['mentions'].each { |m| mentions << m['name'] } mentions.each do |m| - if Databases.blacklist["@" + m.downcase] + if Databases.blacklist["@#{m.downcase}"] @skip = true break end end next if @skip if niceranks[post['user']['id'].to_i] rank = niceranks[post['user']['id'].to_i][:rank] is_human = niceranks[post['user']['id'].to_i][:is_human] + real_person = niceranks[post['user']['id'].to_i][:real_person] else rank = false is_human = 'unknown' + real_person = nil end if post['user'].has_key?('name') name = post['user']['name'].to_s.force_encoding("UTF-8") else @@ -131,9 +145,10 @@ thread_id: post['thread_id'], username: post['user']['username'], user_id: post['user']['id'].to_i, nicerank: rank, is_human: is_human, + real_person: real_person, handle: "@#{post['user']['username']}", type: post['user']['type'], date: parsed_time(post['created_at']), you_starred: post['you_starred'], source_name: source,