Dani123
Author: danicka_
Description Source Code Launch App Current Users

Short Description:

12

Full Description

// vars
var VERSION = '3.0.5',
COMMAND_SHOW_LEADERBOARD = '!lb',
CONFIG_COLOR_LEADER = '#9f9',
INTERVAL_MULTIPLIER = 60000,
UPDATE_TIME = 5000,
RATE_FROM = 25,
RATE_MESSAGE = ":rate-me",
RATE_MESSAGE_DELAY = 1500,
NL = '\n',
user_total_tips = {},
user_last_tip_time = {},
last_top3 = '',
leader_username,
update_counter = 0,
interval_counter = 0,
silent_room = true;

var botVersion = "3.0.2";
var botDate = "March 23th, 2015";
var modelName = cb.room_slug;
var high_tip_username = null;
var high_tip_amount = 0;
var last_tip_username = null;
var last_tip_amount = 0;
var times_goal_reached = 0;
var last_time_goal_reached = null;
var current_goal_tipped = 0;
var current_description = null;
var autoNotice1Text = "";
var autoNotice2Text = "";
var autoNotice3Text = "";
var autoNotice4Text = "";
var botNoteBg = '#FF00FF'
var botNote2Bg = '#00FF00'
var botNote3Bg = '#FFFF00'
var botNote4Bg = '#9933FF'
var timeoutReleaseInterval = 1;
var meanBroadcasters = [''];
var tip_amt = 0;
var separator_char = "| ";

var set_tokens_command = '!settok';
var set_reached_command = '!setreached';
var new_subject_command = '!status';
var help_command = '!help';

