rdiscord_sdk 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +13 -0
  3. data/.vscode/c_cpp_properties.json +24 -0
  4. data/.vscode/settings.json +102 -0
  5. data/Gemfile +11 -0
  6. data/Gemfile.lock +46 -0
  7. data/INTERNALS.md +0 -0
  8. data/LICENSE +674 -0
  9. data/README.md +187 -0
  10. data/Rakefile +17 -0
  11. data/bin/console +15 -0
  12. data/bin/setup +8 -0
  13. data/ext/rdiscord_sdk/activity.cpp +297 -0
  14. data/ext/rdiscord_sdk/activity.h +17 -0
  15. data/ext/rdiscord_sdk/common.cpp +65 -0
  16. data/ext/rdiscord_sdk/common.h +88 -0
  17. data/ext/rdiscord_sdk/extconf.rb +54 -0
  18. data/ext/rdiscord_sdk/gem_activity_manager.cpp +273 -0
  19. data/ext/rdiscord_sdk/gem_activity_manager.h +8 -0
  20. data/ext/rdiscord_sdk/gem_user_manager.cpp +114 -0
  21. data/ext/rdiscord_sdk/gem_user_manager.h +8 -0
  22. data/ext/rdiscord_sdk/rdiscord_sdk.cpp +77 -0
  23. data/ext/rdiscord_sdk/rdiscord_sdk.h +17 -0
  24. data/ext/rdiscord_sdk/user.cpp +98 -0
  25. data/ext/rdiscord_sdk/user.h +19 -0
  26. data/lib/rdiscord_sdk/enums.rb +162 -0
  27. data/lib/rdiscord_sdk/rdiscord_sdk.so +0 -0
  28. data/lib/rdiscord_sdk/version.rb +16 -0
  29. data/lib/rdiscord_sdk.rb +3 -0
  30. data/rdiscord_sdk.gemspec +34 -0
  31. data/third-party/include/achievement_manager.cpp +98 -0
  32. data/third-party/include/achievement_manager.h +34 -0
  33. data/third-party/include/activity_manager.cpp +177 -0
  34. data/third-party/include/activity_manager.h +42 -0
  35. data/third-party/include/application_manager.cpp +78 -0
  36. data/third-party/include/application_manager.h +30 -0
  37. data/third-party/include/core.cpp +182 -0
  38. data/third-party/include/core.h +64 -0
  39. data/third-party/include/discord.h +16 -0
  40. data/third-party/include/event.h +59 -0
  41. data/third-party/include/ffi.h +942 -0
  42. data/third-party/include/image_manager.cpp +57 -0
  43. data/third-party/include/image_manager.h +28 -0
  44. data/third-party/include/lobby_manager.cpp +547 -0
  45. data/third-party/include/lobby_manager.h +88 -0
  46. data/third-party/include/network_manager.cpp +103 -0
  47. data/third-party/include/network_manager.h +63 -0
  48. data/third-party/include/overlay_manager.cpp +112 -0
  49. data/third-party/include/overlay_manager.h +33 -0
  50. data/third-party/include/relationship_manager.cpp +90 -0
  51. data/third-party/include/relationship_manager.h +32 -0
  52. data/third-party/include/storage_manager.cpp +158 -0
  53. data/third-party/include/storage_manager.h +46 -0
  54. data/third-party/include/store_manager.cpp +160 -0
  55. data/third-party/include/store_manager.h +38 -0
  56. data/third-party/include/types.cpp +769 -0
  57. data/third-party/include/types.h +492 -0
  58. data/third-party/include/user_manager.cpp +80 -0
  59. data/third-party/include/user_manager.h +31 -0
  60. data/third-party/include/voice_manager.cpp +124 -0
  61. data/third-party/include/voice_manager.h +37 -0
  62. data/third-party/lib/x86/discord_game_sdk.dll +0 -0
  63. data/third-party/lib/x86/discord_game_sdk.dll.lib +0 -0
  64. data/third-party/lib/x86_64/discord_game_sdk.bundle +0 -0
  65. data/third-party/lib/x86_64/discord_game_sdk.dll +0 -0
  66. data/third-party/lib/x86_64/discord_game_sdk.dll.lib +0 -0
  67. data/third-party/lib/x86_64/discord_game_sdk.dylib +0 -0
  68. data/third-party/lib/x86_64/discord_game_sdk.so +0 -0
  69. metadata +114 -0
