Class: Rubycord::User

Inherits:
Object
  • Object
show all
Includes:
IDObject, UserAttributes
Defined in:
lib/rubycord/data/user.rb

Overview

User on Discord, including internal data like discriminators

Direct Known Subclasses

Member, Profile, Recipient

Constant Summary

Constants included from UserAttributes

Rubycord::UserAttributes::FLAGS

Instance Attribute Summary collapse

Attributes included from UserAttributes

#avatar_id, #bot_account, #discriminator, #global_name, #public_flags, #username, #webhook_account

Attributes included from IDObject

#id

Instance Method Summary collapse

Methods included from UserAttributes

#avatar_url, #display_name, #distinct, #mention

Methods included from IDObject

#==, #creation_time, synthesise

Instance Attribute Details

#activitiesActivitySet (readonly)

Returns the activities of the user.

Returns:



105
106
107
# File 'lib/rubycord/data/user.rb', line 105

def activities
  @activities
end

#client_statusHash<Symbol, Symbol> (readonly)

Returns the current online status (:online, :idle or :dnd) of the user on various device types (:desktop, :mobile, or :web). The value will be nil if the user is offline or invisible.

Returns:

  • (Hash<Symbol, Symbol>)

    the current online status (:online, :idle or :dnd) of the user on various device types (:desktop, :mobile, or :web). The value will be nil if the user is offline or invisible.



109
110
111
# File 'lib/rubycord/data/user.rb', line 109

def client_status
  @client_status
end

#statusSymbol (readonly)

Returns the current online status of the user (:online, :offline or :idle).

Returns:

  • (Symbol)

    the current online status of the user (:online, :offline or :idle)



102
103
104
# File 'lib/rubycord/data/user.rb', line 102

def status
  @status
end

Instance Method Details

#await(key, attributes = {}) ⇒ Object

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 Also:



194
195
196
# File 'lib/rubycord/data/user.rb', line 194

def await(key, attributes = {}, &)
  @bot.add_await(key, Rubycord::Events::MessageEvent, {from: @id}.merge(attributes), &)
end

#await!(attributes = {}) ⇒ Object

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 Also:



201
202
203
# File 'lib/rubycord/data/user.rb', line 201

def await!(attributes = {}, &)
  @bot.add_await!(Rubycord::Events::MessageEvent, {from: @id}.merge(attributes), &)
end

#current_bot?true, false

Is the user the bot?

Returns:

  • (true, false)

    whether this user is the bot



215
216
217
# File 'lib/rubycord/data/user.rb', line 215

def current_bot?
  @bot.profile.id == @id
end

#dnd?true, false

Returns whether this user is set to do not disturb.

Returns:

  • (true, false)

    whether this user is set to do not disturb.



232
233
234
235
236
# File 'lib/rubycord/data/user.rb', line 232

%i[offline idle online dnd].each do |e|
  define_method(:"#{e}?") do
    @status.to_sym == e
  end
end

#gameString?

Deprecated.

Please use ActivitySet#games for information about the user's game activity

Returns the game the user is currently playing, or nil if nothing is being played.

Returns:

  • (String, nil)

    the game the user is currently playing, or nil if nothing is being played.



240
241
242
# File 'lib/rubycord/data/user.rb', line 240

def game
  @activities.games.first&.name
end

#idle?true, false

Returns whether this user is idle.

Returns:

  • (true, false)

    whether this user is idle.



232
233
234
235
236
# File 'lib/rubycord/data/user.rb', line 232

%i[offline idle online dnd].each do |e|
  define_method(:"#{e}?") do
    @status.to_sym == e
  end
end

#inspectObject

The inspect method is overwritten to give more useful output



257
258
259
# File 'lib/rubycord/data/user.rb', line 257

def inspect
  "<User username=#{@username} id=#{@id} discriminator=#{@discriminator}>"
end

#offline?true, false

Returns whether this user is offline.

Returns:

  • (true, false)

    whether this user is offline.



232
233
234
235
236
# File 'lib/rubycord/data/user.rb', line 232

%i[offline idle online dnd].each do |e|
  define_method(:"#{e}?") do
    @status.to_sym == e
  end
end

#on(server) ⇒ Member

Gets the member this user is on a server

Parameters:

  • server (Server)

    The server to get the member for

Returns:

  • (Member)

    this user as a member on a particular server



208
209
210
211
# File 'lib/rubycord/data/user.rb', line 208

def on(server)
  id = server.resolve_id
  @bot.server(id).member(@id)
end

#online?true, false

Returns whether this user is online.

Returns:

  • (true, false)

    whether this user is online.



232
233
234
235
236
# File 'lib/rubycord/data/user.rb', line 232

%i[offline idle online dnd].each do |e|
  define_method(:"#{e}?") do
    @status.to_sym == e
  end
end

#pmChannel #pm(content) ⇒ Message Also known as: dm

Get a user's PM channel or send them a PM

Overloads:

  • #pmChannel

    Creates a private message channel for this user or returns an existing one if it already exists

    Returns:

    • (Channel)

      the PM channel to this user.

  • #pm(content) ⇒ Message

    Sends a private to this user.

    Parameters:

    • content (String)

      The content to send.

    Returns:

    • (Message)

      the message sent to this user.



142
143
144
145
146
147
148
149
150
151
# File 'lib/rubycord/data/user.rb', line 142

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_file(file, caption = nil, filename: nil, spoiler: nil) ⇒ Message

Send the user a file.

Examples:

Send a file from disk

user.send_file(File.open('rubytaco.png', 'r'))

Parameters:

  • file (File)

    The file to send to the user

  • caption (String) (defaults to: nil)

    The caption of the file being sent

  • filename (String) (defaults to: nil)

    Overrides the filename of the uploaded file

  • spoiler (true, false) (defaults to: nil)

    Whether or not this file should appear as a spoiler.

Returns:

  • (Message)

    the message sent to this user.



163
164
165
# File 'lib/rubycord/data/user.rb', line 163

def send_file(file, caption = nil, filename: nil, spoiler: nil)
  pm.send_file(file, caption: caption, filename: filename, spoiler: spoiler)
end

#stream_typeInteger

Deprecated.

Please use ActivitySet#streaming for information about the user's stream activity

Returns 1 for twitch streams, or 0 for no stream.

Returns:

  • (Integer)

    returns 1 for twitch streams, or 0 for no stream.



246
247
248
# File 'lib/rubycord/data/user.rb', line 246

def stream_type
  @activities.streaming ? 1 : 0
end

#stream_urlString?

Deprecated.

Please use ActivitySet#streaming for information about the user's stream activity

Returns the URL to the stream, if the user is currently streaming something.

Returns:

  • (String, nil)

    the URL to the stream, if the user is currently streaming something



252
253
254
# File 'lib/rubycord/data/user.rb', line 252

def stream_url
  @activities.streaming.first&.url
end