Skip to content

Commit

Permalink
fix: Create a Regex object when creating menu from JSON object
Browse files Browse the repository at this point in the history
  • Loading branch information
benchambule committed Jul 27, 2024
1 parent fb018d5 commit 90a544e
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,14 @@ class Bot {
* }
*/
addMenu(menu){
this.at(menu.name, async () => {
this.at(menu.name, async function(req, tags){
if(menu.required && menu.required.regex){
menu.required.regex = new RegExp(menu.required.regex);
}

return {
menu: menu
menu: menu,
tags: tags,
}
});
}
Expand Down Expand Up @@ -597,18 +602,7 @@ function createBotFromJSON(json){
}
);

menus.forEach(menu => {
bot.at(menu.name, async function(req, tags){
if(menu.required && menu.required.regex){
menu.required.regex = new RegExp(menu.required.regex);
}

return {
menu: menu,
tags: tags,
}
});
});
bot.addMenus(menus);

return bot;
}
Expand All @@ -618,4 +612,4 @@ module.exports = {
createBotFromJSON: createBotFromJSON,

version: require('./package.json'),
}
}

0 comments on commit 90a544e

Please sign in to comment.