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
@return [Hash] Collection of known badges for the user
@return [String] Server ID for the user
Public Class Methods
# 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
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
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
Method to determine if the user is a channel founder
# File lib/twitchbot/user.rb, line 65 def founder? @badges.key? 'founder' end
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
Method to grab the best representation of a user
# File lib/twitchbot/user.rb, line 35 def name @display_name || @name end
Method to determine if the user has Twitch Prime
# File lib/twitchbot/user.rb, line 55 def prime? @badges.key? 'premium' end
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
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
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
# File lib/twitchbot/user.rb, line 79 def to_s name end
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
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