class MijDiscord::Data::User
Attributes
avatar_id[R]
bot[R]
bot_account[R]
bot_account?[R]
discriminator[R]
extra[R]
game[R]
name[R]
status[R]
tag[R]
username[R]
Public Class Methods
new(data, bot)
click to toggle source
# File lib/mij-discord/data/user.rb, line 139 def initialize(data, bot) @bot = bot # Kludge for User::resolve2 API call data = data['user'] if data['user'].is_a?(Hash) @id = data['id'].to_i @bot_account = !!data['bot'] update_data(data) @status, @game = :offline, nil @roles = {} end
process_avatar(data, format = :png, empty = false)
click to toggle source
# File lib/mij-discord/data/user.rb, line 250 def process_avatar(data, format = :png, empty = false) if data.is_a?(String) "data:image/#{format};base64,#{data}" elsif data.respond_to?(:read) data.binmode if data.respond_to?(:binmode) data = Base64.strict_encode64(data.read) "data:image/#{format};base64,#{data}" elsif empty && %i[none empty].include?(data) nil else raise ArgumentError, 'Invalid avatar data provided' end end
Public Instance Methods
avatar_url(format = nil)
click to toggle source
# File lib/mij-discord/data/user.rb, line 237 def avatar_url(format = nil) return MijDiscord::Core::API::User.default_avatar(@discriminator) unless @avatar_id MijDiscord::Core::API::User.avatar_url(@id, @avatar_id, format) end
Also aliased as: avatar
current_bot?()
click to toggle source
# File lib/mij-discord/data/user.rb, line 203 def current_bot? @bot.profile == self end
distinct()
click to toggle source
# File lib/mij-discord/data/user.rb, line 176 def distinct "#{@username}##{@discriminator}" end
dnd?()
click to toggle source
# File lib/mij-discord/data/user.rb, line 217 def dnd? @status == :dnd end
Also aliased as: busy?
idle?()
click to toggle source
# File lib/mij-discord/data/user.rb, line 211 def idle? @status == :idle end
Also aliased as: away?
inspect()
click to toggle source
# File lib/mij-discord/data/user.rb, line 244 def inspect MijDiscord.make_inspect(self, :id, :username, :discriminator, :avatar_id, :bot_account) end
invisible?()
click to toggle source
# File lib/mij-discord/data/user.rb, line 223 def invisible? @status == :invisible end
Also aliased as: hidden?
member?()
click to toggle source
# File lib/mij-discord/data/user.rb, line 233 def member? false end
mention()
click to toggle source
# File lib/mij-discord/data/user.rb, line 170 def mention "<@#{@id}>" end
Also aliased as: to_s
offline?()
click to toggle source
# File lib/mij-discord/data/user.rb, line 229 def offline? @status == :offline end
on(server)
click to toggle source
# File lib/mij-discord/data/user.rb, line 194 def on(server) id = server.to_id @bot.server(id).member(@id) end
online?()
click to toggle source
# File lib/mij-discord/data/user.rb, line 207 def online? @status == :online? end
pm(text: nil, embed: nil)
click to toggle source
# File lib/mij-discord/data/user.rb, line 180 def pm(text: nil, embed: nil) if text || embed pm.send_message(text: text || '', embed: embed) else @bot.pm_channel(@id) end end
Also aliased as: dm
send_file(file, caption: nil)
click to toggle source
# File lib/mij-discord/data/user.rb, line 190 def send_file(file, caption: nil) pm.send_file(file, caption: caption) end
update_data(data)
click to toggle source
# File lib/mij-discord/data/user.rb, line 154 def update_data(data) @username = data.fetch('username', @username) @discriminator = data.fetch('discriminator', @discriminator) @avatar_id = data.fetch('avatar', @avatar_id) end
update_presence(presence)
click to toggle source
# File lib/mij-discord/data/user.rb, line 160 def update_presence(presence) @status = presence['status'].to_sym if (game = presence['game']) @game = Game.new(game) else @game = nil end end
webhook?()
click to toggle source
# File lib/mij-discord/data/user.rb, line 199 def webhook? @discriminator == '0000' end