diff --git a/src/classes/AoiError.js b/src/classes/AoiError.js index 2410665f0..eb9251301 100644 --- a/src/classes/AoiError.js +++ b/src/classes/AoiError.js @@ -123,7 +123,7 @@ class AoiError { ) return; msg = await channel.reply(options).catch((e) => { - this.consoleError("CreateMessageError", e); + AoiError.consoleError("CreateMessageError", e); return undefined; }); } else { @@ -135,7 +135,7 @@ class AoiError { ) return; msg = await channel.send(options).catch((e) => { - this.consoleError("CreateMessageError", e); + AoiError.consoleError("CreateMessageError", e); return undefined; }); } diff --git a/src/functions/guild/getGuildTemplate.js b/src/functions/guild/getGuildTemplate.js new file mode 100644 index 000000000..7aad5ca98 --- /dev/null +++ b/src/functions/guild/getGuildTemplate.js @@ -0,0 +1,19 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let template; + + const [templateCode, property] = data.inside.splits; + + try { + template = await d.client.fetchGuildTemplate(`https://discord.new/${templateCode}`); + } catch (err) { + return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Template ID"); + } + + data.result = property.split(".").reduce((obj, prop) => obj && obj[prop], template); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/guild/getGuildTemplates.js b/src/functions/guild/getGuildTemplates.js new file mode 100644 index 000000000..473c3aa00 --- /dev/null +++ b/src/functions/guild/getGuildTemplates.js @@ -0,0 +1,21 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let templates; + + const [guildID = d.guild?.id, option = "code", separator = " , "] = data.inside.splits; + + try { + const guild = await d.util.getGuild(d, guildID); + templates = await guild.fetchTemplates(); + } catch (err) { + data.result = undefined; + return; + } + + data.result = templates.map(x => option.split(".").reduce((obj, prop) => obj && obj[prop], x)).join(separator); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/interaction/addButton.js b/src/functions/interaction/addButton.js index e51f39d10..822de77f8 100644 --- a/src/functions/interaction/addButton.js +++ b/src/functions/interaction/addButton.js @@ -25,6 +25,7 @@ module.exports = async (d) => { d.components[index].components.push(button); return { code: d.util.setCode({function: d.func, inside, code, result: ""}), + data: { ...d.data, components: Object.assign({}, d.data.components, d.components) }, components: d.components, }; }; diff --git a/src/functions/interaction/addField.js b/src/functions/interaction/addField.js index 2db621d48..c66a22903 100644 --- a/src/functions/interaction/addField.js +++ b/src/functions/interaction/addField.js @@ -22,6 +22,7 @@ module.exports = async (d) => { return { code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, embeds: d.embeds, }; }; diff --git a/src/functions/interaction/addSelectMenu.js b/src/functions/interaction/addSelectMenu.js index 7af156ab1..0abeb20d9 100644 --- a/src/functions/interaction/addSelectMenu.js +++ b/src/functions/interaction/addSelectMenu.js @@ -1,71 +1,121 @@ -const {SelectMenuBuilder} = require("discord.js"); +const { StringSelectMenuBuilder, UserSelectMenuBuilder, RoleSelectMenuBuilder, MentionableSelectMenuBuilder, ChannelSelectMenuBuilder } = require("discord.js"); module.exports = async (d) => { - const {code} = d.command; - const inside = d.unpack(); - const err = d.inside(inside); - if (err) return d.error(err); - let [ - index = 1, - customId, - placeHolder, - minValues = 1, - maxValues = 1, - disabled = "false", - ...options - ] = inside.splits; - const components = new SelectMenuBuilder(); - index = Number(index) - 1; - if (isNaN(index) || index < 0) - d.aoiError.fnError(d, "custom", {inside}, "Invalid Index Provided In"); - disabled = disabled === "true"; - placeHolder = placeHolder?.addBrackets(); - customId = customId?.addBrackets(); - minValues = Number(minValues); - maxValues = Number(maxValues); - if (!options.length) - d.aoiError.fnError(d, "custom", {inside}, "Options Are Not Provided In"); - if (minValues > 25 || minValues < 0) - return d.aoiError.fnError( - d, - "custom", - {inside}, - "minValues must be between 0 and 25 (both inclusive). Provided Invalid In", - ); - if (maxValues > 25 || maxValues < 1) - return d.aoiError.fnError( - d, - "custom", - {inside}, - "maxValues must be between 1 and 25 (both Inclusive). Provided Invalid In", - ); - if (placeHolder.length > 100) - return d.aoiError.fnError( - d, - "custom", - {}, - "Placeholder should be at most 100 char long", - ); - d.components[index] = d.components[index] || {type: 1, components: []}; - components - .setCustomId(customId) - .setPlaceholder(placeHolder) - .setMaxValues(maxValues) - .setMinValues(minValues) - .setDisabled(disabled); - for (let option of options) { - option = option.split(":"); - const label = option.shift().addBrackets(); - const description = option.shift().addBrackets(); - const value = option.shift().addBrackets(); - const def = option.shift()?.addBrackets() === "true"; - let emoji = option.join(":")?.addBrackets(); - emoji = emoji === '' ? undefined : emoji; - components.addOptions({label, description, value, default: def, emoji}); + const data = d.util.aoiFunc(d); + const { code } = d.command; + if (data.err) return d.error(data.err); + + let [ index = 1, type, customId, placeHolder, minValues = 1, maxValues = 1, disabled = "false", ...options] = data.inside.splits; + + index = Number(index) - 1; + + if (isNaN(index) || index < 0) + d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Index Provided In"); + + disabled = disabled === "true"; + placeHolder = placeHolder?.addBrackets(); + customId = customId?.addBrackets(); + minValues = Number(minValues); + maxValues = Number(maxValues); + + if (!options.length && type === "string") return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Options Are Not Provided In"); + + if (minValues > 25 || minValues < 0) + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "minValues must be between 0 and 25 (both inclusive). Provided Invalid In" + ); + + if (maxValues > 25 || maxValues < 1) + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "maxValues must be between 1 and 25 (both Inclusive). Provided Invalid In" + ); + + if (placeHolder.length > 100) + return d.aoiError.fnError( + d, + "custom", + {}, + "Placeholder should be at most 100 Characters long" + ); + + let selectBuilder; + + switch (type.toLowerCase()) { + case "string": + selectBuilder = new StringSelectMenuBuilder(); + break; + case "user": + selectBuilder = new UserSelectMenuBuilder(); + break; + case "role": + selectBuilder = new RoleSelectMenuBuilder(); + break; + case "mentionable": + selectBuilder = new MentionableSelectMenuBuilder(); + break; + case "channel": + selectBuilder = new ChannelSelectMenuBuilder(); + break; + default: + return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Select Menu Type"); + } + + selectBuilder + .setCustomId(customId) + .setPlaceholder(placeHolder) + .setMaxValues(maxValues) + .setMinValues(minValues) + .setDisabled(disabled); + + for (let option of options) { + option = option.split(":"); + const label = option[0].addBrackets(); + const description = option[1].addBrackets(); + const value = option[2].addBrackets(); + const def = option[3]?.addBrackets() === "true"; + let emoji = option[4]?.addBrackets(); + emoji = emoji === "" ? undefined : emoji; + + switch (type.toLowerCase()) { + case "string": + selectBuilder.addOptions({ + label, + description, + value, + default: def, + emoji, + }); + break; + case "user": + case "role": + case "mentionable": + case "channel": + selectBuilder.addOption({ + label, + value, + type: type.toUpperCase(), + }); + break; + default: + d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Select Menu Type"); } - d.components[index].components.push(components); - return { - code: d.util.setCode({function: d.func, code, inside}), - components: d.components, - }; + } + + d.components[index] = d.components[index] || { type: 1, components: [] }; + d.components[index].components.push(selectBuilder); + + return { + code: d.util.setCode({ function: d.func, code, inside: data.inside }), + data: { + ...d.data, + components: Object.assign({}, d.data.components, d.components), + }, + components: d.components, + }; }; diff --git a/src/functions/interaction/addTimestamp.js b/src/functions/interaction/addTimestamp.js index f90ad0c4d..d3eabc35f 100644 --- a/src/functions/interaction/addTimestamp.js +++ b/src/functions/interaction/addTimestamp.js @@ -18,6 +18,7 @@ module.exports = async (d) => { return { code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, embeds: d.embeds, }; }; diff --git a/src/functions/interaction/author.js b/src/functions/interaction/author.js index f6deb22fd..2d19a9e4c 100644 --- a/src/functions/interaction/author.js +++ b/src/functions/interaction/author.js @@ -22,6 +22,7 @@ module.exports = async (d) => { return { code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, embeds: d.embeds, }; }; diff --git a/src/functions/interaction/color.js b/src/functions/interaction/color.js index 5101eda3d..a656f6ade 100644 --- a/src/functions/interaction/color.js +++ b/src/functions/interaction/color.js @@ -16,6 +16,7 @@ module.exports = async (d) => { return { code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, embeds: d.embeds, }; }; diff --git a/src/functions/interaction/description.js b/src/functions/interaction/description.js index b24aff163..5c712c9a8 100644 --- a/src/functions/interaction/description.js +++ b/src/functions/interaction/description.js @@ -16,6 +16,7 @@ module.exports = async (d) => { return { code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, embeds: d.embeds, }; }; diff --git a/src/functions/interaction/footer.js b/src/functions/interaction/footer.js index 8d72d0556..6dc06cdcf 100644 --- a/src/functions/interaction/footer.js +++ b/src/functions/interaction/footer.js @@ -20,6 +20,7 @@ module.exports = async (d) => { return { code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, embeds: d.embeds, }; }; diff --git a/src/functions/interaction/image.js b/src/functions/interaction/image.js index 84e59fd1a..886891b15 100644 --- a/src/functions/interaction/image.js +++ b/src/functions/interaction/image.js @@ -16,6 +16,7 @@ module.exports = (d) => { return { code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, embeds: d.embeds, }; }; diff --git a/src/functions/interaction/thumbnail.js b/src/functions/interaction/thumbnail.js index f62a07560..d1c038b4f 100644 --- a/src/functions/interaction/thumbnail.js +++ b/src/functions/interaction/thumbnail.js @@ -16,6 +16,7 @@ module.exports = async (d) => { return { code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, embeds: d.embeds, }; }; diff --git a/src/functions/interaction/title.js b/src/functions/interaction/title.js index c4b53b3aa..a1711e030 100644 --- a/src/functions/interaction/title.js +++ b/src/functions/interaction/title.js @@ -19,6 +19,7 @@ module.exports = async (d) => { return { code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, embeds: d.embeds, - }; + }; }; diff --git a/src/functions/misc/editObjectProperty.js b/src/functions/misc/editObjectProperty.js new file mode 100644 index 000000000..a4bcbe2e1 --- /dev/null +++ b/src/functions/misc/editObjectProperty.js @@ -0,0 +1,33 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const { code } = d.command; + + const [objectName, property, propertyValue] = data.inside.splits; + const properties = property.split('.'); + + if (!d.data.objects) return d.aoiError.fnError(d, "custom", {}, "Object"); + + let object = d.data.objects[objectName] || {}; + + let Object = object; + for (let i = 0; i < properties.length - 1; i++) { + const propertyName = properties[i]; + Object[propertyName] = Object[propertyName] || {}; + Object = Object[propertyName]; + } + + try { + Object[properties[properties.length - 1]] = JSON.parse(propertyValue); + } catch (e){ + Object[properties[properties.length - 1]] = propertyValue; + } + + d.data.objects[objectName] = object; + d.object = object; + + return { + code: d.util.setCode({ function: d.func, code: code, inside: data.inside }), + data: { ...d.data, objects: { ...d.data.objects } }, + }; + }; + \ No newline at end of file diff --git a/src/functions/user/isBotVerified.js b/src/functions/user/isBotVerified.js new file mode 100644 index 000000000..7b4674713 --- /dev/null +++ b/src/functions/user/isBotVerified.js @@ -0,0 +1,16 @@ +const { UserFlags } = require('discord.js'); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id] = data.inside.splits; + + const user = await d.util.getUser(d, userID); + if (!user) return d.aoiError.fnError(d, 'user', {inside: data.inside}); + + data.result = user.flags.has(UserFlags.VerifiedBot); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isPartnered.js b/src/functions/util/isGuildPartnered.js similarity index 100% rename from src/functions/util/isPartnered.js rename to src/functions/util/isGuildPartnered.js diff --git a/src/functions/util/isVerified.js b/src/functions/util/isGuildVerified.js similarity index 100% rename from src/functions/util/isVerified.js rename to src/functions/util/isGuildVerified.js