Skip to content

Commit

Permalink
send mixer roles to custom scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ebiggz committed Oct 31, 2017
1 parent 9d04c6b commit b2fa07d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
31 changes: 28 additions & 3 deletions lib/common/handlers/custom-scripts/customScriptProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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),
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/common/mixer-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down

0 comments on commit b2fa07d

Please sign in to comment.