Skip to content

Commit

Permalink
features & fixes (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
Faf4a authored Oct 12, 2024
1 parent 4cf95c0 commit 31ce419
Show file tree
Hide file tree
Showing 27 changed files with 698 additions and 628 deletions.
544 changes: 247 additions & 297 deletions src/classes/Util.js

Large diffs are not rendered by default.

303 changes: 157 additions & 146 deletions src/core/interpreter.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/events/GuildMessageReactions/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Interpreter = require("../../core/interpreter.js");
* @param {User} user
* @param {import('../../classes/AoiClient.js')} client
*/
module.exports = async (newReaction, user, client) => {
module.exports = async (newReaction, user, burst, client) => {
const cmds = client.cmd?.reactionAdd.V();
if (!cmds) return;
const data = {
Expand Down
2 changes: 1 addition & 1 deletion src/events/GuildMessageReactions/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { MessageReaction } = require("discord.js");
* @param {User} user
* @param {import('../../classes/AoiClient.js')} client
*/
module.exports = async (oldReaction, user, client) => {
module.exports = async (oldReaction, user, burst, client) => {
const cmds = client.cmd?.reactionRemove.V();
if (!cmds) return;
const data = {
Expand Down
2 changes: 1 addition & 1 deletion src/events/GuildMessageReactions/removeAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { Message } = require("discord.js");
* @param {Message} reactionMessage
* @param {import('../../classes/AoiClient.js')} client
*/
module.exports = async (reactionMessage, client) => {
module.exports = async (reactionMessage, burst, client) => {
const cmds = client.cmd?.reactionRemoveAll.V();
if (!cmds) return;
const data = {
Expand Down
2 changes: 1 addition & 1 deletion src/events/GuildMessageReactions/removeEmoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { MessageReaction } = require("discord.js");
* @param {User} user
* @param {import('../../classes/AoiClient.js')} client
*/
module.exports = async (oldReaction, client) => {
module.exports = async (oldReaction, burst, client) => {
const cmds = client.cmd?.reactionRemoveEmoji.V();
if (!cmds) return;
const data = {
Expand Down
17 changes: 7 additions & 10 deletions src/events/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,17 @@ const ComponentParser = async (message, d) => {
return part.join(":").trim();
}

try {
emoji = await d.util.getEmoji(d, part.toString());
emoji = await d.util.getEmoji(d, part.toString());
if (!emoji) {
emoji = part.toString().addBrackets().trim();
} else {
emoji = {
name: emoji.name,
id: emoji.id,
animated: emoji.animated
};
} catch {
emoji = part.toString();
emoji = emoji.addBrackets().trim() || undefined;
} finally {
if (!emoji) return null;
return emoji;
}
return emoji;
}

for (let content of actionRow) {
Expand Down Expand Up @@ -222,7 +219,7 @@ const ComponentParser = async (message, d) => {

if (button && Number(style) !== 6) {
const emoji = await extractEmoji(button, d);
buttonInner.emoji = emoji;
if (emoji) buttonInner.emoji = emoji;
}

actionRowInner.push(buttonInner);
Expand Down Expand Up @@ -270,7 +267,7 @@ const ComponentParser = async (message, d) => {

if (opt) {
const emoji = await extractEmoji(opt, d);
selectMenuInner.emoji = emoji;
if (emoji) selectMenuInner.emoji = emoji;
}

selectMenuOptions.push(selectMenuInner);
Expand Down
90 changes: 45 additions & 45 deletions src/functions/addButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@
* @param {import("..").Data} d
*/
module.exports = async (d) => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

let [index, label, style, custom, disabled = "false", emoji] = data.inside.splits;

if (isNaN(index) || Number(index) < 1) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Index Provided In");
index = Number(index) - 1;
style = isNaN(style) ? d.util.constants.ButtonStyleOptions[style] : Number(style);
disabled = disabled === "true";

if (!style || style > 6 || style < 1) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Style Provided In");
try {
emoji = d.util.getEmoji(d, emoji.addBrackets()).id;
} catch {
emoji = emoji?.addBrackets() ?? undefined;
}

const button = {
label,
type: 2,
style,
disabled,
emoji,
};

// premium
if (style === 6) {
delete button.label;
delete button.emoji;
button["sku_id"] = custom;
// url
} else if (style === 5) {
button["url"] = custom;
} else {
button["customId"] = custom;
}

if (!d.components[index]) d.components[index] = { type: 1, components: [] };
d.components[index].components.push(button);

return {
code: d.util.setCode(data),
};
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

let [index, label, style, custom, disabled = "false", emoji] = data.inside.splits;

if (isNaN(index) || Number(index) < 1) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Index Provided In");

index = Number(index) - 1;
style = isNaN(style) ? d.util.constants.ButtonStyleOptions[style] : Number(style);
disabled = disabled === "true";

if (!style || style > 6 || style < 1) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Style Provided In");

let emojiString;
if (emoji) {
emojiString = await d.util.getEmoji(d, emoji.addBrackets()).id;
if (!emojiString) emojiString = emoji?.addBrackets().trim();
}

const button = {
label,
type: 2,
style,
disabled,
emoji: emojiString
};

// premium
if (style === 6) {
delete button.label;
delete button.emoji;
button["sku_id"] = custom;
// url
} else if (style === 5) {
button["url"] = custom;
} else {
button["customId"] = custom;
}

if (!d.components[index]) d.components[index] = { type: 1, components: [] };
d.components[index].components.push(button);

return {
code: d.util.setCode(data)
};
};
7 changes: 2 additions & 5 deletions src/functions/addButtonTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ module.exports = async (d) => {

if (!style || style > 6 || style < 1) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Button Style Provided In");

try {
emoji = d.util.getEmoji(d, emoji.addBrackets()).id;
} catch {
emoji = emoji?.addBrackets() ?? undefined;
}
emoji = await d.util.getEmoji(d, emoji.addBrackets()).id;
if (!emoji) emoji = emoji.addBrackets().trim();

const button = {
label,
Expand Down
36 changes: 17 additions & 19 deletions src/functions/addClientReactions.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
const { GuildEmoji, ReactionEmoji } = require("discord.js");

/**
* @param {import("..").Data} d
*/
module.exports = async (d) => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

let [...reactions] = data.inside.splits;
let [...reactions] = data.inside.splits;

reactions = reactions.map((x) => {
try {
let emoji = d.util.getEmoji(d, x.addBrackets());
x = emoji.id ? `:${emoji.name}:${emoji.id}` : emoji.name;
} catch {
x = x?.addBrackets() ?? undefined;
} finally {
if (x === undefined) return d.util.aoiError.fnError(d, "custom", { inside: data.inside }, "Emoji");
}
return x;
});
reactions = await Promise.all(
reactions.map(async (x) => {
const reaction = x.addBrackets().trim();
let emoji = await d.util.getEmoji(d, reaction);
if (!emoji) emoji = reaction;

data.result = "";
return emoji;
})
);

return {
code: d.util.setCode(data),
reactions,
};
return {
code: d.util.setCode(data),
reactions
};
};
31 changes: 12 additions & 19 deletions src/functions/addCmdReactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,20 @@
* @param {import("..").Data} d
*/
module.exports = async (d) => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

let [...reactions] = data.inside.splits;
reactions = reactions.reverse();
let [...reactions] = data.inside.splits;
reactions = reactions.reverse();

for (let i = reactions.length - 1; i >= 0; i--) {
let reaction;
try {
reaction = d.util.getEmoji(d, reactions[i].addBrackets()).id;
} catch {
reaction = reactions[i]?.addBrackets() ?? undefined;
} finally {
if (reaction === undefined) return d.util.aoiError.fnError(d, "custom", { inside: data.inside}, "Emoji");
for (let i = reactions.length - 1; i >= 0; i--) {
let reaction;
reaction = await d.util.getEmoji(d, reactions[i].addBrackets().trim());
if (!reaction) reaction = reactions[i].addBrackets().trim();
await d.message.react(reaction).catch((err) => d.aoiError.fnError(d, "custom", {}, err.message));
}
await d.message.react(reaction).catch((err) => d.aoiError.fnError(d, "custom", {}, err.message));
}

data.result = "";

return {
code: d.util.setCode(data),
};
return {
code: d.util.setCode(data)
};
};
39 changes: 15 additions & 24 deletions src/functions/addMessageReactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,25 @@
* @param {import("..").Data} d
*/
module.exports = async (d) => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

let [channelID, messageID, ...reactions] = data.inside.splits;
const channel = await d.util.getChannel(d, channelID);
let [channelID, messageID, ...reactions] = data.inside.splits;
const channel = await d.util.getChannel(d, channelID);

if (!channel)
return d.aoiError.fnError(d, "channel", { inside: data.inside });
const message = await d.util.getMessage(channel, messageID);
if (!channel) return d.aoiError.fnError(d, "channel", { inside: data.inside });
const message = await d.util.getMessage(channel, messageID);

if (!message)
return d.aoiError.fnError(d, "message", { inside: data.inside });
reactions = reactions.reverse();
if (!message) return d.aoiError.fnError(d, "message", { inside: data.inside });
reactions = reactions.reverse();

for (let i = reactions.length - 1; i >= 0; i--) {
let reaction;
try {
reaction = d.util.getEmoji(d, reactions[i].addBrackets()).id;
} catch {
reaction = reactions[i]?.addBrackets() ?? undefined;
} finally {
if (reaction === undefined) return d.util.aoiError.fnError(d, "custom", { inside: data.inside }, "Emoji" );
for (let i = reactions.length - 1; i >= 0; i--) {
let reaction = await d.util.getEmoji(d, reactions[i]);
if (!reaction) reaction = reactions[i].addBrackets().trim();
await message.react(reaction).catch((err) => d.aoiError.fnError(d, "custom", {}, err.message));
}
await message.react(reaction).catch((err) => d.aoiError.fnError(d, "custom", {}, err.message));
}

data.result = "";
return {
code: d.util.setCode(data),
};
return {
code: d.util.setCode(data)
};
};
16 changes: 12 additions & 4 deletions src/functions/addSelectMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,18 @@ module.exports = async (d) => {
value = option[2].addBrackets();
def = option[3]?.addBrackets() === "true";

try {
emoji = d.util.getEmoji(d, option[4]?.addBrackets()).id;
} catch {
emoji = option[4]?.addBrackets() ?? undefined;
if (option.length > 4) {
const emojiString = option.slice(4).join(":");
emoji = await d.util.getEmoji(d, emojiString);
if (!emoji) {
emoji = emojiString;
} else {
emoji = {
name: emoji.name,
id: emoji.id,
animated: emoji.animated
};
}
}
}

Expand Down
16 changes: 12 additions & 4 deletions src/functions/addSelectMenuTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,18 @@ module.exports = async (d) => {
value = option[2].addBrackets();
def = option[3]?.addBrackets() === "true";

try {
emoji = d.util.getEmoji(d, option[4]?.addBrackets()).id;
} catch {
emoji = option[4]?.addBrackets() ?? undefined;
if (option.length > 4) {
const emojiString = option.slice(4).join(":");
emoji = await d.util.getEmoji(d, emojiString);
if (!emoji) {
emoji = emojiString;
} else {
emoji = {
name: emoji.name,
id: emoji.id,
animated: emoji.animated
};
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/functions/awaitMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ module.exports = async (d) => {
channel,
errorMsg.data ?? errorMsg,
errorMsg.options,
d,
);
}
});
Expand Down
Loading

0 comments on commit 31ce419

Please sign in to comment.