@duque.edits/sdk 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/index.js +4 -31
  2. package/dist/managers/base.js +26 -0
  3. package/dist/managers/buffer/BufferManager.js +2 -2
  4. package/dist/managers/guild/GuildManager.js +42 -25
  5. package/dist/managers/index.js +23 -0
  6. package/dist/managers/match/GuildMatchManager.js +42 -31
  7. package/dist/managers/message/MessagesManager.js +48 -0
  8. package/dist/managers/permission/GuildPermissionManager.js +29 -52
  9. package/dist/managers/ticket/TicketManager.js +77 -0
  10. package/dist/managers/user/GuildUserManager.js +73 -85
  11. package/dist/managers/vipmember/VipMemberManager.js +23 -23
  12. package/dist/rest/REST.js +40 -24
  13. package/dist/rest/Routes.js +15 -17
  14. package/dist/rest/index.js +19 -0
  15. package/dist/structures/Collection.js +1 -1
  16. package/dist/structures/guild/Guild.js +59 -94
  17. package/dist/structures/index.js +22 -0
  18. package/dist/structures/match/GuildMatch.js +64 -111
  19. package/dist/structures/ticket/Ticket.js +119 -0
  20. package/dist/structures/user/GuildUser.js +46 -40
  21. package/dist/structures/vipmember/VipMember.js +5 -5
  22. package/dist/types/api/APILogMessage.js +2 -0
  23. package/dist/types/api/index.js +36 -0
  24. package/dist/types/index.js +1 -22
  25. package/package.json +11 -18
  26. package/types/index.d.ts +4 -0
  27. package/types/managers/base.d.ts +17 -0
  28. package/{dist → types}/managers/buffer/BufferManager.d.ts +2 -1
  29. package/{dist → types}/managers/guild/GuildManager.d.ts +12 -4
  30. package/types/managers/index.d.ts +7 -0
  31. package/{dist → types}/managers/match/GuildMatchManager.d.ts +10 -12
  32. package/types/managers/message/MessagesManager.d.ts +17 -0
  33. package/types/managers/permission/GuildPermissionManager.d.ts +8 -0
  34. package/types/managers/ticket/TicketManager.d.ts +22 -0
  35. package/types/managers/user/GuildUserManager.d.ts +19 -0
  36. package/{dist → types}/managers/vipmember/VipMemberManager.d.ts +8 -8
  37. package/types/rest/APIEndpoints.d.ts +11 -0
  38. package/{dist → types}/rest/REST.d.ts +9 -18
  39. package/{dist → types}/rest/Routes.d.ts +2 -2
  40. package/types/rest/index.d.ts +3 -0
  41. package/{dist → types}/structures/guild/Guild.d.ts +12 -29
  42. package/types/structures/index.d.ts +6 -0
  43. package/{dist → types}/structures/match/GuildMatch.d.ts +12 -22
  44. package/types/structures/ticket/Ticket.d.ts +30 -0
  45. package/{dist → types}/structures/user/GuildUser.d.ts +5 -3
  46. package/{dist → types}/structures/vipmember/VipMember.d.ts +1 -1
  47. package/types/types/RestTypes.d.ts +34 -0
  48. package/{dist → types}/types/api/APIGuild.d.ts +9 -2
  49. package/{dist → types}/types/api/APIGuildMatch.d.ts +9 -7
  50. package/types/types/api/APIGuildTicket.d.ts +16 -0
  51. package/{dist → types}/types/api/APIGuildUser.d.ts +3 -1
  52. package/types/types/api/APILogMessage.d.ts +7 -0
  53. package/{dist → types}/types/api/APIMessage.d.ts +3 -4
  54. package/{dist → types}/types/api/APIPlayer.d.ts +1 -1
  55. package/{dist → types}/types/api/index.d.ts +23 -1
  56. package/types/types/index.d.ts +2 -0
  57. package/dist/index.d.ts +0 -31
  58. package/dist/managers/bet/GuildBetManager.d.ts +0 -35
  59. package/dist/managers/bet/GuildBetManager.js +0 -126
  60. package/dist/managers/betuser/GuildBetUserManager.d.ts +0 -36
  61. package/dist/managers/betuser/GuildBetUserManager.js +0 -151
  62. package/dist/managers/channel/ChannelManager.d.ts +0 -39
  63. package/dist/managers/channel/ChannelManager.js +0 -148
  64. package/dist/managers/giveaway/GiveawayManager.d.ts +0 -16
  65. package/dist/managers/giveaway/GiveawayManager.js +0 -57
  66. package/dist/managers/groupedchannel/GroupedChannelManager.d.ts +0 -34
  67. package/dist/managers/groupedchannel/GroupedChannelManager.js +0 -92
  68. package/dist/managers/mediator/GuildMediatorManager.d.ts +0 -32
  69. package/dist/managers/mediator/GuildMediatorManager.js +0 -98
  70. package/dist/managers/messages/MessagesManager.d.ts +0 -32
  71. package/dist/managers/messages/MessagesManager.js +0 -89
  72. package/dist/managers/permission/GuildPermissionManager.d.ts +0 -26
  73. package/dist/managers/product/GuildProductManager.d.ts +0 -32
  74. package/dist/managers/product/GuildProductManager.js +0 -103
  75. package/dist/managers/ticket/GuildTicketManager.d.ts +0 -32
  76. package/dist/managers/ticket/GuildTicketManager.js +0 -100
  77. package/dist/managers/user/GuildUserManager.d.ts +0 -33
  78. package/dist/rest/APIEndpoints.d.ts +0 -11
  79. package/dist/structures/bet/GuildBet.d.ts +0 -87
  80. package/dist/structures/bet/GuildBet.js +0 -286
  81. package/dist/structures/betuser/GuildBetUser.d.ts +0 -85
  82. package/dist/structures/betuser/GuildBetUser.js +0 -211
  83. package/dist/structures/channel/Channel.d.ts +0 -31
  84. package/dist/structures/channel/Channel.js +0 -57
  85. package/dist/structures/giveaway/Giveaway.d.ts +0 -37
  86. package/dist/structures/giveaway/Giveaway.js +0 -208
  87. package/dist/structures/groupedchannel/GroupedChannel.d.ts +0 -34
  88. package/dist/structures/groupedchannel/GroupedChannel.js +0 -121
  89. package/dist/structures/mediator/GuildMediator.d.ts +0 -41
  90. package/dist/structures/mediator/GuildMediator.js +0 -131
  91. package/dist/structures/product/GuildProduct.d.ts +0 -52
  92. package/dist/structures/product/GuildProduct.js +0 -175
  93. package/dist/structures/shop/GuildShop.d.ts +0 -34
  94. package/dist/structures/shop/GuildShop.js +0 -80
  95. package/dist/structures/ticket/GuildTicket.d.ts +0 -52
  96. package/dist/structures/ticket/GuildTicket.js +0 -172
  97. package/dist/types/api/APIGuildTicket.d.ts +0 -26
  98. package/dist/types/index.d.ts +0 -23
  99. /package/dist/types/{api/APIGuildMessage.js → RestTypes.js} +0 -0
  100. /package/{dist → types}/structures/Collection.d.ts +0 -0
  101. /package/{dist → types}/types/api/APIBaseChannel.d.ts +0 -0
  102. /package/{dist → types}/types/api/APIBetChannel.d.ts +0 -0
  103. /package/{dist → types}/types/api/APIBetMessage.d.ts +0 -0
  104. /package/{dist → types}/types/api/APIGiveaway.d.ts +0 -0
  105. /package/{dist → types}/types/api/APIGuildBet.d.ts +0 -0
  106. /package/{dist → types}/types/api/APIGuildBetUser.d.ts +0 -0
  107. /package/{dist → types}/types/api/APIGuildChannel.d.ts +0 -0
  108. /package/{dist → types}/types/api/APIGuildEmoji.d.ts +0 -0
  109. /package/{dist → types}/types/api/APIGuildGroupedChannel.d.ts +0 -0
  110. /package/{dist → types}/types/api/APIGuildMediator.d.ts +0 -0
  111. /package/{dist → types}/types/api/APIGuildMessage.d.ts +0 -0
  112. /package/{dist → types}/types/api/APIGuildPermissions.d.ts +0 -0
  113. /package/{dist → types}/types/api/APIGuildRole.d.ts +0 -0
  114. /package/{dist → types}/types/api/APIGuildShop.d.ts +0 -0
  115. /package/{dist → types}/types/api/APIProduct.d.ts +0 -0
  116. /package/{dist → types}/types/api/APIVipMember.d.ts +0 -0
  117. /package/{dist → types}/utils/Assertion.d.ts +0 -0
  118. /package/{dist → types}/utils/getRandomNumber.d.ts +0 -0
