Bots Home
|
Create an App
libritest
Author:
multilibri
Description
Source Code
Launch Bot
Current Users
Created by:
Multilibri
// // Name : SparklesBot // Author : cerebio // // Date Ver. Rev. Description // 2017/04/03 0.0 0.1 - Initial implementation. // 2017/04/07 0.0 0.2 - Added additional notifiers // 2017/04/19 0.0 0.3 - Added spam blocker // 2017/06/25 1.0 0.0 - Added voting counter // - Updated spam blocker // - Full restructure and cleanup // var documentation = "Available commands:\n" + "****** timer commands ******\n" + " /timer;mm:ss;purpose\n" + " /cancel\n" + " /timeleft\n" + "Only one timer can be active at a time.\n" + "the semi-colons separate the parameters, so you cannot use a semi-colon in the 'purpose' text. Other than that the text can be anything.\n" + "so for example to start a two and a half minute timer for hitachi play: /timer;2:30;until hitachi play is done\n\n" + "****** notifier commands ******\n" + " /n;x;notifier text\n" + "Three notifiers are available, so the value 'x' can range from 1 to 3. As with the timer, the notifier can be anything, but must not contain a sem-colon\n" + "So for example to set a notifier with the tip-talk-follow gif: /n;1;:sparkles-ttf\n\n" + " /nt;x;ms\n" + "The notifier intervals can be controlled from chat as well. Again, the value 'x' can range from 1 to 3. The timing value is in milliseconds\n" + "So for example to set an interval of 1.5 minutes on notifier 1: /nt;1;90000\n\n" + "Ofcourse you can also set initial notifiers and intervals when you start the bot.\n\n" + "****** other commands ******\n" + " /settings\n" + "To view the current settings\n\n" ; var initialised = false; function initialise() { if ( !initialised ) { initialised = true; initialiseNotifiers(); cb.sendNotice( "SparklesBot: initialised", "", notifierBG, notifierFG, "bold" ); } } cb.setTimeout( initialise, 1000 ); function startsWith( s, starter ) { for ( var i = 0, cur_c; i != starter.length; ++i ) { cur_c = starter[i]; if ( s[i] !== starter[i] ) return false; } return true; } // *** BEGIN NOTIFIER MODULE **************************************************** var notifierBG = '#DDDDDD'; var notifierFG = '#660033'; var notifierText1 = ''; var notifierText2 = ''; var notifierText3 = ''; var notifierText4 = ''; var notifierText5 = ''; var notifierTimer1 = 220000; var notifierTimer2 = 220000; var notifierTimer3 = 220000; var notifierTimer4 = 220000; var notifierTimer5 = 220000; function initialiseNotifiers() { cb.setTimeout( notify1, ( notifierTimer1 / 3 ) ); cb.setTimeout( notify2, ( notifierTimer1 / 3 ) * 2 ); cb.setTimeout( notify3, notifierTimer1 ); cb.setTimeout( notify4, notifierTimer4 ); cb.setTimeout( notify5, notifierTimer5 ); } function notify1() { if ( "" != notifierText1 ) { cb.sendNotice( notifierText1, "", notifierBG, notifierFG, "bold" ); } cb.setTimeout( notify1, notifierTimer1 ); } function notify2() { if ( "" != notifierText2 ) { cb.sendNotice( notifierText2, "", notifierBG, notifierFG, "bold" ); } cb.setTimeout( notify2, notifierTimer2 ); } function notify3() { if ( "" != notifierText3 ) { cb.sendNotice( notifierText3, "", notifierBG, notifierFG, "bold" ); } cb.setTimeout( notify3, notifierTimer3 ); } function notify4() { if ( "" != notifierText4 ) { cb.sendNotice( notifierText4, "", notifierBG, notifierFG, "bold" ); } cb.setTimeout( notify4, notifierTimer4 ); } function notify5() { if ( "" != notifierText5 ) { cb.sendNotice( notifierText5, "", notifierBG, notifierFG, "bold" ); } cb.setTimeout( notify5, notifierTimer5 ); } // *** END NOTIFIER MODULE **************************************************** // *** BEGIN TIMER MODULE ***************************************************** var timeLeft = 0; var purpose = "until nothing's left"; var stopTimerFlag = false; var timerDoneFlag = false; function startTimer( time, purpose_ ) { timeLeft = convertTime( time ); purpose = purpose_ stopTimerFlag = false; timerDoneFlag = false; countdownStatus(); countdown(); } function cancelTimer () { stopTimerFlag = true; } function convertTime( time ) { var timeParts = time.split( ":" ); var mins = parseInt( timeParts[0] ); var secs = parseInt( timeParts[1] ); return (( mins * 60 ) + secs ) * 1000; } function padLeft( string, pad, length ) { return ( new Array( length + 1 ).join( pad ) + string ).slice( -length ); } function displayTimeLeft() { var totalsecs = timeLeft / 1000; var minutes = Math.floor( totalsecs / 60 ); var seconds = totalsecs - ( minutes * 60 ); return( padLeft( minutes, '0', 2 ) + ':' + padLeft( seconds, '0', 2 )); } function countdown() { timeLeft -= 1000; if ( true == stopTimerFlag ) { cb.sendNotice( "COUNTDOWN: CANCELLED " + purpose, "", "#FF0000", "#FFFFFF", "bold" ); } else if ( 0 == timeLeft ) { timerDoneFlag = true; cb.sendNotice( "COUNTDOWN: DONE " + purpose, "", "#FF0000", "#FFFFFF", "bold" ); } else { cb.setTimeout( countdown, 1000 ); } } function displayTimer() { cb.sendNotice( "COUNTDOWN: " + displayTimeLeft() + " left " + purpose, "", notifierBG, notifierFG, "bold" ); } function countdownStatus() { if ( false == stopTimerFlag && false == timerDoneFlag ) { displayTimer(); var nextLapse; if ( timeLeft <= 10000 ) { nextLapse = 1000; } else if ( timeLeft <= 60000 ) { nextLapse = 10000; } else if ( timeLeft <= 180000 ) { nextLapse = 30000; } else { nextLapse = 60000; } cb.setTimeout( countdownStatus, nextLapse ); } } // *** END TIMER MODULE ******************************************************* // *** BEGIN ANTI-SPAM MODULE ************************************************* var spamList = [ "view" , "c2c" , "guys" , "lookmy" , "room" , "maybeprivateshow" , "maybesex" , "whofuckme" , "maybefuck" ]; function inArray( msg ) { var found = false; for ( var i in spamList ) { if( msg == spamList[i] ) { found = true; break; } } return found; } function isspam( msg ) { var result = ''; msgParts = msg.split( ' ' ); for( var i in msgParts ) { var part = msgParts[i]; if ( ':' != part[0] ) { // ignore gifs var stripped = part.toLowerCase() // take out puncuation, white space and make lower case .replace( /\s/igm, '' ) .replace( /\?/igm, '' ) .replace( /!/igm, '' ) .replace( /-/igm, '' ) .replace( /\./igm, '' ) .replace( /\//igm, '' ); result += stripped; } } return inArray( result ); } // *** END ANTI-SPAM MODULE *************************************************** // *** BEGIN VOTING MODULE **************************************************** var votingActive = false; var votes = []; var tipped; var goal; var options; function parseVoteCommand( command ) { if ( !votingActive ) { var commandParts = command.split( ';' ); goal = commandParts[1]; options = JSON.parse( commandParts[2] ); tipped = 0; for ( i in options ) votes[i] = 0; votingActive = true; } } function updateVotes( amount ) { for ( i in options ) { if ( amount == options[i].tokens ) { ++votes[i]; } } tipped += amount; } function voteNotifier() { if ( votingActive ) { cb.sendNotice( "VOTING ACTIVE (" + tipped + "/" + goal + " tipped)", "", notifierBG, notifierFG, "bold" ); for ( i in options ) { cb.sendNotice( "tip " + options[i].tokens + " for " + options[i].label + " (" + votes[i] + " votes).", "", notifierBG, notifierFG, "bold" ); } cb.setTimeout( voteNotifier, 120000 ); } } function initialiseVoteModule( message ) { parseVoteCommand( message ); cb.setTimeout( voteNotifier, 500 ); } function goalReached() { votingActive = false; cb.sendNotice( "VOTING HAS ENDED!", "", notifierBG, notifierFG, "bold" ); var winningVote = 0; var winningVoteMsg = ""; inconclusive = false; for ( i in options ) { if ( votes[i] > winningVote ) { winningVote = votes[i]; winningVoteMsg = options[i].label; } cb.sendNotice( options[i].label + ": " + votes[i] + " votes.", "", notifierBG, notifierFG, "bold" ); } for ( i in options ) { if ( winningVote == votes[i] && winningVoteMsg != options[i].label ) { inconclusive = true; } } if ( inconclusive ) { cb.sendNotice( "MULTIPLE OPTIONS TIED ON THE VOTE. BROADCASTER DECIDES!", "", notifierBG, notifierFG, "bold" ); } else { cb.sendNotice( winningVoteMsg + " IS THE WINNER!", "", notifierBG, notifierFG, "bold" ); } } // *** END VOTING MODULE ****************************************************** // *** BEGIN CB API *********************************************************** cb.onMessage( function( msg ) { var user = msg['user']; var message = msg['m']; if ( message[0] == '/' && ( cb.room_slug == user || true == msg['is_mod'] || true == msg['in_fanclub'] )) { msg['X-Spam'] = true; if ( '/help' == message ) { cb.sendNotice( documentation, user, notifierBG, notifierFG, "bold" ); } else if ( '/settings' == message ) { cb.sendNotice( "n1 : " + notifierText1, user, notifierBG, notifierFG, "bold" ); cb.sendNotice( "nt1: " + notifierTimer1, user, notifierBG, notifierFG, "bold" ); cb.sendNotice( "n2 : " + notifierText2, user, notifierBG, notifierFG, "bold" ); cb.sendNotice( "nt2: " + notifierTimer2, user, notifierBG, notifierFG, "bold" ); cb.sendNotice( "n3 : " + notifierText3, user, notifierBG, notifierFG, "bold" ); cb.sendNotice( "nt3: " + notifierTimer3, user, notifierBG, notifierFG, "bold" ); cb.sendNotice( "n4 : " + notifierText4, user, notifierBG, notifierFG, "bold" ); cb.sendNotice( "nt4: " + notifierTimer4, user, notifierBG, notifierFG, "bold" ); cb.sendNotice( "n5 : " + notifierText5, user, notifierBG, notifierFG, "bold" ); cb.sendNotice( "nt5: " + notifierTimer5, user, notifierBG, notifierFG, "bold" ); } else if ( startsWith( message, "/timer" )) { var params = message.split( ";" ); startTimer( params[1], params[2] ); } else if ( '/cancel' == message ) { cancelTimer(); } else if ( '/timeleft' == message) { displayTimer(); } else if ( startsWith( message, "/w " )) { // whisper cb.sendNotice( "whisper from " + user + ": " + message.substring( 3 ), cb.room_slug, '#FFFF99', '#000000' ); } else if ( startsWith( message, "/nt" )) { var params = message.split( ";" ); if( '1' == params[1] ) { notifierTimer1 = params[2]; } else if( '2' == params[1] ) { notifierTimer2 = params[2]; } else if( '3' == params[1] ) { notifierTimer3 = params[2]; } else if( '4' == params[1] ) { notifierTimer4 = params[2]; } else if( '5' == params[1] ) { notifierTimer5 = params[2]; } } else if ( startsWith( message, "/n" )) { var params = message.split( ";" ); if( '1' == params[1] ) { notifierText1 = params[2]; } else if( '2' == params[1] ) { notifierText2 = params[2]; } else if( '3' == params[1] ) { notifierText3 = params[2]; } else if( '4' == params[1] ) { notifierText4 = params[2]; } else if( '5' == params[1] ) { notifierText5 = params[2]; } } else if ( "/votestatus" == message ) { voteNotifier(); } else if ( startsWith( message, "/vote;" )) { initialiseVoteModule( message ); } } else if ( isspam( message )) { msg['X-Spam'] = true; cb.sendNotice( "Some spam was blocked :kiss", cb.room_slug, '#FFFF99', '#000000' ); cb.sendNotice( "Your message resembles a known spam bot pattern and was blocked. Please rephrase your message.", user, '#FFFF99', '#000000' ); // Notify the user as a courtesy, just in case. cb.sendNotice( user + ' - ' + message, 'multilibri', '#FFFF99', '#000000' ); // remove this after a day if satisfactory results. } msg['m'] = message; return msg; } ); cb.onEnter( function( user ) { var username = user["user"]; if ( user["is_mod"] || user["in_fanclub"] ) { cb.sendNotice( "Welcome " + username + ". :kiss", username, notifierBG, notifierFG, "bold" ); } else { cb.sendNotice( "Welcome to my room " + username + ". Please read the bio if you are new here :)", username, notifierBG, notifierFG, "bold" ); } } ); cb.onTip(function ( tip ) { if ( votingActive ) { var amount = parseInt( tip['amount'] ); updateVotes( amount ); if ( tipped >= goal ) goalReached(); } } ); // *** END CB API *************************************************************
© Copyright Chaturbate 2011- 2024. All Rights Reserved.