djs-builder 0.5.42 → 0.6.1

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 (156) hide show
  1. package/README.md +161 -339
  2. package/function/function.js +236 -0
  3. package/function/log.js +736 -0
  4. package/handler/helper.js +277 -0
  5. package/handler/starter.js +335 -0
  6. package/package.json +10 -42
  7. package/.tsbuildinfo +0 -1
  8. package/dist/discord/builder/components/Buttons.d.ts +0 -22
  9. package/dist/discord/builder/components/Buttons.d.ts.map +0 -1
  10. package/dist/discord/builder/components/Buttons.js +0 -91
  11. package/dist/discord/builder/components/Buttons.js.map +0 -1
  12. package/dist/discord/builder/components/Menus.d.ts +0 -31
  13. package/dist/discord/builder/components/Menus.d.ts.map +0 -1
  14. package/dist/discord/builder/components/Menus.js +0 -82
  15. package/dist/discord/builder/components/Menus.js.map +0 -1
  16. package/dist/discord/builder/permissions/perms.d.ts +0 -6
  17. package/dist/discord/builder/permissions/perms.d.ts.map +0 -1
  18. package/dist/discord/builder/permissions/perms.js +0 -66
  19. package/dist/discord/builder/permissions/perms.js.map +0 -1
  20. package/dist/discord/builder/system/Pagination.d.ts +0 -68
  21. package/dist/discord/builder/system/Pagination.d.ts.map +0 -1
  22. package/dist/discord/builder/system/Pagination.js +0 -256
  23. package/dist/discord/builder/system/Pagination.js.map +0 -1
  24. package/dist/discord/builder/system/collectors.d.ts +0 -27
  25. package/dist/discord/builder/system/collectors.d.ts.map +0 -1
  26. package/dist/discord/builder/system/collectors.js +0 -137
  27. package/dist/discord/builder/system/collectors.js.map +0 -1
  28. package/dist/discord/builder/utils.d.ts +0 -5
  29. package/dist/discord/builder/utils.d.ts.map +0 -1
  30. package/dist/discord/builder/utils.js +0 -10
  31. package/dist/discord/builder/utils.js.map +0 -1
  32. package/dist/discord/events-handler/eventLoader.d.ts +0 -13
  33. package/dist/discord/events-handler/eventLoader.d.ts.map +0 -1
  34. package/dist/discord/events-handler/eventLoader.js +0 -169
  35. package/dist/discord/events-handler/eventLoader.js.map +0 -1
  36. package/dist/discord/events-handler/events.d.ts +0 -8
  37. package/dist/discord/events-handler/events.d.ts.map +0 -1
  38. package/dist/discord/events-handler/events.js +0 -186
  39. package/dist/discord/events-handler/events.js.map +0 -1
  40. package/dist/discord/events-handler/login.d.ts +0 -9
  41. package/dist/discord/events-handler/login.d.ts.map +0 -1
  42. package/dist/discord/events-handler/login.js +0 -273
  43. package/dist/discord/events-handler/login.js.map +0 -1
  44. package/dist/discord/events-handler/prefix-register.d.ts +0 -23
  45. package/dist/discord/events-handler/prefix-register.d.ts.map +0 -1
  46. package/dist/discord/events-handler/prefix-register.js +0 -109
  47. package/dist/discord/events-handler/prefix-register.js.map +0 -1
  48. package/dist/discord/events-handler/prefix-responder.d.ts +0 -5
  49. package/dist/discord/events-handler/prefix-responder.d.ts.map +0 -1
  50. package/dist/discord/events-handler/prefix-responder.js +0 -155
  51. package/dist/discord/events-handler/prefix-responder.js.map +0 -1
  52. package/dist/discord/events-handler/prefixLoader.d.ts +0 -7
  53. package/dist/discord/events-handler/prefixLoader.d.ts.map +0 -1
  54. package/dist/discord/events-handler/prefixLoader.js +0 -74
  55. package/dist/discord/events-handler/prefixLoader.js.map +0 -1
  56. package/dist/discord/events-handler/slash-register.d.ts +0 -4
  57. package/dist/discord/events-handler/slash-register.d.ts.map +0 -1
  58. package/dist/discord/events-handler/slash-register.js +0 -85
  59. package/dist/discord/events-handler/slash-register.js.map +0 -1
  60. package/dist/discord/events-handler/slash-responder.d.ts +0 -3
  61. package/dist/discord/events-handler/slash-responder.d.ts.map +0 -1
  62. package/dist/discord/events-handler/slash-responder.js +0 -112
  63. package/dist/discord/events-handler/slash-responder.js.map +0 -1
  64. package/dist/discord/events-handler/slashLoader.d.ts +0 -7
  65. package/dist/discord/events-handler/slashLoader.d.ts.map +0 -1
  66. package/dist/discord/events-handler/slashLoader.js +0 -94
  67. package/dist/discord/events-handler/slashLoader.js.map +0 -1
  68. package/dist/discord/events-handler/starter.d.ts +0 -6
  69. package/dist/discord/events-handler/starter.d.ts.map +0 -1
  70. package/dist/discord/events-handler/starter.js +0 -85
  71. package/dist/discord/events-handler/starter.js.map +0 -1
  72. package/dist/discord/functions/anticrash.d.ts +0 -3
  73. package/dist/discord/functions/anticrash.d.ts.map +0 -1
  74. package/dist/discord/functions/anticrash.js +0 -55
  75. package/dist/discord/functions/anticrash.js.map +0 -1
  76. package/dist/discord/functions/devLogs.d.ts +0 -2
  77. package/dist/discord/functions/devLogs.d.ts.map +0 -1
  78. package/dist/discord/functions/devLogs.js +0 -137
  79. package/dist/discord/functions/devLogs.js.map +0 -1
  80. package/dist/discord/functions/logger.d.ts +0 -5
  81. package/dist/discord/functions/logger.d.ts.map +0 -1
  82. package/dist/discord/functions/logger.js +0 -57
  83. package/dist/discord/functions/logger.js.map +0 -1
  84. package/dist/discord/functions/mongoDb.d.ts +0 -4
  85. package/dist/discord/functions/mongoDb.d.ts.map +0 -1
  86. package/dist/discord/functions/mongoDb.js +0 -39
  87. package/dist/discord/functions/mongoDb.js.map +0 -1
  88. package/dist/discord/functions/similarity.d.ts +0 -3
  89. package/dist/discord/functions/similarity.d.ts.map +0 -1
  90. package/dist/discord/functions/similarity.js +0 -56
  91. package/dist/discord/functions/similarity.js.map +0 -1
  92. package/dist/discord/functions/terminal.d.ts +0 -2
  93. package/dist/discord/functions/terminal.d.ts.map +0 -1
  94. package/dist/discord/functions/terminal.js +0 -127
  95. package/dist/discord/functions/terminal.js.map +0 -1
  96. package/dist/discord/functions/utils.d.ts +0 -5
  97. package/dist/discord/functions/utils.d.ts.map +0 -1
  98. package/dist/discord/functions/utils.js +0 -11
  99. package/dist/discord/functions/utils.js.map +0 -1
  100. package/dist/discord/functions/versedb.d.ts +0 -3
  101. package/dist/discord/functions/versedb.d.ts.map +0 -1
  102. package/dist/discord/functions/versedb.js +0 -21
  103. package/dist/discord/functions/versedb.js.map +0 -1
  104. package/dist/discord/games/X-O.d.ts +0 -20
  105. package/dist/discord/games/X-O.d.ts.map +0 -1
  106. package/dist/discord/games/X-O.js +0 -166
  107. package/dist/discord/games/X-O.js.map +0 -1
  108. package/dist/discord/games/rps.d.ts +0 -21
  109. package/dist/discord/games/rps.d.ts.map +0 -1
  110. package/dist/discord/games/rps.js +0 -99
  111. package/dist/discord/games/rps.js.map +0 -1
  112. package/dist/discord/types/starter.d.ts +0 -144
  113. package/dist/discord/types/starter.d.ts.map +0 -1
  114. package/dist/discord/types/starter.js +0 -3
  115. package/dist/discord/types/starter.js.map +0 -1
  116. package/dist/discord/types/utils.d.ts +0 -3
  117. package/dist/discord/types/utils.d.ts.map +0 -1
  118. package/dist/discord/types/utils.js +0 -3
  119. package/dist/discord/types/utils.js.map +0 -1
  120. package/dist/discord/utils.d.ts +0 -15
  121. package/dist/discord/utils.d.ts.map +0 -1
  122. package/dist/discord/utils.js +0 -41
  123. package/dist/discord/utils.js.map +0 -1
  124. package/dist/index.d.ts +0 -4
  125. package/dist/index.d.ts.map +0 -1
  126. package/dist/index.js +0 -71
  127. package/dist/index.js.map +0 -1
  128. package/lib/discord/builder/components/Buttons.ts +0 -123
  129. package/lib/discord/builder/components/Menus.ts +0 -106
  130. package/lib/discord/builder/permissions/perms.ts +0 -66
  131. package/lib/discord/builder/system/Pagination.ts +0 -374
  132. package/lib/discord/builder/system/collectors.ts +0 -197
  133. package/lib/discord/builder/utils.ts +0 -9
  134. package/lib/discord/events-handler/eventLoader.ts +0 -166
  135. package/lib/discord/events-handler/events.ts +0 -160
  136. package/lib/discord/events-handler/login.ts +0 -265
  137. package/lib/discord/events-handler/prefix-register.ts +0 -117
  138. package/lib/discord/events-handler/prefix-responder.ts +0 -176
  139. package/lib/discord/events-handler/prefixLoader.ts +0 -83
  140. package/lib/discord/events-handler/slash-register.ts +0 -81
  141. package/lib/discord/events-handler/slash-responder.ts +0 -136
  142. package/lib/discord/events-handler/slashLoader.ts +0 -104
  143. package/lib/discord/events-handler/starter.ts +0 -85
  144. package/lib/discord/functions/anticrash.ts +0 -60
  145. package/lib/discord/functions/devLogs.ts +0 -128
  146. package/lib/discord/functions/logger.ts +0 -58
  147. package/lib/discord/functions/mongoDb.ts +0 -38
  148. package/lib/discord/functions/similarity.ts +0 -70
  149. package/lib/discord/functions/terminal.ts +0 -162
  150. package/lib/discord/functions/utils.ts +0 -4
  151. package/lib/discord/functions/versedb.ts +0 -17
  152. package/lib/discord/types/starter.ts +0 -158
  153. package/lib/discord/types/utils.ts +0 -2
  154. package/lib/discord/utils.ts +0 -17
  155. package/lib/index.ts +0 -37
  156. package/tsconfig.json +0 -21