cb.settings_choices = [
{
name: 'roomADS',
label: 'Room Adverts Here',
type: 'str',
minLength: 1,
maxLength: 2000,
required: false,
defaultValue: ''},
{
name: 'roomADSMin',
label: 'Number of Minutes for Room Advert',
type: 'int',
minValue: 1,
maxValue: 40,
defaultValue: 5},
{name: 'tokens', type: 'int', minValue: 1, default: 100, label: 'Goal Tokens'},
{name: 'goal_description', type: 'str', minLength: 1, maxLength: 555, label: 'Goal Description'},
{name: 'received_tokens', type: 'int', minValue: 0, default: 0, label: 'Already received tokens'},
{ name: 'autoNotice1',
label: 'Send Notice 1 (use text and emotes)',
type: 'str',
minLength: 0,
maxLength: 512,
required: false,
defaultValue: ''
},
{ name: 'autoNotice1Interval',
label: 'Set time',
type: 'choice',
choice1: 2,
choice2: 3,
choice3: 5,
choice4: 7,
choice5: 10,
choice6: 15,
choice7: 20,
choice8: 25,
choice9: 30,
choice10: 45,
choice11: 60,
defaultValue: 5
},
{ name: 'autoNotice2',
label: 'Send Notice 2 (use text and emotes)',
type: 'str',
minLength: 0,
maxLength: 512,
required: false,
defaultValue: ''
},
{ name: 'autoNotice2Interval',
label: 'Set time',
type: 'choice',
choice1: 2,
choice2: 3,
choice3: 5,
choice4: 7,
choice5: 10,
choice6: 15,
choice7: 20,
choice8: 25,
choice9: 30,
choice10: 45,
choice11: 60,
defaultValue: 5
},
{ name: 'autoNotice3',
label: 'Send Notice 3 (use text and emotes)',
type: 'str',
minLength: 0,
maxLength: 512,
required: false,
defaultValue: ''
},
{ name: 'autoNotice3Interval',
label: 'Set time',
type: 'choice',
choice1: 2,
choice2: 3,
choice3: 5,
choice4: 7,
choice5: 10,
choice6: 15,
choice7: 20,
choice8: 25,
choice9: 30,
choice10: 45,
choice11: 60,
defaultValue: 5
},
{ name: 'autoNotice4',
label: 'Send Notice 4 (use text and emotes)',
type: 'str',
minLength: 0,
maxLength: 512,
required: false,
defaultValue: ''
},
{ name: 'autoNotice4Interval',
label: 'Set time',
type: 'choice',
choice1: 2,
choice2: 3,
choice3: 5,
choice4: 7,
choice5: 10,
choice6: 15,
choice7: 20,
choice8: 25,
choice9: 30,
choice10: 45,
choice11: 60,
defaultValue: 5
},
{name:'rule1', type:'str', minLength:1, maxLength:255, label:'Set Room Rules #1 (Obligatory)'},
{name:'rule2', type:'str', minLength:1, maxLength:255, label:'Rule #2 (optional)', required:false},
{name:'rule3', type:'str', minLength:1, maxLength:255, label:'Rule #3 (optional)', required:false},
{name:'rule4', type:'str', minLength:1, maxLength:255, label:'Rule #4 (optional)', required:false},
{name:'rule5', type:'str', minLength:1, maxLength:255, label:'Rule #5 (optional)', required:false},
{name:'rule6', type:'str', minLength:1, maxLength:255, label:'Rule #6 (optional)', required:false},
{name:'rule7', type:'str', minLength:1, maxLength:255, label:'Rule #7 (optional)', required:false},
{name:'rule8', type:'str', minLength:1, maxLength:255, label:'Rule #8 (optional)', required:false},
{name:'rule9', type:'str', minLength:1, maxLength:255, label:'Rule #9 (optional)', required:false},
{name:'rule10', type:'str', minLength:1, maxLength:255, label:'Rule #10 (optional)', required:false},
{name:'advertisement_wait_time', type:'choice', label:'Set Rules Time (in minutes)',
choice1:5, choice2:10, choice3:15, choice4:20, choice5:25, choice6:30, choice7:45, choice8:60,
defaultValue:15}, {name: 'sepchar', type: 'choice', choice1: 'Vertical Bar', choice2: 'Hearts', defaultValue: 'Vertical Bar', label: "Separator character for Tip Menu"},
{name:'item1', type:'str', label:'Set Tip Menu Notice (for eg : boobs)',},
{name:'item1price', type:'int', label:'Set Tip Menu 1 Price (for eg : 50)'},
{name:'item2', type:'str', required: false, label:'Tip Menu 2',},
{name:'item2price', type:'int', required: false, label:'Tip Menu 2 Price'},
{name:'item3', type:'str', required: false, label:'Tip Menu 3',},
{name:'item3price', type:'int', required: false, label:'Tip Menu 3 Price'},
{name:'item4', type:'str', required: false, label:'Tip Menu 4',},
{name:'item4price', type:'int', required: false, label:'Tip Menu 4 Price'},
{name:'item5', type:'str', required: false, label:'Tip Menu 5',},
{name:'item5price', type:'int', required: false, label:'Tip Menu 5 Price'},
{name:'item6', type:'str', required: false, label:'Tip Menu 6',},
{name:'item6price', type:'int', required: false, label:'Tip Menu 6 Price'},
{name:'noticecolor', type:'str', label:'Tip Menu Notice color (html code default red #FF0000)', defaultValue: '#FF0000'},
{name: 'chat_ad', type:'int', minValue: 1, maxValue: 999, defaultValue: 1,
label: 'Delay in minutes between notice being displayed (minimum 1)'},
{name: 'print_on_tip',
type: 'choice',
choice1: 'always',
choice2: 'only if the top 3 changed',
choice3: 'never',
defaultValue: 'only if the top 3 changed',
label: "Print top 3 after tips"
}, {
name: 'print_interval',
type: 'int',
minValue: 0,
defaultValue: 10,
label: "Print top 3 at least once every (minutes, 0 to disable)",
required: true
}, {
name: 'highlight',
type: 'choice',
choice1: 'yes',
choice2: 'no',
defaultValue: 'no',
label: "Highlight tip leader in chat"
}, {
name: 'rate',
type: 'choice',
choice1: 'yes',
choice2: 'no',
defaultValue: 'yes',
label: "Remind tippers who tipped 25 tokens to rate"}
];

// handlers
cb.onTip(function(tip) {
handleTip(tip.amount, tip.from_user);
scheduleUpdate();
current_goal_tipped += tip['amount']
if (current_goal_tipped >= cb.settings.tokens) {
goalReached(tip['from_user']);
}

update_subject();
last_tip_amount = tip['amount']
last_tip_username = tip['from_user']
if (tip['amount'] > high_tip_amount) {
high_tip_amount = tip['amount']
high_tip_username = tip['from_user']

}
cb.drawPanel();
});

