class Discorb::User
Represents a user of discord.
Attributes
@return [Discorb::Asset] The user's avatar.
@return [Boolean] Whether the user is a bot.
@return [Boolean] Whether the user is a bot.
@return [Time] The time the user was created.
@return [String] The user's discriminator.
@return [Discorb::User::Flag] The user's flags.
@return [Discorb::Snowflake] The user's ID.
@return [String] The user's username.
@return [String] The user's username.
@return [Boolean] Whether the user is verified.
Public Class Methods
@!visibility private
# File lib/discorb/user.rb, line 30 def initialize(client, data) @client = client @data = {} @dm_channel_id = nil _set_data(data) end
Public Instance Methods
Whether the user is a owner of the client. @macro async @macro http
@param [Boolean] strict Whether don't allow if the user is a member of the team.
@return [Boolean] Whether the user is a owner of the client.
# File lib/discorb/user.rb, line 61 def bot_owner?(strict: false) Async do app = @client.fetch_application.wait if app.team.nil? app.owner == self elsif strict app.team.owner == self else app.team.members.any? { |m| m.user == self } end end end
@!visibility private
# File lib/discorb/user.rb, line 77 def channel_id Async do next @dm_channel_id if @dm_channel_id _resp, dm_channel = @client.http.post("/users/@me/channels", { recipient_id: @id }).wait @dm_channel_id = dm_channel[:id] @dm_channel_id end end
# File lib/discorb/user.rb, line 48 def inspect "#<#{self.class} #{self}>" end
Format the user as `Username#Discriminator` style.
@return [String] The formatted username.
# File lib/discorb/user.rb, line 42 def to_s "#{@username}##{@discriminator}" end
Private Instance Methods
# File lib/discorb/user.rb, line 124 def _set_data(data) @username = data[:username] @verified = data[:verified] @id = Snowflake.new(data[:id]) @flag = User::Flag.new(data[:public_flags] | (data[:flags] || 0)) @discriminator = data[:discriminator] @avatar = data[:avatar] ? Asset.new(self, data[:avatar]) : DefaultAvatar.new(data[:discriminator]) @bot = data[:bot] @raw_data = data @client.users[@id] = self if !data[:no_cache] && data.is_a?(User) @created_at = @id.timestamp @data.update(data) end