Bots Home
|
Create an App
tbr_rules
Author:
tb_tobora
Description
Source Code
Launch Bot
Current Users
Created by:
Tb_Tobora
/* Testbot for learning the API: show welcome and room rules, when entering the room (inspired by ~ Room Rules ~ Bot by zingknaat) DONE: implement $user in welcome message with regex? DONE: implement "show room rules" by command \rules TODO: permissions! TODO: rainbow colored rules TODO: make welcome and rules color independent TODO: try to create a "frame" again - how to solve non-monospaced font issue? TODO: make it possible to set rules in chat? */ cb.settings_choices = [ {name:'welcome_msg', type:'str', minLength:1, maxLength:500, label:'Welcome message text: use "$user" for username (optional)', required:false}, {name:'rule1', type:'str', minLength:1, maxLength:255, label:'Line #1'}, {name:'rule2', type:'str', minLength:1, maxLength:255, label:'Line #2 (optional)', required:false}, {name:'rule3', type:'str', minLength:1, maxLength:255, label:'Line #3 (optional)', required:false}, {name:'rule4', type:'str', minLength:1, maxLength:255, label:'Line #4 (optional)', required:false}, {name:'rule5', type:'str', minLength:1, maxLength:255, label:'Line #5 (optional)', required:false}, {name:'rule6', type:'str', minLength:1, maxLength:255, label:'Line #6 (optional)', required:false}, {name:'rule7', type:'str', minLength:1, maxLength:255, label:'Line #7 (optional)', required:false}, {name:'rule8', type:'str', minLength:1, maxLength:255, label:'Line #8 (optional)', required:false}, {name:'rule9', type:'str', minLength:1, maxLength:255, label:'Line #9 (optional)', required:false}, {name:'rule10', type:'str', minLength:1, maxLength:255, label:'Line #10 (optional)', required:false, defaultValue:'Rule 10:'}, {name: 'welcome_msg_lmargin', type:'int', label: 'Left margin for welcome message (spaces)', defaultValue:10}, {name: 'rules_lmargin', type:'int', label: 'Left margin for rules (spaces)', defaultValue:18}, {name: 'rules_txt_clr', type: 'str', label: 'Textcolor for rules (hex)', defaultValue:'#ff9000'}, {name: 'welcome_msg_txt_clr', type: 'str', label: 'Textcolor for welcome (hex)', defaultValue:'#FFFFFF'}, {name: 'sign_onoff', type: 'choice', label: 'Turn ! sign on or off (experimental)', choice1:'on', choice2:'off', defaultValue:'off'}, {name:'more1', type:'str', minLength:1, maxLength:855, label:'Description of rule 1 (get it with \rule1) (optional)' , required:false}, {name:'more2', type:'str', minLength:1, maxLength:855, label:'Description of rule 2 (get it with \rule2) (optional)' , required:false}, {name:'more3', type:'str', minLength:1, maxLength:855, label:'Description of rule 3 (get it with \rule3) (optional)' , required:false}, {name:'more4', type:'str', minLength:1, maxLength:855, label:'Description of rule 4 (get it with \rule4) (optional)' , required:false}, {name:'more5', type:'str', minLength:1, maxLength:855, label:'Description of rule 5 (get it with \rule5) (optional)' , required:false}, {name:'more6', type:'str', minLength:1, maxLength:855, label:'Description of rule 6 (get it with \rule6) (optional)' , required:false}, {name:'more7', type:'str', minLength:1, maxLength:855, label:'Description of rule 7 (get it with \rule7) (optional)' , required:false}, {name:'more8', type:'str', minLength:1, maxLength:855, label:'Description of rule 8 (get it with \rule8) (optional)' , required:false}, {name:'more9', type:'str', minLength:1, maxLength:855, label:'Description of rule 9 (get it with \rule9) (optional)' , required:false}, {name:'more10', type:'str', minLength:1, maxLength:855, label:'Description of rule 10 (get it with \rule10) (optional)' , required:false}, // {name: 'rules_bg_clr', type: 'str', label: 'Background-color for rules (hex)', defaultValue:'#ffffff'}, ]; // function colorText(str,phase) // // found at https://krazydad.com/tutorials/makecolors.php // { // if (phase == undefined) phase = 0; // center = 128; // width = 127; // frequency = Math.PI*2/str.length; // for (var i = 0; i < str.length; ++i) // { // red = Math.sin(frequency*i+2+phase) * width + center; // green = Math.sin(frequency*i+0+phase) * width + center; // blue = Math.sin(frequency*i+4+phase) * width + center; // document.write( '<font style="color:' + RGB2Color(red,green,blue) + '">' + str.substr(i,1) + '</font>'); // } // } var with_welcome; function displayRules(user, with_welcome) { var username = ''; if(user) { username = user['user']; } var notices = ''; var rules_lmargin_spacer = ''; var welcome_msg_lmargin_spacer = ''; // fill rules lmargin spacer for (let i = 1; i<=cb.settings['rules_lmargin']; i++) { rules_lmargin_spacer += '\xa0'; } if (with_welcome == 1) { if (cb.settings['welcome_msg']) { var welcome_msg = cb.settings['welcome_msg'].split("$user"); for (let i = 1; i<=cb.settings['welcome_msg_lmargin']; i++) { welcome_msg_lmargin_spacer += '\xa0'; } cb.sendNotice(welcome_msg_lmargin_spacer + welcome_msg[0] + username + welcome_msg[1] + '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0', username, '#000000', cb.settings['welcome_msg_txt_clr']); }} var sign = ["\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0", "#####\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0", "\xa0\xa0###\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0", "\xa0\xa0\xa0\xa0#\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0", "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0", "\xa0\xa0\xa0\xa0#\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0", "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0", "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0", "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0", "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0", "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0", "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0"]; for(let i=1; i<=10;i++) { if(cb.settings['sign_onoff'] == 'on' && cb.settings['rule' + i]) { notices += '\n' + rules_lmargin_spacer + sign[i-1] + cb.settings['rule'+i]; } else if (cb.settings['rule' + i]) { notices += '\n' + rules_lmargin_spacer + cb.settings['rule'+i]; } } // if(cb.settings['welcome_msg']) { // cb.sendNotice(cb.settings['welcome_msg'], username, '#000000', '#ff9000'); // } // for (let i=1; i<=50; i++) { // notices += '#'; // } // for(let i=1; i<=10;i++) { // if(cb.settings['rule' + i]) { // var frame_spacer = ''; // var frame_spacer_length = (50 - cb.settings['rule' + i].length); // // cb.sendNotice('frame_spacer_length: ' + i + ' = ' + frame_spacer_length); // for (let k=1; k<=frame_spacer_length; k++) { // frame_spacer += '\xa0'; // // frame_spacer += (' ' + k.toString()); // } // notices += '\n# \xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0' + 'Rule '+ i +': ' + cb.settings['rule'+i] + frame_spacer + "#"; // } // } // for (let i=1; i<=50; i++) { // notices += '#'; // } // var test_str = '\n\n ## testing... ##'; // for(let i=1; i<=10;i++) { // test_str += '\nRule ' + i + ' spacer: ' + (50 - cb.settings['rule'+i].length) + ' chars'; // } // cb.sendNotice(test_str, username); // cb.sendNotice(notices, username, cb.settings['rules_bg_clr'], cb.settings['rules_txt_clr'], 'bold'); cb.sendNotice(notices, username, '#ffffff', cb.settings['rules_txt_clr'], 'bold'); } function setRules() {} // handlers cb.onMessage(function (message, user) { var username = ''; if(user) { username = user['user']; } if (message['m'] == "/rules") { message['X-SPam'] = true; displayRules(user,0); } for (let i=1; i<=10;i++) { if (message['m'] == "/rule" + i) { message['X-SPam'] = true; cb.sendNotice(cb.settings['more' + i], username, '#ffffff', cb.settings['rules_txt_clr'], 'bold'); } if (message['m'] == "/setrule" + i) { message['X-SPam'] = true; let message_tmp = message['m'].split("/setrule" + i); cb.settings["rule" + i] = message_tmp[1]; } if (message['m'] == "/setmore" + i) { message['X-SPam'] = true; let message_tmp = message['m'].split("/setmore" + i); cb.settings["more" + i] = message_tmp[1]; } } return "Alright."; }); cb.onEnter(function(user) { displayRules(user,1); });
© Copyright Chaturbate 2011- 2024. All Rights Reserved.