cb.onDrawPanel(function(user) {
if (times_goal_reached == 0) {
return {
'template': '3_rows_of_labels',
'row1_label': 'Received / Goal :',
'row1_value': '' + current_goal_tipped + ' / ' + cb.settings.tokens,
'row2_label': 'Highest Tip :',
'row2_value': format_username(high_tip_username) + ' (' + high_tip_amount + ')',
'row3_label': 'Hit Goal For :',
'row3_value': '' + times_goal_reached + ' times',

};
} else {
return {
'template': '3_rows_of_labels',
'row1_label': 'Received / Goal :',
'row1_value': '' + current_goal_tipped + ' / ' + cb.settings.tokens,
'row2_label': 'Highest Tip :',
'row2_value': format_username(high_tip_username) + ' (' + high_tip_amount + ')',
'row3_label': 'Hit Goal For :',
'row3_value': '' + times_goal_reached + ' times',


};
}
cb.onTip(function (tip)
{
var tip_message = tip['message'];
var number_spin = 0;
tip_message = tip_message.toLowerCase();
cb.log("Tip detected");
var indexTipper = findTipper(tip['from_user'], 'add');
cb.log("Tipper: " + tip['from_user'] + " - Index: " + indexTipper + " - Tip amount: " + tip['amount']);
tippersArray[indexTipper][1] = tippersArray[indexTipper][1] + parseInt(tip['amount']);
tip_amt=parseInt(tip['amount']);

for (var i = 1; i <= 6; i++) {
if (tip_amt == parseInt(cb.settings['item' + i + 'price'])) {
cb.sendNotice(tip['from_user'] + ' tipped for ' + cb.settings['item' + i],'','',cb.settings['noticecolor'],'bold');

}
}

});
});

cb.onMessage(function (msg) {

// handle user commands
if ((msg.m.indexOf(COMMAND_SHOW_LEADERBOARD) == 0) && !msg['X-Spam']) {
sendLeaderboard(true, msg.user);
msg['X-Spam'] = true;
}

// highlight leader
if ((cb.settings.highlight == 'yes') && (msg.user == leader_username)) {
msg.background = CONFIG_COLOR_LEADER;
}

// schedule interval
if (update_counter == 0){
scheduleInterval();
}

if (!msg['X-Spam']){
silent_room = false;
}

return msg;

if (msg['user'] == high_tip_username) {
msg['background'] = '#99FF00';
}
if (msg['m'][0] == '!') {
if (msg['user'] == cb.room_slug) {
if (startsWith(msg['m'], set_tokens_command)) {
msg['X-Spam'] = true;

var number = msg['m'].slice(set_tokens_command.length);
times_goal_reached = Math.floor(number / cb.settings.tokens);
current_goal_tipped = number % cb.settings.tokens;
last_time_goal_reached = new Date();

cb.drawPanel();

cb.sendNotice('The tokens received has been updated!', msg['user']);
} else if (startsWith(msg['m'], set_reached_command)) {
msg['X-Spam'] = true;

var number = msg['m'].slice(set_reached_command.length);
times_goal_reached = number;
last_time_goal_reached = new Date();
current_goal_tipped = 0;

cb.drawPanel();

cb.sendNotice('The number of times reached has been updated!', msg['user']);
} else if (startsWith(msg['m'], new_subject_command)) {
msg['X-Spam'] = true;

var new_sub = msg['m'].slice(new_subject_command.length+1);
current_description = new_sub;
update_subject();
cb.drawPanel();
} else if (startsWith(msg['m'], help_command)) {
msg['X-Spam'] = true;

cb.sendNotice('Broadcaster can use following commands:', msg['user'], '#FF0000', '#FFFFFF', 'bolder');
cb.sendNotice('', msg['user']);
cb.sendNotice('!help', msg['user'], '', '', 'bold');
cb.sendNotice('Display this notice only for the broadcaster.', msg['user']);
cb.sendNotice('!status [your goal description here]', msg['user'], '', '', 'bold');
cb.sendNotice('Change the goal description. The description will not be resetted after a new tip.', msg['user']);
cb.sendNotice('!settok [Number of tokens]', msg['user'], '', '', 'bold');
cb.sendNotice('Define how many tokens broadcaster has already received. Can be used when broadcaster decides to change the goal. Values "Hit Goal For" and "Received/Goal (Total)" will be updated on the panel.', msg['user']);
cb.sendNotice('!setreached [Number of goals reached]', msg['user'], '', '', 'bold');
cb.sendNotice('Define how many times goal was already reached. Can be used when broadcaster decides to change the goal. Values "Hit Goal For" and "Received/Goal (Total)" will be updated on the panel.', msg['user']);
}
}
}
});

// functions

function addTipperArray(user) {
var nextuser = 0;
if (tippersArray.length > 0) {
nextuser = tippersArray.length
}
tippersArray[nextuser] = new Array;
tippersArray[nextuser][0] = user;
tippersArray[nextuser][1] = 0;
cb.log("User " + user + " added in the array. Index: " + nextuser)
}

