Apps Home
|
Create an App
Just4Sasha
Author:
flexing
Description
Source Code
Launch App
Current Users
Created by:
Flexing
// vars var times_goal_reached = 0; var last_time_goal_reached = null; var current_goal_tipped = 0; var current_description = null; var current_free_tips = 0; var timeint_just4sasha_notice = 0; var set_tokens_command = '!settok'; var set_reached_command = '!setreached'; var new_subject_command = '!status'; var help_command = '!help'; var just4sasha_command = '!just4sashatimer'; cb.settings_choices = [ {name: 'tokens', type: 'int', minValue: 1, default: 100, label: 'Tokens'}, {name: 'goal_description', type: 'str', minLength: 1, maxLength: 255, label: 'Goal Description'}, {name: 'received_tokens', type: 'int', minValue: 0, default: 0, label: 'Already received tokens'}, {name: 'just4sasha_activation', type: 'choice', choice1:'yes',choice2:'no', defaultValue: 'no'}, {name: 'just4sasha_notice_timer', type: 'int', minValue: 0, default: 30, label: 'Time interval to display the "just4sasha" notice in seconds'} ]; // handlers cb.onTip(function(tip) { if (cb.settings.just4sasha_activation == 'yes') { if (startsWith(tip['message'], 'just4sasha')) { current_free_tips += tip['amount'] cb.sendNotice('Thanks to ' + tip['from_user'] + '. This tip doesnt count for goal.','', '#FF9CFF', '#FFFFFF', 'bolder'); } else { current_goal_tipped += tip['amount'] if (current_goal_tipped >= cb.settings.tokens) { goalReached(tip['from_user']); } } } else { current_goal_tipped += tip['amount'] if (current_goal_tipped >= cb.settings.tokens) { goalReached(tip['from_user']); } } update_subject(); cb.drawPanel(); }); cb.onDrawPanel(function(user) { if (cb.settings.just4sasha_activation == 'yes') { if (times_goal_reached == 0) { return { 'template': '3_rows_of_labels', 'row1_label': 'Received / Goal (Total):', 'row1_value': '' + current_goal_tipped + ' / ' + cb.settings.tokens + ' (' + ((times_goal_reached * cb.settings.tokens) + current_goal_tipped) + ')', 'row2_label': 'Tokens "just4sasha":', 'row2_value': '' + current_free_tips, 'row3_label': 'Hit Goal / Last Time:', 'row3_value': '' + times_goal_reached + ' time / Never' }; } else { return { 'template': '3_rows_of_labels', 'row1_label': 'Received / Goal (Total):', 'row1_value': '' + current_goal_tipped + ' / ' + cb.settings.tokens + ' (' + ((times_goal_reached * cb.settings.tokens) + current_goal_tipped) + ')', 'row2_label': 'Tokens "just4sasha":', 'row2_value': '' + current_free_tips, 'row3_label': 'Hit Goal / Last Time:', 'row3_value': '' + times_goal_reached + ' time(s) / ' + Math.floor(((new Date()).getTime() - last_time_goal_reached.getTime()) / 60000) + ' min ago' }; } } else { if (times_goal_reached == 0) { return { 'template': '3_rows_of_labels', 'row1_label': 'Received / Goal (Total):', 'row1_value': '' + current_goal_tipped + ' / ' + cb.settings.tokens + ' (' + ((times_goal_reached * cb.settings.tokens) + current_goal_tipped) + ')', 'row2_label': 'Hit Goal For:', 'row2_value': '' + times_goal_reached + ' times', 'row3_label': 'Last Reached:', 'row3_value': 'Never' }; } else { return { 'template': '3_rows_of_labels', 'row1_label': 'Received / Goal (Total):', 'row1_value': '' + current_goal_tipped + ' / ' + cb.settings.tokens + ' (' + ((times_goal_reached * cb.settings.tokens) + current_goal_tipped) + ')', 'row2_label': 'Hit Goal For:', 'row2_value': '' + times_goal_reached + ' times', 'row3_label': 'Last Reached:', 'row3_value': '' + Math.floor(((new Date()).getTime() - last_time_goal_reached.getTime()) / 60000) + ' minutes ago' }; } } }); cb.onMessage(function (msg) { if (msg['m'][0] == '!') { if (msg['user'] != cb.room_slug) { if (cb.settings.just4sasha_activation == 'yes') { if (startsWith(msg['m'], help_command)) { msg['X-Spam'] = true; cb.sendNotice('type just4sasha at the beginning of ur tip-note if u dont wanna take part in current goal.', '', '#085B9A', '#FFFFFF', 'bolder'); cb.sendNotice('!just4sashatimer [Number of seconds]: allow you to define every how much seconds the "just4sasha" notice will be displayed. Red and green can use it.','','','','bolder','red'); cb.sendNotice('!just4sashatimer [Number of seconds]: allow you to define every how much seconds the "just4sasha" notice will be displayed. Red and green can use it.','','','','bolder','green'); } else if (startsWith(msg['m'], just4sasha_command)) { if ((msg['is_mod'] == true) || (msg['in_fanclub'] == true)) { msg['X-Spam'] = true; var old_value1 = timeint_just4sasha_notice; timeint_just4sasha_notice = parseInt(msg['m'].slice(just4sasha_command.length+1)) * 1000; if (old_value1 == 0) { notice_just4sasha(); } } } } } else 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'], just4sasha_command)) { msg['X-Spam'] = true; var old_value = timeint_just4sasha_notice; timeint_just4sasha_notice = parseInt(msg['m'].slice(just4sasha_command.length+1)) * 1000; if (old_value == 0) { notice_just4sasha(); } } 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']); if (cb.settings.just4sasha_activation == 'yes') { cb.sendNotice('!just4sashatimer [Number of seconds]', msg['user'], '', '', 'bold'); cb.sendNotice('"just4sasha" notice will be displayed every [Number of seconds] seconds. Put 0 to stop the notice.', msg['user']); } } } } }); // Functions function refresh() { cb.log("Refresh called"); cb.setTimeout(refresh, 20000); cb.drawPanel(); } 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 notice_just4sasha() { if ((cb.settings.just4sasha_activation == 'yes') && (timeint_just4sasha_notice > 0)) { cb.sendNotice('type just4sasha at the beginning of ur tip-note if u dont wanna take part in current goal.', '', '#085B9A', '#FFFFFF', 'bolder'); cb.setTimeout(notice_just4sasha, parseInt(timeint_just4sasha_notice)); } } 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 (Total)" 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 (Total)" will be updated on the panel.', cb.room_slug); if (cb.settings.just4sasha_activation == 'yes') { cb.sendNotice('!just4sashatimer [Number of seconds]', cb.room_slug, '', '', 'bold'); cb.sendNotice('"just4sasha" notice will be displayed every [Number of seconds] seconds. Put 0 to stop the notice. Only if just4sasha function is activated.', cb.room_slug); } current_description = cb.settings.goal_description; current_goal_tipped = cb.settings.received_tokens; if (current_goal_tipped >= cb.settings.tokens) { goalReached(''); } if (cb.settings.just4sasha_activation == 'yes') { timeint_just4sasha_notice = cb.settings.just4sasha_notice_timer * 1000; if (timeint_just4sasha_notice > 0) { cb.setTimeout(notice_just4sasha, parseInt(timeint_just4sasha_notice)); } } cb.drawPanel(); update_subject(); } init(); cb.setTimeout(refresh, 20000);
© Copyright Freesexcam 2011- 2024. All Rights Reserved.