class Twitchbot::User

Class responsible for keeping track of a user attributes such as their display name, id, any badges they have, and implementing helper functions to determine if different qualities of the user

Attributes

badges[R]

@return [Hash] Collection of known badges for the user

id[R]

@return [String] Server ID for the user

Public Class Methods

new(name, display_name = nil, id = nil) click to toggle source
# File lib/twitchbot/user.rb, line 11
def initialize(name, display_name = nil, id = nil)
  @name = name
  @display_name = display_name
  @id = id
  @badges = {}
end

Public Instance Methods

bits_leader?() click to toggle source

Method to determine if the user is on the leaderboard for bit gifts

# File lib/twitchbot/user.rb, line 75
def bits_leader?
  @badges.key? 'bits-leader'
end
donator?() click to toggle source

Method to determine if the user has ever donated to the channel

# File lib/twitchbot/user.rb, line 60
def donator?
  @badges.key? 'bits'
end
founder?() click to toggle source

Method to determine if the user is a channel founder

# File lib/twitchbot/user.rb, line 65
def founder?
  @badges.key? 'founder'
end
mod?() click to toggle source

Method to determine if the user is a moderator of the channel

# File lib/twitchbot/user.rb, line 45
def mod?
  @badges.key? 'moderator'
end
name() click to toggle source

Method to grab the best representation of a user

# File lib/twitchbot/user.rb, line 35
def name
  @display_name || @name
end
prime?() click to toggle source

Method to determine if the user has Twitch Prime

# File lib/twitchbot/user.rb, line 55
def prime?
  @badges.key? 'premium'
end
streamer?() click to toggle source

Method to determine if the user is the broadcaster of the channel

# File lib/twitchbot/user.rb, line 40
def streamer?
  @badges.key? 'broadcaster'
end
sub?() click to toggle source

Method to determine if the user is a subscriber to the channel

# File lib/twitchbot/user.rb, line 50
def sub?
  @badges.key? 'subscriber'
end
sub_gift_leader?() click to toggle source

Method to determine if the user is on the leaderboard for subscriber gifts

# File lib/twitchbot/user.rb, line 70
def sub_gift_leader?
  @badges.key? 'sub-gift-leader'
end
to_s() click to toggle source
# File lib/twitchbot/user.rb, line 79
def to_s
  name
end
update_attributes(display_name, id) click to toggle source

Method to update the main attributes of a user

# File lib/twitchbot/user.rb, line 19
def update_attributes(display_name, id)
  @display_name = display_name
  @user_id = id
end
update_badges(badge) click to toggle source

Method to process the string representation of badges into a Hash so that we can query it for specific badges and levels of the badges

# File lib/twitchbot/user.rb, line 26
def update_badges(badge)
  @badges = {}
  badge.split(',').each do |_badge|
    type, value = _badge.split '/'
    @badges[type] = value.to_i
  end
end