Create @user variable

Since #prepare already calls twitter.user, it'd be best to just save it!
This commit is contained in:
Stawberri 2015-01-15 02:34:45 -08:00
parent 158683fe06
commit d657f25be4

View file

@ -144,6 +144,8 @@ module Ebooks
attr_accessor :access_token attr_accessor :access_token
# @return [String] OAuth access secret from `ebooks auth` # @return [String] OAuth access secret from `ebooks auth`
attr_accessor :access_token_secret attr_accessor :access_token_secret
# @return [Twitter::User] Twitter user object of bot
attr_accessor :user
# @return [String] Twitter username of bot # @return [String] Twitter username of bot
attr_accessor :username attr_accessor :username
# @return [Array<String>] list of usernames to block on contact # @return [Array<String>] list of usernames to block on contact
@ -304,6 +306,16 @@ module Ebooks
end end
end end
# Updates @user and calls on_user_update. Make sure it's the right person before you call it.
def update_user_object(new_me = twitter.user)
new_me = twitter.user unless new_me.is_a? Twitter::User
@user = new_me
@username = user.name
fire(:user_update)
end
# Configures client and fires startup event # Configures client and fires startup event
def prepare def prepare
# Sanity check # Sanity check
@ -323,12 +335,12 @@ module Ebooks
exit 1 exit 1
end end
real_name = twitter.user.screen_name # Save old name
old_name = username
if real_name != @username # Load user object and actual username
log "connected to @#{real_name}-- please update config to match Twitter account name" update_user_object
@username = real_name # Warn about mismatches unless it was clearly intensional
end log "warning: bot expected to be @#{old_name} but connected to @#{username}" unless username == old_name || old_name.empty?
fire(:startup) fire(:startup)
end end