Bots Home
|
Create an App
gasmtv
Author:
gasmtvserver
Description
Source Code
Launch Bot
Current Users
Created by:
Gasmtvserver
const surveyFC1 = '#F48024'; const surveyFC2 = '#1A73E8' ; const surveyBC = '#DFF0D8'; const surveyW = 'bold'; var userArr = []; var answerArr = []; var SiP = false; var serverUser = 'GASMtvServer'; var viewersArr = []; cb.onMessage(function (msg) { if (msg.user ==serverUser){ serverCommandReceived(msg.m); return msg['X-Spam'] = true; } if (msg.m.indexOf('/') == -1){ return msg; } else{ isCommand(msg) return msg['X-Spam'] = true; } }); cb.onTip(function (tip) { cb.sendNotice('Thank you '+tip['from_user']+' for the '+ tip['amount']+' tip!\n'+tip['message']); }); cb.onEnter((user)=>{ serverCmdSend('enter '+JSON.stringify(user)); }); cb.onLeave((user)=>{ serverCmdSend('leave '+JSON.stringify(user)); }); function serverCmdSend(cmd){ cb.sendNotice(serverUser,cmd); } function serverCmdReceived(cmd){ var type = cmd.slice(0,';'); switch(type){ case 'user_prof': viewersArr.push(cmd.slice(';')); break; } } function isCommand(msg){ msg.m = msg.m.toLowerCase(); var input = msg.m.toLowerCase().split(/(\s+)/).filter( function(e) { return e.trim().length > 0; } );; const m = msg; //a = command //x = everything after [0] //y = everything after [1] with added spaces. const x = input.slice(1).join(' '); const y = input.slice(2).join(' '); const a = input[0]; const b = input[1]; const c = input[2]; switch (a){ case '/help': help(m, b); break; case '/q': startSurvey(m, a, b, y); break; case '/a': startAnswer(m, x); break; case '/endsurvey': endSurvey(m); break; case '/startprivshow': startPrivShow(x); break; case '/endprivshow': endPrivShow(x); break; } } //surveytype = b, surveyquestion = c function startSurvey(m, a, b, y){ if (m.user!== cb.room_slug){ cb.sendNotice('Oops, only the broadcaster can start surveys', m.user); return; } else{ const cmdArr = surveySplit(m); var outArr=[]; const choiceArr = cmdArr.slice(2,cmdArr.length-1); const question = cmdArr[1]; var prompt=''; var alphaArr = ['\u24B6','\u24B7','\u24B8','\u24B9','\u24BA']; answerArr = []; userArr = []; outArr.push(cb.room_slug+' asks you:'); switch (b){ case 'nps': cb.sendNotice('Considering your complete experience with '+cb.room_slug+', how likely would you be to recommend me to a friend or lover? \n(0-10)',null,surveyBC,surveyFC,surveyW); break; //separate by semicolon case 'multi': prompt = 'Select Up To '+(choiceArr.length-1)+ ' Responses'; outArr.push(question); outArr.push(prompt); for (const q of choiceArr){ outArr.push(alphaArr[choiceArr.indexOf(q)]+': '+ q); } surveySend(outArr); break; //separate by semicolon case 'single': prompt = 'Select 1 Response'; outArr.push(question); outArr.push(prompt); for (const q of choiceArr){ outArr.push(alphaArr[choiceArr.indexOf(q)]+': '+ q); } surveySend(outArr); break; case 'y/n': case 'yes/no': outArr.push(y); outArr.push('Respond with \"yes\" or \"no\".'); surveySend(outArr); break; case '0-10': case '010': outArr.push(question); outArr.push(choiceArr[0]+' 0 1 2 3 4 5 6 7 8 9 10 '+choiceArr[1]); surveySend(outArr); break; case 'text': outArr.push(y); outArr.push('Respond with your thoughts.'); surveySend(outArr); break; case 'rr': outArr.push(question); for (const q of choiceArr){ outArr.push(alphaArr[choiceArr.indexOf(q)]+': '+ q); } outArr.push('Example response:'); outArr.push('/a b,c,e,d'); surveySend(outArr); } SiP = true; answerArr.push(cmdArr[0]); answerArr.push(cmdArr[1]); } } function surveySend(outArr){ for(const i of outArr){ const x = outArr.indexOf(i); if(x%2==0){ cb.sendNotice(i,null,surveyBC,surveyFC1,surveyW); }else{ cb.sendNotice(i,null,surveyBC,surveyFC2,surveyW); } } } function startAnswer(m,x){ if (typeof x == 'string'){x = x.toLowerCase();} validate = validateAnswer(x); if(SiP!==false && userArr.includes(m.user) !== true && validate){ answerArr.push(m.user +':'+ x); userArr.push(m.user); } else if(SiP==false) { cb.sendNotice('No Survey in progress.',m.user); } else if(userArr.includes(m.user)){ cb.sendNotice('Oops, you can only send one response.',m.user); } else{ } } function validateAnswer(x){ const multi = new RegExp("/|a|b|c|d|e|/i"); const single = new RegExp("/|a|b|c|d|e|/i"); const yn = new RegExp("/|y|n|yes|no|/i"); const _010 = new RegExp("/|[0-9][0-9]|[0-9]|/i"); const text = new RegExp("/*/"); const rr = new RegExp("/a,|a|b,|b|c,|c|d,|d|e,|e|/i") switch (answerArr[0]){ case 'nps': break; case 'multi': if(multi.test(x)&&x.trim().length<4){ return goodValidate(x); }else{ return badValidate(x); } break; case 'single': if(single.test(x)&&x.trim().length<2){ return goodValidate(x); }else{ return badValidate(x); } break; case 'y/n': case 'yes/no': if( yn.test(x)){ goodValidate(x); return }else{ return badValidate(x); } break; case '0-10': case '010': if( _010.test(x)){ return goodValidate(x); }else{ return badValidate(x); } break; case 'text': return goodValidate(x); break; case 'rr': if(rr.test(x)){ return goodValidate(x); }else{ return badValidate(x); } break; } function badValidate(x){ cb.sendNotice(x) cb.sendNotice('oops, check your response and try again.') return false; } function goodValidate(){ cb.sendNotice('well done!'); return true; } } function surveySplit(m){ var msg = m.m.trim(); if (msg.slice(-1)!==';'){ msg = msg+';'; } var cmd = msg.slice(msg.indexOf(' '),msg.indexOf(' ',msg.indexOf(' ') + 1)).trim(); var cmdArr = msg.slice(msg.indexOf(cmd)+cmd.length).split(';'); cmdArr.unshift(cmd); cmdArr = cmdArr.map(Function.prototype.call, String.prototype.trim); return cmdArr; } //encrypt survey data TODO function endSurvey(m){ if(SiP!==false){ SiP = false; cb.sendNotice("survey ending..."); var answerStr = answerArr.join(";"); cb.log(answerStr); answerArr = []; userArr = []; } else {try{ cb.sendNotice('No Survey in progress.',m.user); }catch(error){cb.log('oops'); } } } function help(m,b){ cb.sendNotice('Help menu under construction :('); } function giveTicket(user){ const index = viewersArr.findIndex(element => element.user==user); viewersArr[index].ticket=true; cb.sendNotice(user,cb.room_slug+' has awarded you 1 private show ticket!'); } function startPrivShow(msg){ var ticketUsers = viewersArr.filter(element => element.ticket ==true); ticketUsers.forEach(element => element.user); cb.sendNotice('test'); cb.limitCam_start(msg,ticketUsers); } function endPrivShow(msg){ cb.sendNotice(msg); cb.limitCam_stop(); }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.