Class: MijDiscord::Data::User
- Inherits:
-
Object
- Object
- MijDiscord::Data::User
show all
- Includes:
- IDObject
- Defined in:
- lib/mij-discord/data/user.rb
Instance Attribute Summary collapse
Attributes included from IDObject
#id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from IDObject
#==, #creation_time, #hash, synthesize, timestamp
Constructor Details
#initialize(data, bot) ⇒ User
Returns a new instance of User.
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/mij-discord/data/user.rb', line 139
def initialize(data, bot)
@bot = bot
data = data['user'] if data['user'].is_a?(Hash)
@id = data['id'].to_i
@bot_account = !!data['bot']
update_data(data)
@status, @game = :offline, nil
@roles = {}
end
|
Instance Attribute Details
#avatar_id ⇒ Object
Returns the value of attribute avatar_id.
131
132
133
|
# File 'lib/mij-discord/data/user.rb', line 131
def avatar_id
@avatar_id
end
|
#bot ⇒ Object
Returns the value of attribute bot.
120
121
122
|
# File 'lib/mij-discord/data/user.rb', line 120
def bot
@bot
end
|
#bot_account ⇒ Object
Also known as:
bot_account?
Returns the value of attribute bot_account.
128
129
130
|
# File 'lib/mij-discord/data/user.rb', line 128
def bot_account
@bot_account
end
|
#discriminator ⇒ Object
Also known as:
tag
Returns the value of attribute discriminator.
125
126
127
|
# File 'lib/mij-discord/data/user.rb', line 125
def discriminator
@discriminator
end
|
Returns the value of attribute extra.
137
138
139
|
# File 'lib/mij-discord/data/user.rb', line 137
def
@extra
end
|
#game ⇒ Object
Returns the value of attribute game.
135
136
137
|
# File 'lib/mij-discord/data/user.rb', line 135
def game
@game
end
|
#status ⇒ Object
Returns the value of attribute status.
133
134
135
|
# File 'lib/mij-discord/data/user.rb', line 133
def status
@status
end
|
#username ⇒ Object
Also known as:
name
Returns the value of attribute username.
122
123
124
|
# File 'lib/mij-discord/data/user.rb', line 122
def username
@username
end
|
Class Method Details
.process_avatar(data, format = :png, empty = false) ⇒ Object
250
251
252
253
254
255
256
257
258
259
260
261
262
|
# File 'lib/mij-discord/data/user.rb', line 250
def process_avatar(data, format = :png, empty = false)
if data.is_a?(String)
"data:image/#{format};base64,#{data}"
elsif data.respond_to?(:read)
data.binmode if data.respond_to?(:binmode)
data = Base64.strict_encode64(data.read)
"data:image/#{format};base64,#{data}"
elsif empty && %i[none empty].include?(data)
nil
else
raise ArgumentError, 'Invalid avatar data provided'
end
end
|
Instance Method Details
#avatar_url(format = nil) ⇒ Object
Also known as:
avatar
#current_bot? ⇒ Boolean
203
204
205
|
# File 'lib/mij-discord/data/user.rb', line 203
def current_bot?
@bot.profile == self
end
|
#distinct ⇒ Object
176
177
178
|
# File 'lib/mij-discord/data/user.rb', line 176
def distinct
"#{@username}##{@discriminator}"
end
|
#dnd? ⇒ Boolean
Also known as:
busy?
217
218
219
|
# File 'lib/mij-discord/data/user.rb', line 217
def dnd?
@status == :dnd
end
|
#idle? ⇒ Boolean
Also known as:
away?
211
212
213
|
# File 'lib/mij-discord/data/user.rb', line 211
def idle?
@status == :idle
end
|
#inspect ⇒ Object
244
245
246
247
|
# File 'lib/mij-discord/data/user.rb', line 244
def inspect
MijDiscord.make_inspect(self,
:id, :username, :discriminator, :avatar_id, :bot_account)
end
|
#invisible? ⇒ Boolean
Also known as:
hidden?
223
224
225
|
# File 'lib/mij-discord/data/user.rb', line 223
def invisible?
@status == :invisible
end
|
#member? ⇒ Boolean
233
234
235
|
# File 'lib/mij-discord/data/user.rb', line 233
def member?
false
end
|
#mention ⇒ Object
Also known as:
to_s
170
171
172
|
# File 'lib/mij-discord/data/user.rb', line 170
def mention
"<@#{@id}>"
end
|
#offline? ⇒ Boolean
229
230
231
|
# File 'lib/mij-discord/data/user.rb', line 229
def offline?
@status == :offline
end
|
#on(server) ⇒ Object
194
195
196
197
|
# File 'lib/mij-discord/data/user.rb', line 194
def on(server)
id = server.to_id
@bot.server(id).member(@id)
end
|
#online? ⇒ Boolean
207
208
209
|
# File 'lib/mij-discord/data/user.rb', line 207
def online?
@status == :online?
end
|
#pm(text: nil, embed: nil) ⇒ Object
Also known as:
dm
180
181
182
183
184
185
186
|
# File 'lib/mij-discord/data/user.rb', line 180
def pm(text: nil, embed: nil)
if text || embed
pm.send_message(text: text || '', embed: embed)
else
@bot.pm_channel(@id)
end
end
|
#send_file(file, caption: nil) ⇒ Object
190
191
192
|
# File 'lib/mij-discord/data/user.rb', line 190
def send_file(file, caption: nil)
pm.send_file(file, caption: caption)
end
|
#update_data(data) ⇒ Object
154
155
156
157
158
|
# File 'lib/mij-discord/data/user.rb', line 154
def update_data(data)
@username = data.fetch('username', @username)
@discriminator = data.fetch('discriminator', @discriminator)
@avatar_id = data.fetch('avatar', @avatar_id)
end
|
#update_presence(presence) ⇒ Object
160
161
162
163
164
165
166
167
168
|
# File 'lib/mij-discord/data/user.rb', line 160
def update_presence(presence)
@status = presence['status'].to_sym
if (game = presence['game'])
@game = Game.new(game)
else
@game = nil
end
end
|
#webhook? ⇒ Boolean
199
200
201
|
# File 'lib/mij-discord/data/user.rb', line 199
def webhook?
@discriminator == '0000'
end
|