package/dist/index.js CHANGED
@@ -14,34 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./managers/bet/GuildBetManager"), exports);
18
- __exportStar(require("./managers/betuser/GuildBetUserManager"), exports);
19
- __exportStar(require("./managers/channel/ChannelManager"), exports);
20
- __exportStar(require("./managers/groupedchannel/GroupedChannelManager"), exports);
21
- __exportStar(require("./managers/guild/GuildManager"), exports);
22
- __exportStar(require("./managers/match/GuildMatchManager"), exports);
23
- __exportStar(require("./managers/mediator/GuildMediatorManager"), exports);
24
- __exportStar(require("./managers/messages/MessagesManager"), exports);
25
- __exportStar(require("./managers/permission/GuildPermissionManager"), exports);
26
- __exportStar(require("./managers/product/GuildProductManager"), exports);
27
- __exportStar(require("./managers/ticket/GuildTicketManager"), exports);
28
- __exportStar(require("./managers/user/GuildUserManager"), exports);
29
- __exportStar(require("./managers/vipmember/VipMemberManager"), exports);
30
- __exportStar(require("./managers/giveaway/GiveawayManager"), exports);
31
- __exportStar(require("./structures/bet/GuildBet"), exports);
32
- __exportStar(require("./structures/betuser/GuildBetUser"), exports);
33
- __exportStar(require("./structures/channel/Channel"), exports);
34
- __exportStar(require("./structures/groupedchannel/GroupedChannel"), exports);
35
- __exportStar(require("./structures/guild/Guild"), exports);
36
- __exportStar(require("./structures/match/GuildMatch"), exports);
37
- __exportStar(require("./structures/mediator/GuildMediator"), exports);
38
- __exportStar(require("./structures/product/GuildProduct"), exports);
39
- __exportStar(require("./structures/shop/GuildShop"), exports);
40
- __exportStar(require("./structures/ticket/GuildTicket"), exports);
41
- __exportStar(require("./structures/user/GuildUser"), exports);
42
- __exportStar(require("./structures/vipmember/VipMember"), exports);
43
- __exportStar(require("./structures/giveaway/Giveaway"), exports);
44
- __exportStar(require("./structures/Collection"), exports);
45
- __exportStar(require("./rest/REST"), exports);
46
- __exportStar(require("./rest/Routes"), exports);
47
- __exportStar(require("./types/index"), exports);
17
+ __exportStar(require("./managers"), exports);
18
+ __exportStar(require("./structures"), exports);
19
+ __exportStar(require("./rest"), exports);
20
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseManager = void 0;
4
+ const Collection_1 = require("../structures/Collection");
5
+ class BaseManager {
6
+ /** This url of the manager */
7
+ base_url;
8
+ /** The rest client */
9
+ rest;
10
+ /** The guild of the manager */
11
+ guild;
12
+ /** Cache */
13
+ cache;
14
+ /** Internal data when manager is initialized */
15
+ _data;
16
+ constructor(guild, data) {
17
+ this.guild = guild;
18
+ this.rest = guild.rest;
19
+ this.cache = new Collection_1.Collection();
20
+ this._data = data;
21
+ }
22
+ get data() {
23
+ return this._data;
24
+ }
25
+ }
26
+ exports.BaseManager = BaseManager;
@@ -16,13 +16,13 @@ class BufferManager {
16
16
  const { rest } = this.guild;
17
17
  const cache = this[key];
18
18
  const { size, clear } = cache;
19
- if (size >= 3) {
19
+ if (size >= 2) {
20
20
  const response = await rest.request({
21
21
  method: "POST",
22
22
  url: Routes_1.Routes.guilds.resources(this.guild.id, key, "bulk"),
23
23
  payload: { [key]: this[key].toArray() },
24
24
  });
25
- this.guild[key].setAll(response);
25
+ this.guild[key].set(response);
26
26
  clear();
27
27
  return response;
28
28
  }
@@ -24,17 +24,19 @@ class GuildManager {
24
24
  * @param id Id of the guild to fetch
25
25
  * @returns APIGuild
26
26
  */
27
- async fetch(id) {
28
- const route = Routes_1.Routes.guilds.get(id);
29
- const response = await this.rest.request({
30
- method: "get",
31
- url: route,
32
- });
33
- const guild = new Guild_1.Guild(response, this.rest);
34
- this.cache.set(guild.id, guild);
35
- return guild;
36
- }
37
- async fetchAll() {
27
+ async fetch(options) {
28
+ if (options && options.cache)
29
+ return this.cache;
30
+ if (options && options.guildId) {
31
+ const route = Routes_1.Routes.guilds.get(options.guildId);
32
+ const response = await this.rest.request({
33
+ method: "get",
34
+ url: route,
35
+ });
36
+ const guild = new Guild_1.Guild(response, this.rest);
37
+ this.cache.set(guild.id, guild);
38
+ return guild;
39
+ }
38
40
  const route = Routes_1.Routes.guilds.getAll();
39
41
  const response = await this.rest.request({
40
42
  method: "get",
@@ -45,23 +47,22 @@ class GuildManager {
45
47
  continue;
46
48
  const guild = new Guild_1.Guild(guildData, this.rest);
47
49
  this.cache.set(guild.id, guild);
48
- this.rest.guilds.cache.set(guild.id, guild);
49
50
  }
50
51
  return this.cache;
51
52
  }
52
- async delete(id) {
53
- Assertion_1.Assertion.assertString(id);
54
- const route = Routes_1.Routes.guilds.delete(id);
55
- const guild = this.cache.get(id);
56
- this.rest.emit("guildDelete", guild);
57
- await this.rest.request({
58
- method: "DELETE",
59
- url: route,
60
- });
61
- this.cache.delete(id);
62
- return this.cache;
63
- }
64
- async deleteAll() {
53
+ async delete(options) {
54
+ if (options && options.guildId) {
55
+ Assertion_1.Assertion.assertString(options.guildId);
56
+ const route = Routes_1.Routes.guilds.delete(options.guildId);
57
+ const guild = this.cache.get(options.guildId);
58
+ this.rest.emit("guildDelete", guild);
59
+ await this.rest.request({
60
+ method: "DELETE",
61
+ url: route,
62
+ });
63
+ this.cache.delete(options.guildId);
64
+ return this.cache;
65
+ }
65
66
  const route = Routes_1.Routes.guilds.deleteAll();
66
67
  this.rest.emit("guildsDelete", this.cache);
67
68
  const value = await this.rest.request({
@@ -71,5 +72,21 @@ class GuildManager {
71
72
  this.cache.clear();
72
73
  return value;
73
74
  }
75
+ set(data) {
76
+ if (!data)
77
+ return this.cache;
78
+ if (Array.isArray(data)) {
79
+ for (let _guild of data) {
80
+ const guild = new Guild_1.Guild(_guild, this.rest);
81
+ this.cache.set(guild.id, guild);
82
+ }
83
+ return this.cache;
84
+ }
85
+ else {
86
+ const guild = new Guild_1.Guild(data, this.rest);
87
+ this.cache.set(guild.id, guild);
88
+ return guild;
89
+ }
90
+ }
74
91
  }
75
92
  exports.GuildManager = GuildManager;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./buffer/BufferManager"), exports);
18
+ __exportStar(require("./guild/GuildManager"), exports);
19
+ __exportStar(require("./match/GuildMatchManager"), exports);
20
+ __exportStar(require("./permission/GuildPermissionManager"), exports);
21
+ __exportStar(require("./user/GuildUserManager"), exports);
22
+ __exportStar(require("./vipmember/VipMemberManager"), exports);
23
+ __exportStar(require("./ticket/TicketManager"), exports);
@@ -5,40 +5,51 @@ const Routes_1 = require("../../rest/Routes");
5
5
  const GuildMatch_1 = require("../../structures/match/GuildMatch");
6
6
  const Collection_1 = require("../../structures/Collection");
7
7
  const Assertion_1 = require("../../utils/Assertion");
8
- class GuildMatchManager {
9
- /** A cache of users */
10
- cache;
11
- /** The rest client */
12
- rest;
13
- /** GuildMatch match guild */
14
- guild;
8
+ const base_1 = require("../base");
9
+ class GuildMatchManager extends base_1.BaseManager {
15
10
  /**
16
11
  * Manage users with the given client
17
12
  * @param users An array of users
18
13
  * @param rest The rest client
19
14
  */
20
- constructor(guild, rest) {
15
+ constructor(guild) {
16
+ super(guild, guild.rest);
21
17
  this.guild = guild;
18
+ this.rest = guild.rest;
19
+ this.base_url = Routes_1.Routes.guilds.resource(guild.id, "matches");
22
20
  this.cache = new Collection_1.Collection("matches");
23
- this.rest = rest;
24
21
  }
25
22
  /**
26
23
  * Fetch a match
27
24
  * @param id Id of the match to fetch
28
25
  * @returns APIBetUser
29
26
  */
30
- async fetch(id) {
31
- const route = Routes_1.Routes.guilds.matches.get(this.guild.id, id);
27
+ async fetch(options) {
28
+ if (options && options.cache)
29
+ return this.cache;
30
+ if (options && options.matchId) {
31
+ const route = Routes_1.Routes.guilds.matches.get(this.guild.id, options.matchId);
32
+ const response = await this.rest.request({
33
+ method: "get",
34
+ url: route,
35
+ });
36
+ return this.set(response);
37
+ }
38
+ const route = Routes_1.Routes.guilds.matches.getAll(this.guild.id);
32
39
  const response = await this.rest.request({
33
40
  method: "get",
34
41
  url: route,
35
42
  });
36
- if (!response.creatorId)
37
- return null;
38
- const match = new GuildMatch_1.GuildMatch(response, this.guild, this, this.rest);
39
- this.cache.set(match._id, match);
40
- this.rest.matches.set(match._id, match);
41
- return match;
43
+ if (!response)
44
+ return this.cache;
45
+ const coll = new Collection_1.Collection();
46
+ for (let match of response ?? []) {
47
+ const guildMatch = new GuildMatch_1.GuildMatch(match, this);
48
+ coll.set(match._id, guildMatch);
49
+ this.rest.matches.set(match._id, guildMatch);
50
+ }
51
+ this.cache = coll;
52
+ return coll;
42
53
  }
43
54
  async fetchAll() {
44
55
  const route = Routes_1.Routes.guilds.matches.getAll(this.guild.id);
@@ -50,23 +61,24 @@ class GuildMatchManager {
50
61
  this.cache.clear();
51
62
  return this.cache;
52
63
  }
53
- this.setAll(response);
64
+ this.set(response);
54
65
  return this.cache;
55
66
  }
56
67
  set(data) {
57
- if (!data?._id)
58
- return;
59
- const match = new GuildMatch_1.GuildMatch(data, this?.guild, this, this.rest);
60
- this.cache.set(data?._id, match);
61
- this.rest.matches.set(data?._id, match);
62
- return match;
63
- }
64
- setAll(data) {
65
68
  if (!data)
66
69
  return this.cache;
67
- for (let match of data || [])
68
- this.set(match);
69
- return this.cache;
70
+ if (Array.isArray(data)) {
71
+ for (let _match of data) {
72
+ const match = new GuildMatch_1.GuildMatch(_match, this);
73
+ this.cache.set(match._id, match);
74
+ }
75
+ return this.cache;
76
+ }
77
+ else {
78
+ const match = new GuildMatch_1.GuildMatch(data, this);
79
+ this.cache.set(match._id, match);
80
+ return match;
81
+ }
70
82
  }
71
83
  async create(payload) {
72
84
  Assertion_1.Assertion.assertObject(payload);
@@ -76,8 +88,7 @@ class GuildMatchManager {
76
88
  url: route,
77
89
  payload,
78
90
  });
79
- const match = this.set(response);
80
- return match;
91
+ return this.set(response);
81
92
  }
82
93
  async delete(id) {
83
94
  Assertion_1.Assertion.assertString(id);
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessagesManager = void 0;
4
+ const Collection_1 = require("../../structures/Collection");
5
+ class MessagesManager {
6
+ cache;
7
+ base_url;
8
+ rest;
9
+ constructor(structure, base_url) {
10
+ this.rest = structure.rest;
11
+ this.cache = new Collection_1.Collection();
12
+ this.base_url = base_url;
13
+ }
14
+ async fetch() {
15
+ const response = await this.rest.request({
16
+ method: "GET",
17
+ url: this.base_url,
18
+ payload: {},
19
+ });
20
+ this.cache.set(response._id, response);
21
+ return response;
22
+ }
23
+ async create(data) {
24
+ const messages = [...this.cache.toArray()];
25
+ if (Array.isArray(data))
26
+ messages.push(...data);
27
+ else
28
+ messages.push(data);
29
+ const response = await this.rest.request({
30
+ method: "POST",
31
+ url: this.base_url,
32
+ payload: { messages },
33
+ });
34
+ for (let message of response)
35
+ this.cache.set(message._id, message);
36
+ return response;
37
+ }
38
+ setAll(data) {
39
+ if (Array.isArray(data)) {
40
+ for (let message of data)
41
+ this.cache.set(message._id, message);
42
+ }
43
+ else
44
+ this.cache.set(data._id, data);
45
+ return this.cache;
46
+ }
47
+ }
48
+ exports.MessagesManager = MessagesManager;
@@ -2,69 +2,46 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GuildPermissionManager = void 0;
4
4
  const Routes_1 = require("../../rest/Routes");
5
- class GuildPermissionManager {
6
- /** The rest client */
7
- rest;
8
- /** GuildBet bet guild */
9
- guild;
10
- permissions;
11
- /**
12
- * Manage users with the given client
13
- * @param users An array of users
14
- * @param rest The rest client
15
- */
16
- constructor(guild, rest) {
5
+ const base_1 = require("../base");
6
+ class GuildPermissionManager extends base_1.BaseManager {
7
+ constructor(guild) {
8
+ super(guild, guild.permissions);
17
9
  this.guild = guild;
18
- this.rest = rest;
10
+ this.rest = guild.rest;
11
+ this.base_url = Routes_1.Routes.guilds.resource(guild.id, "permissions");
19
12
  }
20
- /**
21
- * Fetch a bet
22
- * @param id Id of the bet to fetch
23
- * @returns APIBetUser
24
- */
25
- async fetch() {
26
- const route = Routes_1.Routes.guilds.resource(this.guild.id, "permissions");
13
+ async addRole(permissionId, roleId) {
14
+ const perm = this.guild.permissions[permissionId];
15
+ if (perm.includes(roleId))
16
+ return this.guild;
17
+ perm.push(roleId);
18
+ const perms = { ...this.guild.permissions, perm };
19
+ const payload = { set: perms };
27
20
  const response = await this.rest.request({
28
- method: "get",
29
- url: route,
30
- });
31
- this.setAll(response);
32
- }
33
- async addId(permissionId, roleId) {
34
- const route = Routes_1.Routes.guilds.resources(this.guild.id, "permissions", permissionId, "ids");
35
- const payload = { id: roleId };
36
- const response = await this.rest.request({
37
- method: "post",
38
- url: route,
21
+ method: "PATCH",
22
+ url: this.base_url,
39
23
  payload,
40
24
  });
41
- this.permissions[permissionId] = response;
25
+ this.guild.permissions = response.permissions;
26
+ this.rest.guilds.cache.set(this.guild.id, this.guild);
42
27
  return response;
43
28
  }
44
- async removeId(permissionId, roleId) {
45
- const route = Routes_1.Routes.guilds.resources(this.guild.id, "permissions", permissionId, "ids", roleId);
46
- const payload = { id: roleId };
29
+ async removeRole(permissionId, roleId) {
30
+ let perm = this.guild.permissions[permissionId];
31
+ if (!perm.includes(roleId))
32
+ return this.guild;
33
+ perm = perm.filter((i) => i !== roleId);
34
+ let perms = { ...this.guild.permissions };
35
+ perms[permissionId] = perm;
36
+ const payload = { set: perms };
47
37
  const response = await this.rest.request({
48
- method: "delete",
49
- url: route,
38
+ method: "PATCH",
39
+ url: this.base_url,
50
40
  payload,
51
41
  });
52
- this.permissions[permissionId] = response;
42
+ this.guild.permissions = response.permissions;
43
+ this.rest.guilds.cache.set(this.guild.id, this.guild);
53
44
  return response;
54
45
  }
55
- setAll(data) {
56
- if (!data)
57
- return this.permissions;
58
- this.permissions = data;
59
- }
60
- toJSON() {
61
- const json = {};
62
- for (const [key, value] of Object.entries(this)) {
63
- if (typeof value !== "function") {
64
- json[key] = value;
65
- }
66
- }
67
- return json;
68
- }
69
46
  }
70
47
  exports.GuildPermissionManager = GuildPermissionManager;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TicketManager = void 0;
4
+ const rest_1 = require("../../rest");
5
+ const structures_1 = require("../../structures");
6
+ const Collection_1 = require("../../structures/Collection");
7
+ class TicketManager {
8
+ cache;
9
+ guild;
10
+ rest;
11
+ constructor(guild) {
12
+ this.guild = guild;
13
+ this.rest = guild.rest;
14
+ this.cache = new Collection_1.Collection("tickets");
15
+ }
16
+ async fetch(options) {
17
+ if (options && options.cache)
18
+ return this.cache;
19
+ if (options && options.ticketId) {
20
+ const route = rest_1.Routes.guilds.tickets.get(this.guild.id, options.ticketId);
21
+ const response = await this.rest.request({
22
+ method: "GET",
23
+ url: route,
24
+ });
25
+ return this.set(response);
26
+ }
27
+ const route = rest_1.Routes.guilds.tickets.getAll(this.guild.id);
28
+ const response = await this.rest.request({
29
+ method: "GET",
30
+ url: route,
31
+ });
32
+ return this.set(response);
33
+ }
34
+ async create(data) {
35
+ const route = rest_1.Routes.guilds.tickets.create(this.guild.id);
36
+ const response = await this.rest.request({
37
+ method: "POST",
38
+ url: route,
39
+ payload: data,
40
+ });
41
+ return this.set(response);
42
+ }
43
+ async delete(options) {
44
+ if (options && options.ticketId) {
45
+ const route = rest_1.Routes.guilds.tickets.delete(this.guild.id, options.ticketId);
46
+ await this.rest.request({
47
+ method: "DELETE",
48
+ url: route,
49
+ });
50
+ return true;
51
+ }
52
+ const route = rest_1.Routes.guilds.tickets.deleteAll(this.guild.id);
53
+ await this.rest.request({
54
+ method: "DELETE",
55
+ url: route,
56
+ });
57
+ this.cache.clear();
58
+ return true;
59
+ }
60
+ set(data) {
61
+ if (!data)
62
+ return this.cache;
63
+ if (Array.isArray(data)) {
64
+ for (let _ticket of data) {
65
+ const ticket = new structures_1.GuildTicket(_ticket, this);
66
+ this.cache.set(ticket._id, ticket);
67
+ }
68
+ return this.cache;
69
+ }
70
+ else {
71
+ const ticket = new structures_1.GuildTicket(data, this);
72
+ this.cache.set(ticket._id, ticket);
73
+ return ticket;
74
+ }
75
+ }
76
+ }
77
+ exports.TicketManager = TicketManager;