Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug fix] some stuff #491

Merged
merged 11 commits into from
Nov 20, 2023
10 changes: 8 additions & 2 deletions src/functions/array/arrayShuffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ 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 {
code: d.util.setCode(data),
arrays: d.arrays,
data: d.data,
}
}
}
14 changes: 14 additions & 0 deletions src/functions/guild/findGuild.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
103 changes: 50 additions & 53 deletions src/functions/interaction/clear.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,53 @@
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}),
};
};
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) =>
Faf4a marked this conversation as resolved.
Show resolved Hide resolved
Faf4a marked this conversation as resolved.
Show resolved Hide resolved
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 }),
};
};
2 changes: 1 addition & 1 deletion src/functions/interaction/killShard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/functions/interaction/spawnShard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/functions/user/userID.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 10 additions & 9 deletions src/functions/util/charCount.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
return {
code: d.util.setCode(data),
};
};
66 changes: 38 additions & 28 deletions src/utils/CustomBox.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
const chalk = require('chalk');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably should be moved entirely in util helpers or in another class of Utils so able to be exported.


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;
Loading