From fc14edc47b72d822dd3d1c193eb5472f2d837d3c Mon Sep 17 00:00:00 2001 From: Faf4a Date: Mon, 9 Oct 2023 23:03:40 +0200 Subject: [PATCH 1/8] fix: arrayshuffle --- src/functions/array/arrayShuffle.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/functions/array/arrayShuffle.js b/src/functions/array/arrayShuffle.js index f21c5ee9c..4956fa10b 100644 --- a/src/functions/array/arrayShuffle.js +++ b/src/functions/array/arrayShuffle.js @@ -3,7 +3,13 @@ module.exports = async d => { if (data.err) return d.error(data.err); const [name] = data.inside.splits; - d.arrays[name] = d.util.shuffleArray(d.arrays[name]); + const array = d.arrays[name]; + + for (let i = array.length - 1; i > 0; i--) { + const u = Math.floor(Math.random() * (i + 1)); + [array[i], array[u]] = [array[u], array[i]]; + } + d.data.arrays = d.arrays; return { @@ -11,4 +17,4 @@ module.exports = async d => { arrays: d.arrays, data: d.data, } -} \ No newline at end of file +} From 3b35de8bf736eff4a3ab66b25f0ae9643a4cfa3d Mon Sep 17 00:00:00 2001 From: Faf4a Date: Sat, 21 Oct 2023 09:04:55 +0200 Subject: [PATCH 2/8] fix: improve clear function --- src/functions/interaction/clear.js | 128 +++++++++++++++++------------ 1 file changed, 75 insertions(+), 53 deletions(-) diff --git a/src/functions/interaction/clear.js b/src/functions/interaction/clear.js index 0983725d1..e748354f1 100644 --- a/src/functions/interaction/clear.js +++ b/src/functions/interaction/clear.js @@ -1,56 +1,78 @@ module.exports = async (d) => { - const {code} = d.command; - const inside = d.unpack(); - const err = d.inside(inside); - if (err) return d.error(err); - - let [amt, filter = "everyone", returnCount = "false", channelID = d.channel.id] = - inside.splits; - - amt = Number(amt); - if (isNaN(amt)) - return d.aoiError.fnError( - d, - "custom", - {inside}, - "Invalid Amout Provided In", - ); - - const channel = await d.util.getChannel(d, channelID); - if (!channel) return d.aoiError.fnError(d, "channel", {inside}); - - let messages = await channel.messages - .fetch({limit: 100, cache: false}) - .catch((err) => { - d.aoiError.fnError( - d, - "custom", - {}, - "Failed To Fetch Messages With Reason: " + err, - ); - }); - - messages = [...messages.filter((x) => - filter === "everyone" - ? true - : filter === "unPins" - ? !x.pinned - : filter === "bot" - ? x.author?.bot - : x.author?.id === filter, - ).values()].slice(0, amt); - - let result = await channel.bulkDelete(messages, true).catch((err) => { - d.aoiError.fnError( - d, - "custom", - {}, - "Failed To Delete Message With Reason: " + err, - ); + const data = d.util.aoiFunc(d); + const { code } = d.command; + if (data.err) return d.error(data.err); + + let [ + channelID = d.channel.id, + amount, + filters = "everyone", + returnCount = false, + ] = data.inside.splits; + + if (isNaN(amount)) + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "Amount Provided In" + ); + amount = +amount + 1; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) + return d.aoiError.fnError(d, "channel", { inside: data.inside }); + + let messages = await channel.messages + .fetch({ limit: 100, cache: false }) + .catch((err) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Fetch Messages With Reason: " + err + ); }); - result = returnCount === "true" ? result.size : undefined; - return { - code: d.util.setCode({function: d.func, code, inside, result}), - }; -}; \ No newline at end of file + filters = filters.toLowerCase().split(","); + + messages = [...messages.values()] + .filter((x) => { + if (filters.includes("everyone")) return true; + if (filters.includes("notpinned") && x.pinned) return false; + if (filters.includes("bots") && x.author?.bot) return true; + if ( + filters.some( + (filter) => + filter.startsWith("user:") && x.author?.id === filter.split(":")[1] + ) + ) + return true; + return false; + }) + .slice(0, amount); + + if (!messages.length) { + messages = [...messages.values()].slice(0, amount); + } + + let result = await channel.bulkDelete(messages, true).catch((err) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Delete Message With Reason: " + err + ); + }); + + result = returnCount === true ? result.size : undefined; + + return { + code: d.util.setCode({ + function: d.func, + code, + inside: data.inside, + result, + }), + }; +}; From 5f02679097328ce9aab9fae9ae062b11f8149eb6 Mon Sep 17 00:00:00 2001 From: Faf4a Date: Sat, 21 Oct 2023 09:05:08 +0200 Subject: [PATCH 3/8] fix: invalid usage of data --- src/functions/interaction/killShard.js | 2 +- src/functions/interaction/spawnShard.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions/interaction/killShard.js b/src/functions/interaction/killShard.js index 1d2749a1b..cf41f4392 100644 --- a/src/functions/interaction/killShard.js +++ b/src/functions/interaction/killShard.js @@ -2,7 +2,7 @@ module.exports = async d => { const data = d.util.aoiFunc(d); if (data.err) return d.error(data.err); - const shardId = data.inside.inside; + const [shardId = 0] = data.inside.splits; await d.client.shard.broadcastEval(c => { if (c.shard.ids.includes(Number(shardId))) process.exit(); diff --git a/src/functions/interaction/spawnShard.js b/src/functions/interaction/spawnShard.js index d4a45fab6..0be32f158 100644 --- a/src/functions/interaction/spawnShard.js +++ b/src/functions/interaction/spawnShard.js @@ -2,7 +2,7 @@ module.exports = async d => { const data = d.util.aoiFunc(d); if (data.err) return d.error(data.err); - const shardId = data.inside.inside; + const [shardId = 0] = data.inside.splits; await d.client.shard.broadcastEval(c => { if (c.shard.ids.includes(Number(shardId))) c.spawn(); From 1614826ed4434dc22c5d4943d7566eb9e09f4b28 Mon Sep 17 00:00:00 2001 From: Faf4a Date: Sat, 21 Oct 2023 09:07:35 +0200 Subject: [PATCH 4/8] fix: userId not working --- src/functions/user/userID.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/user/userID.js b/src/functions/user/userID.js index f1f67d441..048c78cff 100644 --- a/src/functions/user/userID.js +++ b/src/functions/user/userID.js @@ -7,7 +7,7 @@ module.exports = async d => { const res = d.client.users.cache.findKey(x => x.username.toLowerCase() === user.addBrackets().toLowerCase()); if (!res) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid User Provided In'); - data.result = res.id; + data.result = res; return { code: d.util.setCode(data) From b55a541575ea173e67d3438623eded0170c88094 Mon Sep 17 00:00:00 2001 From: Faf4a Date: Thu, 26 Oct 2023 17:46:54 +0200 Subject: [PATCH 5/8] feat: ability to count characters --- src/functions/util/charCount.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/functions/util/charCount.js b/src/functions/util/charCount.js index 6e2f13d6b..80b133930 100644 --- a/src/functions/util/charCount.js +++ b/src/functions/util/charCount.js @@ -1,11 +1,12 @@ -module.exports = async d => { - const data = d.util.aoiFunc(d); +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const [text, find] = data.inside.splits; - const [text = d.args.join(" ")] = data.inside.splits; + data.result = find + ? (text.split(find).length - 1) * find.length + : text.length; - data.result = text.addBrackets().length - - return { - code: d.util.setCode(data) - } -} \ No newline at end of file + return { + code: d.util.setCode(data), + }; +}; From cb45d61249d4a2e58f0860e994ceb05d6add7baa Mon Sep 17 00:00:00 2001 From: Faf4a Date: Thu, 26 Oct 2023 17:57:16 +0200 Subject: [PATCH 6/8] feat: findGuild(resolve) --- src/functions/guild/findGuild.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/functions/guild/findGuild.js diff --git a/src/functions/guild/findGuild.js b/src/functions/guild/findGuild.js new file mode 100644 index 000000000..0b12e7519 --- /dev/null +++ b/src/functions/guild/findGuild.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [resolve] = data.inside.splits; + + const guild = d.client.guilds.cache.get(resolve) || d.client.guilds.cache.find(g => g.name.toLowerCase() === resolve.toLowerCase()); + + data.result = guild ? guild.id : undefined; + + return { + code: d.util.setCode(data) + } +} From 7ae52567c4d5ec31f3b905a1ebe668031facf15a Mon Sep 17 00:00:00 2001 From: Faf4a <87046111+Faf4a@users.noreply.github.com> Date: Sat, 4 Nov 2023 08:52:24 +0000 Subject: [PATCH 7/8] fix spacing --- src/functions/interaction/clear.js | 35 +++++------------------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/src/functions/interaction/clear.js b/src/functions/interaction/clear.js index e748354f1..3803081bd 100644 --- a/src/functions/interaction/clear.js +++ b/src/functions/interaction/clear.js @@ -3,20 +3,10 @@ module.exports = async (d) => { const { code } = d.command; if (data.err) return d.error(data.err); - let [ - channelID = d.channel.id, - amount, - filters = "everyone", - returnCount = false, - ] = data.inside.splits; + let [channelID = d.channel.id, amount, filters = "everyone", returnCount = false ] = data.inside.splits; if (isNaN(amount)) - return d.aoiError.fnError( - d, - "custom", - { inside: data.inside }, - "Amount Provided In" - ); + return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Amount Provided In" ); amount = +amount + 1; const channel = await d.util.getChannel(d, channelID); @@ -26,12 +16,7 @@ module.exports = async (d) => { let messages = await channel.messages .fetch({ limit: 100, cache: false }) .catch((err) => { - d.aoiError.fnError( - d, - "custom", - {}, - "Failed To Fetch Messages With Reason: " + err - ); + d.aoiError.fnError(d, "custom", {}, "Failed To Fetch Messages With Reason: " + err); }); filters = filters.toLowerCase().split(","); @@ -57,22 +42,12 @@ module.exports = async (d) => { } let result = await channel.bulkDelete(messages, true).catch((err) => { - d.aoiError.fnError( - d, - "custom", - {}, - "Failed To Delete Message With Reason: " + err - ); + d.aoiError.fnError(d, "custom" ,{}, "Failed To Delete Message With Reason: " + err); }); result = returnCount === true ? result.size : undefined; return { - code: d.util.setCode({ - function: d.func, - code, - inside: data.inside, - result, - }), + code: d.util.setCode({ function: d.func, code, inside: data.inside, result }), }; }; From 4599f0495f34946b82dc42214aca3bed8e6f36bd Mon Sep 17 00:00:00 2001 From: Faf4a <87046111+Faf4a@users.noreply.github.com> Date: Sat, 4 Nov 2023 13:43:25 +0000 Subject: [PATCH 8/8] feat: slightly improve customboxedmessage component --- src/utils/CustomBox.js | 66 ++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/src/utils/CustomBox.js b/src/utils/CustomBox.js index 8551b10d0..d5dd2b3b5 100644 --- a/src/utils/CustomBox.js +++ b/src/utils/CustomBox.js @@ -1,33 +1,43 @@ const chalk = require('chalk'); -function createCustomBoxedMessage(messages, borderColor = 'yellow', title = null) { - if (!Array.isArray(messages)) { - messages = [messages]; - } - - const maxLength = title - ? Math.max(...messages.map(msg => msg.text.length), title.text.length) - : Math.max(...messages.map(msg => msg.text.length)); - - const topBorder = chalk[borderColor](`╭${'─'.repeat(maxLength + 2)}╮`); - const bottomBorder = chalk[borderColor](`╰${'─'.repeat(maxLength + 2)}╯`); - - console.log(topBorder); - - if (title) { - const titlePadding = ' '.repeat((maxLength - title.text.length) / 2); - const titleText = `${chalk[borderColor]('│')} ${titlePadding}${chalk[title.textColor](title.text)}${titlePadding} ${chalk[borderColor]('│')}`; - console.log(titleText); - } - - messages.forEach((message, index) => { - const padding = ' '.repeat(maxLength - message.text.length); - const textColor = message.textColor || 'reset'; // Default to reset color if not specified - const messageText = `${chalk[borderColor]('│')} ${chalk[textColor](message.text)}${padding} ${chalk[borderColor]('│')}`; - console.log(messageText); - }); - - console.log(bottomBorder); +function createCustomBoxedMessage( + messages, + borderColor = "yellow", + title = null +) { + if (!Array.isArray(messages)) { + messages = [messages]; + } + + const maxLength = title + ? Math.max(...messages.map((msg) => msg.text.length), title.text.length) + : Math.max(...messages.map((msg) => msg.text.length)); + + const topBorder = chalk[borderColor](`╭${"─".repeat(maxLength + 2)}╮`); + const bottomBorder = chalk[borderColor](`╰${"─".repeat(maxLength + 2)}╯`); + + console.log(topBorder); + + if (title) { + const titlePadding = " ".repeat((maxLength - title.text.length) / 2); + const titleText = `${chalk[borderColor]("│")} ${titlePadding}${chalk[ + title.textColor + ](title.text)}${titlePadding} ${chalk[borderColor]("│")}`; + console.log(titleText); + } + + messages.forEach((message, index) => { + const paddingLength = (maxLength - message.text.length) / 2; + const leftPadding = " ".repeat(Math.floor(paddingLength)); + const rightPadding = " ".repeat(Math.ceil(paddingLength)); + const textColor = message.textColor || "reset"; + const messageText = `${chalk[borderColor]("│")} ${leftPadding}${chalk[ + textColor + ](message.text)}${rightPadding} ${chalk[borderColor]("│")}`; + console.log(messageText); + }); + + console.log(bottomBorder); } module.exports = createCustomBoxedMessage;