Skip to content

Commit

Permalink
Merge pull request #71 from sinfuls-acedia/master
Browse files Browse the repository at this point in the history
New mod, multiple regex comparisons
  • Loading branch information
devvyyxyz authored Aug 14, 2024
2 parents 488abcb + 17c6fd9 commit 3b0a6f1
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions Actions/multiRegexCompare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
module.exports = {
data: {
name: "Multiple Regex Comparisons",
},
category: "Control",

info:{
source: "https://github.com/RatWasHere/bmods/blob/master/Actions",
creator: "Acedia",
},

UI: [
{
element: "input",
storeAs: "input",
name: "Value To Compare"
},
"-",
{
element: "menu",
storeAs: "cases",
name: "Comparisons",
types: {
comparison: "Comparison"
},
max: 1000,
UItypes:{
comparison:{
data:{},
name: "Regex",
UI: [
{
element: "input",
storeAs: "value",
name: "Regex Term"
},
"-",
{
element: "condition",
storeAs: "true",
storeActionsAs: "trueActions",
name: "If True"
},
"-",
{
element: "condition",
storeAs: "false",
storeActionsAs: "falseActions",
name: "If False"
}
]
}
}
}
],

subtitle: (data) => {
return `Compare ${data.input} To ${data.cases.length} Regex Terms`
},

compatibility: ["Any"],

async run(values, message, client, bridge) {

let firstValue = bridge.transf(values.input);
let matchesCriteria = false;
let comparison = null;

for (let c in values.cases) {
comparison = values.cases[c].data;
let secondValue = bridge.transf(comparison.value);

matchesCriteria = Boolean(
firstValue.match(new RegExp("^" + secondValue + "$", "i"))
);

if (matchesCriteria) {
break;
}
}

if (matchesCriteria) {
await bridge.call(comparison.true, comparison.trueActions);
} else {
await bridge.call(comparison.false, comparison.falseActions);
}
}

}

0 comments on commit 3b0a6f1

Please sign in to comment.