Skip to content

Commit a4172f0

Browse files
author
jg
committed
Text button type added.
1 parent b236b89 commit a4172f0

File tree

4 files changed

+83
-28
lines changed

4 files changed

+83
-28
lines changed

lib/interactive/api-buttons/apiProcessor.js

+21-22
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,28 @@ function apiProcessor(report){
2525
var buttonID = button['id'];
2626
var typeSettings = button['typeSettings'];
2727
var apiType = typeSettings['apiType'];
28-
var sendAs = typeSettings['sendAs'];
29-
var chatter = sendAs+'Chat';
30-
31-
if(apiType == "Advice"){
32-
randomAdvice(chatter);
33-
} else if (apiType == "Cat Picture"){
34-
randomCat(chatter);
35-
} else if (apiType == "Cat Fact"){
36-
randomCatFact(chatter);
37-
} else if (apiType == "Dog Picture"){
38-
randomDog(chatter);
39-
} else if (apiType == "Dog Fact"){
40-
randomDogFact(chatter);
41-
} else if (apiType == "Aww"){
42-
randomAww(chatter);
43-
} else if (apiType == "Pokemon"){
44-
randomPokemon(chatter);
45-
} else if (apiType == "Number Trivia"){
46-
numberTrivia(chatter);
47-
}
48-
} else if (holding > 0){
49-
errorLog.log('API Buttons should only have pressFrequency on in the dev lab.');
28+
var chatter = typeSettings['sendAs'];
29+
30+
if(apiType == "Advice"){
31+
randomAdvice(chatter);
32+
} else if (apiType == "Cat Picture"){
33+
randomCat(chatter);
34+
} else if (apiType == "Cat Fact"){
35+
randomCatFact(chatter);
36+
} else if (apiType == "Dog Picture"){
37+
randomDog(chatter);
38+
} else if (apiType == "Dog Fact"){
39+
randomDogFact(chatter);
40+
} else if (apiType == "Aww"){
41+
randomAww(chatter);
42+
} else if (apiType == "Pokemon"){
43+
randomPokemon(chatter);
44+
} else if (apiType == "Number Trivia"){
45+
numberTrivia(chatter);
5046
}
47+
} else if (holding > 0){
48+
errorLog.log('API Buttons should only have pressFrequency on in the dev lab.');
49+
}
5150
}
5251

5352
function randomAdvice(chatter){

lib/interactive/chat-connect.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function createBotChatSocket (chatter, userId, channelId, endpoints, authkey) {
128128
// Handle errors
129129
global.chat.on('error', error => {
130130
// Popup error.
131-
errorLog.log('There was an error with the chat socket. (chat-connect)')
131+
errorLog.log('There was an error with the chat socket for '+chatter+'. (chat-connect)')
132132
// Send error message to gui
133133
renderWindow.webContents.send('chat-disconnect');
134134
console.error('Socket error', error);
@@ -157,19 +157,26 @@ function chatDisconnect(){
157157
// Send a whisper to a specific person from whoever the chatter is (streamer or bot).
158158
function whisper(chatter, username, message){
159159
var chat = chatter+'Chat';
160-
global.chat.call('whisper', [username, message]);
160+
try{
161+
global.chat.call('whisper', [username, message]);
162+
}catch(err){
163+
errorLog.log('There was an error sending your message from '+chatter+'. (chat-connect)');
164+
}
165+
161166
}
162167

163168
// Broadcast
164169
// Send a broadcast to the channel from whoever the chatter is (streamer or bot).
165170
function broadcast(chatter, message){
166171
var chat = chatter+'Chat';
167-
global.chat.call('msg', [message]);
172+
try{
173+
global.chat.call('msg', [message]);
174+
} catch(err){
175+
errorLog.log('There was an error sending your message from '+chatter+'. (chat-connect)');
176+
}
168177
}
169178

170179

171-
172-
173180
// Export Functions
174181
exports.connect = chatConnect;
175182
exports.disconnect = chatDisconnect;

lib/interactive/controls-router.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const soundBoard = require('./soundboard/soundProcessor.js');
1111
// API Processor
1212
const apiButtons = require('./api-buttons/apiProcessor.js');
1313

14+
// Text Processor
15+
const textButtons = require('./text-buttons/textProcessor.js');
16+
1417
// Progress Processors
1518
const progressReport = require('./progress-reports/progressProcessor.js');
1619

@@ -60,8 +63,10 @@ function reportHandler(report) {
6063
gameTactile.tactile(buttonReport);
6164
} else if (buttonType == "Sound"){
6265
soundBoard.play(buttonReport);
63-
} else if ("API Buttons"){
66+
} else if (buttonType == "Api Buttons"){
6467
apiButtons.play(buttonReport);
68+
} else if (buttonType == "Text Buttons"){
69+
textButtons.play(buttonReport);
6570
}
6671

6772
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const JsonDB = require('node-json-db');
2+
const chat = require('../chat-connect.js');
3+
const errorLog = require('../../error-logging/error-logging.js')
4+
5+
function textProcessor(report){
6+
var dbSettings = new JsonDB('./user-settings/settings', true, false);
7+
var activeProfile = dbSettings.getData('./interactive/activeBoard');
8+
9+
var dbControls = new JsonDB('./user-settings/controls/' + activeProfile, true, false);
10+
var controls = dbControls.getData('/tactile');
11+
12+
// Get report info
13+
var rawid = report.id;
14+
var holding = report.holding;
15+
var press = report.pressFrequency;
16+
var button = controls[rawid];
17+
18+
if(press > 0){
19+
20+
// Get user specific settings
21+
var buttonID = button['id'];
22+
var typeSettings = button['typeSettings'];
23+
var textLine = typeSettings['textLine'];
24+
var sendAs = typeSettings['sendAs'];
25+
var whisperTo = typeSettings['whisperTo'];
26+
27+
if(whisperTo !== "" && whisperTo !== undefined && whisperTo !== null){
28+
// Send a whisper
29+
console.log('sending text', sendAs, whisperTo, textLine);
30+
chat.whisper(sendAs, whisperTo, textLine);
31+
} else {
32+
// Send a broadcast
33+
console.log('sending broadcast', sendAs, textLine);
34+
chat.broadcast(sendAs, textLine);
35+
}
36+
37+
} else if (holding > 0){
38+
errorLog.log('Text Buttons should only have pressFrequency on in the dev lab.');
39+
}
40+
}
41+
42+
43+
// Export Functions
44+
exports.play = textProcessor;

0 commit comments

Comments
 (0)