Skip to content

Commit

Permalink
Modified AwaitData
Browse files Browse the repository at this point in the history
  • Loading branch information
supremesupreme committed Oct 5, 2024
1 parent 37cbab3 commit 87e81e6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
65 changes: 37 additions & 28 deletions src/functions/ForEachObjectArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = async (d) => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

const [name, property, awaitedCmd, awaitData = "{}", endCmd] = data.inside.splits;
const [name, property, awaitedCmd, endCmd] = data.inside.splits;

if (!d.data.objects?.[name]) {
return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Array With Name '" + name + "' Does Not Exist.");
Expand All @@ -21,39 +21,48 @@ module.exports = async (d) => {
if (!cmd) {
return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Awaited Command With Name '" + awaitedCmd + "' Does Not Exist.");
}
let parsedData;
try {
parsedData = JSON.parse(awaitData);
} catch (e) {
return d.aoiError.fnError(d, "custom", {}, `Failed To Parse Data With Reason: ${e.message}`);
}

for (const key in property) {
console.log(`Key: ${key}`);

property[key].forEach((value) => {
console.log(value);
});
}
let parsedData = {};
for (const key in d.data.objects[name]) {
if (Array.isArray(d.data.objects[name][key])) {
parsedData[key] = d.data.objects[name][key]
}
}

let i = 0;
for (const el of d.arrays[name]) {
const c = { ...cmd };
c.code = c.code.replaceAll("{value}", el);
await Interpreter(d.client, d.message, d.args, c, d.client.db, true, undefined, { ...d.data, awaitData: parsedData, index: i });
i++;
}
for (const key in d.data.objects[name]) {
if (d.data.objects[name].hasOwnProperty(key)) {

const el = d.data.objects[name][key];
const c = { ...cmd };
c.code = c.code.replaceAll("{value}", el);

if (endCmd.trim() !== "") {
const cmd = d.client.cmd.awaited.find((x) => x.name.toLowerCase() === endCmd.addBrackets().toLowerCase());
if (!cmd) return;
await d.interpreter(d.client, d.message, d.args, cmd, d.client.db, false, undefined, {
awaitData,
index: i
});
if(Array.isArray(el)){
let parsedResult = JSON.stringify(parsedData[property][i])
const result = await Interpreter(
d.client,
d.message,
d.args,
c,
d.client.db,
true,
undefined,
{ ...d.data, awaitData: parsedResult, index: i }
);
i++;
}
}
}

if (endCmd.trim() !== "") {
const cmd = d.client.cmd.awaited.find((x) => x.name.toLowerCase() === endCmd.addBrackets().toLowerCase());
if (!cmd) return;
await d.interpreter(d.client, d.message, d.args, cmd, d.client.db, false, undefined, {
index: i-1
});
}

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

try {
data.result = eval(`d.data.awaitData?.${option.addBrackets()}`);
} catch (e) {
data.result = undefined;
} finally{
data.result = eval(`d.data.awaitData`);
}
return {
code: d.util.setCode(data),
Expand Down

0 comments on commit 87e81e6

Please sign in to comment.