Class: MijDiscord::Data::User

Inherits:
Object
  • Object
show all
Includes:
IDObject
Defined in:
lib/mij-discord/data/user.rb

Direct Known Subclasses

Member, Profile, Recipient

Instance Attribute Summary collapse

Attributes included from IDObject

#id

Instance Method Summary collapse

Methods included from IDObject

#==, #creation_time, #hash, synthesize

Constructor Details

#initialize(data, bot) ⇒ User

Returns a new instance of User.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mij-discord/data/user.rb', line 28

def initialize(data, bot)
  @bot = bot

  @id = data['id'].to_i
  @bot_account = !!data['bot']
  update_data(data)

  @status = :offline

  @roles = {}
end

Instance Attribute Details

#avatar_idObject (readonly)

Returns the value of attribute avatar_id.



18
19
20
# File 'lib/mij-discord/data/user.rb', line 18

def avatar_id
  @avatar_id
end

#botObject (readonly)

Returns the value of attribute bot.



7
8
9
# File 'lib/mij-discord/data/user.rb', line 7

def bot
  @bot
end

#bot_accountObject (readonly) Also known as: bot_account?

Returns the value of attribute bot_account.



15
16
17
# File 'lib/mij-discord/data/user.rb', line 15

def 
  @bot_account
end

#discriminatorObject (readonly) Also known as: tag

Returns the value of attribute discriminator.



12
13
14
# File 'lib/mij-discord/data/user.rb', line 12

def discriminator
  @discriminator
end

#gameObject (readonly)

Returns the value of attribute game.



22
23
24
# File 'lib/mij-discord/data/user.rb', line 22

def game
  @game
end

#statusObject (readonly)

Returns the value of attribute status.



20
21
22
# File 'lib/mij-discord/data/user.rb', line 20

def status
  @status
end

#stream_typeObject (readonly)

Returns the value of attribute stream_type.



26
27
28
# File 'lib/mij-discord/data/user.rb', line 26

def stream_type
  @stream_type
end

#stream_urlObject (readonly)

Returns the value of attribute stream_url.



24
25
26
# File 'lib/mij-discord/data/user.rb', line 24

def stream_url
  @stream_url
end

#usernameObject (readonly) Also known as: name

Returns the value of attribute username.



9
10
11
# File 'lib/mij-discord/data/user.rb', line 9

def username
  @username
end

Instance Method Details

#avatar_url(format = nil) ⇒ Object



125
126
127
128
# File 'lib/mij-discord/data/user.rb', line 125

def avatar_url(format = nil)
  return MijDiscord::Core::API::User.default_avatar(@discriminator) unless @avatar_id
  MijDiscord::Core::API::User.avatar_url(@id, @avatar_id, format)
end

#current_bot?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/mij-discord/data/user.rb', line 91

def current_bot?
  @bot.profile == self
end

#distinctObject



64
65
66
# File 'lib/mij-discord/data/user.rb', line 64

def distinct
  "#{@username}##{@discriminator}"
end

#dnd?Boolean Also known as: busy?

Returns:

  • (Boolean)


105
106
107
# File 'lib/mij-discord/data/user.rb', line 105

def dnd?
  @status == :dnd
end

#idle?Boolean Also known as: away?

Returns:

  • (Boolean)


99
100
101
# File 'lib/mij-discord/data/user.rb', line 99

def idle?
  @status == :idle
end

#invisible?Boolean Also known as: hidden?

Returns:

  • (Boolean)


111
112
113
# File 'lib/mij-discord/data/user.rb', line 111

def invisible?
  @status == :invisible
end

#member?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/mij-discord/data/user.rb', line 121

def member?
  false
end

#mentionObject Also known as: to_s



58
59
60
# File 'lib/mij-discord/data/user.rb', line 58

def mention
  "<@#{@id}>"
end

#offline?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/mij-discord/data/user.rb', line 117

def offline?
  @status == :offline
end

#on(server) ⇒ Object



82
83
84
85
# File 'lib/mij-discord/data/user.rb', line 82

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

#online?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/mij-discord/data/user.rb', line 95

def online?
  @status == :online?
end

#pm(text: nil, embed: nil) ⇒ Object Also known as: dm



68
69
70
71
72
73
74
# File 'lib/mij-discord/data/user.rb', line 68

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



78
79
80
# File 'lib/mij-discord/data/user.rb', line 78

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

#update_data(data) ⇒ Object



40
41
42
43
44
# File 'lib/mij-discord/data/user.rb', line 40

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



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mij-discord/data/user.rb', line 46

def update_presence(presence)
  @status = presence['status'].to_sym

  if (game = presence['game'])
    @game = game['name']
    @stream_url = game['url']
    @stream_type = game['type']
  else
    @game = @stream_url = @stream_type = nil
  end
end

#webhook?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/mij-discord/data/user.rb', line 87

def webhook?
  @discriminator == '0000'
end