vox 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/deploy_docs.yml +39 -0
- data/.github/workflows/rspec.yml +29 -0
- data/.github/workflows/rubocop.yml +24 -0
- data/.github/workflows/yard.yml +32 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +22 -0
- data/.yardopts +4 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.md +25 -0
- data/README.md +44 -0
- data/Rakefile +14 -0
- data/lib/vox.rb +10 -0
- data/lib/vox/http/client.rb +146 -0
- data/lib/vox/http/error.rb +56 -0
- data/lib/vox/http/middleware.rb +14 -0
- data/lib/vox/http/middleware/log_formatter.rb +62 -0
- data/lib/vox/http/middleware/rate_limiter.rb +206 -0
- data/lib/vox/http/route.rb +59 -0
- data/lib/vox/http/routes.rb +22 -0
- data/lib/vox/http/routes/audit_log.rb +71 -0
- data/lib/vox/http/routes/channel.rb +425 -0
- data/lib/vox/http/routes/emoji.rb +87 -0
- data/lib/vox/http/routes/guild.rb +292 -0
- data/lib/vox/http/routes/invite.rb +37 -0
- data/lib/vox/http/routes/user.rb +114 -0
- data/lib/vox/http/routes/voice.rb +22 -0
- data/lib/vox/http/routes/webhook.rb +177 -0
- data/lib/vox/http/upload_io.rb +23 -0
- data/lib/vox/http/util.rb +33 -0
- data/lib/vox/version.rb +6 -0
- data/vox.gemspec +42 -0
- metadata +234 -0
@@ -0,0 +1,292 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'vox/http/route'
|
4
|
+
require 'vox/http/util'
|
5
|
+
|
6
|
+
module Vox
|
7
|
+
module HTTP
|
8
|
+
module Routes
|
9
|
+
# Mixin for guild routes.
|
10
|
+
module Guild
|
11
|
+
include Util
|
12
|
+
|
13
|
+
# @param name [String] The name of the guild.
|
14
|
+
# @param region [String] A [voice region](https://discord.com/developers/docs/resources/voice#voice-region-object).
|
15
|
+
# @param icon [UploadIO] TODO
|
16
|
+
# @param verification_level [Integer] [Verification level](https://discord.com/developers/docs/resources/guild#guild-object-verification-level).
|
17
|
+
# @param default_message_notifications [Integer] [Notification level](https://discord.com/developers/docs/resources/guild#guild-object-default-message-notification-level).
|
18
|
+
# @param explicit_content_filter [Integer] [Content filter level](https://discord.com/developers/docs/resources/guild#guild-object-explicit-content-filter-level).
|
19
|
+
# @param roles [Array<Hash<Symbol, Object>>] An array of [role](https://discord.com/developers/docs/topics/permissions#role-object)
|
20
|
+
# objects.
|
21
|
+
# @param channels [Array<Hash<Symbol, Object>>] An array of partial [channel](https://discord.com/developers/docs/resources/channel#channel-object)
|
22
|
+
# objects.
|
23
|
+
# @param afk_channel_id [String, Integer] The ID for the AFK channel.
|
24
|
+
# @param afk_timeout [Integer] AFK timeout in seconds.
|
25
|
+
# @param system_channel_id [String, Integer] The ID of the channel where guild notices such as welcome messages
|
26
|
+
# and boost events are posted
|
27
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#create-guild
|
28
|
+
def create_guild(name:, region: :undef, icon: :undef, verification_level: :undef,
|
29
|
+
default_message_notifications: :undef, explicit_content_filter: :undef,
|
30
|
+
roles: :undef, channels: :undef, afk_channel_id: :undef,
|
31
|
+
afk_timeout: :undef, system_channel_id: :undef)
|
32
|
+
json = filter_undef(
|
33
|
+
{
|
34
|
+
name: name, region: region, icon: icon, verification_level: verification_level,
|
35
|
+
default_message_notifications: default_message_notifications,
|
36
|
+
explicit_content_filter: explicit_content_filter, roles: roles, channels: channels,
|
37
|
+
afk_channel_id: afk_channel_id, afk_timeout: afk_timeout, system_channel_id: system_channel_id
|
38
|
+
}
|
39
|
+
)
|
40
|
+
request(Route.new(:POST, '/guilds'), json: json)
|
41
|
+
end
|
42
|
+
|
43
|
+
# @param guild_id [String, Integer]
|
44
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#get-guild-preview
|
45
|
+
def get_guild_preview(guild_id)
|
46
|
+
request(Route.new(:GET, '/guilds/%{guild_id}/preview', guild_id: guild_id))
|
47
|
+
end
|
48
|
+
|
49
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#modify-guild
|
50
|
+
def modify_guild(guild_id, name: :undef, region: :undef, verification_level: :undef,
|
51
|
+
default_message_notifications: :undef, explicit_content_filter: :undef,
|
52
|
+
afk_channel_id: :undef, afk_timeout: :undef, icon: :undef, owner_id: :undef,
|
53
|
+
splash: :undef, banner: :undef, system_channel_id: :undef,
|
54
|
+
rules_channel_id: :undef, public_updates_channel_id: :undef,
|
55
|
+
preferred_locale: :undef, reason: nil)
|
56
|
+
json = filter_undef(
|
57
|
+
{
|
58
|
+
name: name, region: region, verification_level: verification_level,
|
59
|
+
default_message_notifications: default_message_notifications,
|
60
|
+
explicit_content_filter: explicit_content_filter, afk_channel_id: afk_channel_id,
|
61
|
+
afk_timeout: afk_timeout, icon: icon, owner_id: owner_id, splash: splash, banner: banner,
|
62
|
+
system_channel_id: system_channel_id, rules_channel_id: rules_channel_id,
|
63
|
+
public_updates_channel_id: public_updates_channel_id, preferred_locale: preferred_locale
|
64
|
+
}
|
65
|
+
)
|
66
|
+
request(Route.new(:PATCH, '/guilds/%{guild_id}', guild_id: guild_id), json: json, reason: reason)
|
67
|
+
end
|
68
|
+
|
69
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#delete-guild
|
70
|
+
def delete_guild(guild_id)
|
71
|
+
request(Route.new(:DELETE, '/guilds/%{guild_id}', guild_id: guild_id))
|
72
|
+
end
|
73
|
+
|
74
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#get-guild-channels
|
75
|
+
def get_guild_channels(guild_id)
|
76
|
+
request(Route.new(:GET, '/guilds/%{guild_id}/channels', guild_id: guild_id))
|
77
|
+
end
|
78
|
+
|
79
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#create-guild-channel
|
80
|
+
def create_guild_channel(guild_id, name: :undef, type: :undef, topic: :undef, bitrate: :undef,
|
81
|
+
user_limit: :undef, rate_limit_per_user: :undef, position: :undef,
|
82
|
+
permission_overwrites: :undef, parent_id: :undef, nsfw: :undef, reason: nil)
|
83
|
+
json = filter_undef(
|
84
|
+
{
|
85
|
+
name: name, type: type, topic: topic, bitrate: bitrate, user_limit: user_limit,
|
86
|
+
rate_limit_per_user: rate_limit_per_user, position: position,
|
87
|
+
permission_overwrites: permission_overwrites, parent_id: parent_id, nsfw: nsfw
|
88
|
+
}
|
89
|
+
)
|
90
|
+
request(Route.new(:POST, '/guilds/%{guild_id}/channels', guild_id: guild_id), json: json, reason: reason)
|
91
|
+
end
|
92
|
+
|
93
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions
|
94
|
+
def modify_guild_channel_positions(guild_id, positions, reason: nil)
|
95
|
+
route = Route.new(:PATCH, '/guilds/%{guild_id}/channels', guild_id: guild_id)
|
96
|
+
request(route, json: positions, reason: reason)
|
97
|
+
end
|
98
|
+
|
99
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#get-guild-member
|
100
|
+
def get_guild_member(guild_id, user_id)
|
101
|
+
request(Route.new(:GET, '/guilds/%{guild_id}/members/%{user_id}', guild_id: guild_id, user_id: user_id))
|
102
|
+
end
|
103
|
+
|
104
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#list-guild-members
|
105
|
+
def list_guild_members(guild_id, limit: :undef, after: :undef)
|
106
|
+
params = filter_undef({ limit: limit, after: after })
|
107
|
+
request(Route.new(:GET, '/guilds/%{guild_id}/members', guild_id: guild_id), query: params)
|
108
|
+
end
|
109
|
+
|
110
|
+
# @vox.oauth_scope guilds.join
|
111
|
+
def add_guild_member(guild_id, user_id, access_token:, nick: :undef, roles: :undef, mute: :undef, deaf: :undef)
|
112
|
+
json = filter_undef({ access_token: access_token, nick: nick, roles: roles, mute: mute, deaf: deaf })
|
113
|
+
route = Route.new(:PUT, '/guilds/%{guild_id}/members/%{user_id}', guild_id: guild_id, user_id: user_id)
|
114
|
+
request(route, json: json)
|
115
|
+
end
|
116
|
+
|
117
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#modify-guild-member
|
118
|
+
def modify_guild_member(guild_id, user_id, nick: :undef, roles: :undef, mute: :undef, deaf: :undef,
|
119
|
+
channel_id: :undef, reason: nil)
|
120
|
+
json = filter_undef({ nick: nick, roles: roles, mute: mute, deaf: deaf, channel_id: channel_id })
|
121
|
+
route = Route.new(:PATCH, '/guilds/%{guild_id}/members/%{user_id}', guild_id: guild_id, user_id: user_id)
|
122
|
+
request(route, json: json, reason: reason)
|
123
|
+
end
|
124
|
+
|
125
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#modify-current-user-nick
|
126
|
+
def modify_current_user_nick(guild_id, nick: :undef, reason: nil)
|
127
|
+
json = filter_undef({ nick: nick })
|
128
|
+
route = Route.new(:PATCH, '/guilds/%{guild_id}/members/@me/nick', guild_id: guild_id)
|
129
|
+
request(route, json: json, reason: reason)
|
130
|
+
end
|
131
|
+
|
132
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#add-guild-member-role
|
133
|
+
def add_guild_member_role(guild_id, user_id, role_id, reason: nil)
|
134
|
+
route = Route.new(:PUT, '/guilds/%{guild_id}/members/%{user_id}/roles/%{role_id}',
|
135
|
+
guild_id: guild_id, user_id: user_id, role_id: role_id)
|
136
|
+
request(route, reason: reason)
|
137
|
+
end
|
138
|
+
|
139
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#remove-guild-member-role
|
140
|
+
def remove_guild_member_role(guild_id, user_id, role_id, reason: nil)
|
141
|
+
route = Route.new(:DELETE, '/guilds/%{guild_id}/members/%{user_id}/roles/%{role_id}',
|
142
|
+
guild_id: guild_id, user_id: user_id, role_id: role_id)
|
143
|
+
request(route, reason: reason)
|
144
|
+
end
|
145
|
+
|
146
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#remove-guild-member
|
147
|
+
def remove_guild_member(guild_id, user_id, reason: nil)
|
148
|
+
route = Route.new(:DELETE, '/guilds/%{guild_id}/members/%{user_id}', guild_id: guild_id, user_id: user_id)
|
149
|
+
request(route, reason: reason)
|
150
|
+
end
|
151
|
+
|
152
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#get-guild-bans
|
153
|
+
def get_guild_bans(guild_id)
|
154
|
+
request(Route.new(:GET, '/guilds/%{guild_id}/bans', guild_id: guild_id))
|
155
|
+
end
|
156
|
+
|
157
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#get-guild-ban
|
158
|
+
def get_guild_ban(guild_id, user_id)
|
159
|
+
request(Route.new(:GET, '/guilds/%{guild_id}/bans/%{user_id}', guild_id: guild_id, user_id: user_id))
|
160
|
+
end
|
161
|
+
|
162
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#create-guild-ban
|
163
|
+
def create_guild_ban(guild_id, user_id, deleted_message_days: :undef, reason: :undef)
|
164
|
+
json = filter_undef({ deleted_message_days: deleted_message_days, reason: reason })
|
165
|
+
route = Route.new(:PUT, '/guilds/%{guild_id}/bans/%{user_id}', guild_id: guild_id, user_id: user_id)
|
166
|
+
request(route, json: json)
|
167
|
+
end
|
168
|
+
|
169
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#remove-guild-ban
|
170
|
+
def remove_guild_ban(guild_id, user_id, reason: nil)
|
171
|
+
route = Route.new(:DELETE, '/guilds/%{guild_id}/bans/%{user_id}', guild_id: guild_id, user_id: user_id)
|
172
|
+
request(route, reason: reason)
|
173
|
+
end
|
174
|
+
|
175
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#get-guild-roles
|
176
|
+
def get_guild_roles(guild_id)
|
177
|
+
request(Route.new(:GET, '/guilds/%{guild_id}/roles', guild_id: guild_id))
|
178
|
+
end
|
179
|
+
|
180
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#create-guild-role
|
181
|
+
def create_guild_role(guild_id, name: :undef, permissions: :undef, color: :undef, hoist: :undef,
|
182
|
+
mentionable: :undef, reason: nil)
|
183
|
+
json = filter_undef({ name: name, permissions: permissions, color: color,
|
184
|
+
hoist: hoist, mentionable: mentionable })
|
185
|
+
request(Route.new(:POST, '/guilds/%{guild_id}/roles', guild_id: guild_id), json: json, reason: reason)
|
186
|
+
end
|
187
|
+
|
188
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#modify-guild-role-positions
|
189
|
+
def modify_guild_role_positions(guild_id, positions, reason: nil)
|
190
|
+
request(Route.new(:PATCH, '/guilds/%{guild_id}/roles', guild_id: guild_id), json: positions, reason: reason)
|
191
|
+
end
|
192
|
+
|
193
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#modify-guild-role
|
194
|
+
def modify_guild_role(guild_id, role_id, name: :undef, permissions: :undef, color: :undef, hoist: :undef,
|
195
|
+
mentionable: :undef, reason: nil)
|
196
|
+
json = filter_undef({ name: name, permissions: permissions, color: color,
|
197
|
+
hoist: hoist, mentionable: mentionable })
|
198
|
+
route = Route.new(:PATCH, '/guilds/%{guild_id}/roles/%{role_id}', guild_id: guild_id, role_id: role_id)
|
199
|
+
request(route, json: json, reason: reason)
|
200
|
+
end
|
201
|
+
|
202
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#delete-guild-role
|
203
|
+
def delete_guild_role(guild_id, role_id, reason: nil)
|
204
|
+
route = Route.new(:DELETE, '/guilds/%{guild_id}/roles/%{role_id}', guild_id: guild_id, role_id: role_id)
|
205
|
+
request(route, reason: reason)
|
206
|
+
end
|
207
|
+
|
208
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#get-guild-prune-count
|
209
|
+
def get_guild_prune_count(guild_id, days: :undef, include_roles: :undef)
|
210
|
+
params = filter_undef({ days: days, include_roles: include_roles })
|
211
|
+
request(Route.new(:GET, '/guilds/%{guild_id}/prune', guild_id: guild_id), query: params)
|
212
|
+
end
|
213
|
+
|
214
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#begin-guild-prune
|
215
|
+
def begin_guild_prune(guild_id, days: :undef, compute_prune_count: :undef, include_roles: :undef, reason: nil)
|
216
|
+
json = filter_undef({ days: days, compute_prune_count: compute_prune_count, include_roles: include_roles })
|
217
|
+
route = Route.new(:POST, '/guilds/%{guild_id}/prune', guild_id: guild_id)
|
218
|
+
request(route, json: json, reason: reason)
|
219
|
+
end
|
220
|
+
|
221
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#get-guild-voice-regions
|
222
|
+
def get_guild_voice_regions(guild_id)
|
223
|
+
request(Route.new(:GET, '/guilds/%{guild_id}/regions', guild_id: guild_id))
|
224
|
+
end
|
225
|
+
|
226
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#get-guild-invites
|
227
|
+
def get_guild_invites(guild_id)
|
228
|
+
request(Route.new(:GET, '/guilds/%{guild_id}/invites', guild_id: guild_id))
|
229
|
+
end
|
230
|
+
|
231
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#get-guild-integrations
|
232
|
+
def get_guild_integrations(guild_id)
|
233
|
+
request(Route.new(:GET, '/guilds/%{guild_id}/integrations', guild_id: guild_id))
|
234
|
+
end
|
235
|
+
|
236
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#create-guild-integration
|
237
|
+
def create_guild_integration(guild_id, type:, id:)
|
238
|
+
json = { type: type, id: id }
|
239
|
+
request(Route.new(:POST, '/guilds/%{guild_id}/integrations', guild_id: guild_id), json: json)
|
240
|
+
end
|
241
|
+
|
242
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#modify-guild-integration
|
243
|
+
def modify_guild_integration(guild_id, integration_id, expire_behavior: :undef, expire_grace_period: :undef,
|
244
|
+
enable_emoticons: :undef, reason: nil)
|
245
|
+
json = filter_undef({ expire_behavior: expire_behavior, expire_grace_period: expire_grace_period,
|
246
|
+
enable_emoticons: enable_emoticons })
|
247
|
+
route = Route.new(:PATCH, '/guilds/%{guild_id}/integrations/%{integration_id}',
|
248
|
+
guild_id: guild_id, integration_id: integration_id)
|
249
|
+
request(route, json: json, reason: reason)
|
250
|
+
end
|
251
|
+
|
252
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#delete-guild-integration
|
253
|
+
def delete_guild_integration(guild_id, integration_id, reason: nil)
|
254
|
+
route = Route.new(:DELETE, '/guilds/%{guild_id}/integrations/%{integration_id}',
|
255
|
+
guild_id: guild_id, integration_id: integration_id)
|
256
|
+
request(route, reason: reason)
|
257
|
+
end
|
258
|
+
|
259
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#sync-guild-integration
|
260
|
+
def sync_guild_integration(guild_id, integration_id, reason: nil)
|
261
|
+
route = Route.new(:POST, '/guilds/%{guild_id}/integrations/%{integration_id}/sync',
|
262
|
+
guild_id: guild_id, integration_id: integration_id)
|
263
|
+
request(route, reason: reason)
|
264
|
+
end
|
265
|
+
|
266
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#get-guild-widget
|
267
|
+
def get_guild_widget(guild_id)
|
268
|
+
request(Route.new(:GET, '/guilds/%{guild_id}/widget', guild_id: guild_id))
|
269
|
+
end
|
270
|
+
|
271
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#modify-guild-widget
|
272
|
+
def modify_guild_widget(guild_id, enabled: :undef, channel_id: :undef, reason: nil)
|
273
|
+
json = filter_undef({ enabled: enabled, channel_id: channel_id })
|
274
|
+
route = Route.new(:PATCH, '/guilds/%{guild_id}/widget', guild_id: guild_id)
|
275
|
+
request(route, json: json, reason: reason)
|
276
|
+
end
|
277
|
+
|
278
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#get-guild-vanity-url
|
279
|
+
def get_guild_vanity_url(guild_id)
|
280
|
+
request(Route.new(:GET, '/guilds/%{guild_id}/vanity-url', guild_id: guild_id))
|
281
|
+
end
|
282
|
+
|
283
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/guild#get-guild-widget-image
|
284
|
+
def get_guild_widget_image(guild_id, style: :undef)
|
285
|
+
params = filter_undef({ style: style })
|
286
|
+
route = Route.new(:GET, '/guilds/%{guild_id}/widget.png', guild_id: guild_id)
|
287
|
+
request(route, query: params, raw: true)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'vox/http/route'
|
4
|
+
require 'vox/http/util'
|
5
|
+
|
6
|
+
module Vox
|
7
|
+
module HTTP
|
8
|
+
module Routes
|
9
|
+
# Mixin for invite routes.
|
10
|
+
module Invite
|
11
|
+
include Util
|
12
|
+
|
13
|
+
# Get an invite by its code.
|
14
|
+
# @param invite_code [String]
|
15
|
+
# @param with_counts [true, false] Whether the invite object should contain approximate member counts.
|
16
|
+
# @return [Hash<Symbol, Object>] The [invite](https://discord.com/developers/docs/resources/invite#invite-object)
|
17
|
+
# object.
|
18
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/invite#get-invite
|
19
|
+
def get_invite(invite_code, with_counts: :undef)
|
20
|
+
route = Route.new(:GET, '/invites/%{invite_code}', invite_code: invite_code)
|
21
|
+
request(route, query: filter_undef({ with_counts: with_counts }))
|
22
|
+
end
|
23
|
+
|
24
|
+
# Delete an invite by its code.
|
25
|
+
# @param invite_code [String]
|
26
|
+
# @return [Hash<Symbol, Object>] The deleted [invite](https://discord.com/developers/docs/resources/invite#invite-object)
|
27
|
+
# object.
|
28
|
+
# @vox.permissions MANAGE_CHANNELS or MANAGE_GUILD
|
29
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/invite#delete-invite
|
30
|
+
def delete_invite(invite_code, reason: nil)
|
31
|
+
route = Route.new(:DELETE, '/invites/%{invite_code}', invite_code: invite_code)
|
32
|
+
request(route, reason: reason)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'vox/http/route'
|
4
|
+
require 'vox/http/util'
|
5
|
+
|
6
|
+
module Vox
|
7
|
+
module HTTP
|
8
|
+
module Routes
|
9
|
+
# Mixin for user routes.
|
10
|
+
module User
|
11
|
+
include Util
|
12
|
+
|
13
|
+
# rubocop:disable Naming/AccessorMethodName
|
14
|
+
|
15
|
+
# Get information about the current user.
|
16
|
+
# @return [Hash<Symbol, Object>] The [user](https://discord.com/developers/docs/resources/user#user-object)
|
17
|
+
# object for the current user.
|
18
|
+
# @vox.oauth_scope identify
|
19
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/user#get-current-user
|
20
|
+
def get_current_user
|
21
|
+
request(Route.new(:GET, '/users/@me'))
|
22
|
+
end
|
23
|
+
|
24
|
+
# Get information about a user by ID.
|
25
|
+
# @return [Hash<Symbol, Object] The [user](https://discord.com/developers/docs/resources/user#user-object)
|
26
|
+
# object for the target user.
|
27
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/user#get-user
|
28
|
+
def get_user(user_id)
|
29
|
+
request(Route.new(:GET, '/users/%{user_id}', user_id: user_id))
|
30
|
+
end
|
31
|
+
|
32
|
+
# Modify the current user.
|
33
|
+
# @param username [String]
|
34
|
+
# @param avatar [UploadIO]
|
35
|
+
# @return [Hash<Symbol, Object>] The updated [user](https://discord.com/developers/docs/resources/user#user-object)
|
36
|
+
# object.
|
37
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/user#modify-current-user
|
38
|
+
def modify_current_user(username: :undef, avatar: :undef)
|
39
|
+
avatar = if avatar != :undef && !avatar.nil?
|
40
|
+
image_data = avatar.io.read
|
41
|
+
"data:#{avatar.content_type};base64,#{Base64.encode64(image_data)}"
|
42
|
+
else
|
43
|
+
:undef
|
44
|
+
end
|
45
|
+
json = filter_undef({ username: username, avatar: avatar })
|
46
|
+
request(Route.new(:PATCH, '/users/@me'), json: json)
|
47
|
+
end
|
48
|
+
|
49
|
+
# List the guilds that the current user is in.
|
50
|
+
# @param before [String, Integer] Get guilds before this ID.
|
51
|
+
# @param after [String, Integer] Get guilds after this ID.
|
52
|
+
# @param limit [String, Integer] Maximum number of guilds to return.
|
53
|
+
# @return [Array<Hash<Symbol, Object>>] An array of [guild](https://discord.com/developers/docs/resources/guild#guild-object)
|
54
|
+
# objects.
|
55
|
+
# @vox.oauth_scope guilds
|
56
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/user#get-current-user-guilds
|
57
|
+
def get_current_user_guilds(before: :undef, after: :undef, limit: :undef)
|
58
|
+
params = filter_undef({ before: before, after: after, limit: limit })
|
59
|
+
request(Route.new(:GET, '/users/@me/guilds'), query: params)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Leave a guild.
|
63
|
+
# @param guild_id [String, Integer] The ID of the guild to leave.
|
64
|
+
# @return [nil] Returns nil on success.
|
65
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/user#get-current-user-guilds
|
66
|
+
def leave_guild(guild_id)
|
67
|
+
request(Route.new(:DELETE, '/users/@me/guilds/%{guild_id}', guild_id: guild_id))
|
68
|
+
end
|
69
|
+
|
70
|
+
# Get a list of the current user's DM channels.
|
71
|
+
# @return [Array<Hash<Symbol, Object>>] An array of [DM channel](https://discord.com/developers/docs/resources/channel#channel-object)
|
72
|
+
# objects.
|
73
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/user#get-user-dms
|
74
|
+
def get_user_dms
|
75
|
+
request(Route.new(:GET, '/users/@me/channels'))
|
76
|
+
end
|
77
|
+
|
78
|
+
# Create a new DM channel with a user.
|
79
|
+
# @param recipient_id [String, Integer] The ID of the recipient to open a DM with.
|
80
|
+
# @return [Hash<Symbol, Object>] The [DM channel](https://discord.com/developers/docs/resources/channel#channel-object)
|
81
|
+
# object.
|
82
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/user#create-dm
|
83
|
+
def create_dm(recipient_id)
|
84
|
+
request(Route.new(:POST, '/users/@me/channels'), json: { recipient_id: recipient_id })
|
85
|
+
end
|
86
|
+
|
87
|
+
# Create a new DM with multiple users.
|
88
|
+
# @param access_tokens [Array<String, Integer>] Access tokens of users that have granted your app the `gdm.join`
|
89
|
+
# scope.
|
90
|
+
# @param nicks [Hash<(String, Integer), String>] A hash mapping user IDs to their nicknames.
|
91
|
+
# @note This endpoint was intended for a now deprecated SDK. DMs created with this endpoint are not
|
92
|
+
# visible in the Discord client.
|
93
|
+
# @note This endpoint is limited to 10 active group DMs.
|
94
|
+
# @vox.oauth_scope gdm.join
|
95
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/user#create-group-dm
|
96
|
+
def create_group_dm(access_tokens, nicks: :undef)
|
97
|
+
json = filter_undef({ access_tokens: access_tokens, nicks: nicks })
|
98
|
+
request(Route.new(:POST, '/users/@me/channels'), json: json)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Get a list of connection objects for the current user.
|
102
|
+
# @return [Array<Hash<Symbol, Object>>] An array of [connection](https://discord.com/developers/docs/resources/user#connection-object)
|
103
|
+
# objects.
|
104
|
+
# @vox.oauth_scope connections
|
105
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/user#get-user-connections
|
106
|
+
def get_user_connections
|
107
|
+
request(Route.new(:GET, '/users/@me/connections'))
|
108
|
+
end
|
109
|
+
|
110
|
+
# rubocop:enable Naming/AccessorMethodName
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'vox/http/route'
|
4
|
+
require 'vox/http/util'
|
5
|
+
|
6
|
+
module Vox
|
7
|
+
module HTTP
|
8
|
+
module Routes
|
9
|
+
# Mixin for voice routes.
|
10
|
+
module Voice
|
11
|
+
# Lists voice regions that can be used when creating guilds.
|
12
|
+
# @return [Array<Hash<Symbol, Object>>] An array of [voice region](https://discord.com/developers/docs/resources/voice#voice-region-object)
|
13
|
+
# objects.
|
14
|
+
# @vox.api_docs https://discord.com/developers/docs/resources/voice#list-voice-regions
|
15
|
+
def list_voice_regions
|
16
|
+
route = Route.new(:GET, '/voice/regions')
|
17
|
+
request(route)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|