function findTipper(user, fonction) {
for (var i = 0;
i < tippersArray.length;
i++) {
if (tippersArray[i][0] == user) {
cb.log("User found in the tippers array with index " + i);
break
}
}
if ((i == tippersArray.length) && (fonction == 'add')) {
cb.log("User not in the tippers array ==> add him");
addTipperArray(user);
findTipper(user, 'none')
} else if (i == tippersArray.length) {
i = -1
}
return i
}

function message_TipAmount(user, message) {
var indexTipper = findTipper(user, 'none');
if (indexTipper >= 0) {
message = '|' + tippersArray[indexTipper][1] + '| ' + message
}
return message
}

function handleTip(amount, user) {
if (amount <= 0) return;

var before = user_total_tips[user] || 0,
after = user_total_tips[user] = before + amount;

user_last_tip_time[user] = new Date().valueOf();

if ((before < RATE_FROM) && (after >= RATE_FROM)){
cb.setTimeout(function(){
cb.chatNotice(RATE_MESSAGE, user);
}, RATE_MESSAGE_DELAY);
}
}

function sortLeaderboard(){
var lb = [];

for (var user in user_total_tips) {
if (user_total_tips.hasOwnProperty(user)){
lb.push([user_total_tips[user], -user_last_tip_time[user], user]);
}
}

if (lb.length > 0){
lb.sort(function(a, b){
for (var i=0; i < a.length; i++){
if (a[i] < b[i]){
return 1;
}
if (a[i] > b[i]){
return -1;
}
}
return 0;
});
leader_username = lb[0][2];
}

return lb;
}

function formatRanking(leaderboard, rank){
if (rank < leaderboard.length) {
var p = leaderboard[rank];
return p[2] + ' (' + p[0] + ' token' + (p[0]!=1 ? 's' : '') + ')';
}
else {
return '--';
}
}

function getTop3(leaderboard){
var rank, result='';
for (rank=0; rank<3; rank++){
if (rank>0){
result += '|';
}
if (rank < leaderboard.length){
result += leaderboard[rank][2];
}
}
return result;
}

function sendLeaderboard(force, to_user) {
var lb = sortLeaderboard(),
l = to_user ? lb.length : 3,
out = 'Tippers leaderboard By Nepystar';

if (!force) {
var top3 = getTop3(lb);
if (top3 == last_top3){
return;
}
last_top3 = top3;
}

if (l<3) { l=3; }

if (l < lb.length) {
out += ' top 3 (Type !lb to see the full leaderboard)';
}
if (to_user){
out += ' [v' + VERSION+']';
}

for (var rank=0; rank 0) {
var counter = ++interval_counter;

cb.setTimeout(function(){
if (interval_counter == counter){
sendLeaderboard(!silent_room);
}
}, interval*INTERVAL_MULTIPLIER);

silent_room = true;
}
}

function init(){

}

function refresh() {
cb.log("Refresh called");
cb.setTimeout(refresh, 60000);
cb.drawPanel();
}

function format_username(val) {
if (val === null) {
return "--";
} else {
return val.substring(0, 12);
}
}

function update_subject() {
var new_subject_command = current_description +
" [" + tips_remaining() + " tokens remaining]";
cb.log("Changing subject to: " + new_subject_command);
cb.changeRoomSubject(new_subject_command);
}

function goalReached(userName) {
last_time_goal_reached = new Date();

var curr_times_reached = Math.floor(current_goal_tipped / cb.settings.tokens);

for (var i = 0; i < curr_times_reached; i++) {
times_goal_reached++;
current_goal_tipped -= cb.settings.tokens;
if (userName != '') {
cb.sendNotice("Goal was reached for the " + getNumberString(times_goal_reached) + " time!");
cb.sendNotice('The user ' + userName + ' has reached the goal.', cb.room_slug, "#FEF9CD", "#1A1AD7", "bold");
}
}
}

function getNumberString(number) {
var numberString = null;

var lastChar = String(number).charAt(String(number).length - 1);

if ((lastChar == '1') && ((number % 100) != 11)) {
numberString = number + "st";
} else if ((lastChar == '2') && ((number % 100) != 12)) {
numberString = number + "nd";
} else if ((lastChar == '3') && ((number % 100) != 13)) {
numberString = number + "rd";
} else {
numberString = "" + number + "th";
}

return (numberString);
}

function tips_remaining() {
var r = cb.settings.tokens - current_goal_tipped;
if (r < 0) {
return 0;
} else {
return r;
}
}

function startsWith(source, str) {
return source.substring(0, str.length) === str;
}

