class Discordrb::User
User
on Discord, including internal data like discriminators
Attributes
@return [String, nil] the game the user is currently playing, or `nil` if none is being played.
@return [Symbol] the current online status of the user (`:online`, `:offline` or `:idle`)
@return [String, Integer
, nil] the type of the stream. Can technically be set to anything, most of the time it
will be 0 for no stream or 1 for Twitch streams.
@return [String, nil] the URL to the stream, if the user is currently streaming something.
Public Class Methods
# File lib/discordrb/data.rb, line 165 def initialize(data, bot) @bot = bot @username = data['username'] @id = data['id'].to_i @discriminator = data['discriminator'] @avatar_id = data['avatar'] @roles = {} @bot_account = false @bot_account = true if data['bot'] @status = :offline end
Public Instance Methods
Add an await for a message from this user. Specifically, this adds a global await for a MessageEvent with this user's ID as a :from attribute. @see Bot#add_await
# File lib/discordrb/data.rb, line 238 def await(key, attributes = {}, &block) @bot.add_await(key, Discordrb::Events::MessageEvent, { from: @id }.merge(attributes), &block) end
Add a blocking await for a message from this user. Specifically, this adds a global await for a MessageEvent with this user's ID as a :from attribute. @see Bot#add_await!
# File lib/discordrb/data.rb, line 245 def await!(attributes = {}) @bot.add_await!(Discordrb::Events::MessageEvent, { from: @id }.merge(attributes)) end
Is the user the bot? @return [true, false] whether this user is the bot
# File lib/discordrb/data.rb, line 259 def current_bot? @bot.profile.id == @id end
The inspect method is overwritten to give more useful output
# File lib/discordrb/data.rb, line 275 def inspect "<User username=#{@username} id=#{@id} discriminator=#{@discriminator}>" end
Gets the member this user is on a server @param server [Server] The server to get the member for @return [Member] this user as a member on a particular server
# File lib/discordrb/data.rb, line 252 def on(server) id = server.resolve_id @bot.server(id).member(@id) end
Get a user's PM channel or send them a PM @overload pm
Creates a private message channel for this user or returns an existing one if it already exists @return [Channel] the PM channel to this user.
@overload pm(content)
Sends a private to this user. @param content [String] The content to send. @return [Message] the message sent to this user.
# File lib/discordrb/data.rb, line 188 def pm(content = nil) if content # Recursively call pm to get the channel, then send a message to it channel = pm channel.send_message(content) else # If no message was specified, return the PM channel @bot.pm_channel(@id) end end
Send the user a file. @param file [File] The file to send to the user @param caption [String] The caption of the file being sent @return [Message] the message sent to this user. @example Send a file from disk
user.send_file(File.open('rubytaco.png', 'r'))
# File lib/discordrb/data.rb, line 207 def send_file(file, caption = nil) pm.send_file(file, caption: caption) end
Set the user's presence data @note for internal use only @!visibility private
# File lib/discordrb/data.rb, line 221 def update_presence(data) @status = data['status'].to_sym if data['game'] game = data['game'] @game = game['name'] @stream_url = game['url'] @stream_type = game['type'] else @game = @stream_url = @stream_type = nil end end
Set the user's name @note for internal use only @!visibility private
# File lib/discordrb/data.rb, line 214 def update_username(username) @username = username end
@return [true, false] whether this user is a fake user for a webhook message
# File lib/discordrb/data.rb, line 264 def webhook? @discriminator == Message::ZERO_DISCRIM end