more obs control

This commit is contained in:
Chris Ham
2018-09-12 07:43:10 -07:00
parent 3e1874ce4d
commit bd93260e21
15 changed files with 55 additions and 34 deletions

View File

@@ -15,7 +15,11 @@
"channels": ["#greenham"], "channels": ["#greenham"],
"cmdPrefix": "$", "cmdPrefix": "$",
"blacklistedUsers": [], "blacklistedUsers": [],
"admins": ["greenham","greenhambot"] "admins": ["greenham","greenhambot"],
"editorLogin": {
"username": "greenham",
"oauth": "oauth:gmi4sjl3k0we0d4gsppkrcqcjpdma6"
}
}, },
"obs": { "obs": {
"websocket": { "websocket": {

BIN
sfx/bananas.mp3 Executable file

Binary file not shown.

BIN
sfx/dbio.mp3 Executable file

Binary file not shown.

BIN
sfx/highscore.mp3 Executable file

Binary file not shown.

BIN
sfx/lanmo.mp3 Executable file

Binary file not shown.

BIN
sfx/loz.mp3 Executable file

Binary file not shown.

BIN
sfx/mash.mp3 Executable file

Binary file not shown.

BIN
sfx/mmmm.mp3 Executable file

Binary file not shown.

BIN
sfx/onejoint.mp3 Executable file

Binary file not shown.

BIN
sfx/robotears.mp3 Executable file

Binary file not shown.

BIN
sfx/toofat.mp3 Executable file

Binary file not shown.

BIN
sfx/trinexx.mp3 Executable file

Binary file not shown.

BIN
sfx/vitty.mp3 Executable file

Binary file not shown.

BIN
sfx/youguys.mp3 Executable file

Binary file not shown.

View File

@@ -2,6 +2,10 @@
* GHBot4Twitch * GHBot4Twitch
*/ */
// @TODO: Make the bot aware of what video is current active
// @TODO: Change video playlist source on an interval
// Import modules // Import modules
const irc = require('irc'); const irc = require('irc');
const OBSWebSocket = require('obs-websocket-js'); const OBSWebSocket = require('obs-websocket-js');
@@ -19,8 +23,8 @@ const init = (config) => {
obs.connect({ address: config.obs.websocket.address, password: config.obs.websocket.password }) obs.connect({ address: config.obs.websocket.address, password: config.obs.websocket.password })
.then(() => { .then(() => {
console.log(`Success! We're connected to OBS!`); console.log(`Success! We're connected to OBS!`);
obs.getSourcesList().then(data => {console.log(data.sources)}).catch(console.error); //obs.getSourcesList().then(data => {console.log(data.sources)}).catch(console.error);
twitchChat = twitchInit(config, obs); twitchInit(config, obs);
}) })
.catch(err => { .catch(err => {
console.log(err); console.log(err);
@@ -33,7 +37,7 @@ const init = (config) => {
const twitchInit = (config, obs) => { const twitchInit = (config, obs) => {
console.log('Connecting to Twitch...'); console.log('Connecting to Twitch...');
// Connect to Twitch IRC server // Connect to Twitch IRC server with the Bot
let twitchChat = new irc.Client(config.twitch.ircServer, config.twitch.username, { let twitchChat = new irc.Client(config.twitch.ircServer, config.twitch.username, {
password: config.twitch.oauth, password: config.twitch.oauth,
autoRejoin: true, autoRejoin: true,
@@ -42,6 +46,15 @@ const init = (config) => {
debug: config.debug debug: config.debug
}); });
// Also connect with an editor account
let editorChat = new irc.Client(config.twitch.ircServer, config.twitch.editorLogin.username, {
password: config.twitch.editorLogin.oauth,
autoRejoin: true,
retryCount: 10,
channels: config.twitch.channels,
debug: config.debug
});
// Set up event listeners for Twitch // Set up event listeners for Twitch
twitchChat.addListener('message', (from, to, message) => { twitchChat.addListener('message', (from, to, message) => {
// Ignore everything from blacklisted users // Ignore everything from blacklisted users
@@ -54,42 +67,32 @@ const init = (config) => {
// Listen for specific commands from admins // Listen for specific commands from admins
if (config.twitch.admins.includes(from) || from === config.twitch.username.toLowerCase()) { if (config.twitch.admins.includes(from) || from === config.twitch.username.toLowerCase()) {
if (commandNoPrefix === 'show') { if (commandNoPrefix === 'show' || commandNoPrefix === 'hide') {
let newVisibility = (commandNoPrefix === 'show');
let visibleTerm = (newVisibility ? 'visible' : 'hidden');
let target = commandParts[1] || false; let target = commandParts[1] || false;
if (!target) { if (!target) {
twitchChat.say(to, `A scene item name is required!`); twitchChat.say(to, `A scene item name is required!`);
return; return;
} }
obs.getSceneItemProperties({"item": target}) let sceneItem = {"item": target};
.then(data => {
if (data.visible === true) { let sceneOrGroup = commandParts[2] || false;
twitchChat.say(to, "This scene item is already visible. DerpHam"); if (sceneOrGroup !== false) {
} else { sceneItem["scene-name"] = sceneOrGroup;
obs.setSceneItemProperties({"item": target, "visible": true})
.then(res => {
twitchChat.say(to, `${target} is now visible.`);
})
.catch(console.error);
} }
})
.catch(err => { obs.getSceneItemProperties(sceneItem)
twitchChat.say(to, JSON.stringify(err));
});
} else if (commandNoPrefix === 'hide') {
let target = commandParts[1] || false;
if (!target) {
twitchChat.say(to, `A scene item name is required!`);
return;
}
obs.getSceneItemProperties({"item": target})
.then(data => { .then(data => {
if (data.visible === false) { if (data.visible === newVisibility) {
twitchChat.say(to, "This scene item is already hidden. DerpHam"); twitchChat.say(to, `This scene item is already ${visibleTerm}. DerpHam`);
} else { } else {
obs.setSceneItemProperties({"item": target, "visible": false}) sceneItem.visible = newVisibility;
obs.setSceneItemProperties(sceneItem)
.then(res => { .then(res => {
twitchChat.say(to, `${target} is now hidden.`); twitchChat.say(to, `${target} is now ${visibleTerm}.`);
}) })
.catch(console.error); .catch(console.error);
} }
@@ -98,15 +101,26 @@ const init = (config) => {
twitchChat.say(to, JSON.stringify(err)); twitchChat.say(to, JSON.stringify(err));
}); });
} else if (commandNoPrefix === 'auw') { } else if (commandNoPrefix === 'auw') {
// @TODO: pause songrequest or otherwise fade out its audio
obs.setSceneItemProperties({"item": "everybody-wow", "visible": true}) obs.setSceneItemProperties({"item": "everybody-wow", "visible": true})
.then(res => { .then(res => {
// fade out headphone audio
/*for (i = 100; i >= 0; i--) {
obs.setVolume({"source": "headphones", "volume": i/100});
}*/
// @TODO: send command to mute the songrequest audio
editorChat.say(to, '!volume 0');
twitchChat.say(to, 'Everybody OwenWow'); twitchChat.say(to, 'Everybody OwenWow');
// hide the source after a certain amount of time (248s in this case) // hide the source after a certain amount of time (248s in this case)
setTimeout(() => { setTimeout(() => {
obs.setSceneItemProperties({"item": "everybody-wow", "visible": false}) obs.setSceneItemProperties({"item": "everybody-wow", "visible": false})
.then(res => { .then(res => {
// @TODO: resume songrequest or otherwise fade in its audio // fade in headphone audio
/*for (i = 1; i <= 100; i++) {
obs.setVolume({"source": "headphones", "volume": i/100});
}*/
// @TODO: send command to unmute the songrequest audio
editorChat.say(to, '!volume 75');
twitchChat.say(to, 'OwenWow'); twitchChat.say(to, 'OwenWow');
}).catch(console.error); }).catch(console.error);
}, 248000); }, 248000);
@@ -143,6 +157,11 @@ const init = (config) => {
console.error('error from Twitch IRC Server: ', message); console.error('error from Twitch IRC Server: ', message);
} }
}); });
editorChat.addListener('error', message => {
if (message.command != 'err_unknowncommand') {
console.error('error from Twitch IRC Server: ', message);
}
});
twitchChat.addListener('registered', message => { twitchChat.addListener('registered', message => {
console.log(`Connected to ${message.server}`); console.log(`Connected to ${message.server}`);
@@ -163,8 +182,6 @@ const init = (config) => {
twitchChat.addListener('motd', motd => { twitchChat.addListener('motd', motd => {
console.log(`Received MOTD: ${motd}`); console.log(`Received MOTD: ${motd}`);
}); });
return twitchChat;
} }
} }