automation wip

This commit is contained in:
Chris Ham
2018-09-13 17:37:34 -07:00
parent 950ad92364
commit 5dbc673669
3 changed files with 50 additions and 23 deletions

13
package-lock.json generated
View File

@@ -28,6 +28,14 @@
"resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz",
"integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU="
}, },
"async": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/async/-/async-2.6.1.tgz",
"integrity": "sha512-fNEiL2+AZt6AlAw/29Cr0UDe4sRAHCpEHh54WMz+Bb7QfNcFw4h3loofyJpLeQs4Yx7yuqu/2dLgM5hKOs6HlQ==",
"requires": {
"lodash": "4.17.11"
}
},
"async-limiter": { "async-limiter": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
@@ -331,6 +339,11 @@
"verror": "1.10.0" "verror": "1.10.0"
} }
}, },
"lodash": {
"version": "4.17.11",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
},
"long": { "long": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz",

View File

@@ -4,6 +4,7 @@
"description": "", "description": "",
"main": "main.js", "main": "main.js",
"dependencies": { "dependencies": {
"async": "^2.6.1",
"discord.js": "^11.4.2", "discord.js": "^11.4.2",
"ffmpeg-binaries": "^3.2.2", "ffmpeg-binaries": "^3.2.2",
"irc": "^0.5.2", "irc": "^0.5.2",

View File

@@ -17,7 +17,7 @@ const util = require('./lib/util');
// Read internal configuration // Read internal configuration
let config = require('./config.json'); let config = require('./config.json');
let currentPlaylist = config.obs.defaultPlaylist; let currentPlaylist = config.obs.defaultPlaylist;
let twitchChannel = '#' + config.twitch.channels[0].toLowerCase(); let twitchChannel = config.twitch.channels[0].toLowerCase();
// Connect to OBS Websocket // Connect to OBS Websocket
const obs = new OBSWebSocket(); const obs = new OBSWebSocket();
@@ -242,9 +242,9 @@ const streamInit = (config, obs, twitch) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.log(`Initializing stream timers...`); console.log(`Initializing stream timers...`);
// When: Hourly at 55 past // When: Every 4 hours at 55 past
// What: AUW // What: AUW
let auwJob = schedule.scheduleJob({minute: 55}, (fireDate) => { let auwJob = schedule.scheduleJob("55 */4 * * *", () => {
// AUW // AUW
twitch.editorChat.say(twitchChannel, `${config.twitch.cmdPrefix}auw`); twitch.editorChat.say(twitchChannel, `${config.twitch.cmdPrefix}auw`);
}); });
@@ -254,13 +254,14 @@ const streamInit = (config, obs, twitch) => {
let playlistChoices = config.obs.availablePlaylists.map((e, i, a) => { let playlistChoices = config.obs.availablePlaylists.map((e, i, a) => {
return `[${i+1}] ${e.chatName}`; return `[${i+1}] ${e.chatName}`;
}); });
setTimeout(() => { const sayVote = () => {twitch.botChat.say(twitchChannel, `Vote for which video playlist you'd like to see next using ${config.twitch.cmdPrefix}vote #: ${playlistChoices.join(' | ')}`)};
twitch.botChat.say(twitchChannel, `Vote for which video playlist you'd like to see next using ${config.twitch.cmdPrefix}vote #: ${playlistChoices.join(' | ')}`); /*setTimeout(sayVote, 5000);
}, 5000); setInterval(sayVote, 900000);*/
// When: Every 2 Hours // When: Every 2 Hours
// What: Change the video playlist // What: Change the video playlist
let changePlaylistJob = schedule.scheduleJob("*/5 * * * *", () => { let changePlaylistJob = schedule.scheduleJob("* */2 * * *", () => {
// Base the selection on user votes collected since the last invocation (unless there are 0 votes, then choose randomly) // Base the selection on user votes collected since the last invocation (unless there are 0 votes, then choose randomly)
let newPlaylist; let newPlaylist;
if (userVotes.length === 0) { if (userVotes.length === 0) {
@@ -270,16 +271,19 @@ const streamInit = (config, obs, twitch) => {
choices.splice(currentChoice, 1); choices.splice(currentChoice, 1);
newPlaylist = util.randElement(choices); newPlaylist = util.randElement(choices);
console.log(`PLAYLIST CHOSEN RANDOMLY: ${newPlaylist.chatName}`); console.log(`PLAYLIST CHOSEN RANDOMLY: ${newPlaylist.chatName}`);
twitch.botChat.say(twitchChannel, `No Votes Logged -- Next Playlist Chosen at Random: ${newPlaylist.chatName}`);
} else { } else {
// tally and sort votes // tally and sort votes
let tallied = userVotes.reduce((voteTallies, currentValue) => { let voteTallies = [];
tallyIndex = voteTallies.find(e.id === currentValue.vote); util.asyncForEach(userVotes, vote => {
tallyIndex = voteTallies.findIndex(e => e.id === vote.vote);
if (tallyIndex !== -1) { if (tallyIndex !== -1) {
voteTallies[tallyIndex].count++; voteTallies[tallyIndex].count++;
} else { } else {
voteTallies.push({id: currentValue.vote, count: 1}); voteTallies.push({id: vote.vote, count: 1});
} }
}).sort((a, b) => { });
voteTallies.sort((a, b) => {
if (a.count < b.count) { if (a.count < b.count) {
return -1; return -1;
} }
@@ -290,22 +294,31 @@ const streamInit = (config, obs, twitch) => {
return 0; return 0;
}); });
console.log(`[TEST] Voting Results: ${JSON.stringify(tallied)}`); console.log(`Voting Results: ${JSON.stringify(voteTallies)}`);
newPlaylist = config.obs.availablePlaylists[tallied[0].id-1]; newPlaylist = config.obs.availablePlaylists[voteTallies[0].id-1];
console.log(`WINNER OF THE VOTE: ${newPlaylist.chatName}`); console.log(`WINNER OF THE VOTE: ${newPlaylist.chatName}`);
//twitch.botChat.say(twitchChannel, `[TEST] Voting Results: ${JSON.stringify(tallied)}`); twitch.botChat.say(twitchChannel, `Winner of the Playlist Vote: ${newPlaylist.chatName}`);
// clear user votes // clear user votes
userVotes = []; userVotes = [];
} }
/*twitch.botChat.say(twitchChannel, `[TEST] Changing playlist from ${currentPlaylist} to ${newPlaylist.chatName}`); // only do this if the playlists are actually different
twitch.editorChat.say(twitchChannel, `[TEST] ${config.twitch.cmdPrefix}swap ${currentPlaylist} ${newPlaylist.sceneItem}`); if (currentPlaylist === newPlaylist.sceneItem) {
twitch.editorChat.say(twitchChannel, `[TEST] !setcurrent NOW SHOWING: ${newPlaylist.activity}`);*/ twitch.botChat.say(twitchChannel, `We gucci. Stay comfy, nerds. DataComfy`);
console.log(`Changing playlist from ${currentPlaylist} to ${newPlaylist.chatName}`); } else {
console.log(`${config.twitch.cmdPrefix}swap ${currentPlaylist} ${newPlaylist.sceneItem}`); console.log(`Changing playlist from ${currentPlaylist} to ${newPlaylist.sceneItem}`);
console.log(`!setcurrent NOW SHOWING: ${newPlaylist.activity}`); // @TODO: Don't use twitch chat for this
twitch.editorChat.say(twitchChannel, `${config.twitch.cmdPrefix}swap ${currentPlaylist} ${newPlaylist.sceneItem}`);
twitch.editorChat.say(twitchChannel, `!setcurrent NOW SHOWING: ${newPlaylist.activity}`);
// if we're showing TTAS segments, hide the label, if it's anything else, show
if (newPlaylist.sceneItem === 'ttas-segments') {
twitch.editorChat.say(twitchChannel, `${config.twitch.cmdPrefix}hide current-activity`);
} else {
twitch.editorChat.say(twitchChannel, `${config.twitch.cmdPrefix}show current-activity`);
}
currentPlaylist = newPlaylist.sceneItem; currentPlaylist = newPlaylist.sceneItem;
}
}); });
console.log(`Playlist will be changed at ${changePlaylistJob.nextInvocation()}`); console.log(`Playlist will be changed at ${changePlaylistJob.nextInvocation()}`);
@@ -322,7 +335,7 @@ const streamInit = (config, obs, twitch) => {
let userVote = commandParts[1] || false; let userVote = commandParts[1] || false;
if (userVote === false) { if (userVote === false) {
return twitch.botChat.say(to, `Vote for which video playlist you'd like to see next using ${config.twitch.cmdPrefix}vote #: ${playlistChoices.join(' | ')}`); return sayVote();
} }
userVote = Number.parseInt(userVote); userVote = Number.parseInt(userVote);
@@ -343,7 +356,7 @@ const streamInit = (config, obs, twitch) => {
} else { } else {
// log user vote // log user vote
userVotes.push({"from": from, "vote": userVote}); userVotes.push({"from": from, "vote": userVote});
twitch.botChat.say(to, `@${from}, your vote has been registered!`); twitch.botChat.say(to, `@${from}, your vote has been logged!`);
} }
} }
} }