Class: Discordrb::User
- Inherits:
-
Object
- Object
- Discordrb::User
- Includes:
- IDObject, UserAttributes
- Defined in:
- lib/discordrb/data.rb
Overview
User on Discord, including internal data like discriminators
Instance Attribute Summary collapse
-
#game ⇒ String?
The game the user is currently playing, or
nil
if none is being played. -
#status ⇒ Symbol
The current online status of the user (
:online
,:offline
or:idle
).
Attributes included from UserAttributes
#avatar_id, #bot_account, #discriminator, #username
Attributes included from IDObject
Instance Method Summary collapse
-
#await(key, attributes = {}, &block) ⇒ Object
Add an await for a message from this user.
-
#current_bot? ⇒ true, false
Is the user the bot?.
-
#initialize(data, bot) ⇒ User
constructor
A new instance of User.
-
#inspect ⇒ Object
The inspect method is overwritten to give more useful output.
-
#on(server) ⇒ Member
Gets the member this user is on a server.
-
#pm(content = nil) ⇒ Object
Get a user's PM channel or send them a PM.
Methods included from UserAttributes
#avatar_url, #distinct, #mention
Methods included from IDObject
Constructor Details
#initialize(data, bot) ⇒ User
Returns a new instance of User.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/discordrb/data.rb', line 137 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 |
Instance Attribute Details
#game ⇒ String?
Returns the game the user is currently playing, or nil
if none is being played.
135 136 137 |
# File 'lib/discordrb/data.rb', line 135 def game @game end |
#status ⇒ Symbol
Returns the current online status of the user (:online
, :offline
or :idle
).
131 132 133 |
# File 'lib/discordrb/data.rb', line 131 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.
181 182 183 |
# File 'lib/discordrb/data.rb', line 181 def await(key, attributes = {}, &block) @bot.add_await(key, Discordrb::Events::MessageEvent, { from: @id }.merge(attributes), &block) end |
#current_bot? ⇒ true, false
Is the user the bot?
195 196 197 |
# File 'lib/discordrb/data.rb', line 195 def current_bot? @bot.profile.id == @id end |
#inspect ⇒ Object
The inspect method is overwritten to give more useful output
200 201 202 |
# File 'lib/discordrb/data.rb', line 200 def inspect "<User username=#{@username} id=#{@id} discriminator=#{@discriminator}>" end |
#on(server) ⇒ Member
Gets the member this user is on a server
188 189 190 191 |
# File 'lib/discordrb/data.rb', line 188 def on(server) id = server.resolve_id @bot.server(id).member(@id) end |
#pm ⇒ Channel #pm(content) ⇒ Message
Get a user's PM channel or send them a PM
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/discordrb/data.rb', line 160 def pm(content = nil) if content # Recursively call pm to get the channel, then send a message to it channel = pm channel.(content) else # If no message was specified, return the PM channel @bot.private_channel(@id) end end |