-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86e4d6f
commit 37cbab3
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const Interpreter = require("../core/interpreter.js"); | ||
/** | ||
* @param {import("..").Data} d | ||
*/ | ||
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; | ||
|
||
if (!d.data.objects?.[name]) { | ||
return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Array With Name '" + name + "' Does Not Exist."); | ||
} | ||
|
||
if (!property) { | ||
return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Property not found. "); | ||
} | ||
|
||
let cmd = d.client.cmd.awaited.find((c) => c.name.toLowerCase() === awaitedCmd.toLowerCase()); | ||
|
||
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 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++; | ||
} | ||
|
||
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 | ||
}); | ||
} | ||
|
||
return { | ||
code: d.util.setCode(data) | ||
}; | ||
}; |