diff --git a/lib/common/handlers/custom-scripts/customScriptProcessor.js b/lib/common/handlers/custom-scripts/customScriptProcessor.js index 99745323b..0fd28d2d6 100644 --- a/lib/common/handlers/custom-scripts/customScriptProcessor.js +++ b/lib/common/handlers/custom-scripts/customScriptProcessor.js @@ -70,10 +70,19 @@ function scriptProcessor(scriptName, parameters, control, participant, firebotJs modules: modules, buttonId: buttonName, username: username, + user: { + name: username + }, parameters: simpleParams } - - response = customScript.run(runRequest); + + response = getUserRoles(participant).then(roles => { + runRequest.user.roles = roles; + }).then(() => { + return customScript.run(runRequest); + }); + + } else { response = customScript.run(buttonName, username, modules); } @@ -85,7 +94,7 @@ function scriptProcessor(scriptName, parameters, control, participant, firebotJs if (response instanceof Promise) { response.then((data) => { if (isV2Script) { - /* In a V2 script, we are expecting a reponse like this: + /* In a V2 script, we are expecting a response like this: { success: boolean, errorMessage: string (optional), @@ -198,6 +207,22 @@ function scriptProcessor(scriptName, parameters, control, participant, firebotJs } } +function getUserRoles(participant) { + return new Promise((resolve, reject) => { + if(participant.userID != null) { + chat.getUser(participant.userID, r => { + if(r != null) { + resolve(r.body.userRoles); + } else { + resolve([]); + } + }); + } else { + resolve([]); + } + }); +} + // Opens the custom scripts folder ipcMain.on('openScriptsFolder', function(event) { // We include "fakescript.js" as a workaround to make it open into the 'scripts' folder instead diff --git a/lib/common/mixer-chat.js b/lib/common/mixer-chat.js index abf741cda..e18b92744 100644 --- a/lib/common/mixer-chat.js +++ b/lib/common/mixer-chat.js @@ -294,8 +294,9 @@ function getChatUserInfo(userID, callback){ callback(response); }) .catch(error => { - // Log error for dev. + // Log error for dev. console.log('Something went wrong when trying to get use info from chat api.', error); + callback(null); }); }