@duque.edits/sdk 0.1.5 → 0.1.7

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
@@ -1,35 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { GuildBet } from "../../structures/bet/GuildBet";
3
- import { Collection } from "../../structures/Collection";
4
- import { Guild } from "../../structures/guild/Guild";
5
- import { Optional } from "../../types/api";
6
- import { APIGuildBet } from "../../types/api/APIGuildBet";
7
- type OptionalGuildBet = Optional<APIGuildBet>;
8
- export declare class GuildBetManager {
9
- /** A cache of users */
10
- cache: Collection<string, GuildBet>;
11
- /** The rest client */
12
- rest: REST;
13
- /** GuildBet bet guild */
14
- guild: Guild;
15
- /**
16
- * Manage users with the given client
17
- * @param users An array of users
18
- * @param rest The rest client
19
- */
20
- constructor(guild: Guild, rest: REST);
21
- create(payload: Optional<APIGuildBet>): Promise<GuildBet>;
22
- createMany(bets: OptionalGuildBet[]): Promise<Collection<string, GuildBet>>;
23
- /**
24
- * Fetch a bet
25
- * @param id Id of the bet to fetch
26
- * @returns APIBetUser
27
- */
28
- fetch(id: string): Promise<GuildBet>;
29
- fetchAll(): Promise<Collection<string, GuildBet>>;
30
- set(data: APIGuildBet): GuildBet;
31
- setAll(data: APIGuildBet[]): Collection<string, GuildBet>;
32
- delete(id: string): Promise<Collection<string, GuildBet>>;
33
- deleteAll(): Promise<boolean>;
34
- }
35
- export {};
@@ -1,126 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GuildBetManager = void 0;
4
- const Routes_1 = require("../../rest/Routes");
5
- const GuildBet_1 = require("../../structures/bet/GuildBet");
6
- const Collection_1 = require("../../structures/Collection");
7
- const Assertion_1 = require("../../utils/Assertion");
8
- class GuildBetManager {
9
- /** A cache of users */
10
- cache;
11
- /** The rest client */
12
- rest;
13
- /** GuildBet bet guild */
14
- guild;
15
- /**
16
- * Manage users with the given client
17
- * @param users An array of users
18
- * @param rest The rest client
19
- */
20
- constructor(guild, rest) {
21
- this.guild = guild;
22
- this.rest = rest;
23
- this.cache = new Collection_1.Collection("bets");
24
- }
25
- async create(payload) {
26
- Assertion_1.Assertion.assertObject(payload);
27
- const route = Routes_1.Routes.guilds.bets.create(this.guild.id);
28
- const response = await this.rest.request({
29
- method: "POST",
30
- url: route,
31
- payload,
32
- });
33
- const bet = this.set(response);
34
- return bet;
35
- }
36
- async createMany(bets) {
37
- Assertion_1.Assertion.assertArray(bets);
38
- const route = Routes_1.Routes.guilds.bets.resource(this.guild.id, "bulk");
39
- const payload = { bets };
40
- const response = await this.rest.request({
41
- method: "POST",
42
- url: route,
43
- payload,
44
- });
45
- this.rest.emit("betBulkCreate", response);
46
- this.setAll(response);
47
- const coll = new Collection_1.Collection();
48
- for (let bt of response) {
49
- const bet = new GuildBet_1.GuildBet(bt, this.guild, this, this.rest);
50
- coll.set(bt._id, bet);
51
- }
52
- return coll;
53
- }
54
- /**
55
- * Fetch a bet
56
- * @param id Id of the bet to fetch
57
- * @returns APIBetUser
58
- */
59
- async fetch(id) {
60
- const route = Routes_1.Routes.guilds.bets.get(this.guild.id, id);
61
- const response = await this.rest.request({
62
- method: "get",
63
- url: route,
64
- });
65
- const bet = new GuildBet_1.GuildBet(response, this.guild, this, this.rest);
66
- this.cache.set(bet._id, bet);
67
- this.rest.bets.set(bet._id, bet);
68
- return bet;
69
- }
70
- async fetchAll() {
71
- const route = Routes_1.Routes.guilds.bets.getAll(this.guild.id);
72
- const response = await this.rest.request({
73
- method: "get",
74
- url: route,
75
- });
76
- if (Array.isArray(response) && response.length === 0) {
77
- this.cache.clear();
78
- return this.cache;
79
- }
80
- for (let betData of response) {
81
- const bet = new GuildBet_1.GuildBet(betData, this.guild, this, this.rest);
82
- this.cache.set(bet._id, bet);
83
- }
84
- return this.cache;
85
- }
86
- set(data) {
87
- if (!data?._id)
88
- return;
89
- if (!this.guild)
90
- return;
91
- const bet = new GuildBet_1.GuildBet(data, this.guild, this, this.rest);
92
- this.cache.set(bet._id, bet);
93
- this.rest.bets.set(bet._id, bet);
94
- return bet;
95
- }
96
- setAll(data) {
97
- if (!data)
98
- return this.cache;
99
- for (let bet of data)
100
- this.set(bet);
101
- return this.cache;
102
- }
103
- async delete(id) {
104
- Assertion_1.Assertion.assertString(id);
105
- const route = Routes_1.Routes.guilds.bets.delete(id, this.guild.id);
106
- const bet = this.cache.get(id);
107
- this.rest.emit("betDelete", bet);
108
- await this.rest.request({
109
- method: "DELETE",
110
- url: route,
111
- });
112
- this.cache.delete(id);
113
- return this.cache;
114
- }
115
- async deleteAll() {
116
- const route = Routes_1.Routes.guilds.bets.deleteAll(this.guild.id);
117
- this.rest.emit("betsDelete", this.cache);
118
- const value = await this.rest.request({
119
- method: "DELETE",
120
- url: route,
121
- });
122
- this.cache.clear();
123
- return value;
124
- }
125
- }
126
- exports.GuildBetManager = GuildBetManager;
@@ -1,36 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { GuildBetUser } from "../../structures/betuser/GuildBetUser";
3
- import { Collection } from "../../structures/Collection";
4
- import { Guild } from "../../structures/guild/Guild";
5
- import { APIPlayer, Optional } from "../../types";
6
- import { APIGuildBetUser } from "../../types/api/APIGuildBetUser";
7
- export declare class GuildBetUserManager {
8
- /** A cache of users */
9
- cache: Collection<string, GuildBetUser>;
10
- /** The rest client */
11
- rest: REST;
12
- /** Bet user guild */
13
- guild: Guild;
14
- /**
15
- * Manage users with the given client
16
- * @param users An array of users
17
- * @param rest The rest client
18
- */
19
- constructor(guild: Guild, rest: REST);
20
- updateMany(data: Optional<APIPlayer>[]): Promise<Collection<string, GuildBetUser>>;
21
- update(id: string, data: Optional<APIGuildBetUser> & {
22
- type: "add" | "remove";
23
- }): Promise<GuildBetUser>;
24
- set(data: APIGuildBetUser): Collection<string, GuildBetUser>;
25
- setAll(data: APIGuildBetUser[]): Collection<string, GuildBetUser>;
26
- resetAll(): Promise<Collection<string, GuildBetUser>>;
27
- /**
28
- * Fetch a user
29
- * @param id Id of the user to fetch
30
- * @returns GuildBetUser
31
- */
32
- fetch(id: string, name: string): Promise<GuildBetUser>;
33
- fetchAll(): Promise<Collection<string, GuildBetUser>>;
34
- delete(id: string): Promise<Collection<string, GuildBetUser>>;
35
- deleteAll(): Promise<boolean>;
36
- }
@@ -1,151 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GuildBetUserManager = void 0;
4
- const Routes_1 = require("../../rest/Routes");
5
- const GuildBetUser_1 = require("../../structures/betuser/GuildBetUser");
6
- const Collection_1 = require("../../structures/Collection");
7
- const Assertion_1 = require("../../utils/Assertion");
8
- class GuildBetUserManager {
9
- /** A cache of users */
10
- cache;
11
- /** The rest client */
12
- rest;
13
- /** Bet user guild */
14
- guild;
15
- /**
16
- * Manage users with the given client
17
- * @param users An array of users
18
- * @param rest The rest client
19
- */
20
- constructor(guild, rest) {
21
- this.guild = guild;
22
- this.rest = rest;
23
- this.cache = new Collection_1.Collection("betUsers");
24
- }
25
- async updateMany(data) {
26
- const route = Routes_1.Routes.guilds.resources(this.guild.id, "betUsers", "bulk");
27
- const payload = { betUsers: data };
28
- const response = await this.rest.request({
29
- method: "PATCH",
30
- url: route,
31
- payload,
32
- });
33
- this.setAll(response);
34
- return this.cache;
35
- }
36
- async update(id, data) {
37
- const route = Routes_1.Routes.guilds.betUsers.update(this.guild.id, id);
38
- const payload = {};
39
- const numericFields = ["coins", "wins", "credit", "losses", "mvps", "games"];
40
- const arrayFields = ["items", "betsPlayed"];
41
- if (data.type === "add" || data.type === "remove") {
42
- for (const key in data) {
43
- if (key === "type")
44
- continue;
45
- const value = data[key];
46
- if (numericFields.includes(key)) {
47
- const current = this[key];
48
- const num = value;
49
- payload[key] = Math.max(0, data.type === "add" ? current + num : num - current);
50
- }
51
- else if (key === "blacklist") {
52
- payload["blacklist"] = value;
53
- }
54
- else if (arrayFields.includes(key)) {
55
- const current = this[key];
56
- const incoming = value;
57
- payload[key] =
58
- data.type === "add"
59
- ? [...new Set([...current, ...incoming])]
60
- : current.filter((x) => !incoming.includes(x));
61
- }
62
- }
63
- }
64
- const response = await this.rest.request({
65
- method: "patch",
66
- url: route,
67
- payload,
68
- });
69
- const user = new GuildBetUser_1.GuildBetUser(response, this, this.rest);
70
- this.cache.set(user.id, user);
71
- return user;
72
- }
73
- set(data) {
74
- if (!data?.id)
75
- return;
76
- const user = new GuildBetUser_1.GuildBetUser(data, this, this.rest);
77
- this.rest.betUsers.set(user.id, user);
78
- return this.cache.set(user.id, user);
79
- }
80
- setAll(data) {
81
- if (!data)
82
- return this.cache;
83
- for (let user of data)
84
- this.set(user);
85
- return this.cache;
86
- }
87
- async resetAll() {
88
- const route = Routes_1.Routes.guilds.betUsers.getAll(this.guild.id);
89
- const response = await this.rest.request({
90
- method: "PUT",
91
- url: route,
92
- });
93
- this.setAll(response);
94
- return this.cache;
95
- }
96
- /**
97
- * Fetch a user
98
- * @param id Id of the user to fetch
99
- * @returns GuildBetUser
100
- */
101
- async fetch(id, name) {
102
- const route = Routes_1.Routes.guilds.betUsers.get(this.guild.id, id);
103
- const response = await this.rest.request({
104
- method: "get",
105
- url: route,
106
- payload: { name },
107
- });
108
- if (!response)
109
- return this.cache.get(id);
110
- const user = new GuildBetUser_1.GuildBetUser(response, this, this.rest);
111
- this.cache.set(user?.id, user);
112
- this.rest.betUsers.set(user?.id, user);
113
- return user;
114
- }
115
- async fetchAll() {
116
- const route = Routes_1.Routes.guilds.betUsers.getAll(this.guild.id);
117
- const response = await this.rest.request({
118
- method: "get",
119
- url: route,
120
- });
121
- if (Array.isArray(response) && response.length === 0) {
122
- this.cache.clear();
123
- return this.cache;
124
- }
125
- this.setAll(response);
126
- return this.cache;
127
- }
128
- async delete(id) {
129
- Assertion_1.Assertion.assertString(id);
130
- const route = Routes_1.Routes.guilds.betUsers.delete(id, this.guild.id);
131
- const betUser = this.cache.get(id);
132
- this.rest.emit("betDelete", betUser);
133
- await this.rest.request({
134
- method: "DELETE",
135
- url: route,
136
- });
137
- this.cache.delete(id);
138
- return this.cache;
139
- }
140
- async deleteAll() {
141
- const route = Routes_1.Routes.guilds.betUsers.deleteAll(this.guild.id);
142
- this.rest.emit("betsDelete", this.cache);
143
- const value = await this.rest.request({
144
- method: "DELETE",
145
- url: route,
146
- });
147
- this.cache.clear();
148
- return value;
149
- }
150
- }
151
- exports.GuildBetUserManager = GuildBetUserManager;
@@ -1,39 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { GuildBet } from "../../structures/bet/GuildBet";
3
- import { Channel } from "../../structures/channel/Channel";
4
- import { Collection } from "../../structures/Collection";
5
- import { Guild } from "../../structures/guild/Guild";
6
- import { GuildMatch } from "../../structures/match/GuildMatch";
7
- import { Optional } from "../../types/api";
8
- import { APIBaseChannel } from "../../types/api/APIBaseChannel";
9
- type Channels = Optional<APIBaseChannel>;
10
- export declare class ChannelManager<Structure extends GuildBet | GuildMatch> {
11
- /** A cache of bet channels */
12
- cache: Collection<string, Channel<Structure>>;
13
- /** The rest client */
14
- rest: REST;
15
- /** GuildBet user guild */
16
- guild: Guild;
17
- /** The bet */
18
- structure: Structure;
19
- /** Base Url */
20
- baseUrl: string;
21
- /**
22
- * Manage channels of a bet
23
- * @param guild The guild at hand
24
- * @param bet The bet at hand
25
- * @param rest The rest client
26
- */
27
- constructor(guild: Guild, structure: Structure, rest: REST);
28
- create(data: Optional<APIBaseChannel>): Promise<Channel<Structure>>;
29
- createMany(...channels: Channels[]): Promise<Collection<string, Channel<Structure>>>;
30
- deleteMany(...channels: Optional<APIBaseChannel>[]): Promise<Collection<string, Channel<Structure>>>;
31
- setAll(data: APIBaseChannel[]): Collection<string, Channel<Structure>>;
32
- set(data: APIBaseChannel): Channel<Structure>;
33
- update(type: string, payload: Optional<APIBaseChannel>): Promise<Channel<Structure>>;
34
- fetch(type: string): Promise<Channel<Structure>>;
35
- fetchAll(): Promise<Collection<string, Channel<Structure>>>;
36
- delete(type: string): Promise<Collection<string, Channel<Structure>>>;
37
- deleteAll(): Promise<boolean>;
38
- }
39
- export {};
@@ -1,148 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ChannelManager = void 0;
4
- const Routes_1 = require("../../rest/Routes");
5
- const Channel_1 = require("../../structures/channel/Channel");
6
- const Collection_1 = require("../../structures/Collection");
7
- const Assertion_1 = require("../../utils/Assertion");
8
- class ChannelManager {
9
- /** A cache of bet channels */
10
- cache;
11
- /** The rest client */
12
- rest;
13
- /** GuildBet user guild */
14
- guild;
15
- /** The bet */
16
- structure;
17
- /** Base Url */
18
- baseUrl;
19
- /**
20
- * Manage channels of a bet
21
- * @param guild The guild at hand
22
- * @param bet The bet at hand
23
- * @param rest The rest client
24
- */
25
- constructor(guild, structure, rest) {
26
- this.structure = structure;
27
- this.rest = rest;
28
- this.guild = guild;
29
- this.cache = new Collection_1.Collection("channels");
30
- this.baseUrl = Routes_1.Routes.guilds[structure.key].resource(guild.id, structure._id, "channels");
31
- }
32
- async create(data) {
33
- const { id, type } = data;
34
- Assertion_1.Assertion.assertString(id);
35
- Assertion_1.Assertion.assertString(type);
36
- const route = this.baseUrl;
37
- const payload = { id, type };
38
- const response = await this.rest.request({
39
- method: "POST",
40
- url: route,
41
- payload,
42
- });
43
- const channel = this.set(response);
44
- this.rest.emit("channelCreate", channel);
45
- return channel;
46
- }
47
- async createMany(...channels) {
48
- Assertion_1.Assertion.assertArray(channels);
49
- const route = Routes_1.Routes.fields(this.baseUrl, "bulk");
50
- const payload = { channels };
51
- const response = await this.rest.request({
52
- method: "POST",
53
- url: route,
54
- payload,
55
- });
56
- this.rest.emit("channelBulkCreate", response);
57
- return this.setAll(response);
58
- }
59
- async deleteMany(...channels) {
60
- Assertion_1.Assertion.assertArray(channels);
61
- const route = Routes_1.Routes.fields(this.baseUrl, "bulk");
62
- const payload = { channels };
63
- const response = await this.rest.request({
64
- method: "DELETE",
65
- url: route,
66
- payload,
67
- });
68
- const channel = this.setAll(response);
69
- this.rest.emit("channelBulkDelete", channel);
70
- return channel;
71
- }
72
- setAll(data) {
73
- if (!data)
74
- return this.cache;
75
- for (let channelData of data)
76
- this.set(channelData);
77
- return this.cache;
78
- }
79
- set(data) {
80
- if (!data?.type)
81
- return;
82
- const channel = new Channel_1.Channel({
83
- baseUrl: Routes_1.Routes.guilds[this.structure.key].resource(this.guild.id, this.structure._id, "channels"),
84
- data: data,
85
- guild: this.guild,
86
- manager: this,
87
- }, this.rest);
88
- this.cache.set(data.type, channel);
89
- return channel;
90
- }
91
- async update(type, payload) {
92
- Assertion_1.Assertion.assertString(type);
93
- Assertion_1.Assertion.assertObject(payload);
94
- const route = Routes_1.Routes.fields(this.baseUrl, type);
95
- const response = await this.rest.request({
96
- method: "PATCH",
97
- url: route,
98
- payload,
99
- });
100
- const channel = this.set(response);
101
- this.rest.emit("betUpdate", this.structure, this.structure);
102
- return channel;
103
- }
104
- async fetch(type) {
105
- Assertion_1.Assertion.assertString(type);
106
- const route = Routes_1.Routes.fields(this.baseUrl, type);
107
- const response = await this.rest.request({
108
- method: "GET",
109
- url: route,
110
- });
111
- const channel = this.set(response);
112
- this.cache.set(channel.type, channel);
113
- return channel;
114
- }
115
- async fetchAll() {
116
- const response = await this.rest.request({
117
- method: "GET",
118
- url: this.baseUrl,
119
- });
120
- if (Array.isArray(response) && response.length === 0) {
121
- this.cache.clear();
122
- return this.cache;
123
- }
124
- for (let channelData of response)
125
- this.set(channelData);
126
- return this.cache;
127
- }
128
- async delete(type) {
129
- Assertion_1.Assertion.assertString(type);
130
- const route = this.baseUrl;
131
- const response = await this.rest.request({
132
- method: "DELETE",
133
- url: Routes_1.Routes.fields(route, type),
134
- });
135
- this.cache.delete(type);
136
- return this.cache;
137
- }
138
- async deleteAll() {
139
- const route = this.baseUrl;
140
- const value = await this.rest.request({
141
- method: "DELETE",
142
- url: route,
143
- });
144
- this.cache.clear();
145
- return value;
146
- }
147
- }
148
- exports.ChannelManager = ChannelManager;
@@ -1,16 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { Collection } from "../../structures/Collection";
3
- import { Giveaway } from "../../structures/giveaway/Giveaway";
4
- import { Optional } from "../../types";
5
- import { APIGiveaway } from "../../types/api/APIGiveaway";
6
- type AllowedTypes = Optional<APIGiveaway> | Giveaway | Giveaway[] | Optional<APIGiveaway>[];
7
- export declare class GiveawayManager {
8
- cache: Collection<String, Giveaway>;
9
- readonly rest: REST;
10
- constructor(rest: REST);
11
- fetchAll(): Promise<Collection<String, Giveaway>>;
12
- create(data: Optional<APIGiveaway>): Promise<Giveaway>;
13
- deleteAll(): Promise<Collection<String, Giveaway>>;
14
- set(data: AllowedTypes): void;
15
- }
16
- export {};
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GiveawayManager = void 0;
4
- const Routes_1 = require("../../rest/Routes");
5
- const Collection_1 = require("../../structures/Collection");
6
- const Giveaway_1 = require("../../structures/giveaway/Giveaway");
7
- class GiveawayManager {
8
- cache;
9
- rest;
10
- constructor(rest) {
11
- this.rest = rest;
12
- this.cache = new Collection_1.Collection("giveaways");
13
- }
14
- async fetchAll() {
15
- const route = Routes_1.Routes.giveaways.getAll();
16
- const response = await this.rest.request({
17
- method: "get",
18
- url: route,
19
- });
20
- this.set(response);
21
- return this.cache;
22
- }
23
- async create(data) {
24
- const route = Routes_1.Routes.giveaways.create();
25
- const payload = data;
26
- const response = await this.rest.request({
27
- method: "post",
28
- url: route,
29
- payload,
30
- });
31
- const giveaway = new Giveaway_1.Giveaway(response, this);
32
- this.set(giveaway);
33
- return giveaway;
34
- }
35
- async deleteAll() {
36
- const route = Routes_1.Routes.giveaways.deleteAll();
37
- const response = await this.rest.request({
38
- method: "delete",
39
- url: route,
40
- });
41
- this.cache.clear();
42
- return this.cache;
43
- }
44
- set(data) {
45
- if (Array.isArray(data)) {
46
- for (let giv of data) {
47
- giv = new Giveaway_1.Giveaway(giv, this);
48
- this.cache.set(giv._id, giv);
49
- }
50
- }
51
- else {
52
- data = new Giveaway_1.Giveaway(data, this);
53
- this.cache.set(data._id, data);
54
- }
55
- }
56
- }
57
- exports.GiveawayManager = GiveawayManager;
@@ -1,34 +0,0 @@
1
- import { REST } from "../../rest/REST";
2
- import { GroupedChannel } from "../../structures/groupedchannel/GroupedChannel";
3
- import { Collection } from "../../structures/Collection";
4
- import { Guild } from "../../structures/guild/Guild";
5
- import { Optional } from "../../types/api";
6
- import { APIGuildGroupedChannel } from "../../types/api/APIGuildGroupedChannel";
7
- export declare class GroupedChannelManager {
8
- /** A cache of channels */
9
- cache: Collection<string, GroupedChannel>;
10
- /** Key */
11
- key: string;
12
- baseUrl: string;
13
- /** The rest client */
14
- rest: REST;
15
- /** GroupedChannel groupedChannel guild */
16
- guild: Guild;
17
- /**
18
- * Manage channels with the given client
19
- * @param channels An array of channels
20
- * @param rest The rest client
21
- */
22
- constructor(guild: Guild, key: string, rest: REST);
23
- delete(type: string): Promise<boolean>;
24
- create(payload: Optional<APIGuildGroupedChannel>): Promise<GroupedChannel>;
25
- /**
26
- * Fetch a groupedChannel
27
- * @param id Id of the groupedChannel to fetch
28
- * @returns APIgroupedChannelUser
29
- */
30
- fetch(type: string): Promise<GroupedChannel>;
31
- fetchAll(): Promise<Collection<string, GroupedChannel>>;
32
- setAll(data: APIGuildGroupedChannel[]): Collection<string, GroupedChannel>;
33
- set(data: APIGuildGroupedChannel): GroupedChannel;
34
- }