Last active
August 23, 2017 08:39
-
-
Save naniwaKun/eece90e2b390b28b15650d085ca26e74 to your computer and use it in GitHub Desktop.
ツイッターボットでアラブ人を自動フォロバしない。 ref: http://qiita.com/naniwaKun/items/f159d1e80f1fd4fb2fba
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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