@@ -0,0 +1,492 @@
1
+ #pragma once
2
+
3
+ #include "ffi.h"
4
+ #include "event.h"
5
+ #include <cstdint>
6
+
7
+ namespace discord {
8
+
9
+ enum class Result {
10
+ Ok = 0,
11
+ ServiceUnavailable = 1,
12
+ InvalidVersion = 2,
13
+ LockFailed = 3,
14
+ InternalError = 4,
15
+ InvalidPayload = 5,
16
+ InvalidCommand = 6,
17
+ InvalidPermissions = 7,
18
+ NotFetched = 8,
19
+ NotFound = 9,
20
+ Conflict = 10,
21
+ InvalidSecret = 11,
22
+ InvalidJoinSecret = 12,
23
+ NoEligibleActivity = 13,
24
+ InvalidInvite = 14,
25
+ NotAuthenticated = 15,
26
+ InvalidAccessToken = 16,
27
+ ApplicationMismatch = 17,
28
+ InvalidDataUrl = 18,
29
+ InvalidBase64 = 19,
30
+ NotFiltered = 20,
31
+ LobbyFull = 21,
32
+ InvalidLobbySecret = 22,
33
+ InvalidFilename = 23,
34
+ InvalidFileSize = 24,
35
+ InvalidEntitlement = 25,
36
+ NotInstalled = 26,
37
+ NotRunning = 27,
38
+ InsufficientBuffer = 28,
39
+ PurchaseCanceled = 29,
40
+ InvalidGuild = 30,
41
+ InvalidEvent = 31,
42
+ InvalidChannel = 32,
43
+ InvalidOrigin = 33,
44
+ RateLimited = 34,
45
+ OAuth2Error = 35,
46
+ SelectChannelTimeout = 36,
47
+ GetGuildTimeout = 37,
48
+ SelectVoiceForceRequired = 38,
49
+ CaptureShortcutAlreadyListening = 39,
50
+ UnauthorizedForAchievement = 40,
51
+ InvalidGiftCode = 41,
52
+ PurchaseError = 42,
53
+ TransactionAborted = 43,
54
+ };
55
+
56
+ enum class CreateFlags {
57
+ Default = 0,
58
+ NoRequireDiscord = 1,
59
+ };
60
+
61
+ enum class LogLevel {
62
+ Error = 1,
63
+ Warn,
64
+ Info,
65
+ Debug,
66
+ };
67
+
68
+ enum class UserFlag {
69
+ Partner = 2,
70
+ HypeSquadEvents = 4,
71
+ HypeSquadHouse1 = 64,
72
+ HypeSquadHouse2 = 128,
73
+ HypeSquadHouse3 = 256,
74
+ };
75
+
76
+ enum class PremiumType {
77
+ None = 0,
78
+ Tier1 = 1,
79
+ Tier2 = 2,
80
+ };
81
+
82
+ enum class ImageType {
83
+ User,
84
+ };
85
+
86
+ enum class ActivityType {
87
+ Playing,
88
+ Streaming,
89
+ Listening,
90
+ Watching,
91
+ };
92
+
93
+ enum class ActivityActionType {
94
+ Join = 1,
95
+ Spectate,
96
+ };
97
+
98
+ enum class ActivityJoinRequestReply {
99
+ No,
100
+ Yes,
101
+ Ignore,
102
+ };
103
+
104
+ enum class Status {
105
+ Offline = 0,
106
+ Online = 1,
107
+ Idle = 2,
108
+ DoNotDisturb = 3,
109
+ };
110
+
111
+ enum class RelationshipType {
112
+ None,
113
+ Friend,
114
+ Blocked,
115
+ PendingIncoming,
116
+ PendingOutgoing,
117
+ Implicit,
118
+ };
119
+
120
+ enum class LobbyType {
121
+ Private = 1,
122
+ Public,
123
+ };
124
+
125
+ enum class LobbySearchComparison {
126
+ LessThanOrEqual = -2,
127
+ LessThan,
128
+ Equal,
129
+ GreaterThan,
130
+ GreaterThanOrEqual,
131
+ NotEqual,
132
+ };
133
+
134
+ enum class LobbySearchCast {
135
+ String = 1,
136
+ Number,
137
+ };
138
+
139
+ enum class LobbySearchDistance {
140
+ Local,
141
+ Default,
142
+ Extended,
143
+ Global,
144
+ };
145
+
146
+ enum class EntitlementType {
147
+ Purchase = 1,
148
+ PremiumSubscription,
149
+ DeveloperGift,
150
+ TestModePurchase,
151
+ FreePurchase,
152
+ UserGift,
153
+ PremiumPurchase,
154
+ };
155
+
156
+ enum class SkuType {
157
+ Application = 1,
158
+ DLC,
159
+ Consumable,
160
+ Bundle,
161
+ };
162
+
163
+ enum class InputModeType {
164
+ VoiceActivity = 0,
165
+ PushToTalk,
166
+ };
167
+
168
+ using ClientId = std::int64_t;
169
+ using Version = std::int32_t;
170
+ using Snowflake = std::int64_t;
171
+ using Timestamp = std::int64_t;
172
+ using UserId = Snowflake;
173
+ using Locale = char const*;
174
+ using Branch = char const*;
175
+ using LobbyId = Snowflake;
176
+ using LobbySecret = char const*;
177
+ using MetadataKey = char const*;
178
+ using MetadataValue = char const*;
179
+ using NetworkPeerId = std::uint64_t;
180
+ using NetworkChannelId = std::uint8_t;
181
+ using Path = char const*;
182
+ using DateTime = char const*;
183
+
184
+ class User final {
185
+ public:
186
+ void SetId(UserId id);
187
+ UserId GetId() const;
188
+ void SetUsername(char const* username);
189
+ char const* GetUsername() const;
190
+ void SetDiscriminator(char const* discriminator);
191
+ char const* GetDiscriminator() const;
192
+ void SetAvatar(char const* avatar);
193
+ char const* GetAvatar() const;
194
+ void SetBot(bool bot);
195
+ bool GetBot() const;
196
+
197
+ private:
198
+ DiscordUser internal_;
199
+ };
200
+
201
+ class OAuth2Token final {
202
+ public:
203
+ void SetAccessToken(char const* accessToken);
204
+ char const* GetAccessToken() const;
205
+ void SetScopes(char const* scopes);
206
+ char const* GetScopes() const;
207
+ void SetExpires(Timestamp expires);
208
+ Timestamp GetExpires() const;
209
+
210
+ private:
211
+ DiscordOAuth2Token internal_;
212
+ };
213
+
214
+ class ImageHandle final {
215
+ public:
216
+ void SetType(ImageType type);
217
+ ImageType GetType() const;
218
+ void SetId(std::int64_t id);
219
+ std::int64_t GetId() const;
220
+ void SetSize(std::uint32_t size);
221
+ std::uint32_t GetSize() const;
222
+
223
+ private:
224
+ DiscordImageHandle internal_;
225
+ };
226
+
227
+ class ImageDimensions final {
228
+ public:
229
+ void SetWidth(std::uint32_t width);
230
+ std::uint32_t GetWidth() const;
231
+ void SetHeight(std::uint32_t height);
232
+ std::uint32_t GetHeight() const;
233
+
234
+ private:
235
+ DiscordImageDimensions internal_;
236
+ };
237
+
238
+ class ActivityTimestamps final {
239
+ public:
240
+ void SetStart(Timestamp start);
241
+ Timestamp GetStart() const;
242
+ void SetEnd(Timestamp end);
243
+ Timestamp GetEnd() const;
244
+
245
+ private:
246
+ DiscordActivityTimestamps internal_;
247
+ };
248
+
249
+ class ActivityAssets final {
250
+ public:
251
+ void SetLargeImage(char const* largeImage);
252
+ char const* GetLargeImage() const;
253
+ void SetLargeText(char const* largeText);
254
+ char const* GetLargeText() const;
255
+ void SetSmallImage(char const* smallImage);
256
+ char const* GetSmallImage() const;
257
+ void SetSmallText(char const* smallText);
258
+ char const* GetSmallText() const;
259
+
260
+ private:
261
+ DiscordActivityAssets internal_;
262
+ };
263
+
264
+ class PartySize final {
265
+ public:
266
+ void SetCurrentSize(std::int32_t currentSize);
267
+ std::int32_t GetCurrentSize() const;
268
+ void SetMaxSize(std::int32_t maxSize);
269
+ std::int32_t GetMaxSize() const;
270
+
271
+ private:
272
+ DiscordPartySize internal_;
273
+ };
274
+
275
+ class ActivityParty final {
276
+ public:
277
+ void SetId(char const* id);
278
+ char const* GetId() const;
279
+ PartySize& GetSize();
280
+ PartySize const& GetSize() const;
281
+
282
+ private:
283
+ DiscordActivityParty internal_;
284
+ };
285
+
286
+ class ActivitySecrets final {
287
+ public:
288
+ void SetMatch(char const* match);
289
+ char const* GetMatch() const;
290
+ void SetJoin(char const* join);
291
+ char const* GetJoin() const;
292
+ void SetSpectate(char const* spectate);
293
+ char const* GetSpectate() const;
294
+
295
+ private:
296
+ DiscordActivitySecrets internal_;
297
+ };
298
+
299
+ class Activity final {
300
+ public:
301
+ void SetType(ActivityType type);
302
+ ActivityType GetType() const;
303
+ void SetApplicationId(std::int64_t applicationId);
304
+ std::int64_t GetApplicationId() const;
305
+ void SetName(char const* name);
306
+ char const* GetName() const;
307
+ void SetState(char const* state);
308
+ char const* GetState() const;
309
+ void SetDetails(char const* details);
310
+ char const* GetDetails() const;
311
+ ActivityTimestamps& GetTimestamps();
312
+ ActivityTimestamps const& GetTimestamps() const;
313
+ ActivityAssets& GetAssets();
314
+ ActivityAssets const& GetAssets() const;
315
+ ActivityParty& GetParty();
316
+ ActivityParty const& GetParty() const;
317
+ ActivitySecrets& GetSecrets();
318
+ ActivitySecrets const& GetSecrets() const;
319
+ void SetInstance(bool instance);
320
+ bool GetInstance() const;
321
+
322
+ private:
323
+ DiscordActivity internal_;
324
+ };
325
+
326
+ class Presence final {
327
+ public:
328
+ void SetStatus(Status status);
329
+ Status GetStatus() const;
330
+ Activity& GetActivity();
331
+ Activity const& GetActivity() const;
332
+
333
+ private:
334
+ DiscordPresence internal_;
335
+ };
336
+
337
+ class Relationship final {
338
+ public:
339
+ void SetType(RelationshipType type);
340
+ RelationshipType GetType() const;
341
+ User& GetUser();
342
+ User const& GetUser() const;
343
+ Presence& GetPresence();
344
+ Presence const& GetPresence() const;
345
+
346
+ private:
347
+ DiscordRelationship internal_;
348
+ };
349
+
350
+ class Lobby final {
351
+ public:
352
+ void SetId(LobbyId id);
353
+ LobbyId GetId() const;
354
+ void SetType(LobbyType type);
355
+ LobbyType GetType() const;
356
+ void SetOwnerId(UserId ownerId);
357
+ UserId GetOwnerId() const;
358
+ void SetSecret(LobbySecret secret);
359
+ LobbySecret GetSecret() const;
360
+ void SetCapacity(std::uint32_t capacity);
361
+ std::uint32_t GetCapacity() const;
362
+ void SetLocked(bool locked);
363
+ bool GetLocked() const;
364
+
365
+ private:
366
+ DiscordLobby internal_;
367
+ };
368
+
369
+ class FileStat final {
370
+ public:
371
+ void SetFilename(char const* filename);
372
+ char const* GetFilename() const;
373
+ void SetSize(std::uint64_t size);
374
+ std::uint64_t GetSize() const;
375
+ void SetLastModified(std::uint64_t lastModified);
376
+ std::uint64_t GetLastModified() const;
377
+
378
+ private:
379
+ DiscordFileStat internal_;
380
+ };
381
+
382
+ class Entitlement final {
383
+ public:
384
+ void SetId(Snowflake id);
385
+ Snowflake GetId() const;
386
+ void SetType(EntitlementType type);
387
+ EntitlementType GetType() const;
388
+ void SetSkuId(Snowflake skuId);
389
+ Snowflake GetSkuId() const;
390
+
391
+ private:
392
+ DiscordEntitlement internal_;
393
+ };
394
+
395
+ class SkuPrice final {
396
+ public:
397
+ void SetAmount(std::uint32_t amount);
398
+ std::uint32_t GetAmount() const;
399
+ void SetCurrency(char const* currency);
400
+ char const* GetCurrency() const;
401
+
402
+ private:
403
+ DiscordSkuPrice internal_;
404
+ };
405
+
406
+ class Sku final {
407
+ public:
408
+ void SetId(Snowflake id);
409
+ Snowflake GetId() const;
410
+ void SetType(SkuType type);
411
+ SkuType GetType() const;
412
+ void SetName(char const* name);
413
+ char const* GetName() const;
414
+ SkuPrice& GetPrice();
415
+ SkuPrice const& GetPrice() const;
416
+
417
+ private:
418
+ DiscordSku internal_;
419
+ };
420
+
421
+ class InputMode final {
422
+ public:
423
+ void SetType(InputModeType type);
424
+ InputModeType GetType() const;
425
+ void SetShortcut(char const* shortcut);
426
+ char const* GetShortcut() const;
427
+
428
+ private:
429
+ DiscordInputMode internal_;
430
+ };
431
+
432
+ class UserAchievement final {
433
+ public:
434
+ void SetUserId(Snowflake userId);
435
+ Snowflake GetUserId() const;
436
+ void SetAchievementId(Snowflake achievementId);
437
+ Snowflake GetAchievementId() const;
438
+ void SetPercentComplete(std::uint8_t percentComplete);
439
+ std::uint8_t GetPercentComplete() const;
440
+ void SetUnlockedAt(DateTime unlockedAt);
441
+ DateTime GetUnlockedAt() const;
442
+
443
+ private:
444
+ DiscordUserAchievement internal_;
445
+ };
446
+
447
+ class LobbyTransaction final {
448
+ public:
449
+ Result SetType(LobbyType type);
450
+ Result SetOwner(UserId ownerId);
451
+ Result SetCapacity(std::uint32_t capacity);
452
+ Result SetMetadata(MetadataKey key, MetadataValue value);
453
+ Result DeleteMetadata(MetadataKey key);
454
+ Result SetLocked(bool locked);
455
+
456
+ IDiscordLobbyTransaction** Receive() { return &internal_; }
457
+ IDiscordLobbyTransaction* Internal() { return internal_; }
458
+
459
+ private:
460
+ IDiscordLobbyTransaction* internal_;
461
+ };
462
+
463
+ class LobbyMemberTransaction final {
464
+ public:
465
+ Result SetMetadata(MetadataKey key, MetadataValue value);
466
+ Result DeleteMetadata(MetadataKey key);
467
+
468
+ IDiscordLobbyMemberTransaction** Receive() { return &internal_; }
469
+ IDiscordLobbyMemberTransaction* Internal() { return internal_; }
470
+
471
+ private:
472
+ IDiscordLobbyMemberTransaction* internal_;
473
+ };
474
+
475
+ class LobbySearchQuery final {
476
+ public:
477
+ Result Filter(MetadataKey key,
478
+ LobbySearchComparison comparison,
479
+ LobbySearchCast cast,
480
+ MetadataValue value);
481
+ Result Sort(MetadataKey key, LobbySearchCast cast, MetadataValue value);
482
+ Result Limit(std::uint32_t limit);
483
+ Result Distance(LobbySearchDistance distance);
484
+
485
+ IDiscordLobbySearchQuery** Receive() { return &internal_; }
486
+ IDiscordLobbySearchQuery* Internal() { return internal_; }
487
+
488
+ private:
489
+ IDiscordLobbySearchQuery* internal_;
490
+ };
491
+
492
+ } // namespace discord
@@ -0,0 +1,80 @@
1
+ #if !defined(_CRT_SECURE_NO_WARNINGS)
2
+ #define _CRT_SECURE_NO_WARNINGS
3
+ #endif
4
+
5
+ #include "user_manager.h"
6
+
7
+ #include "core.h"
8
+
9
+ #include <cstring>
10
+ #include <memory>
11
+
12
+ namespace discord {
13
+
14
+ class UserEvents final {
15
+ public:
16
+ static void OnCurrentUserUpdate(void* callbackData)
17
+ {
18
+ auto* core = reinterpret_cast<Core*>(callbackData);
19
+ if (!core) {
20
+ return;
21
+ }
22
+
23
+ auto& module = core->UserManager();
24
+ module.OnCurrentUserUpdate();
25
+ }
26
+ };
27
+
28
+ IDiscordUserEvents UserManager::events_{
29
+ &UserEvents::OnCurrentUserUpdate,
30
+ };
31
+
32
+ Result UserManager::GetCurrentUser(User* currentUser)
33
+ {
34
+ if (!currentUser) {
35
+ return Result::InternalError;
36
+ }
37
+
38
+ auto result =
39
+ internal_->get_current_user(internal_, reinterpret_cast<DiscordUser*>(currentUser));
40
+ return static_cast<Result>(result);
41
+ }
42
+
43
+ void UserManager::GetUser(UserId userId, std::function<void(Result, User const&)> callback)
44
+ {
45
+ static auto wrapper = [](void* callbackData, EDiscordResult result, DiscordUser* user) -> void {
46
+ std::unique_ptr<std::function<void(Result, User const&)>> cb(
47
+ reinterpret_cast<std::function<void(Result, User const&)>*>(callbackData));
48
+ if (!cb || !(*cb)) {
49
+ return;
50
+ }
51
+ (*cb)(static_cast<Result>(result), *reinterpret_cast<User const*>(user));
52
+ };
53
+ std::unique_ptr<std::function<void(Result, User const&)>> cb{};
54
+ cb.reset(new std::function<void(Result, User const&)>(std::move(callback)));
55
+ internal_->get_user(internal_, userId, cb.release(), wrapper);
56
+ }
57
+
58
+ Result UserManager::GetCurrentUserPremiumType(PremiumType* premiumType)
59
+ {
60
+ if (!premiumType) {
61
+ return Result::InternalError;
62
+ }
63
+
64
+ auto result = internal_->get_current_user_premium_type(
65
+ internal_, reinterpret_cast<EDiscordPremiumType*>(premiumType));
66
+ return static_cast<Result>(result);
67
+ }
68
+
69
+ Result UserManager::CurrentUserHasFlag(UserFlag flag, bool* hasFlag)
70
+ {
71
+ if (!hasFlag) {
72
+ return Result::InternalError;
73
+ }
74
+
75
+ auto result = internal_->current_user_has_flag(
76
+ internal_, static_cast<EDiscordUserFlag>(flag), reinterpret_cast<bool*>(hasFlag));
77
+ return static_cast<Result>(result);
78
+ }
79
+
80
+ } // namespace discord
@@ -0,0 +1,31 @@
1
+ #pragma once
2
+
3
+ #include "types.h"
4
+
5
+ namespace discord {
6
+
7
+ class UserManager final {
8
+ public:
9
+ ~UserManager() = default;
10
+
11
+ Result GetCurrentUser(User* currentUser);
12
+ void GetUser(UserId userId, std::function<void(Result, User const&)> callback);
13
+ Result GetCurrentUserPremiumType(PremiumType* premiumType);
14
+ Result CurrentUserHasFlag(UserFlag flag, bool* hasFlag);
15
+
16
+ Event<> OnCurrentUserUpdate;
17
+
18
+ private:
19
+ friend class Core;
20
+
21
+ UserManager() = default;
22
+ UserManager(UserManager const& rhs) = delete;
23
+ UserManager& operator=(UserManager const& rhs) = delete;
24
+ UserManager(UserManager&& rhs) = delete;
25
+ UserManager& operator=(UserManager&& rhs) = delete;
26
+
27
+ IDiscordUserManager* internal_;
28
+ static IDiscordUserEvents events_;
29
+ };
30
+
31
+ } // namespace discord
@@ -0,0 +1,124 @@
1
+ #if !defined(_CRT_SECURE_NO_WARNINGS)
2
+ #define _CRT_SECURE_NO_WARNINGS
3
+ #endif
4
+
5
+ #include "voice_manager.h"
6
+
7
+ #include "core.h"
8
+
9
+ #include <cstring>
10
+ #include <memory>
11
+
12
+ namespace discord {
13
+
14
+ class VoiceEvents final {
15
+ public:
16
+ static void OnSettingsUpdate(void* callbackData)
17
+ {
18
+ auto* core = reinterpret_cast<Core*>(callbackData);
19
+ if (!core) {
20
+ return;
21
+ }
22
+
23
+ auto& module = core->VoiceManager();
24
+ module.OnSettingsUpdate();
25
+ }
26
+ };
27
+
28
+ IDiscordVoiceEvents VoiceManager::events_{
29
+ &VoiceEvents::OnSettingsUpdate,
30
+ };
31
+
32
+ Result VoiceManager::GetInputMode(InputMode* inputMode)
33
+ {
34
+ if (!inputMode) {
35
+ return Result::InternalError;
36
+ }
37
+
38
+ auto result =
39
+ internal_->get_input_mode(internal_, reinterpret_cast<DiscordInputMode*>(inputMode));
40
+ return static_cast<Result>(result);
41
+ }
42
+
43
+ void VoiceManager::SetInputMode(InputMode inputMode, std::function<void(Result)> callback)
44
+ {
45
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
46
+ std::unique_ptr<std::function<void(Result)>> cb(
47
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
48
+ if (!cb || !(*cb)) {
49
+ return;
50
+ }
51
+ (*cb)(static_cast<Result>(result));
52
+ };
53
+ std::unique_ptr<std::function<void(Result)>> cb{};
54
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
55
+ internal_->set_input_mode(
56
+ internal_, *reinterpret_cast<DiscordInputMode const*>(&inputMode), cb.release(), wrapper);
57
+ }
58
+
59
+ Result VoiceManager::IsSelfMute(bool* mute)
60
+ {
61
+ if (!mute) {
62
+ return Result::InternalError;
63
+ }
64
+
65
+ auto result = internal_->is_self_mute(internal_, reinterpret_cast<bool*>(mute));
66
+ return static_cast<Result>(result);
67
+ }
68
+
69
+ Result VoiceManager::SetSelfMute(bool mute)
70
+ {
71
+ auto result = internal_->set_self_mute(internal_, (mute ? 1 : 0));
72
+ return static_cast<Result>(result);
73
+ }
74
+
75
+ Result VoiceManager::IsSelfDeaf(bool* deaf)
76
+ {
77
+ if (!deaf) {
78
+ return Result::InternalError;
79
+ }
80
+
81
+ auto result = internal_->is_self_deaf(internal_, reinterpret_cast<bool*>(deaf));
82
+ return static_cast<Result>(result);
83
+ }
84
+
85
+ Result VoiceManager::SetSelfDeaf(bool deaf)
86
+ {
87
+ auto result = internal_->set_self_deaf(internal_, (deaf ? 1 : 0));
88
+ return static_cast<Result>(result);
89
+ }
90
+
91
+ Result VoiceManager::IsLocalMute(Snowflake userId, bool* mute)
92
+ {
93
+ if (!mute) {
94
+ return Result::InternalError;
95
+ }
96
+
97
+ auto result = internal_->is_local_mute(internal_, userId, reinterpret_cast<bool*>(mute));
98
+ return static_cast<Result>(result);
99
+ }
100
+
101
+ Result VoiceManager::SetLocalMute(Snowflake userId, bool mute)
102
+ {
103
+ auto result = internal_->set_local_mute(internal_, userId, (mute ? 1 : 0));
104
+ return static_cast<Result>(result);
105
+ }
106
+
107
+ Result VoiceManager::GetLocalVolume(Snowflake userId, std::uint8_t* volume)
108
+ {
109
+ if (!volume) {
110
+ return Result::InternalError;
111
+ }
112
+
113
+ auto result =
114
+ internal_->get_local_volume(internal_, userId, reinterpret_cast<uint8_t*>(volume));
115
+ return static_cast<Result>(result);
116
+ }
117
+
118
+ Result VoiceManager::SetLocalVolume(Snowflake userId, std::uint8_t volume)
119
+ {
120
+ auto result = internal_->set_local_volume(internal_, userId, volume);
121
+ return static_cast<Result>(result);
122
+ }
123
+
124
+ } // namespace discord