Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New mod, multiple regex comparisons #71

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}

}