no more websocket calls in automation
This commit is contained in:
110
fgfm.js
110
fgfm.js
@@ -70,7 +70,6 @@ const twitchInit = (config) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Initialize Stream automation
|
// Initialize Stream automation
|
||||||
// @TODO: Move anything that calls websocket here to GHOBS lib
|
|
||||||
const streamInit = (config, twitch) => {
|
const streamInit = (config, twitch) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// Set up the initial queue by randomly choosing the configured amount of vods included in shuffling
|
// Set up the initial queue by randomly choosing the configured amount of vods included in shuffling
|
||||||
@@ -225,88 +224,33 @@ const streamInit = (config, twitch) => {
|
|||||||
|
|
||||||
// SHOW/HIDE SOURCE
|
// SHOW/HIDE SOURCE
|
||||||
if (commandNoPrefix === 'show' || commandNoPrefix === 'hide') {
|
if (commandNoPrefix === 'show' || commandNoPrefix === 'hide') {
|
||||||
|
|
||||||
let newVisibility = (commandNoPrefix === 'show');
|
let newVisibility = (commandNoPrefix === 'show');
|
||||||
let visibleTerm = (newVisibility ? 'visible' : 'hidden');
|
|
||||||
|
|
||||||
let target = commandParts[1] || false;
|
let sceneItem = commandParts[1] || false;
|
||||||
if (!target) {
|
if (!sceneItem) {
|
||||||
twitch.botChat.say(to, `A scene item name is required!`);
|
twitch.botChat.say(to, `A scene item name is required!`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let sceneItem = {"item": target};
|
let sceneOrGroup = commandParts[2] || obs.currentScene;
|
||||||
|
obs.setVisible(sceneItem, sceneOrGroup, newVisibility).catch(console.error);
|
||||||
let sceneOrGroup = commandParts[2] || false;
|
|
||||||
if (sceneOrGroup !== false) {
|
|
||||||
sceneItem["scene-name"] = sceneOrGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
obs.websocket.getSceneItemProperties(sceneItem)
|
|
||||||
.then(data => {
|
|
||||||
if (data.visible === newVisibility) {
|
|
||||||
twitch.botChat.say(to, `This scene item is already ${visibleTerm}. DerpHam`);
|
|
||||||
} else {
|
|
||||||
sceneItem.visible = newVisibility;
|
|
||||||
obs.websocket.setSceneItemProperties(sceneItem)
|
|
||||||
.then(res => {
|
|
||||||
twitch.botChat.say(to, `${target} is now ${visibleTerm}.`);
|
|
||||||
})
|
|
||||||
.catch(console.error);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
twitch.botChat.say(to, JSON.stringify(err));
|
|
||||||
});
|
|
||||||
|
|
||||||
// TOGGLE SOURCE VISIBILITY
|
// TOGGLE SOURCE VISIBILITY
|
||||||
} else if (commandNoPrefix === 't') {
|
} else if (commandNoPrefix === 't') {
|
||||||
let target = commandParts[1] || false;
|
let sceneItem = commandParts[1] || false;
|
||||||
if (!target) {
|
if (!sceneItem) {
|
||||||
twitch.botChat.say(to, `A scene item name is required!`);
|
twitch.botChat.say(to, `A scene item name is required!`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let sceneItem = {"item": target};
|
obs.toggleVisible(sceneItem).catch(console.error);
|
||||||
|
|
||||||
obs.websocket.getSceneItemProperties(sceneItem)
|
|
||||||
.then(data => {
|
|
||||||
let newVisibility = !data.visible;
|
|
||||||
let visibleTerm = (newVisibility ? 'visible' : 'hidden');
|
|
||||||
|
|
||||||
sceneItem.visible = newVisibility;
|
|
||||||
obs.websocket.setSceneItemProperties(sceneItem)
|
|
||||||
.then(res => {
|
|
||||||
twitch.botChat.say(to, `${target} is now ${visibleTerm}.`);
|
|
||||||
})
|
|
||||||
.catch(console.error);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
twitch.botChat.say(to, JSON.stringify(err));
|
|
||||||
});
|
|
||||||
|
|
||||||
// SWAP -- Hide one source, show another
|
|
||||||
} else if (commandNoPrefix === 'swap') {
|
|
||||||
// hide first argument, show second argument
|
|
||||||
let targetToHide = commandParts[1] || false;
|
|
||||||
let targetToShow = commandParts[2] || false;
|
|
||||||
if (targetToHide === false || targetToShow == false) {
|
|
||||||
twitch.botChat.say(to, `Format: ${config.twitch.cmdPrefix}swap <item-to-hide> <item-to-show>`);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
obs.websocket.setSceneItemProperties({"item": targetToHide, "visible": false})
|
|
||||||
.then(res => {
|
|
||||||
obs.websocket.setSceneItemProperties({"item": targetToShow, "visible": true});
|
|
||||||
})
|
|
||||||
.catch(console.error);
|
|
||||||
|
|
||||||
// Black Box "Everybody Wow"
|
// EVERYBODY WOW
|
||||||
} else if (commandNoPrefix === 'auw') {
|
} else if (commandNoPrefix === 'auw') {
|
||||||
state.commercialPlaying = true;
|
state.commercialPlaying = true;
|
||||||
showMeme('auw').then(() => state.commercialPlaying = false).catch(console.error);
|
showMeme('auw').then(() => state.commercialPlaying = false).catch(console.error);
|
||||||
|
|
||||||
// Memes on-demand
|
// MEMES ON-DEMAND
|
||||||
} else if (commandNoPrefix === 'meme') {
|
} else if (commandNoPrefix === 'meme') {
|
||||||
let memeId = commandParts[1] || false;
|
let memeId = commandParts[1] || false;
|
||||||
if (memeId) {
|
if (memeId) {
|
||||||
@@ -326,38 +270,23 @@ const streamInit = (config, twitch) => {
|
|||||||
// SWITCH SCENES
|
// SWITCH SCENES
|
||||||
} else if (commandNoPrefix === 'switch') {
|
} else if (commandNoPrefix === 'switch') {
|
||||||
|
|
||||||
let target = commandParts[1] || false;
|
let newScene = commandParts[1] || false;
|
||||||
if (!target) {
|
if (!newScene) {
|
||||||
twitch.botChat.say(to, `A scene name is required!`);
|
twitch.botChat.say(to, `A scene name is required!`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
obs.websocket.getCurrentScene()
|
obs.switchToScene(newScene).catch(console.error);
|
||||||
.then(data => {
|
|
||||||
if (data.name === target) {
|
|
||||||
twitch.botChat.say(to, `That scene is already active! DerpHam`);
|
|
||||||
} else {
|
|
||||||
obs.websocket.setCurrentScene({"scene-name": target})
|
|
||||||
.then(() => {twitch.botChat.say(to, `${target} is now active`)})
|
|
||||||
.catch(console.error);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(console.error);
|
|
||||||
|
|
||||||
// SET ON-SCREEN ACTIVITY
|
// SET ON-SCREEN ACTIVITY
|
||||||
} else if (commandNoPrefix === 'setactivity') {
|
} else if (commandNoPrefix === 'setactivity') {
|
||||||
let target = commandParts.slice(1).join(' ');
|
let newActivity = commandParts.slice(1).join(' ');
|
||||||
if (!target) {
|
if (!newActivity) {
|
||||||
twitch.botChat.say(to, `Please provide a new activity`);
|
twitch.botChat.say(to, `Please provide a new activity`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
obs.websocket.setTextGDIPlusProperties({"source": config.currentActivitySceneItemName, "scene-name": config.defaultSceneName, "render": true, "text": target})
|
obs.showActivity(newActivity).then(() => twitch.botChat.say(to, `Activity updated!`)).catch(console.error);
|
||||||
.then(res => {
|
|
||||||
twitch.botChat.say(to, `Activity updated!`);
|
|
||||||
return;
|
|
||||||
})
|
|
||||||
.catch(console.error);
|
|
||||||
|
|
||||||
// REBOOT
|
// REBOOT
|
||||||
} else if (commandNoPrefix === 'reboot') {
|
} else if (commandNoPrefix === 'reboot') {
|
||||||
@@ -368,10 +297,7 @@ const streamInit = (config, twitch) => {
|
|||||||
// SKIP
|
// SKIP
|
||||||
} else if (commandNoPrefix === 'skip') {
|
} else if (commandNoPrefix === 'skip') {
|
||||||
clearTimeout(state.videoTimer);
|
clearTimeout(state.videoTimer);
|
||||||
obs.websocket.setSceneItemProperties({"item": state.currentVideo.sceneItem, "scene-name": config.defaultSceneName, "visible": false})
|
obs.hide(state.currentVideo.sceneItem, config.defaultSceneName).then(nextVideo).catch(console.error);
|
||||||
.then(res => {
|
|
||||||
nextVideo();
|
|
||||||
});
|
|
||||||
|
|
||||||
// ADD
|
// ADD
|
||||||
} else if (commandNoPrefix === 'add') {
|
} else if (commandNoPrefix === 'add') {
|
||||||
@@ -401,8 +327,8 @@ const streamInit = (config, twitch) => {
|
|||||||
|
|
||||||
// START VOTE
|
// START VOTE
|
||||||
} else if (commandNoPrefix === 'startvote') {
|
} else if (commandNoPrefix === 'startvote') {
|
||||||
videoVoteJob.reschedule("*/15 * * * *");
|
videoVoteJob.reschedule(`*/${config.videoPollIntervalMinutes} * * * *`);
|
||||||
twitch.botChat.say(to, `Video Queue Voting will start in 15 minutes!`);
|
twitch.botChat.say(to, `Video Queue Voting will start in ${config.videoPollIntervalMinutes} minutes!`);
|
||||||
|
|
||||||
// PAUSE VOTE
|
// PAUSE VOTE
|
||||||
} else if (commandNoPrefix === 'pausevote') {
|
} else if (commandNoPrefix === 'pausevote') {
|
||||||
|
|||||||
21
lib/ghobs.js
21
lib/ghobs.js
@@ -97,6 +97,17 @@ function GHOBS(config) {
|
|||||||
return this.websocket.setSceneItemProperties({"item": item, "scene-name": scene, "visible": visible});
|
return this.websocket.setSceneItemProperties({"item": item, "scene-name": scene, "visible": visible});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.toggleVisible(item) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.websocket.getSceneItemProperties({"item": item})
|
||||||
|
.then(data => {
|
||||||
|
let newVisibility = !data.visible;
|
||||||
|
this.websocket.setSceneItemProperties({"item": item, "visible": newVisibility}).then(resolve);
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.show = (item, scene) => {
|
this.show = (item, scene) => {
|
||||||
return this.setVisible(item, scene, true);
|
return this.setVisible(item, scene, true);
|
||||||
};
|
};
|
||||||
@@ -104,6 +115,16 @@ function GHOBS(config) {
|
|||||||
this.hide = (item, scene) => {
|
this.hide = (item, scene) => {
|
||||||
return this.setVisible(item, scene, false);
|
return this.setVisible(item, scene, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.switchToScene(scene) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (this.currentScene === scene) {
|
||||||
|
resolve(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.websocket.setCurrentScene({"scene-name": scene}).then(resolve).catch(reject);
|
||||||
|
});
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = GHOBS;
|
module.exports = GHOBS;
|
||||||
|
|||||||
Reference in New Issue
Block a user