This may be useless but here is an option for anyone that finds this useful.
Idea taken from Discord Server Suggestion.
$quickSwitch
Usage
$quickSwitch[...shorthands;none]
Parameters
| Name | Description | Level |
| ---------- | ------------------------------------- | -------- |
| Shorthands | Shorthands to be solved | Required |
| None | Result if any shorthand wasn't solved | Required |
Information
Shorthands must have the following format.
condition => result
Examples
$quickSwitch[$ping < 100 => 🟩 Stable;$ping < 500 => 🟨 Elevated;🟥 Unusable]
$quickSwitch[$message == Hi => Hello!;$message == Bye => Goodbye!;Unhandled message.]
Function code
const { CheckCondition } = require('aoi.js/src/utils/helpers/checkCondition')
const { mustEscape } = require('aoi.js/src/utils/helpers/mustEscape')
<AoiClient>.functionManager.createFunction({
name: '$quickSwitch',
type: 'djs',
code: async (d) => {
const data = d.util.aoiFunc(d)
const [...shorthands] = data.inside.splits
if (!shorthands[0])
return d.aoiError.fnError(d, "custom", {}, "Missing shorthands")
if (shorthands.at(-1).includes('=>'))
return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid last shorthand")
let done = false
for (const shorthand of shorthands.slice(0, -1)) {
const [left, right] = shorthand.split('=>').map(x => x.trim())
const conditionResult = eval(CheckCondition.solve(mustEscape(left)))
if (conditionResult === true) data.result = right?.addBrackets(), done = true
}
if (done === false) data.result = shorthands?.at(-1)?.addBrackets()
return {
code: d.util.setCode(data)
}
}
})