Skip to content

Instantly share code, notes, and snippets.

@hogashi
Last active October 9, 2017 03:49
Show Gist options
  • Save hogashi/e67da2378ca86f1f8e61 to your computer and use it in GitHub Desktop.
Save hogashi/e67da2378ca86f1f8e61 to your computer and use it in GitHub Desktop.
hogasupdate_name
# -*- coding: utf-8 -*-
require 'rubygems'
require 'twitter'
CONSUMER_KEY = '********'
CONSUMER_SECRET = '********'
ACCESS_TOKEN = '********'
ACCESS_TOKEN_SECRET = '********'
client = Twitter::REST::Client.new do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
config.access_token = ACCESS_TOKEN
config.access_token_secret = ACCESS_TOKEN_SECRET
end
stream_client = Twitter::Streaming::Client.new do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
config.access_token = ACCESS_TOKEN
config.access_token_secret = ACCESS_TOKEN_SECRET
end
stream_client.user do |status|
next unless status.is_a? Twitter::Tweet
next if status.text.start_with? "RT"
if status.text =~ /.*?(\(|()(\s| )*@hogextend(\s| )*(\)|)).*?/i
new_name = status.text.gsub(/(\s| )*(\(|()(\s| )*@hogextend(\s| )*(\)|)).*/i, "")
if new_name.empty?
new_name = "hogas"
end
begin
client.update_profile({name: new_name})
client.update("@#{status.user.screen_name} renamed:「#{new_name}」", in_reply_to_status: status)
rescue
client.update("@#{status.user.screen_name} Something happened:「#{new_name}」", in_reply_to_status: status)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment