Class: Discordrb::User

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

Overview

User on Discord, including internal data like discriminators

Direct Known Subclasses

Member, Profile, Recipient

Instance Attribute Summary collapse

Attributes included from UserAttributes

#avatar_id, #bot_account, #discriminator, #username

Attributes included from IDObject

#id

Instance Method Summary collapse

Methods included from UserAttributes

#avatar_url, #distinct, #mention

Methods included from IDObject

#==, #creation_time, synthesise

Instance Attribute Details

#activitiesActivitySet (readonly)



55
56
57
# File 'lib/discordrb/data/user.rb', line 55

def activities
  @activities
end

#client_statusHash<Symbol, Symbol> (readonly)



59
60
61
# File 'lib/discordrb/data/user.rb', line 59

def client_status
  @client_status
end

#statusSymbol (readonly)



52
53
54
# File 'lib/discordrb/data/user.rb', line 52

def status
  @status
end

Instance Method Details

#await(key, attributes = {}, &block) ⇒ 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:



132
133
134
# File 'lib/discordrb/data/user.rb', line 132

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

#await!(attributes = {}, &block) ⇒ 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:



139
140
141
# File 'lib/discordrb/data/user.rb', line 139

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

#current_bot?true, false

Is the user the bot?



153
154
155
# File 'lib/discordrb/data/user.rb', line 153

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

#dnd?true, false



175
176
177
178
179
# File 'lib/discordrb/data/user.rb', line 175

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.



183
184
185
# File 'lib/discordrb/data/user.rb', line 183

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

#idle?true, false



175
176
177
178
179
# File 'lib/discordrb/data/user.rb', line 175

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



200
201
202
# File 'lib/discordrb/data/user.rb', line 200

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

#offline?true, false



175
176
177
178
179
# File 'lib/discordrb/data/user.rb', line 175

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



146
147
148
149
# File 'lib/discordrb/data/user.rb', line 146

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

#online?true, false



175
176
177
178
179
# File 'lib/discordrb/data/user.rb', line 175

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

  • #pm(content) ⇒ Message

    Sends a private to this user.



87
88
89
90
91
92
93
94
95
96
# File 'lib/discordrb/data/user.rb', line 87

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'))


108
109
110
# File 'lib/discordrb/data/user.rb', line 108

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.



189
190
191
# File 'lib/discordrb/data/user.rb', line 189

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.



195
196
197
# File 'lib/discordrb/data/user.rb', line 195

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

#webhook?true, false



158
159
160
# File 'lib/discordrb/data/user.rb', line 158

def webhook?
  @discriminator == Message::ZERO_DISCRIM
end