@ayanaware/bentocord
Version:
Bentocord is a Bento plugin designed to rapidly build fully functional Discord Bots.
31 lines • 928 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParseCustomId = void 0;
/**
* custom_id format: primary delimeter is ","
* the first group contains the id with optional prefix, remaining
* groups contain k/v pair states delimetered by "="
* Example of a full custom_id: prefix:some_id,foo=bar,bizz=bazz
*
* @param raw
*/
function ParseCustomId(raw) {
const parse = { id: null, state: {} };
const [id, ...rest] = raw.split(',');
const prefix = id.split(':');
if (prefix.length > 1) {
parse.prefix = prefix.slice(0, -1).join(':');
parse.id = prefix.at(-1);
}
else {
parse.id = prefix[0];
}
// loop over state k/v pairs
for (const kv of rest) {
const [k, v] = kv.split('=');
parse.state[k] = v ?? 'true';
}
return parse;
}
exports.ParseCustomId = ParseCustomId;
//# sourceMappingURL=ParseCustomId.js.map