From 12ee612580ce7a04739a5a625f32c5bd4c7b3425 Mon Sep 17 00:00:00 2001 From: Faf4a <87046111+Faf4a@users.noreply.github.com> Date: Sun, 6 Oct 2024 09:29:10 +0200 Subject: [PATCH 01/11] fix: emoji parsing --- src/classes/Util.js | 544 +++++++++++++++------------------ src/functions/addSelectMenu.js | 16 +- 2 files changed, 259 insertions(+), 301 deletions(-) diff --git a/src/classes/Util.js b/src/classes/Util.js index b67b460f7..51bed6970 100644 --- a/src/classes/Util.js +++ b/src/classes/Util.js @@ -3,326 +3,276 @@ const Discord = require("discord.js"); const parsers = require("../events/parsers.js"); class Util { - static constants = Constants; - static parsers = parsers; + static constants = Constants; + static parsers = parsers; + + static async getUser(d, id) { + let user = d.client.users.cache.get(id); + if (!user) { + user = await this.fetchUser(d, id); + } + return user; + } - static async getUser(d, id) { - let user = d.client.users.cache.get(id); - if (!user) { - user = await this.fetchUser(d, id); + static async fetchUser(d, id) { + try { + return await d.client.users.fetch(id, { force: true }); + } catch (err) { + return undefined; + } } - return user; - } - - static async fetchUser(d, id) { - try { - return await d.client.users.fetch(id, { force: true }); - } catch (err) { - return undefined; + + static async fetchChannel(d, id) { + try { + return await d.client.channels.fetch(id, { force: true }); + } catch (e) { + return undefined; + } } - } - static async fetchChannel(d, id) { - try { - return await d.client.channels.fetch(id, { force: true }); - } catch (e) { - return undefined; + static getChannel(d, id, force = false) { + if (d.channel?.id === id) return d.channel; + else { + let channel = d.client.channels.cache.get(id); + if (!channel && force) channel = this.fetchChannel(d, id); + return channel; + } } - } - - static getChannel(d, id, force = false) { - if (d.channel?.id === id) return d.channel; - else { - let channel = d.client.channels.cache.get(id); - if (!channel && force) channel = this.fetchChannel(d, id); - return channel; + + static async fetchMember(guild, id) { + try { + return await guild.members.fetch(id, { force: true }); + } catch (err) { + return undefined; + } } - } - static async fetchMember(guild, id) { - try { - return await guild.members.fetch(id, { force: true }); - } catch (err) { - return undefined; + static async fetchMembers(guild, options) { + return guild.members.fetch(options); } - } - - static async fetchMembers(guild, options) { - return guild.members.fetch(options); - } - - static getMember(guild, id) { - let member = guild.members.cache.get(id); - if (!member) member = this.fetchMember(guild, id); - return member; - } - - static getMembers( - guild, - options = { type: "startsWith", query: "", limit: 10 }, - force = false - ) { - let members; - if (!force) { - members = guild.members.cache - .filter( - (x) => - x.user.username.toLowerCase()[options.type](options.query) || - x.displayName?.toLowerCase()[options.type](options.query) - ) - .first(options.limit); - } else { - members = this.fetchMembers(guild, options); + + static getMember(guild, id) { + let member = guild.members.cache.get(id); + if (!member) member = this.fetchMember(guild, id); + return member; } - return members; - } - - static async fetchMessage(channel, id) { - try { - return await channel.messages.fetch(id, { force: true }); - } catch (err) { - return undefined; + + static getMembers(guild, options = { type: "startsWith", query: "", limit: 10 }, force = false) { + let members; + if (!force) { + members = guild.members.cache.filter((x) => x.user.username.toLowerCase()[options.type](options.query) || x.displayName?.toLowerCase()[options.type](options.query)).first(options.limit); + } else { + members = this.fetchMembers(guild, options); + } + return members; } - } - - static getMessage(channel, id) { - let message = channel.messages.cache.get(id); - if (!message) message = this.fetchMessage(channel, id); - return message; - } - - static setCode(options = {}, escape = true) { - return options.code.replaceLast( - options.inside - ? `${options.function}${options.inside}` - : `${options.function}`, - (escape - ? options.result?.toString()?.deleteBrackets() - : options.result.toString()) ?? "" - ); - } - - static async getGuild(d, id) { - if (d.guild?.id === id && d.guild?.id) return d.guild; - else { - if (!d.client.shard) return d.client.guilds.cache.get(id); - else { - const arr = await d.client.shard.broadcastEval((client) => - client.guilds.cache.get(id) + + static async fetchMessage(channel, id) { + try { + return await channel.messages.fetch(id, { force: true }); + } catch (err) { + return undefined; + } + } + + static getMessage(channel, id) { + let message = channel.messages.cache.get(id); + if (!message) message = this.fetchMessage(channel, id); + return message; + } + + static setCode(options = {}, escape = true) { + return options.code.replaceLast( + options.inside ? `${options.function}${options.inside}` : `${options.function}`, + (escape ? options.result?.toString()?.deleteBrackets() : options.result.toString()) ?? "" ); - return arr.find((x) => x); - } } - } - - static get channelTypes() { - return { - Text: Discord.ChannelType.GuildText, - Voice: Discord.ChannelType.GuildVoice, - Category: Discord.ChannelType.GuildCategory, - DM: Discord.ChannelType.DM, - Announcement: Discord.ChannelType.GuildAnnouncement, - AnnouncementThread: Discord.ChannelType.AnnouncementThread, - PublicThread: Discord.ChannelType.PublicThread, - PrivateThread: Discord.ChannelType.PrivateThread, - Stage: Discord.ChannelType.GuildStageVoice, - Forum: Discord.ChannelType.GuildForum, - Media: Discord.ChannelType.GuildMedia, - GuildDirectory: Discord.ChannelType.GuildDirectory, - GroupDM: Discord.ChannelType.GroupDM, - }; - } - - static get threadTypes() { - return { - public: Discord.ChannelType.PublicThread, - private: Discord.ChannelType.PrivateThread, - }; - } - - static async errorParser(errorM, d) { - let error; - if (typeof errorM === "object") return errorM; - - try { - error = await this.parsers.ErrorHandler(errorM, d, true); - } catch (e) { - error = undefined; + + static async getGuild(d, id) { + if (d.guild?.id === id && d.guild?.id) return d.guild; + else { + if (!d.client.shard) return d.client.guilds.cache.get(id); + else { + const arr = await d.client.shard.broadcastEval((client) => client.guilds.cache.get(id)); + return arr.find((x) => x); + } + } } - return error; - } - - static async getRole(guild, id) { - try { - let role = guild.roles.cache.get(id); - if (!role) role = await this.fetchRole(guild, id); - return role; - } catch (err) { - return undefined; + + static get channelTypes() { + return { + Text: Discord.ChannelType.GuildText, + Voice: Discord.ChannelType.GuildVoice, + Category: Discord.ChannelType.GuildCategory, + DM: Discord.ChannelType.DM, + Announcement: Discord.ChannelType.GuildAnnouncement, + AnnouncementThread: Discord.ChannelType.AnnouncementThread, + PublicThread: Discord.ChannelType.PublicThread, + PrivateThread: Discord.ChannelType.PrivateThread, + Stage: Discord.ChannelType.GuildStageVoice, + Forum: Discord.ChannelType.GuildForum, + Media: Discord.ChannelType.GuildMedia, + GuildDirectory: Discord.ChannelType.GuildDirectory, + GroupDM: Discord.ChannelType.GroupDM + }; + } + + static get threadTypes() { + return { + public: Discord.ChannelType.PublicThread, + private: Discord.ChannelType.PrivateThread + }; + } + + static async errorParser(errorM, d) { + let error; + if (typeof errorM === "object") return errorM; + + try { + error = await this.parsers.ErrorHandler(errorM, d, true); + } catch (e) { + error = undefined; + } + return error; } - } - static async fetchRole(guild, id) { - try { - return await guild.roles.fetch(id, { force: true }); - } catch (err) { - return undefined; + static async getRole(guild, id) { + try { + let role = guild.roles.cache.get(id); + if (!role) role = await this.fetchRole(guild, id); + return role; + } catch (err) { + return undefined; + } } - } - - static aoiFunc(d, FieldsRequired = true) { - const data = { - inside: d.unpack(), - code: d.command.code, - function: d.func, - }; - if (FieldsRequired) { - data.err = d.inside(data.inside); + + static async fetchRole(guild, id) { + try { + return await guild.roles.fetch(id, { force: true }); + } catch (err) { + return undefined; + } } - return data; - } - static async getEmoji(d, Emoji) { - if (Emoji.includes(":")) { - Emoji = Emoji.split(":")[2].split(">")[0]; + static aoiFunc(d, FieldsRequired = true) { + const data = { + inside: d.unpack(), + code: d.command.code, + function: d.func + }; + if (FieldsRequired) { + data.err = d.inside(data.inside); + } + return data; + } + + static getEmoji(d, Emoji) { + if (!Emoji) return; + if (Emoji.includes(":")) { + Emoji = Emoji.split(":")[2].split(">")[0]; + } + + const clientEmojis = d.client.emojis.cache.find((x) => x.name.toLowerCase().addBrackets() === Emoji.toLowerCase() || x.id === Emoji || x.toString() === Emoji); + + if (clientEmojis) return clientEmojis; + + const application = d.client.application; + const fetchEmojis = application.emojis.cache.size ? Promise.resolve() : application.emojis.fetch(); + + return fetchEmojis.then(() => { + const appEmojis = application.emojis.cache.find((x) => x.name.toLowerCase().addBrackets() === Emoji.toLowerCase() || x.id === Emoji || x.toString() === Emoji); + + return appEmojis; + }); } - const clientEmojis = d.client.emojis.cache.find( - (x) => - x.name.toLowerCase() === Emoji.toLowerCase().addBrackets() || - x.id === Emoji || - x.toString() === Emoji - ); - - if (clientEmojis) return clientEmojis; - - // https://discord.js.org/docs/packages/discord.js/14.16.1/ApplicationEmojiManager:Class#fetch - const application = d.client.application; - if (!application.emojis.cache.size) await application.emojis.fetch(); - - const appEmojis = application.emojis.cache.find( - (x) => - x.name.toLowerCase() === Emoji.toLowerCase().addBrackets() || - x.id === Emoji || - x.toString() === Emoji - ); - - return appEmojis; - } - - static getSticker(guild, Sticker) { - return guild.stickers.cache.find( - (x) => - x.name.toLowerCase() === Sticker.toLowerCase().addBrackets() || - x.id === Sticker - ); - } - - static findMember(guild, memberResolver) { - return guild.members.cache.findKey( - (x) => - x.displayName.toLowerCase() === memberResolver.toLowerCase() || - x.user.username.toLowerCase() === memberResolver.toLowerCase() || - x.id === memberResolver || - x.toString() === memberResolver - ); - } - - static findGuildChannel(guild, ChannelResolver) { - return guild.channels.cache.findKey( - (x) => - x.name.toLowerCase() === ChannelResolver.toLowerCase() || - x.id === ChannelResolver || - x.toString() === ChannelResolver - ); - } - - static findChannel(client, ChannelResolver) { - return client.channels.cache.findKey( - (x) => - x.name.toLowerCase() === ChannelResolver.toLowerCase() || - x.id === ChannelResolver || - x.toString() === ChannelResolver - ); - } - - static findRole(guild, RoleResolver) { - return guild.roles.cache.findKey( - (x) => - x.name.toLowerCase() === RoleResolver.toLowerCase() || - x.id === RoleResolver || - x.toString() === RoleResolver - ); - } - - static findUser(client, UserResolver) { - return client.users.cache.findKey( - (x) => - x.username.toLowerCase() === UserResolver.toLowerCase() || - x.tag.toLowerCase() === UserResolver.toLowerCase() || - x.id === UserResolver || - x.toString() === UserResolver - ); - } - - static findRoles( - guild, - options = { type: "startsWith", query: "", limit: 10 } - ) { - return guild.roles.cache - .filter((x) => { - return x.name.toLowerCase()[options.type](options.query.toLowerCase()); - }) - .first(options.limit); - } + static getSticker(guild, Sticker) { + return guild.stickers.cache.find((x) => x.name.toLowerCase() === Sticker.toLowerCase().addBrackets() || x.id === Sticker); + } + + static findMember(guild, memberResolver) { + return guild.members.cache.findKey( + (x) => + x.displayName.toLowerCase() === memberResolver.toLowerCase() || + x.user.username.toLowerCase() === memberResolver.toLowerCase() || + x.id === memberResolver || + x.toString() === memberResolver + ); + } + + static findGuildChannel(guild, ChannelResolver) { + return guild.channels.cache.findKey((x) => x.name.toLowerCase() === ChannelResolver.toLowerCase() || x.id === ChannelResolver || x.toString() === ChannelResolver); + } + + static findChannel(client, ChannelResolver) { + return client.channels.cache.findKey((x) => x.name.toLowerCase() === ChannelResolver.toLowerCase() || x.id === ChannelResolver || x.toString() === ChannelResolver); + } + + static findRole(guild, RoleResolver) { + return guild.roles.cache.findKey((x) => x.name.toLowerCase() === RoleResolver.toLowerCase() || x.id === RoleResolver || x.toString() === RoleResolver); + } + + static findUser(client, UserResolver) { + return client.users.cache.findKey( + (x) => x.username.toLowerCase() === UserResolver.toLowerCase() || x.tag.toLowerCase() === UserResolver.toLowerCase() || x.id === UserResolver || x.toString() === UserResolver + ); + } + + static findRoles(guild, options = { type: "startsWith", query: "", limit: 10 }) { + return guild.roles.cache + .filter((x) => { + return x.name.toLowerCase()[options.type](options.query.toLowerCase()); + }) + .first(options.limit); + } } Util.searchType = ["soundcloud", "localfile", "url", "youtube", "spotify"]; Util.audioFilters = { - nightcore: (value) => { - return { - asetrate: 48000 * value, - aresample: 48000, - }; - }, - bassboost: (value) => { - return { - bass: `g=${value}`, - }; - }, - "8d": () => { - return { - extrastereo: "", - aecho: "1:1:40:0.5", - apulsator: "hz=0.125", - stereowiden: "", - }; - }, - pitch: (value) => { - return { - asetrate: 48000 * value, - atempo: 1 - Number(`${value}`.split(".")[1]), - aresample: 48000, - }; - }, - karaoke: (value) => { - return { - stereotools: `mlev=${0.015625 * value}`, - }; - }, - slowed: (value) => { - return { - asetrate: 48000 * Math.abs(Math.ceil(value) - value), - aresample: 48000, - }; - }, - deep: (value) => { - return { - asetrate: 48000 * Math.abs(Math.ceil(value) - value), - atempo: 2 - Math.abs(Math.ceil(value) - value), - aresample: 48000, - }; - }, + nightcore: (value) => { + return { + asetrate: 48000 * value, + aresample: 48000 + }; + }, + bassboost: (value) => { + return { + bass: `g=${value}` + }; + }, + "8d": () => { + return { + extrastereo: "", + aecho: "1:1:40:0.5", + apulsator: "hz=0.125", + stereowiden: "" + }; + }, + pitch: (value) => { + return { + asetrate: 48000 * value, + atempo: 1 - Number(`${value}`.split(".")[1]), + aresample: 48000 + }; + }, + karaoke: (value) => { + return { + stereotools: `mlev=${0.015625 * value}` + }; + }, + slowed: (value) => { + return { + asetrate: 48000 * Math.abs(Math.ceil(value) - value), + aresample: 48000 + }; + }, + deep: (value) => { + return { + asetrate: 48000 * Math.abs(Math.ceil(value) - value), + atempo: 2 - Math.abs(Math.ceil(value) - value), + aresample: 48000 + }; + } }; -module.exports = Util; \ No newline at end of file +module.exports = Util; diff --git a/src/functions/addSelectMenu.js b/src/functions/addSelectMenu.js index d36e698af..a5ad327ad 100644 --- a/src/functions/addSelectMenu.js +++ b/src/functions/addSelectMenu.js @@ -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(":"); + try { + emoji = d.util.getEmoji(d, emojiString); + emoji = { + name: emoji.name, + id: emoji.id, + animated: emoji.animated + }; + } catch { + emoji = emojiString.addBrackets().trim() || undefined; + } } } From f9da7b5e6bee0acedfb1a686faaa5815f3aceec3 Mon Sep 17 00:00:00 2001 From: Faf4a <87046111+Faf4a@users.noreply.github.com> Date: Sun, 6 Oct 2024 09:29:46 +0200 Subject: [PATCH 02/11] feat: new automod functions --- src/functions/getAutomodRule.js | 17 +++++++++++++++++ src/functions/getAutomodRules.js | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/functions/getAutomodRule.js create mode 100644 src/functions/getAutomodRules.js diff --git a/src/functions/getAutomodRule.js b/src/functions/getAutomodRule.js new file mode 100644 index 000000000..be4ae8e63 --- /dev/null +++ b/src/functions/getAutomodRule.js @@ -0,0 +1,17 @@ +/** + * @param {import("..").Data} d + */ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const [guildID = d.guild?.id, name, option = "name"] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + + const autoModerationRules = await guild.autoModerationRules.fetch({ force: true }); + const autoModerationRule = autoModerationRules.find((rule) => rule.name === name || rule.id === name); + data.result = option.includes("{") ? option.replaceAll(/{(.+?)}/g, (_, prop) => autoModerationRule[prop]) : autoModerationRule[option]; + + return { + code: d.util.setCode(data) + }; +}; diff --git a/src/functions/getAutomodRules.js b/src/functions/getAutomodRules.js new file mode 100644 index 000000000..91e67409c --- /dev/null +++ b/src/functions/getAutomodRules.js @@ -0,0 +1,25 @@ +/** + * @param {import("..").Data} d + */ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const [guildID = d.guild?.id, option = "name", sep = ", "] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + + const autoModerationRules = await guild.autoModerationRules.fetch({ force: true }); + data.result = autoModerationRules.map((automodRule) => { + if (option.includes("{")) { + return option.replaceAll(/{(.+?)}/g, (_, prop) => automodRule[prop]); + } else { + return automodRule[option]; + } + }) + .join(sep) + .removeBrackets(); + + + return { + code: d.util.setCode(data) + }; +}; From efa2b6eb6babc4e137f4d6c5cbe2074ef87a6f26 Mon Sep 17 00:00:00 2001 From: Faf4a <87046111+Faf4a@users.noreply.github.com> Date: Sun, 6 Oct 2024 09:45:50 +0200 Subject: [PATCH 03/11] feat: getGuildBoosters --- src/functions/getGuildBoosters.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/functions/getGuildBoosters.js diff --git a/src/functions/getGuildBoosters.js b/src/functions/getGuildBoosters.js new file mode 100644 index 000000000..e4f6cff45 --- /dev/null +++ b/src/functions/getGuildBoosters.js @@ -0,0 +1,24 @@ +/** + * @param {import("..").Data} d + */ +module.exports = async (d) => { + let data = d.util.aoiFunc(d); + let [guildId = d.guild?.id, option = "id", sep = ", "] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildId); + const guildBoosters = guild.members.cache.filter((member) => member.premiumSince !== null); + + data.result = guildBoosters.map((member) => { + if (option.includes("{")) { + return option.replaceAll(/{(.+?)}/g, (_, prop) => member.user[prop]); + } else { + return member.user[option]; + } + }) + .join(sep) + .removeBrackets(); + + return { + code: d.util.setCode(data) + }; +}; From 73995c51ff033d7d5ac18a28a2c3ca2769de199a Mon Sep 17 00:00:00 2001 From: Faf4a <87046111+Faf4a@users.noreply.github.com> Date: Sun, 6 Oct 2024 09:49:19 +0200 Subject: [PATCH 04/11] feat: voiceMemberCount --- src/functions/voiceMemberCount.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/functions/voiceMemberCount.js diff --git a/src/functions/voiceMemberCount.js b/src/functions/voiceMemberCount.js new file mode 100644 index 000000000..6e939cdca --- /dev/null +++ b/src/functions/voiceMemberCount.js @@ -0,0 +1,20 @@ +/** + * @param {import("..").Data} d + */ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [channelID = d.member?.voice?.channelId] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + + if (!channel) return d.aoiError.fnError(d, "channel", { inside: data.inside }); + + if (![d.util.channelTypes.Voice, d.util.channelTypes.Stage].includes(channel.type)) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Channel Type Is Not Voice/Stage"); + + data.result = channel.members.size ?? 0; + + return { + code: d.util.setCode(data) + }; +}; From a9a94c3e6747420497b26bf9037eb67721879da9 Mon Sep 17 00:00:00 2001 From: Faf4a <87046111+Faf4a@users.noreply.github.com> Date: Mon, 7 Oct 2024 10:10:54 +0200 Subject: [PATCH 05/11] fix: emoji related issues --- src/core/interpreter.js | 303 ++++++++++++++------------- src/events/parsers.js | 17 +- src/functions/addButton.js | 90 ++++---- src/functions/addButtonTo.js | 7 +- src/functions/addClientReactions.js | 36 ++-- src/functions/addCmdReactions.js | 31 ++- src/functions/addMessageReactions.js | 39 ++-- src/functions/addSelectMenu.js | 8 +- src/functions/addSelectMenuTo.js | 16 +- src/functions/createPoll.js | 17 +- src/functions/emojiExists.js | 22 +- src/functions/reactionCount.js | 13 +- src/functions/resolveEmojiID.js | 2 +- 13 files changed, 293 insertions(+), 308 deletions(-) diff --git a/src/core/interpreter.js b/src/core/interpreter.js index 7385ee526..69c56781c 100644 --- a/src/core/interpreter.js +++ b/src/core/interpreter.js @@ -102,17 +102,17 @@ const Interpreter = async (client, message, args, command, _db, returnCode = fal const d = {}; Object.assign(d, codeData); let param = []; - const unpacked = unpack(code, func); + const unpacked = unpack(code, func); - if (!unpacked.inside && codeData.params.length) { - throw new Error(`${func} needs params, provided none`); - } + if (!unpacked.inside && codeData.params.length) { + throw new Error(`${func} needs params, provided none`); + } for (let p = codeData.params.length - 1; p >= 0; p--) { d.code = d.code.replace(`{${codeData.params[p]}}`, unpacked.splits[p]); param.push(unpacked.splits[p]); } - param.reverse(); - + param.reverse(); + hadCustomAoijsFunction = true; code = code.replaceLast(codeData.params.length ? `${func}[${param.join(";")}]` : func, d.code); } @@ -120,10 +120,8 @@ const Interpreter = async (client, message, args, command, _db, returnCode = fal if (hadCustomAoijsFunction) { funcs = client.functionManager.findFunctions(code); command.functions = funcs; - command.code = code; + command.code = code; } - - } if (command["$if"] === "old") { @@ -306,140 +304,140 @@ const Interpreter = async (client, message, args, command, _db, returnCode = fal // ); // FuncData.code = code.replaceLast(functionObj.params.length ? `${func}${param.join(";")}` : func, FuncData.code); // } else { - FuncData = await client.functionManager.cache.get(func.replace("$", "").replace("[", ""))?.code({ - randoms: randoms, - command: { - name: command.name, - type: command.type, - code: code, - error: command.error, - async: command.async || false, - functions: command.functions, - __path__: command.__path__, - codeLines: command.codeLines, - funcLine: funcLine - }, - helpers: { - time: Time, - checkCondition: CheckCondition, - mustEscape - }, - args: args, - aoiError: require("../classes/AoiError.js"), - data: data, - func: func, - funcLine, - util: Util, - allowedMentions: allowedMentions, - embeds: embeds || [], - components: components, - files: attachments || [], - timezone: timezone, - channelUsed: channelUsed, - vars: letVars, - object: object, - disableMentions: disableMentions, - array: array, - arrays, - reactions: reactions, - message: message.message || message, - msg: msg.message || msg, - author: author, - guild: guild, - channel: channel, - member: member, - mentions: mentions, //cleanup (ignore) - unpack() { - const last = code.split(func.replace("[", "")).length - 1; - const sliced = code.split(func.replace("[", ""))[last]; + FuncData = await client.functionManager.cache.get(func.replace("$", "").replace("[", ""))?.code({ + randoms: randoms, + command: { + name: command.name, + type: command.type, + code: code, + error: command.error, + async: command.async || false, + functions: command.functions, + __path__: command.__path__, + codeLines: command.codeLines, + funcLine: funcLine + }, + helpers: { + time: Time, + checkCondition: CheckCondition, + mustEscape + }, + args: args, + aoiError: require("../classes/AoiError.js"), + data: data, + func: func, + funcLine, + util: Util, + allowedMentions: allowedMentions, + embeds: embeds || [], + components: components, + files: attachments || [], + timezone: timezone, + channelUsed: channelUsed, + vars: letVars, + object: object, + disableMentions: disableMentions, + array: array, + arrays, + reactions: reactions, + message: message.message || message, + msg: msg.message || msg, + author: author, + guild: guild, + channel: channel, + member: member, + mentions: mentions, //cleanup (ignore) + unpack() { + const last = code.split(func.replace("[", "")).length - 1; + const sliced = code.split(func.replace("[", ""))[last]; - return sliced.after(); - }, - inside(unpacked) { - if (typeof unpacked.inside !== "string") { - if (suppressErrors) return suppressErrors; - else { - return client.aoiOptions.suppressAllErrors ? client.aoiOptions.errorMessage : `AoiError: \`${this.func}\`: Missing Brackets`; - } - } else return false; - }, - noop() {}, - async error(err, d) { - error = true; - client.emit( - "functionError", - { - error: err?.addBrackets(), - function: func, - command: command.name, - channel, - guild - }, - client - ); - if (client.aoiOptions.suppressAllErrors) { - if (client.aoiOptions.errorMessage) { - const msg = message; - if (!msg || !msg.channel) { - console.error(client.aoiOptions.errorMessage.addBrackets()); - } else { - if (!errorOccurred) { - try { - await Interpreter( - client, - msg ?? data, - args ?? [], - { code: client.aoiOptions.errorMessage }, - client.db, - false, - msg.channel ?? [], - {}, - msg.channel ?? [], - false, - false, - false, - true - ); - } catch (e) { - console.error(client.aoiOptions.errorMessage.addBrackets()); - } - errorOccurred = true; + return sliced.after(); + }, + inside(unpacked) { + if (typeof unpacked.inside !== "string") { + if (suppressErrors) return suppressErrors; + else { + return client.aoiOptions.suppressAllErrors ? client.aoiOptions.errorMessage : `AoiError: \`${this.func}\`: Missing Brackets`; + } + } else return false; + }, + noop() {}, + async error(err, d) { + error = true; + client.emit( + "functionError", + { + error: err?.addBrackets(), + function: func, + command: command.name, + channel, + guild + }, + client + ); + if (client.aoiOptions.suppressAllErrors) { + if (client.aoiOptions.errorMessage) { + const msg = message; + if (!msg || !msg.channel) { + console.error(client.aoiOptions.errorMessage.addBrackets()); + } else { + if (!errorOccurred) { + try { + await Interpreter( + client, + msg ?? data, + args ?? [], + { code: client.aoiOptions.errorMessage }, + client.db, + false, + msg.channel ?? [], + {}, + msg.channel ?? [], + false, + false, + false, + true + ); + } catch (e) { + console.error(client.aoiOptions.errorMessage.addBrackets()); } + errorOccurred = true; } } - } else { - if (!message || !message.channel) { - console.error(err.addBrackets()); - } else if (suppressErrors && !errorOccurred) { - if (suppressErrors.trim() !== "") { - const { makeMessageError } = require("../classes/AoiError.js"); - const msg = await Util.errorParser(suppressErrors?.split("{error}").join(err.addBrackets()), { - channel: channel, - message: message, - guild: guild, - author: author - }); - await makeMessageError(client, channel, msg.data ?? msg, msg.options, { - channel: channel, - message: message, - guild: guild, - author: author, - data: data - }); - } - } else { - await message.channel.send(typeof err === "object" ? err : err?.addBrackets()); + } + } else { + if (!message || !message.channel) { + console.error(err.addBrackets()); + } else if (suppressErrors && !errorOccurred) { + if (suppressErrors.trim() !== "") { + const { makeMessageError } = require("../classes/AoiError.js"); + const msg = await Util.errorParser(suppressErrors?.split("{error}").join(err.addBrackets()), { + channel: channel, + message: message, + guild: guild, + author: author + }); + await makeMessageError(client, channel, msg.data ?? msg, msg.options, { + channel: channel, + message: message, + guild: guild, + author: author, + data: data + }); } - errorOccurred = true; + } else { + await message.channel.send(typeof err === "object" ? err : err?.addBrackets()); } - }, - interpreter: Interpreter, - client: client, - embed: Discord.EmbedBuilder - }); - if (client?.aoiOptions?.debugs?.interpreter) { - debug[func].funcData = require("util").inspect(FuncData, { depth: 0 }); - } + errorOccurred = true; + } + }, + interpreter: Interpreter, + client: client, + embed: Discord.EmbedBuilder + }); + if (client?.aoiOptions?.debugs?.interpreter) { + debug[func].funcData = require("util").inspect(FuncData, { depth: 0 }); + } // } code = FuncData?.code ?? code; @@ -504,7 +502,6 @@ const Interpreter = async (client, message, args, command, _db, returnCode = fal } } - const ended = (performance.now() - start).toFixed(3); embeds = JSON.parse(JSON.stringify(embeds || [])?.replaceAll("$executionTime", ended)); @@ -522,12 +519,12 @@ const Interpreter = async (client, message, args, command, _db, returnCode = fal return AoiError.consoleError("EmbedError", "Index are not defined."); } if (returnCode) { - returnData.code = !error ?code : null; + returnData.code = !error ? code : null; } if (returnExecution) { returnData.data = data; } - + if ((code.length || embeds?.length || attachments?.length) && !errorOccurred && !error) { try { const send = { @@ -549,9 +546,13 @@ const Interpreter = async (client, message, args, command, _db, returnCode = fal if (returnCode && !sendMessage) { } else { if (!useChannel) { - msgobj = await message.channel?.send(send); + msgobj = await message.channel?.send(send)?.catch((e) => { + console.error(e); + }); } else { - msgobj = await useChannel.send(send); + msgobj = await useChannel?.send(send)?.catch((e) => { + console.error(e); + }); } } @@ -562,23 +563,33 @@ const Interpreter = async (client, message, args, command, _db, returnCode = fal if (reactions?.length) { const react = setInterval(() => { const r = reactions.shift(); - msgobj.react(r); + msgobj.react(r).catch((e) => { + console.error(e); + }); if (!reactions.length) { clearInterval(react); } - }, 1500); + }, 1e3); } if (editIn) { const ee = setInterval(() => { const m = editIn.msgs; - msgobj.edit(m.shift()); + msgobj.edit(m.shift()).catch((e) => { + console.error(e); + }); if (!m.length) { clearInterval(ee); } }, editIn.time); } if (deleteIn) { - setTimeout(() => msgobj.delete(), deleteIn); + setTimeout( + () => + msgobj.delete().catch((e) => { + console.error(e); + }), + deleteIn + ); } if (returnID) { diff --git a/src/events/parsers.js b/src/events/parsers.js index fa787e900..4bc971154 100644 --- a/src/events/parsers.js +++ b/src/events/parsers.js @@ -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) { @@ -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); @@ -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); diff --git a/src/functions/addButton.js b/src/functions/addButton.js index 545e347f3..0eb149074 100644 --- a/src/functions/addButton.js +++ b/src/functions/addButton.js @@ -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) + }; }; diff --git a/src/functions/addButtonTo.js b/src/functions/addButtonTo.js index 64d4d35f3..550aeef6d 100644 --- a/src/functions/addButtonTo.js +++ b/src/functions/addButtonTo.js @@ -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, diff --git a/src/functions/addClientReactions.js b/src/functions/addClientReactions.js index ecbc0c396..32fdb3ee8 100644 --- a/src/functions/addClientReactions.js +++ b/src/functions/addClientReactions.js @@ -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 + }; }; diff --git a/src/functions/addCmdReactions.js b/src/functions/addCmdReactions.js index ec340d999..4c1997a05 100644 --- a/src/functions/addCmdReactions.js +++ b/src/functions/addCmdReactions.js @@ -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) + }; }; diff --git a/src/functions/addMessageReactions.js b/src/functions/addMessageReactions.js index 4f9fece64..466f804fb 100644 --- a/src/functions/addMessageReactions.js +++ b/src/functions/addMessageReactions.js @@ -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) + }; }; diff --git a/src/functions/addSelectMenu.js b/src/functions/addSelectMenu.js index a5ad327ad..4e7920f69 100644 --- a/src/functions/addSelectMenu.js +++ b/src/functions/addSelectMenu.js @@ -69,15 +69,15 @@ module.exports = async (d) => { if (option.length > 4) { const emojiString = option.slice(4).join(":"); - try { - emoji = d.util.getEmoji(d, emojiString); + emoji = await d.util.getEmoji(d, emojiString); + if (!emoji) { + emoji = emojiString; + } else { emoji = { name: emoji.name, id: emoji.id, animated: emoji.animated }; - } catch { - emoji = emojiString.addBrackets().trim() || undefined; } } } diff --git a/src/functions/addSelectMenuTo.js b/src/functions/addSelectMenuTo.js index 1f5ba6db6..7fa5cab45 100644 --- a/src/functions/addSelectMenuTo.js +++ b/src/functions/addSelectMenuTo.js @@ -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 + }; + } } } diff --git a/src/functions/createPoll.js b/src/functions/createPoll.js index 0cf518c36..34ce2ba08 100644 --- a/src/functions/createPoll.js +++ b/src/functions/createPoll.js @@ -22,22 +22,23 @@ module.exports = async (d) => { if (Math.floor(time) > 168) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Poll duration must be less than or equal to 7 days"); if (Math.floor(time) < 1) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Poll duration must be longer than or equal 1 hour"); - answers.forEach((x) => { + answers = answers.map(async (x) => { const answer = x.split(":"); let emoji = answer[1]; - try { - emoji = d.util.getEmoji(d, emoji.addBrackets()).id; - } catch { - emoji = emoji?.addBrackets() ?? undefined; + if (emoji) { + emoji = (await d.util.getEmoji(d, emoji.addBrackets()))?.id; + if (!emoji) emoji = answer[1].addBrackets().trim(); } - answers[answers.indexOf(x)] = { + return { text: answer[0], - emoji + emoji: emoji || null }; }); + answers = await Promise.all(answers); + if (answers.length > 10) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Poll answers must be less than or equal to 10"); duration = time; @@ -56,4 +57,4 @@ module.exports = async (d) => { return { code: d.util.setCode(data) }; -}; +}; \ No newline at end of file diff --git a/src/functions/emojiExists.js b/src/functions/emojiExists.js index d85f5881a..f27220676 100644 --- a/src/functions/emojiExists.js +++ b/src/functions/emojiExists.js @@ -1,3 +1,5 @@ +const { GuildEmoji } = require("discord.js"); + /** * @param {import("..").Data} d */ @@ -5,24 +7,16 @@ module.exports = async (d) => { const data = d.util.aoiFunc(d); if (data.err) return d.error(data.err); - let [emoji] = data.inside.splits; + const [emoji] = data.inside.splits; - try { - emoji = d.util.getEmoji(d, emoji.addBrackets()).id; - data.result = true; - } catch { - emoji = emoji?.addBrackets() ?? undefined; - } + let emojiString = (await d.util.getEmoji(d, emoji.addBrackets())); + if (!emojiString) emojiString = emoji.toString().addBrackets(); - if (data.result === true) { + if (!(emojiString instanceof GuildEmoji)) { data.result = true; } else { - if (!emoji) { - data.result = false; - } else { - const regex = /\p{Extended_Pictographic}/gu; - data.result = regex.test(emoji); - } + const regex = /\p{Extended_Pictographic}/gu; + data.result = regex.test(emojiId); } return { diff --git a/src/functions/reactionCount.js b/src/functions/reactionCount.js index 281dc7882..81f453a7d 100644 --- a/src/functions/reactionCount.js +++ b/src/functions/reactionCount.js @@ -13,19 +13,14 @@ module.exports = async (d) => { const message = await d.util.getMessage(channel, messageID); if (!message) return d.aoiError.fnError(d, "message", { inside: data.inside }); - let emoji; + let emoji = (await d.util.getEmoji(d, emojiResolver))?.id; + if (!emoji) emoji = emojiResolver.addBrackets().trim(); - try { - emoji = message.reactions.cache.find((x) => x.emoji.id === d.util.getEmoji(d, emojiResolver).id)?.count; - } catch { - emoji = message.reactions.cache.find((x) => x.emoji.toString().toLowerCase() === emojiResolver.toLowerCase())?.count; - } finally { - emoji = emoji ?? 0; - } + emoji = message.reactions.cache.find((x) => x.emoji.id === emoji || x.emoji.toString().toLowerCase() === emoji.toLowerCase())?.count ?? 0; data.result = emoji; return { - code: d.util.setCode(data), + code: d.util.setCode(data) }; }; diff --git a/src/functions/resolveEmojiID.js b/src/functions/resolveEmojiID.js index 2c25a09b1..262a4a83a 100644 --- a/src/functions/resolveEmojiID.js +++ b/src/functions/resolveEmojiID.js @@ -7,7 +7,7 @@ module.exports = async (d) => { const emoji = data.inside.inside; - data.result = (await d.util.getEmoji(d, emoji))?.id ?? ""; + data.result = (await d.util.getEmoji(d, emoji))?.id ?? null; return { code: d.util.setCode(data), From 80a1d421ab8d40265c704493053eb886a43780b2 Mon Sep 17 00:00:00 2001 From: Faf4a <87046111+Faf4a@users.noreply.github.com> Date: Mon, 7 Oct 2024 10:15:57 +0200 Subject: [PATCH 06/11] feat: avatarUrl option for member events --- src/utils/Constants.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/Constants.js b/src/utils/Constants.js index 1f41d7e85..99b471c3e 100644 --- a/src/utils/Constants.js +++ b/src/utils/Constants.js @@ -127,6 +127,7 @@ const ChannelOptions = { const MemberOptions = { id: (member) => member.id, name: (member) => member.user?.username?.deleteBrackets(), + avatarUrl: (member) => member.user.displayAvatarURL(), guildID: (member) => member.guild.id, nick: (member) => member.nickname || "", roles: (member) => From 510025c88f03ee6fbbebd098ca8648ec5739164f Mon Sep 17 00:00:00 2001 From: Faf4a <87046111+Faf4a@users.noreply.github.com> Date: Mon, 7 Oct 2024 10:24:15 +0200 Subject: [PATCH 07/11] feat: setVoiceStatus --- src/functions/setVoiceStatus.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/functions/setVoiceStatus.js diff --git a/src/functions/setVoiceStatus.js b/src/functions/setVoiceStatus.js new file mode 100644 index 000000000..91b1a6fe7 --- /dev/null +++ b/src/functions/setVoiceStatus.js @@ -0,0 +1,27 @@ +const { Routes } = 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 [voiceID, voiceStatus] = data.inside.splits; + + if (voiceStatus.length > 300) return d.aoiError.fnError(d, "custom", {}, "Voice Status cannot be longer than 300 characters"); + + try { + await d.client.rest.put(Routes.channel(voiceID) + "/voice-status", { + body: { + status: voiceStatus.toString() + } + }); + } catch (e) { + return d.aoiError.fnError(d, "custom", {}, e.message); + } + + return { + code: d.util.setCode(data) + }; +}; From 409bdc978c0c27921d812c5617b0e5f79fc32deb Mon Sep 17 00:00:00 2001 From: Fafa <87046111+Faf4a@users.noreply.github.com> Date: Wed, 9 Oct 2024 12:16:08 +0200 Subject: [PATCH 08/11] fix: invalid check for get --- src/functions/get.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/functions/get.js b/src/functions/get.js index 54a2fcd4f..577518d4c 100644 --- a/src/functions/get.js +++ b/src/functions/get.js @@ -2,16 +2,18 @@ * @param {import("..").Data} d */ module.exports = async d => { - const data = d.util.aoiFunc(d); - if (data.err) return d.error(data.err); - - const [name] = data.inside.splits; + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name] = data.inside.splits; - if (!d.data?.vars?.[name.addBrackets()]) return d.aoiError.fnError(d, "custom", { inside: d.data.inside }, "Invalid variable name"); + if (!d.data?.vars?.hasOwnProperty(name.addBrackets())) { + return d.aoiError.fnError(d, "custom", { inside: d.data.inside }, "Invalid variable name"); + } - data.result = d.data.vars[name?.addBrackets()]; + data.result = d.data.vars[name.addBrackets()]; - return { - code: d.util.setCode(data) - } -} \ No newline at end of file + return { + code: d.util.setCode(data) + }; +}; From 60409a31033eee054f8210528c3f9e97cf74d07a Mon Sep 17 00:00:00 2001 From: Fafa <87046111+Faf4a@users.noreply.github.com> Date: Wed, 9 Oct 2024 12:18:24 +0200 Subject: [PATCH 09/11] fix: invalid property --- src/functions/get.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions/get.js b/src/functions/get.js index 577518d4c..60dd86908 100644 --- a/src/functions/get.js +++ b/src/functions/get.js @@ -8,7 +8,7 @@ module.exports = async d => { const [name] = data.inside.splits; if (!d.data?.vars?.hasOwnProperty(name.addBrackets())) { - return d.aoiError.fnError(d, "custom", { inside: d.data.inside }, "Invalid variable name"); + return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid variable name"); } data.result = d.data.vars[name.addBrackets()]; From c5589008b7091d977f21f2c11fc0c378b2f8800c Mon Sep 17 00:00:00 2001 From: Faf4a <87046111+Faf4a@users.noreply.github.com> Date: Fri, 11 Oct 2024 18:44:55 +0200 Subject: [PATCH 10/11] fix: reaction events --- src/events/GuildMessageReactions/add.js | 2 +- src/events/GuildMessageReactions/remove.js | 2 +- src/events/GuildMessageReactions/removeAll.js | 2 +- src/events/GuildMessageReactions/removeEmoji.js | 2 +- src/functions/reactionData.js | 15 ++++++--------- src/utils/Constants.js | 13 +++++++++++++ 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/events/GuildMessageReactions/add.js b/src/events/GuildMessageReactions/add.js index 8643fc31f..60242281c 100644 --- a/src/events/GuildMessageReactions/add.js +++ b/src/events/GuildMessageReactions/add.js @@ -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 = { diff --git a/src/events/GuildMessageReactions/remove.js b/src/events/GuildMessageReactions/remove.js index 45512519a..7588d3e23 100644 --- a/src/events/GuildMessageReactions/remove.js +++ b/src/events/GuildMessageReactions/remove.js @@ -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 = { diff --git a/src/events/GuildMessageReactions/removeAll.js b/src/events/GuildMessageReactions/removeAll.js index bcd97fa61..cee0a14ae 100644 --- a/src/events/GuildMessageReactions/removeAll.js +++ b/src/events/GuildMessageReactions/removeAll.js @@ -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 = { diff --git a/src/events/GuildMessageReactions/removeEmoji.js b/src/events/GuildMessageReactions/removeEmoji.js index 290da5e1f..ee845c7c8 100644 --- a/src/events/GuildMessageReactions/removeEmoji.js +++ b/src/events/GuildMessageReactions/removeEmoji.js @@ -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 = { diff --git a/src/functions/reactionData.js b/src/functions/reactionData.js index dc2e51a7b..0a57eb884 100644 --- a/src/functions/reactionData.js +++ b/src/functions/reactionData.js @@ -1,20 +1,17 @@ -const {Emoji} = require('../core/functions.js'); +const { ReactionOptions } = require("../utils/Constants"); /** * @param {import("..").Data} d */ -module.exports = async d => { +module.exports = async (d) => { const data = d.util.aoiFunc(d); const [option = "name"] = data.inside.splits; - const reactionData = Emoji(d.data.reactionData.emoji); - reactionData.usernames = d.data.reactionData.users.cache.map(y => y.username.deleteBrackets()).join(" , "); - reactionData.userIds = d.data.reactionData.users.cache.map(y => y.id).join(" , "); - reactionData.tags = d.data.reactionData.users.cache.map(y => y.tag.deleteBrackets()).join(" , "); + const reactionData = ReactionOptions[option](d.data.reactionData); - data.result = reactionData?.[option].deleteBrackets(); + data.result = reactionData ?? null; return { code: d.util.setCode(data) - } -} \ No newline at end of file + }; +}; diff --git a/src/utils/Constants.js b/src/utils/Constants.js index 99b471c3e..a00ed7cb0 100644 --- a/src/utils/Constants.js +++ b/src/utils/Constants.js @@ -173,6 +173,18 @@ const MemberOptions = { threadFlags: (member) => member.flags?.toArray() || [] }; +const ReactionOptions = { + channelId: (reaction) => reaction.message.channel.id, + guildId: (reaction) => reaction.message.guild.id, + messageId: (reaction) => reaction.message.id, + name: (reaction) => reaction._emoji.name, + id: (reaction) => reaction._emoji.id, + emoji: (reaction) => reaction._emoji.toString(), + count: (reaction) => reaction.count, + usernames: (reaction) => reaction.users.cache.map(y => y.username.deleteBrackets()).join(" , "), + userIds: (reaction) => reaction.users.cache.map(y => y.id).join(" , "), +} + const ButtonStyleOptions = { primary: 1, secondary: 2, @@ -514,6 +526,7 @@ module.exports = { ButtonStyleOptions, ChannelOptions, MemberOptions, + ReactionOptions, CacheOptions, SlashOptionTypes, Permissions, From 13917237dbcf4877d72eac5071771265823819b6 Mon Sep 17 00:00:00 2001 From: Fafa <87046111+Faf4a@users.noreply.github.com> Date: Sat, 12 Oct 2024 13:26:18 +0200 Subject: [PATCH 11/11] fix: awaitmessages error message --- src/functions/awaitMessages.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions/awaitMessages.js b/src/functions/awaitMessages.js index 4872a797b..e710ce2e8 100644 --- a/src/functions/awaitMessages.js +++ b/src/functions/awaitMessages.js @@ -77,6 +77,7 @@ module.exports = async (d) => { channel, errorMsg.data ?? errorMsg, errorMsg.options, + d, ); } });