lib/ayadn/workers.rb in ayadn-1.2.2 vs lib/ayadn/workers.rb in ayadn-1.2.3
- old
+ new
@@ -115,12 +115,14 @@
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]
else
rank = false
+ is_human = 'unknown'
end
if post['user'].has_key?('name')
name = post['user']['name'].to_s.force_encoding("UTF-8")
else
@@ -135,10 +137,11 @@
name: name,
thread_id: post['thread_id'],
username: post['user']['username'],
user_id: post['user']['id'].to_i,
nicerank: rank,
+ is_human: is_human,
handle: "@#{post['user']['username']}",
type: post['user']['type'],
date: parsed_time(post['created_at']),
you_starred: post['you_starred'],
source_name: source,
@@ -160,11 +163,11 @@
values[:original_poster] = post['user']['username']
end
unless post['text'].nil?
values[:raw_text] = post['text']
- values[:text] = colorize_text(post['text'], mentions)
+ values[:text] = colorize_text(post['text'], mentions, hashtags)
else
values[:raw_text] = ""
values[:text] = "(no text)"
end
@@ -260,20 +263,39 @@
"#{string[0...10]} #{string[11...19]}"
end
def self.add_arobase_if_missing(username) # expects an array of username(s), works on the first one and outputs a string
unless username.first == "me"
- username = username.first.chars.to_a
+ username = username.first.chars
username.unshift("@") unless username.first == "@"
else
- username = "me".chars.to_a
+ username = "me".chars
end
username.join
end
+ def self.add_arobases_to_usernames args
+ args.map! do |username|
+ if username == 'me'
+ self.who_am_i
+ else
+ temp = username.chars
+ temp.unshift("@") unless temp.first == "@"
+ temp.join
+ end
+ end
+ args
+ end
+
+ def self.who_am_i
+ db = Databases.init(Dir.home + "/ayadn/accounts.db")
+ active = db['ACTIVE']
+ db[active][:handle]
+ end
+
def self.remove_arobase_if_present(username)
- username = username.chars.to_a
+ username = username.chars
username.shift if username.first == "@"
username.join
end
def self.extract_users(resp)
@@ -282,11 +304,11 @@
users_hash[item['id']] = [item['username'], item['name'], item['you_follow'], item['follows_you']]
end
users_hash
end
- def colorize_text(text, mentions)
+ def colorize_text(text, mentions, hashtags)
reg_split = '[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]'
#reg_tag = '#([A-Za-z0-9_]{1,255})(?![\w+])'
reg_tag = '#([[:alpha:]0-9_]{1,255})(?![\w+])'
reg_mention = '@([A-Za-z0-9_]{1,20})(?![\w+])'
reg_sentence = '^.+[\r\n]*'
@@ -297,10 +319,27 @@
hashtag_color = Settings.options[:colors][:hashtags]
mention_color = Settings.options[:colors][:mentions]
text.scan(/#{reg_sentence}/) do |sentence|
sentence.split(' ').each do |word|
if word =~ /#\w+/
- words << word.gsub(/#{reg_tag}/, '#\1'.color(hashtag_color))
+ slices = word.split('#')
+ has_h = false
+ slices.each do |tag|
+ bit = tag.downcase.scan(/[[:alpha:]0-9_]/).join('')
+ if hashtags.include? bit
+ has_h = true
+ end
+ end
+ if has_h == true
+ if slices.length > 1
+ word = slices.join('#')
+ words << word.gsub(/#{reg_tag}/, '#\1'.color(hashtag_color))
+ else
+ words << word.gsub(/#{reg_tag}/, '#\1'.color(hashtag_color))
+ end
+ else
+ words << word
+ end
elsif word =~ /@\w+/
@str = def_str(word, reg_split)
if handles.include?(@str.downcase)
words << word.gsub(/#{reg_mention}/, '@\1'.color(mention_color))
else