Skip to content

Instantly share code, notes, and snippets.

@naniwaKun
Last active August 23, 2017 08:39
Show Gist options
  • Save naniwaKun/eece90e2b390b28b15650d085ca26e74 to your computer and use it in GitHub Desktop.
Save naniwaKun/eece90e2b390b28b15650d085ca26e74 to your computer and use it in GitHub Desktop.
ツイッターボットでアラブ人を自動フォロバしない。 ref: http://qiita.com/naniwaKun/items/f159d1e80f1fd4fb2fba
require "twitter"
require 'json'
USERNAME = "********"
client = Twitter::REST::Client.new do |config|
config.consumer_key = "********"
config.consumer_secret = "********"
config.access_token = "********"
config.access_token_secret = "********"
end
client_streaming = Twitter::Streaming::Client.new do |config|
config.consumer_key = "********"
config.consumer_secret = "********"
config.access_token = "********"
config.access_token_secret = "********"
end
client_streaming.user do |object|
case object
when Twitter::Tweet
username = object.user.screen_name
if (/おはよ/ =~ object.text) && !(/RT/ =~ object.text) && ( username != USERNAME )
##タイムラインに「おはよ」が現れたときの処理を書く。
end
when Twitter::Streaming::Event
if(object.name == "follow".to_sym) && (object.source.id != ********)
##日本語の正規表現
regex = /[\p{Han}\p{Hiragana}\p{Katakana},.、。ー・]+/
profile = client.user(object.source.id).description
japanese_arr = profile.scan(regex)
##日本語のプロフィールだけフォロバ
unless (japanese_arr.empty?)
client.follow(object.source.id)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment