Module: MijDiscord::Core::API::User

Defined in:
lib/mij-discord/core/api/user.rb

Class Method Summary collapse

Class Method Details

.avatar_url(user_id, avatar_id, format = nil) ⇒ Object

Make an avatar URL from the user and avatar IDs



138
139
140
141
# File 'lib/mij-discord/core/api/user.rb', line 138

def avatar_url(user_id, avatar_id, format = nil)
  format ||= avatar_id.start_with?('a_') ? :gif : :webp
  "#{MijDiscord::Core::API::CDN_URL}/avatars/#{user_id}/#{avatar_id}.#{format}"
end

.change_own_nickname(auth, server_id, nick, reason = nil) ⇒ Object

Change the current bot’s nickname on a server



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mij-discord/core/api/user.rb', line 30

def change_own_nickname(auth, server_id, nick, reason = nil)
  MijDiscord::Core::API.request(
    :guilds_sid_members_me_nick,
    server_id, # This is technically a guild endpoint
    :patch,
    "#{MijDiscord::Core::API::APIBASE_URL}/guilds/#{server_id}/members/@me/nick",
    { nick: nick }.to_json,
    Authorization: auth,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.change_status_setting(auth, status) ⇒ Object

Change user status setting



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/mij-discord/core/api/user.rb', line 120

def change_status_setting(auth, status)
  MijDiscord::Core::API.request(
    :users_me_settings,
    nil,
    :patch,
    "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/settings",
    { status: status }.to_json,
    Authorization: auth,
    content_type: :json
  )
end

.connections(auth) ⇒ Object

Get information about a user’s connections discordapp.com/developers/docs/resources/user#get-users-connections



109
110
111
112
113
114
115
116
117
# File 'lib/mij-discord/core/api/user.rb', line 109

def connections(auth)
  MijDiscord::Core::API.request(
    :users_me_connections,
    nil,
    :get,
    "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/connections",
    Authorization: auth
  )
end

.create_pm(auth, recipient_id) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/mij-discord/core/api/user.rb', line 95

def create_pm(auth, recipient_id)
  MijDiscord::Core::API.request(
    :users_me_channels,
    nil,
    :post,
    "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/channels",
    { recipient_id: recipient_id }.to_json,
    Authorization: auth,
    content_type: :json
  )
end

.default_avatar(discrim = 0) ⇒ Object

Returns one of the “default” discord avatars from the CDN given a discriminator



133
134
135
# File 'lib/mij-discord/core/api/user.rb', line 133

def default_avatar(discrim = 0)
  "#{MijDiscord::Core::API::CDN_URL}/embed/avatars/#{discrim.to_i % 5}.png"
end

.leave_server(auth, server_id) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/mij-discord/core/api/user.rb', line 71

def leave_server(auth, server_id)
  MijDiscord::Core::API.request(
    :users_me_guilds_sid,
    nil,
    :delete,
    "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/guilds/#{server_id}",
    Authorization: auth
  )
end

.profile(auth) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/mij-discord/core/api/user.rb', line 19

def profile(auth)
  MijDiscord::Core::API.request(
    :users_me,
    nil,
    :get,
    "#{MijDiscord::Core::API::APIBASE_URL}/users/@me",
    Authorization: auth
  )
end

.resolve(auth, user_id) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/mij-discord/core/api/user.rb', line 7

def resolve(auth, user_id)
  MijDiscord::Core::API.request(
    :users_uid,
    nil,
    :get,
    "#{MijDiscord::Core::API::APIBASE_URL}/users/#{user_id}",
    Authorization: auth
  )
end

.servers(auth) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/mij-discord/core/api/user.rb', line 59

def servers(auth)
  MijDiscord::Core::API.request(
    :users_me_guilds,
    nil,
    :get,
    "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/guilds",
    Authorization: auth
  )
end

.update_profile(auth, username, avatar) ⇒ Object



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

def update_profile(auth, username, avatar)
  MijDiscord::Core::API.request(
    :users_me,
    nil,
    :patch,
    "#{MijDiscord::Core::API::APIBASE_URL}/users/@me",
    { avatar: avatar, username: username }.delete_if {|_,v| v.nil? }.to_json,
    Authorization: auth,
    content_type: :json
  )
end

.user_dms(auth) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/mij-discord/core/api/user.rb', line 83

def user_dms(auth)
  MijDiscord::Core::API.request(
    :users_me_channels,
    nil,
    :get,
    "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/channels",
    Authorization: auth
  )
end