Part TWO: (the forum has a limit of 15k characters, the script does not):
-------
/* NEW HAT CHANGE DETECTION CODE BASED ON CHANNEL POINTS */
if (context["custom-reward-id"] === "YOUR_CUSTOM_REWARD_ID") {
/* BEANIE */
if((msg.toLowerCase()).includes("1")) {
var username = context["display-name"];
client.say(target,'Please put on The Cloth Beanie');
}
/*Cowboy Leather*/
if((msg.toLowerCase()).includes("2")) {
var username = context["display-name"];
client.say(target, 'Please put on The Cowboy Leather hat');
}
/*Leather Skullcap*/
if((msg.toLowerCase()).includes("3")) {
var username = context["display-name"];
client.say(target, 'Please put on The Leather Skullcap');
}
/*Military Beret*/
if((msg.toLowerCase()).includes("4")) {
var username = context["display-name"];
client.say(target, 'Please requests you put on The Military Beret');
}
/*Military Field Cap*/
if((msg.toLowerCase()).includes("5")) {
var username = context["display-name"];
client.say(target, 'Please requests you put on The Military Field Cap');
}
/*Glengarry*/
if((msg.toLowerCase()).includes("6")) {
var username = context["display-name"];
client.say(target, 'Please requests you put on The Glengarry');
}
/*Porkpie*/
if((msg.toLowerCase()).includes("7")) {
var username = context["display-name"];
client.say(target, 'Please requests you put on The Pork Pie');
}
/*Monkey*/
if((msg.toLowerCase()).includes("8")) {
var username = context["display-name"];
client.say(target, 'Please requests you put on The Monkey Hat');
}
/*Raccoon*/
if((msg.toLowerCase()).includes("9")) {
var username = context["display-name"];
client.say(target, 'Please requests you put on The Raccoon Hat');
}
/* Play a drum sound to get attention */
exec("cmdmp3win Drum.wav", (error, stdout, stderr) => {});
}
/* No Hat */
if((msg.toLowerCase()).includes("no hat")) {
var username = context["display-name"];
client.say(target, username + ' says you can take off your hat!');
exec("cmdmp3win Drum.wav", (error, stdout, stderr) => {});
}
if(commandName === '!hats') {
client.say(target, 'To request thatFontGuy to switch to a specific hat please use Channel Points to buy a Change Hats token, or you can request he take off the hat using !nohat');
console.log(context.username + " asked about hats");
}
}
function FlashChatAnim () {
/* Flash Chat Animation: */
pushCompanionButton('
http://127.0.0.1:8888/press/bank/1/6','')
}
// Called every time the bot connects to Twitch chat
function onConnectedHandler (addr, port) {
console.log(`* Connected to ${addr}:${port}`);
}
// Check every 30s to see what the current viewer count is
// If its over a specified threshhold then toggle the ViewerCount icon in the Status Bar scene
function checkViewerCount() {
http.get('
http://tmi.twitch.tv/group/user/thatfontguy/chatters', (resp) => {
let data = '';
// a chunk of data has been received
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
// Get Chatter count:
let response = JSON.parse(data);
ChatterCount = response.chatter_count;
// Convert to an Integer:
var val = parseInt(ChatterCount, 10);
// Are we over the threshold?
threshhold = 10;
if(val >= threshhold) {
// Turn on the scene element that marks the threshold
pushCompanionButton('
http://127.0.0.1:8888/press/bank/1/7','');
} else if(val < threshhold) {
// Turn on the scene element that marks the threshold
pushCompanionButton('
http://127.0.0.1:8888/press/bank/1/15','');
}
// Display the number of viewers between 0 and 10+ as the Count
switch(val) {
case 0:
// Change value of Count to show val number:
pushCompanionButton('
http://127.0.0.1:8888/press/bank/2/31','');
break;
case 1:
// Change value of Count to show val number:
pushCompanionButton('
http://127.0.0.1:8888/press/bank/2/6','');
break;
case 2:
// Change value of Count to show val number:
pushCompanionButton('
http://127.0.0.1:8888/press/bank/2/7','');
break;
case 3:
// Change value of Count to show val number:
pushCompanionButton('
http://127.0.0.1:8888/press/bank/2/8','');
break;
case 4:
// Change value of Count to show val number:
pushCompanionButton('
http://127.0.0.1:8888/press/bank/2/14','');
break;
case 5:
// Change value of Count to show val number:
pushCompanionButton('
http://127.0.0.1:8888/press/bank/2/15','');
break;
case 6:
// Change value of Count to show val number:
pushCompanionButton('
http://127.0.0.1:8888/press/bank/2/16','');
break;
case 7:
// Change value of Count to show val number:
pushCompanionButton('
http://127.0.0.1:8888/press/bank/2/22','');
break;
case 8:
// Change value of Count to show val number:
pushCompanionButton('
http://127.0.0.1:8888/press/bank/2/23','');
break;
case 9:
// Change value of Count to show val number:
pushCompanionButton('
http://127.0.0.1:8888/press/bank/2/24','');
break;
case (val >= 10):
// Change value of Count to show val number:
pushCompanionButton('
http://127.0.0.1:8888/press/bank/2/30','');
break;
}
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
}
checkViewerCount();
function pushCompanionButton(bank, msg) {
http.get(bank, (resp) => {
let data = '';
// a chunk of data has been received
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
if(msg != '') {
console.log(msg);
}
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
}
/* This function turns off the visibility of all scene elements like the Gull Warning, Applause etc */
function resetAll() {
pushCompanionButton('
http://127.0.0.1:8888/press/bank/2/25','* Resetting all Toggles');
}
function turnOffBotSign() {
pushCompanionButton('
http://127.0.0.1:8888/press/bank/1/8', '* Turning off the bot sign');
}
function setCstatus(val) {
Cstatus = val;
}
function getCstatus(){
return Cstatus;
};
function toggleCstatus() {
if(getCstatus() === 1) {
Cstatus = 0;
} else {
Cstatus = 1;
}
return Cstatus;
}
setInterval(function(){
checkViewerCount()
}, 30000)
/* Switches OBS to the specified Scene */
/* NOTE that I will be attempting to use this in place of many of the Companion requests above so that I can reduce the requirement to use
Companion as much as possible. I have not tried that yet but the changeScene code does work at the moment*/
function changeScene(TargetScene) {
const obs = new OBSWebSocket();
obs.connect({ address: 'localhost:4444', password: 'YOUR_PASSWORD' }).then(() => {
obs.send('SetCurrentScene', {
'scene-name': TargetScene
})
.then(() => {})
.catch(err =>{
console.log(err);
})
});
}