Bots Home
|
Create an App
mau55's auction bot
Author:
dangermau55
Description
Source Code
Launch Bot
Current Users
Created by:
Dangermau55
/** * * mau55's auction_bot * * Once the auction is configured, type "/sa" to start it. * * Other commands are "/status", "/rules", "/bids", "/intro" * */ var __stillRunning = false; var _biddersArray = new Array; var _bidsArray = new Array; var _number = 0; var _countDownDateTime = 0; var _days = 0; var _hours = 0; var _minutes = 0; var _seconds = 0; var _timerTimeout; var _statusInterval = 5; cb.settings_choices = [ {name:'__auctionItem', type:'str', maxLength: 100, label:"Item for Auction"}, {name:'__originalTokenValue', type:'int', minValue: 1, maxValue: 10000, defaultValue: 1,label: 'Item Value (including shipping)'}, {name:'__duration', type:'int', minValue: 1, maxValue: 999, defaultValue: 5,label: 'Auction Duration (minutes, minimum = 1)'}, {name:'__interval', type:'int', minValue: 1, maxValue: 999, defaultValue: 2,label: 'Notification Rotation (minutes, minimum = 1)'} ]; cb.onEnter(function (user) { var outMsg = "Welcome to my room " + user['user'] + "\n"; if ( __stillRunning ){ outMsg += "We're having an auction and you still have a chance to win!!"; } cb.sendNotice( outMsg, user['user']); printIntro(user['user']); }); cb.onTip(function ( tip ) { var _amountTipped = 0; _amountTipped = parseInt(tip['amount']); var str = tip['message']; str = str.toLowerCase(); if ( str.includes("bid") ){ handleBid(tip['from_user'], _amountTipped); } }); // // whenever anyone adds a message to the chat room... // cb.onMessage(function (msg) { // // "/bids" -> prints out the leader board // if ( msg['m'] == '/bids' ){ msg['X-Spam'] = true; printLeaderBoard(msg['user']); } // // "/rules" -> prints out the rules // if ( msg['m'] == '/rules' ){ msg['X-Spam'] = true; printRules( msg['user'] ); } // // only the broadcaster or the mod... // if(( msg['user'] == cb.room_slug )||(msg['is_mod'] == true)){ // // // if ( msg['m'] == '/testbid'){ msg['X-Spam'] = true; handleBid( cb.room_slug, 1 ); } // // prints out the status for everyone to see // if ( msg['m'] == '/status' ){ msg['X-Spam'] = true; printStatus(); } // // prints out the intro message only for the him/her to see // if ( msg['m'] == '/intro' ){ msg['X-Spam'] = true; printIntro( msg['user'] ); } // // YOU MUST TYPE "/sa" TO START THE AUCTION!!! // if ( msg['m'] == '/sa' ){ msg['X-Spam'] = true; if( cb.settings['__auctionItem']){ // // sets the correct flag to let all of the // other functions know that the auction is running. // __stillRunning = true; // // Depending on the configured duration, will set the end-time // setEndDateTime(); // // Starts the time thread // _timerTimeout = cb.setTimeout(countdownTimer, 1000); // // Two seconds after the auction is started, print the // intro message and the rules to the chat // cb.setTimeout(function(){ printIntro(); printRules(); }, 2000); } } } }); // // // function setEndDateTime(){ // Get current date and time var now = new Date().getTime(); var minutes = 0; minutes = parseInt(cb.settings.__duration); _countDownDateTime = now + ( minutes * 60000 ); } // // If a username is provided, this function will print out the rules // only to the user. // // If no username is provided, everyone sees the rules. // function printRules(user){ var userStr = ""; var outMsg = ""; if(user){ userStr = user; } outMsg = " --- AUCTION RULES --- \n"; outMsg += " - To bid, you must type \"bid\" in your tip note message. \n"; outMsg += " - If there is a tie, the first to have bid the highest amount, wins.\n"; outMsg += " - All of your bids will accumulate and will be remembered if you leave the room.\n"; outMsg += " - Type \"/bids\" to see the leader board.\n"; outMsg += " - Type \"/rules\" to see these rules again."; cb.sendNotice( outMsg, userStr ); } // // If a username is provided, this function will print out the leader board // only to the user. // // If no username is provided, everyone sees the leader board. // function printLeaderBoard(user){ var userStr = ""; var outMsg = ""; if(user){ userStr = user; } if(( _hours > 0 )||( _minutes > 0 ) || ( _seconds > 0 )){ outMsg = " --- LEADER BOARD with " + _hours + " hours, " + _minutes + " minutes and " + _seconds + " seconds left --- \n"; } else{ outMsg = " --- LEADER BOARD --- \n"; } for( var x = 0; x < _bidsArray.length; x++ ){ outMsg += _bidsArray[x][1] + " tokens bid by " + _bidsArray[x][0] + "\n"; } if( _bidsArray.length < 1 ){ outMsg += "No one has bid yet.\n"; } outMsg = outMsg.slice(0, -1); cb.sendNotice( outMsg, userStr ); } // // If a username is provided, this function will print out the intro message // only to the user. // // If no username is provided, everyone sees the message. // function printIntro(user){ if ( __stillRunning ){ var outStr = ""; var userStr = ""; if(user){ userStr = user; } // // if NO ONE has bid // if( _bidsArray.length < 1 ){ outStr = " --- AUCTION TIME --- \n"; outStr += "Bid on \"" + cb.settings['__auctionItem'] + "\" valued at " + cb.settings['__originalTokenValue'] + " tokens.\n"; outStr += " - To bid, you must type \"bid\" in your tip note message. \n"; outStr += "Bidding ends in " + _hours + " hours, " + _minutes + " minutes and " + _seconds + " seconds.\n"; outStr += " - Type \"/bids\" to see the leader board.\n - Type \"/rules\" to see the rules."; } // // someone has bid // else{ outStr = " --- AUCTION TIME --- \n"; outStr += "Bid on \"" + cb.settings['__auctionItem'] + "\" valued at " + cb.settings['__originalTokenValue'] + " tokens.\n"; outStr += " - To bid, you must type \"bid\" in your tip note message. \n"; outStr += _bidsArray[0][0] + " is the current leader with " + _bidsArray[0][1] + " tokens.\n"; outStr += "Bidding ends in " + _hours + " hours, " + _minutes + " minutes and " + _seconds + " seconds.\n"; outStr += " - Type \"/bids\" to see the leader board.\n - Type \"/rules\" to see the rules."; } cb.sendNotice( outStr, userStr ); } } // // // function handleBid(user, amt) { var retVal = 0; if ( __stillRunning ) { var tempArr = [user, amt]; // // if the user is already in the array, look him up in the second array, and update his bid // if(cbjs.arrayContains(_biddersArray, user)) { for( var x = 0; x < _bidsArray.length; x++ ){ if( _bidsArray[x][0] == user) { _bidsArray[x][1] += amt; cb.sendNotice( "You have bid a total of " + _bidsArray[x][1] + " tokens.", user ); } } retVal = 1; } // // if the user is not in the array, add him to both arrays // else{ cb.sendNotice( "You have bid a total of " + amt + " tokens.", user ); _biddersArray[_number] = user; _bidsArray[_number] = tempArr; _number++; retVal = 0; } // // Sort the bids // bubbleSort(_bidsArray); var bidStr = ""; // // Announce the leader // bidStr = _bidsArray[0][0] + " is the current leader with " + _bidsArray[0][1] + " tokens bid.\n"; // // Announce the remaining time // bidStr += "Bidding ends in " + _hours + " hours, " + _minutes + " minutes and " + _seconds + " seconds.\n"; bidStr += " - To bid, you must type \"bid\" in your tip note message."; cb.sendNotice( bidStr, ''); } else{ // // Announce the time is up and that no more bids can be accepted. // cb.sendNotice( "Sorry, time has expired. We cannot accept any further bids.", user ); } return retVal; } // // prints the status // function printStatus(){ if ( __stillRunning ){ var outStr = ""; // // if NO ONE has bid // if( _bidsArray.length < 1 ){ outStr = " --- AUCTION TIME --- \n"; outStr += "Bid on \"" + cb.settings['__auctionItem'] + "\" valued at " + cb.settings['__originalTokenValue'] + " tokens.\n"; outStr += " - To bid, you must type \"bid\" in your tip note message. \n"; outStr += "Bidding ends in " + _hours + " hours, " + _minutes + " minutes and " + _seconds + " seconds.\n"; outStr += " - Type \"/bids\" to see the leader board.\n - Type \"/rules\" to see the rules."; } // // someone has bid // else{ outStr = " --- AUCTION UPDATE --- \n"; outStr += "Bid on \"" + cb.settings['__auctionItem'] + "\" valued at " + cb.settings['__originalTokenValue'] + " tokens.\n"; outStr += " - To bid, you must type \"bid\" in your tip note message. \n"; outStr += _bidsArray[0][0] + " is the current leader with " + _bidsArray[0][1] + " tokens bid.\n"; outStr += "Bidding ends in " + _hours + " hours, " + _minutes + " minutes and " + _seconds + " seconds.\n"; outStr += " - Type \"/bids\" to see the leader board.\n - Type \"/rules\" to see the rules."; } cb.sendNotice( outStr, '' ); } } // // // function countdownTimer(){ // Get current date and time var now = new Date().getTime(); // Find the distance between now and the count down date var distance = _countDownDateTime - now; // // Time remaining in days, hours, minutes and seconds // _days = Math.floor(distance / (1000 * 60 * 60 * 24)); _hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); _minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); _seconds = Math.floor((distance % (1000 * 60)) / 1000); // // If the count down is over, write some text // if (distance < 0) { var winnerStr = ""; // // If anyone has bid, announce the winner and the winning bid. // if( _bidsArray.length > 0 ){ winnerStr = " --- WE HAVE A WINNER --- \n"; winnerStr += _bidsArray[0][0] + " wins \"" + cb.settings['__auctionItem'] + "\" for " + _bidsArray[0][1] + " tokens bid. CONGRATULATIONS!!!!"; cb.sendNotice( winnerStr, '' ); } else{ cb.sendNotice( "Time for the auction has expired.", '' ); } // // Print out the final results // printLeaderBoard(); // // Turn off the flag that keeps everything running // __stillRunning = false; // // Stop the timer thread // cb.cancelTimeout(countdownTimer); } // // Still running... // else{ // // prints out the status at an interval // if (( _minutes > 1 ) && ( _minutes % _statusInterval === 0 ) && ( _seconds === 0 )){ printStatus(); } // // one minute or less to go // if(( _minutes === 1 ) && ( _seconds === 0 )){ cb.sendNotice( "60 seconds until the auction closes!", '' ); } if(( _minutes === 0 ) && ( _seconds === 30 )){ cb.sendNotice( "30 seconds until the auction closes!!!!", '' ); } if(( _minutes === 0 ) && ( _seconds === 10 )){ cb.sendNotice( "*** LAST CALL *** ONLY 10 seconds until the auction closes!!!!!!", '' ); } // keep going cb.setTimeout(countdownTimer, 1000); } } function init(){ _statusInterval = parseInt(cb.settings['__interval']); } init(); function bubbleSort(array) { var swapped; do { swapped = false; for(var i = 0; i < array.length; i++) { if(array[i] && array[i + 1] && array[i][1] < array[i + 1][1]) { swap(array, i, i + 1); swapped = true; } } } while(swapped); return array; } // // swap function helper // function swap(array, i, j) { var temp = array[i]; array[i] = array[j]; array[j] = temp; }
© Copyright Camscaster.Com 2011- 2025. All Rights Reserved.