First commit of "advanced" MCI formatting via theme.hjson entries allowing mini-formatting langauge to apply

Example: {BN!styleFirstLower} in 'text' property
This commit is contained in:
Bryan Ashby
2022-10-05 21:46:13 -06:00
parent 1021226020
commit 065658f6b8
6 changed files with 38 additions and 57 deletions

View File

@@ -22,6 +22,7 @@ const moment = require('moment');
const async = require('async');
exports.getPredefinedMCIValue = getPredefinedMCIValue;
exports.getPredefinedMCIFormatObject = getPredefinedMCIFormatObject;
exports.init = init;
function init(cb) {
@@ -532,3 +533,21 @@ function getPredefinedMCIValue(client, code, extra) {
return value;
}
}
function getPredefinedMCIFormatObject(client, text) {
const re = /\{([A-Z]{2})(?:[!:][^}]+)?\}/g;
let m;
const formatObj = {};
while ((m = re.exec(text))) {
const v = getPredefinedMCIValue(client, m[1]);
if (v) {
if (!isNaN(v)) {
formatObj[m[1]] = parseInt(v);
} else {
formatObj[m[1]] = v;
}
}
}
return _.isEmpty(formatObj) ? null : formatObj;
}