Bots Home
|
Create an App
toggleable tip menu
Author:
warppipe
Description
Source Code
Launch Bot
Current Users
Created by:
Warppipe
var menus = [[], []] var current_m = 0 // each array item is an object: Item as str, cost as int, cooldown as int, available as bool cb.settings_choices = [ {label: 'Menu 1', name: 'menu_1', type: 'str'}, {label: 'Menu 2', name: 'menu_2', type: 'str'}, {label: 'Separator', name: 'separator', type: 'str'}, {label: 'Menu inverval (in minutes)', name: 'interval', type: 'int'}, {label: 'Text Color', name: 'text_color', type: 'str', defaultValue: '#7B68EE'}, ] cb.onTip(function (tip) { for (let i = 0; i < menus[current_m].length; i++){ if (tip['amount'] == menus[current_m][i]['cost']){ if(menus[current_m][i]['available']){ var notice_string = '' if(tip['is_anon_tip']){ notice_string = 'Someone tipped for ' + menus[current_m][i]['item']; } else { notice_string = tip['from_user'] + ' tipped for ' + menus[current_m][i]['item']; }; if(menus[current_m][i]['timer'] != 0){ menus[current_m][i]['available'] = false let reinstate_m = current_m cb.setTimeout(function(){reinstate(reinstate_m, i)}, menus[current_m][i]['timer'] * 60000) notice_string += '\nThis item is on a cooldown and will not be available again for ' + menus[current_m][i]['timer'] + ' minutes.' }; cb.sendNotice(notice_string, '', '', cb.settings['text_color'], 'bold'); } else { cb.sendNotice(menus[current_m][i]['item'] + ' is not available within ' + menus[current_m][i]['timer'] + ' minutes of someone tipping for it.', '', '', cb.settings['text_color'], 'bold'); }; }; }; }) cb.onMessage(function (msg) { if (msg["user"] == cb.room_slug || msg['is_mod']){ if (msg['m'] == '/toggle'){ msg['X-Spam'] = true; current_m++ current_m %= 2 cb.sendNotice('New Menu', '', '', cb.settings['text_color'], 'bold'); cb.sendNotice(make_menu_string(), '', '', cb.settings['text_color'], 'bold'); }; }; if(msg['m'] == '/menu' || msg['m'] == '/tipmenu'){ cb.sendNotice(make_menu_string(), msg['user'], '', cb.settings['text_color'], 'bold'); msg['X-Spam'] = true }; }) function post_menu(){ cb.sendNotice(make_menu_string(), '', '', cb.settings['text_color'], 'bold'); cb.setTimeout(post_menu, cb.settings.interval * 60000); } function make_menu_string(){ var menu_string = '' for (let i = 0; i < menus[current_m].length; i++){ if(!menus[current_m][i]['available']){continue;}; if (menu_string != ''){ menu_string += ' ' + cb.settings.separator + ' ' } menu_string += menus[current_m][i]['cost'] + ' tokens for ' + menus[current_m][i]['item'] } return menu_string; } function make_menu_arrays(){ for(let menu = 1; menu <= 2; menu++){ if (cb.settings['menu_' + menu] != '' && cb.settings['menu_' + menu] != null){ var menu_string = cb.settings['menu_' + menu]; var intermediate_array = []; intermediate_array = menu_string.split('--'); for (let i = 0; i < intermediate_array.length; i++){ var _cost = intermediate_array[i].substring(0, intermediate_array[i].indexOf(' ')); var _item = intermediate_array[i].substring(intermediate_array[i].indexOf(' ') + 1); var _timer = 0; if (_cost.includes('/')){ _timer = _cost.substring(_cost.indexOf('/') +1); _cost = _cost.substring(0, _cost.indexOf('/')); }; menus[menu - 1].push({cost: _cost, item: _item, timer: _timer, available : true}); }; }; }; } function reinstate(menu, item){ cb.sendNotice(menu + ' ' + item, '', '', cb.settings.text_color, 'bold') menus[menu][item]['available'] = true cb.sendNotice(menus[menu][item]['item'] + ' is available again!', '', '', cb.settings.text_color, 'bold') } make_menu_arrays(); post_menu();
© Copyright Chaturbate 2011- 2025. All Rights Reserved.