Bots Home
|
Create an App
devinebot
Author:
formerlyknown
Description
Source Code
Launch Bot
Current Users
Created by:
Formerlyknown
// // Name : DevineBot // Author : formerlyknown // var initialised = false; function initialise() { if ( !initialised ) { initialised = true; cb.sendNotice( "DevineBot: initialised", "", notifierBG, notifierFG, "bold" ); } } cb.setTimeout( initialise, 1000 ); function stringStartsWith( 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; } function stringEndsWith(str, suffix) { return str.indexOf(suffix, str.length - suffix.length) !== -1; } // *** BEGIN NOTIFIER MODULE ************************************************** var notifierBG = '#EEEEEE'; var notifierFG = '#CC3333'; var notifiers = []; var eventCounter = 0; var notifiersRunning = false; var interval = 220000; function initialiseNotifier() { if ( !notifiersRunning ) { cb.setTimeout( notifierEvent, 1000 ); notifiersRuning = true; } } function parseNotifierCommand( command ) { var commandParts = command.split( ';' ); notifiers = JSON.parse( commandParts[1] ); interval = notifiers.interval; initialiseNotifier(); } function notifierEvent() { for ( i in notifiers.texts ) { if ( i == eventCounter % notifiers.texts.length ) { cb.sendNotice( notifiers.texts[i].text, "", notifierBG, notifierFG, "bold" ); } } ++eventCounter; cb.setTimeout( notifierEvent, interval ); } // *** 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 = [ "halloc2cjungen" ]; var spamThreshold = 6; function parseSpamListCommand( command ) { var commandParts = command.split( ';' ); spamList = JSON.parse( commandParts[1] ); } function parseSpamAddCommand( message, user ) { var term = message.split( ";" )[1]; if ( stringStartsWith( term, "[" )) { terms = JSON.parse( term ); for ( var i in terms ) { term = stripMuck( terms[i] ); spamList[spamList.length] = term; cb.sendNotice( "Added [" + term + "] to spam list", user, notifierBG, notifierFG, "bold" ); } } else { term = stripMuck( term ); spamList[spamList.length] = term; cb.sendNotice( "Added [" + term + "] to spam list", user, notifierBG, notifierFG, "bold" ); } } function dumpSpamList( user ) { for ( var i in spamList ) { cb.sendNotice( i + ': [' + spamList[i] + ']', user, '#FFFF99', '#000000' ); } } function inSpamArray( msg ) { var found = -1; for ( var i in spamList ) { if( msg == spamList[i] || ( stringEndsWith( msg, spamList[i] ) && ( msg.length - spamList[i].length < spamThreshold ))) { found = i; break; } } return found; } function stripMuck( part ) { // take out puncuation, white space, other bits and pieces and make lower case return part.toLowerCase() .replace( /\s/igm, '' ) .replace( /\?/igm, '' ) .replace( /;/igm, '' ) .replace( /!/igm, '' ) .replace( /-/igm, '' ) .replace( /=/igm, '' ) .replace( /</igm, '' ) .replace( /\*/igm, '' ) .replace( /\./igm, '' ) .replace( /,/igm, '' ) .replace( /\//igm, '' ); } function isspam( msg ) { var result = ''; msgParts = msg.split( ' ' ); for( var i in msgParts ) { var part = msgParts[i]; if ( ':' != part[0] ) { // ignore gifs var stripped = stripMuck( part ); result += stripped; } } return inSpamArray( result ); } // *** END ANTI-SPAM MODULE *************************************************** // *** BEGIN VOTING MODULE **************************************************** var votingActive = false; var voteLoopActive = 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 voteStatus() { 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.sendNotice( "Only exact tips count towards vote goal.", "", notifierBG, notifierFG, "bold" ); } } function voteCancel() { votingActive = false; } function voteNotifier() { if ( votingActive ) { voteStatus(); } cb.setTimeout( voteNotifier, 220000 ); } function initialiseVoteModule( message ) { parseVoteCommand( message ); if ( !voteLoopActive ) { cb.setTimeout( voteNotifier, 500 ); voteLoopActive = true; } } function goalReached() { votingActive = false; cb.sendNotice( "VOTING HAS ENDED!", "", "#FF0000", "#FFFFFF", "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!", "", "#FF0000", "#FFFFFF", "bold" ); } else { cb.sendNotice( winningVoteMsg + " IS THE WINNER!", "", "#FF0000", "#FFFFFF", "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 ( stringStartsWith( message, "/timer" )) { var params = message.split( ";" ); startTimer( params[1], params[2] ); } else if ( '/cancel' == message ) { cancelTimer(); } else if ( '/timeleft' == message) { displayTimer(); } else if ( stringStartsWith( message, "/w " )) { // whisper cb.sendNotice( "whisper from " + user + ": " + message.substring( 3 ), cb.room_slug, '#FFFF99', '#000000' ); } else if ( stringStartsWith( message, "/notifier;" )) { parseNotifierCommand( message ); cb.sendNotice( "Notifiers set or updated.", user, notifierBG, notifierFG, "bold" ); } else if ( stringStartsWith( message, "/spamlist;" )) { parseSpamListCommand( message ); cb.sendNotice( "Spam list updated.", user, notifierBG, notifierFG, "bold" ); } else if ( stringStartsWith( message, "/spamthreshold;" )) { var params = message.split( ";" ); spamThreshold = params[1]; cb.sendNotice( "Spam threshold set to [" + params[1] + "].", user, notifierBG, notifierFG, "bold" ); } else if ( stringStartsWith( message, "/spamadd;" )) { parseSpamAddCommand( message, user ); } else if ( stringStartsWith( message, "/spamlist" )) { dumpSpamList( user ); } else if ( "/votecancel" == message ) { voteCancel(); cb.sendNotice( "VOTING HAS BEEN CANCELED!", user, notifierBG, notifierFG, "bold" ); } else if ( "/votestatus" == message ) { voteStatus(); } else if ( stringStartsWith( message, "/vote;" )) { initialiseVoteModule( message ); cb.sendNotice( "Voting command processed.", user, notifierBG, notifierFG, "bold" ); } } else { var spamIndex = isspam( message ); if ( -1 != spamIndex && !( cb.room_slug == user || true == msg['is_mod'] || true == msg['in_fanclub'] || msg['has_tokens'] )) { 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 + '] matches [' + spamList[spamIndex] + '] at index ' + spamIndex, 'multilibri', '#FFFF99', '#000000' ); cb.sendNotice( user + ' - [' + message + '] matches [' + spamList[spamIndex] + '] at index ' + spamIndex, 'cerebio', '#FFFF99', '#000000' ); } } 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 ) { var amount = parseInt( tip['amount'] ); if ( votingActive ) { updateVotes( amount ); if ( tipped >= goal ) goalReached(); } var reminder = ''; switch( amount ) { case 25: { reminder += 'PM'; break; } case 2000: { reminder += 'WHATSAPP'; break; } } if( amount > 2222 ) reminder += "NEW KING"; if ( '' != reminder ) { reminder = tip['from_user'] + ' (possibly) tipped for ' + reminder; cb.sendNotice( reminder, cb.room_slug, "#FF0000", "#FFFFFF", "bold" ); } } ); // *** END CB API *************************************************************
© Copyright Freesexcam 2011- 2024. All Rights Reserved.