Improved input validation of steam method.
This commit is contained in:
parent
2814546627
commit
42ac0ea2bf
1 changed files with 24 additions and 18 deletions
|
@ -79,10 +79,10 @@ returns
|
||||||
def fetchable?(channel)
|
def fetchable?(channel)
|
||||||
return true if Rails.env.test?
|
return true if Rails.env.test?
|
||||||
|
|
||||||
# only fetch once a hour
|
# only fetch once in 30 minutes
|
||||||
return true if !channel.preferences
|
return true if !channel.preferences
|
||||||
return true if !channel.preferences[:last_fetch]
|
return true if !channel.preferences[:last_fetch]
|
||||||
return false if channel.preferences[:last_fetch] > Time.zone.now - 1.hour
|
return false if channel.preferences[:last_fetch] > Time.zone.now - 30.minutes
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -183,26 +183,32 @@ returns
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def stream
|
def stream
|
||||||
|
sync = @channel.options['sync']
|
||||||
|
fail 'Need channel.options[\'sync\'] for account, but no params found' if !sync
|
||||||
|
|
||||||
|
filter = {}
|
||||||
|
if sync['search']
|
||||||
hashtags = []
|
hashtags = []
|
||||||
@channel.options['sync']['search'].each {|item|
|
sync['search'].each {|item|
|
||||||
hashtags.push item['term']
|
hashtags.push item['term']
|
||||||
}
|
}
|
||||||
filter = {
|
filter[:track] = hashtags.join(',')
|
||||||
track: hashtags.join(','),
|
end
|
||||||
}
|
if sync['mentions'] && sync['mentions']['group_id'] != ''
|
||||||
if @channel.options['sync']['mentions']['group_id'] != ''
|
|
||||||
filter[:replies] = 'all'
|
filter[:replies] = 'all'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return if filter.empty?
|
||||||
|
|
||||||
@stream_client.client.user(filter) do |tweet|
|
@stream_client.client.user(filter) do |tweet|
|
||||||
next if tweet.class != Twitter::Tweet && tweet.class != Twitter::DirectMessage
|
next if tweet.class != Twitter::Tweet && tweet.class != Twitter::DirectMessage
|
||||||
next if Ticket::Article.find_by(message_id: tweet.id)
|
next if Ticket::Article.find_by(message_id: tweet.id)
|
||||||
|
|
||||||
# check direct message
|
# check direct message
|
||||||
if tweet.class == Twitter::DirectMessage
|
if tweet.class == Twitter::DirectMessage
|
||||||
if @channel.options['sync']['direct_messages']['group_id'] != ''
|
if sync['direct_messages'] && sync['direct_messages']['group_id'] != ''
|
||||||
next if @stream_client.direct_message_limit_reached(tweet)
|
next if @stream_client.direct_message_limit_reached(tweet)
|
||||||
@stream_client.to_group(tweet, @channel.options['sync']['direct_messages']['group_id'], @channel)
|
@stream_client.to_group(tweet, sync['direct_messages']['group_id'], @channel)
|
||||||
end
|
end
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
@ -210,7 +216,7 @@ returns
|
||||||
next if @stream_client.tweet_limit_reached(tweet)
|
next if @stream_client.tweet_limit_reached(tweet)
|
||||||
|
|
||||||
# check if it's mention
|
# check if it's mention
|
||||||
if @channel.options['sync']['mentions']['group_id'] != ''
|
if sync['mentions'] && sync['mentions']['group_id'] != ''
|
||||||
hit = false
|
hit = false
|
||||||
if tweet.user_mentions
|
if tweet.user_mentions
|
||||||
tweet.user_mentions.each {|user|
|
tweet.user_mentions.each {|user|
|
||||||
|
@ -220,15 +226,15 @@ returns
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
if hit
|
if hit
|
||||||
@stream_client.to_group(tweet, @channel.options['sync']['mentions']['group_id'], @channel)
|
@stream_client.to_group(tweet, sync['mentions']['group_id'], @channel)
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# check hashtags
|
# check hashtags
|
||||||
if @channel.options['sync']['search'] && tweet.hashtags
|
if sync['search'] && tweet.hashtags
|
||||||
hit = false
|
hit = false
|
||||||
@channel.options['sync']['search'].each {|item|
|
sync['search'].each {|item|
|
||||||
tweet.hashtags.each {|hashtag|
|
tweet.hashtags.each {|hashtag|
|
||||||
next if item['term'] !~ /^#/
|
next if item['term'] !~ /^#/
|
||||||
if item['term'].sub(/^#/, '') == hashtag.text
|
if item['term'].sub(/^#/, '') == hashtag.text
|
||||||
|
@ -243,10 +249,10 @@ returns
|
||||||
end
|
end
|
||||||
|
|
||||||
# check stings
|
# check stings
|
||||||
if @channel.options['sync']['search']
|
if sync['search']
|
||||||
hit = false
|
hit = false
|
||||||
body = tweet.text
|
body = tweet.text
|
||||||
@channel.options['sync']['search'].each {|item|
|
sync['search'].each {|item|
|
||||||
next if item['term'] =~ /^#/
|
next if item['term'] =~ /^#/
|
||||||
if body =~ /#{item['term']}/
|
if body =~ /#{item['term']}/
|
||||||
hit = item
|
hit = item
|
||||||
|
|
Loading…
Reference in a new issue