@@ -0,0 +1,236 @@
1
+ const {
2
+ ChannelSelectMenuBuilder,
3
+ StringSelectMenuBuilder,
4
+ RoleSelectMenuBuilder,
5
+ UserSelectMenuBuilder,
6
+ ActionRowBuilder,
7
+ ButtonBuilder,
8
+ WebhookClient,
9
+ } = require("discord.js");
10
+
11
+ const axios = require("axios");
12
+
13
+ //////////////////////////////////* Bar 🔄
14
+
15
+ function CreateBar(progress, max, options = {}) {
16
+ const {
17
+ length = 20,
18
+ fill = "█",
19
+ empty = "░",
20
+ showPercent = true,
21
+ left = "[",
22
+ right = "]",
23
+ partialChar = "",
24
+ } = options;
25
+
26
+ max = Math.max(max, 1);
27
+ progress = Math.min(Math.max(progress, 0), max);
28
+
29
+ const ratio = progress / max;
30
+ const exactFilled = ratio * length;
31
+ const filledLength = Math.floor(exactFilled);
32
+ const partial = exactFilled % 1;
33
+
34
+ let bar = left;
35
+
36
+ bar += fill.repeat(filledLength);
37
+
38
+ if (partial > 0 && filledLength < length) {
39
+ bar += partialChar || (partial < 0.25 ? empty : partial < 0.75 ? "▒" : "▓");
40
+ }
41
+
42
+ const remaining = length - filledLength - (partial > 0 ? 1 : 0);
43
+ bar += empty.repeat(Math.max(remaining, 0));
44
+
45
+ bar += right;
46
+
47
+ const percent = (ratio * 100).toFixed(2).replace(/\.?0+$/, "") + "%";
48
+ return showPercent ? `${bar} ${percent}` : bar;
49
+ }
50
+
51
+ //////////////////////////////////* Wait 🕒
52
+
53
+ async function Wait({
54
+ context,
55
+ userId = null,
56
+ type = "both",
57
+ time = 60000,
58
+ message_Wait = null,
59
+ }) {
60
+ const channel = context.channel;
61
+ if (!channel) throw new Error("context must contain a valid channel.");
62
+
63
+ if (type === "message") {
64
+ const collected = await channel.awaitMessages({
65
+ filter: (m) => !userId || m.author.id === userId,
66
+ time,
67
+ max: 1,
68
+ });
69
+ return collected.first() || null;
70
+ }
71
+
72
+ if (type === "button") {
73
+ const message = message_Wait;
74
+ if (!message)
75
+ throw new Error(
76
+ "You must provide messageWithButtons when using type 'button'."
77
+ );
78
+
79
+ const collected = await message.awaitMessageComponent({
80
+ filter: (i) => !userId || i.user.id === userId,
81
+ time,
82
+ });
83
+ if (!collected) return null;
84
+
85
+ return collected;
86
+ }
87
+
88
+ if (type === "both") {
89
+ if (!message_Wait)
90
+ throw new Error(
91
+ "You must provide messageWithButtons when using type 'both'."
92
+ );
93
+
94
+ return new Promise((resolve) => {
95
+ const collectors = [];
96
+
97
+ const msgCollector = channel.createMessageCollector({
98
+ filter: (m) => !userId || m.author.id === userId,
99
+ max: 1,
100
+ time,
101
+ });
102
+
103
+ msgCollector.on("collect", (msg) => {
104
+ stop();
105
+ resolve({ type: "message", data: msg });
106
+ });
107
+ collectors.push(msgCollector);
108
+
109
+ const btnCollector = messageWithButtons.createMessageComponentCollector({
110
+ filter: (i) => !userId || i.user.id === userId,
111
+ max: 1,
112
+ time,
113
+ });
114
+
115
+ btnCollector.on("collect", async (i) => {
116
+ stop();
117
+ resolve({ type: "button", data: i });
118
+ });
119
+ collectors.push(btnCollector);
120
+
121
+ const timer = setTimeout(() => {
122
+ stop();
123
+ resolve(null);
124
+ }, time);
125
+
126
+ function stop() {
127
+ collectors.forEach((c) => c.stop());
128
+ clearTimeout(timer);
129
+ }
130
+ });
131
+ }
132
+
133
+ return null;
134
+ }
135
+
136
+ //////////////////////////////////* Row creat 🔩
137
+
138
+ function CreateRow(components) {
139
+ if (!Array.isArray(components)) {
140
+ throw new Error("Components should be an array.");
141
+ }
142
+
143
+ const actionRows = [];
144
+ components.forEach((component) => {
145
+ if (!component.type) {
146
+ const buttons = component.map((config) => {
147
+ let buttonConfig;
148
+ if (typeof config === "object") {
149
+ buttonConfig = config;
150
+ }
151
+
152
+ const but = new ButtonBuilder()
153
+ .setCustomId(buttonConfig.id)
154
+ .setStyle(buttonConfig.style || 2);
155
+
156
+ if (buttonConfig.emoji) {
157
+ but.setEmoji(buttonConfig.emoji);
158
+ }
159
+ if (buttonConfig.label) {
160
+ but.setLabel(buttonConfig.label);
161
+ }
162
+ if (buttonConfig.hasOwnProperty("disabled")) {
163
+ but.setDisabled(buttonConfig.disabled);
164
+ }
165
+
166
+ if(buttonConfig.style === 5 && buttonConfig.url) {
167
+ but.setURL(buttonConfig.url);
168
+ }
169
+
170
+ return but;
171
+ });
172
+ actionRows.push(new ActionRowBuilder().addComponents(buttons));
173
+ } else if (component.type) {
174
+ const { type, options } = component;
175
+ const {
176
+ placeholder = "Choose an option",
177
+ description = false,
178
+ data = false,
179
+ label = false,
180
+ emoji = false,
181
+ value = false,
182
+ id = false,
183
+ max = false,
184
+ min = false,
185
+ } = options;
186
+
187
+ const selectOptions = data.map((item, index) => {
188
+ return {
189
+ label: item[label] || `Option ${index + 1}`,
190
+ description: item[description]?.slice(0, 100) || undefined,
191
+ emoji: item[emoji] || undefined,
192
+ value: item[value] || `${index}`,
193
+ };
194
+ });
195
+
196
+ let selectMenu;
197
+ if (type === "string") {
198
+ selectMenu = new StringSelectMenuBuilder();
199
+ } else if (type === "user") {
200
+ selectMenu = new UserSelectMenuBuilder();
201
+ } else if (type === "role") {
202
+ selectMenu = new RoleSelectMenuBuilder();
203
+ } else if (type === "channel") {
204
+ selectMenu = new ChannelSelectMenuBuilder();
205
+ }
206
+
207
+
208
+ selectMenu.setCustomId(id || "selectMenu");
209
+ selectMenu.setPlaceholder(placeholder);
210
+ if (min) {
211
+ const minValue = Math.min(min, data.length);
212
+ selectMenu.setMinValues(minValue);
213
+ selectMenu.setMaxValues(data.length);
214
+ }
215
+
216
+ if(max) selectMenu.setMaxValues(max);
217
+
218
+
219
+ if (type === "string") {
220
+ selectMenu.addOptions(selectOptions);
221
+ }
222
+
223
+ actionRows.push(new ActionRowBuilder().addComponents(selectMenu));
224
+ } else {
225
+ throw new Error("Invalid component format");
226
+ }
227
+ });
228
+
229
+ return actionRows;
230
+ }
231
+
232
+
233
+
234
+
235
+
236
+ module.exports = { Wait, CreateBar, CreateRow };