Skip to content

Commit

Permalink
Merge pull request #487 from Faf4a/v6
Browse files Browse the repository at this point in the history
v6
  • Loading branch information
Leref authored Oct 7, 2023
2 parents e2706d4 + 05f84a5 commit 1b9f946
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 70 deletions.
4 changes: 2 additions & 2 deletions src/classes/AoiError.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -135,7 +135,7 @@ class AoiError {
)
return;
msg = await channel.send(options).catch((e) => {
this.consoleError("CreateMessageError", e);
AoiError.consoleError("CreateMessageError", e);
return undefined;
});
}
Expand Down
19 changes: 19 additions & 0 deletions src/functions/guild/getGuildTemplate.js
Original file line number Diff line number Diff line change
@@ -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),
};
};
21 changes: 21 additions & 0 deletions src/functions/guild/getGuildTemplates.js
Original file line number Diff line number Diff line change
@@ -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),
};
};
1 change: 1 addition & 0 deletions src/functions/interaction/addButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
1 change: 1 addition & 0 deletions src/functions/interaction/addField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
184 changes: 117 additions & 67 deletions src/functions/interaction/addSelectMenu.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
1 change: 1 addition & 0 deletions src/functions/interaction/addTimestamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
1 change: 1 addition & 0 deletions src/functions/interaction/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
1 change: 1 addition & 0 deletions src/functions/interaction/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
1 change: 1 addition & 0 deletions src/functions/interaction/description.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
1 change: 1 addition & 0 deletions src/functions/interaction/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
1 change: 1 addition & 0 deletions src/functions/interaction/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
1 change: 1 addition & 0 deletions src/functions/interaction/thumbnail.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
3 changes: 2 additions & 1 deletion src/functions/interaction/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
};
33 changes: 33 additions & 0 deletions src/functions/misc/editObjectProperty.js
Original file line number Diff line number Diff line change
@@ -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 } },
};
};

16 changes: 16 additions & 0 deletions src/functions/user/isBotVerified.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
File renamed without changes.
File renamed without changes.

0 comments on commit 1b9f946

Please sign in to comment.