function init() {
cb.sendNotice('Broadcaster can use following commands:', cb.room_slug, '#FF0000', '#FFFFFF', 'bolder');
cb.sendNotice('', cb.room_slug);
cb.sendNotice('!help', cb.room_slug, '', '', 'bold');
cb.sendNotice('Display this notice only for the broadcaster.', cb.room_slug);
cb.sendNotice('!status [your goal description here]', cb.room_slug, '', '', 'bold');
cb.sendNotice('Change the goal description. The description will not be resetted after a new tip.', cb.room_slug);
cb.sendNotice('!settok [Number of tokens]', cb.room_slug, '', '', 'bold');
cb.sendNotice('Define how many tokens broadcaster has already received. Can be used when broadcaster decides to change the goal. Values "Hit Goal For" and "Received/Goal" will be updated on the panel.', cb.room_slug);
cb.sendNotice('!setreached [Number of goals reached]', cb.room_slug, '', '', 'bold');
cb.sendNotice('Define how many times goal was already reached. Can be used when broadcaster decides to change the goal. Values "Hit Goal For" and "Received/Goal" will be updated on the panel.', cb.room_slug);
current_description = cb.settings.goal_description;
current_goal_tipped = cb.settings.received_tokens;
if (current_goal_tipped >= cb.settings.tokens) {
goalReached('');
}
cb.drawPanel();
update_subject();

cb.onEnter(function(user) {
if(meanBroadcasters.indexOf(cb.room_slug) < 0) {
cb.sendNotice('Welcome to my room, ' + user['user'] + '. Please take a moment to read my room rules before chatting. Thank you !', user['user'], '#DBFFDB', '', 'bold');
displayRules(user);
}
});

function chatAd() {
var msg = 'Tip Menu: ';

for (i=1;i<=6;i++) {
if (parseInt(cb.settings['item' + i + 'price'])>0) {
if (i>=2) {
msg += separator_char;
}
msg += cb.settings['item' + i] + '(' + parseInt(cb.settings['item' + i + 'price']) + ') ';
}
}
cb.sendNotice(msg,'','',cb.settings['noticecolor'],'bold');
cb.setTimeout(chatAd, (cb.settings.chat_ad * 60000));
}
cb.setTimeout(chatAd, (cb.settings.chat_ad * 60000));

function init()
{
if (cb.settings['sepchar'] == 'Hearts') {
separator_char = ":heart2 ";
}
}

init();
function displayRules(user) {
var username = '';
if(user) username = user['user'];
var notices = '####### Room Rules #######';
for(var i=1; i<=10;i++) {
if(cb.settings['rule' + i]) notices += '\nRule #'+ i +': ' + cb.settings['rule'+i];
}
notices += '\n######################';

cb.sendNotice(notices, username, '#E6FFFF', '#003399', 'bold');
if(!user || user == null) cb.setTimeout(displayRules, cb.settings.advertisement_wait_time * 60000);
}

{
if(meanBroadcasters.indexOf(cb.room_slug) < 0) displayRules();
}
}
function displayNotification1() {
cb.sendNotice(autoNotice1Text,'',botNoteBg,'','bold');
cb.setTimeout(displayNotification1, cb.settings.autoNotice1Interval * 60000);
}

function twitter() {
cb.sendNotice(cb.settings.roomADS, '', '#FFBEFF', '', 'bold');
cb.setTimeout(twitter, (cb.settings.roomADSMin * 60000));
}

function displayNotification2() {
cb.sendNotice(autoNotice2Text,'',botNote2Bg,'','bold');
cb.setTimeout(displayNotification2, cb.settings.autoNotice2Interval * 60000);
}

function displayNotification3() {
cb.sendNotice(autoNotice3Text,'',botNote3Bg,'','bold');
cb.setTimeout(displayNotification3, cb.settings.autoNotice3Interval * 60000);
}

function displayNotification4() {
cb.sendNotice(autoNotice4Text,'',botNote4Bg,'','bold');
cb.setTimeout(displayNotification4, cb.settings.autoNotice4Interval * 60000);
}

if (cb.settings.autoNotice1) {
autoNotice1Text = cb.settings.autoNotice1.trim();
}

if (cb.settings.autoNotice2) {
autoNotice2Text = cb.settings.autoNotice2.trim();
}

if (cb.settings.autoNotice3) {
autoNotice3Text = cb.settings.autoNotice3.trim();
}

if (cb.settings.autoNotice4) {
autoNotice4Text = cb.settings.autoNotice4.trim();
}

© Copyright Freesexcam 2011- 2024. All Rights Reserved.