Bots Home
|
Create an App
RoboCumBoard
Author:
fatkarl
Description
Source Code
Launch Bot
Current Users
Created by:
Fatkarl
function default_notice(msg, user) { if (user == undefined) user = ""; cb.chatNotice(msg, user, '#ffffff', cb.settings.notify_color); } function broadcaster_notice(msg) { cb.chatNotice(msg, cb.room_slug, '#ffffff', '#CD5C5C'); } function make_x(len) { var x = ""; for (var i = 0; i < len; i++) { x += "x"; } return x; } function isdef_str(x) { return (x !== undefined && x.length > 0); } function get_body(components, start_from) { if (start_from == undefined) start_from = 1; var s = ""; for (var i = start_from; i < components.length; i++) { s += components[i] + " "; } return s; } function num_line(line) { var num = []; var palette = "0123456789"; var mark = 0; var is_num = function(c) { return palette.indexOf(c) != -1; }; var in_num = is_num(line[0]); for (var i = 1; i < line.length; i++) { var cu_num = is_num(line[i]); if (in_num && !cu_num) { in_num = false; num.push(parseInt(line.substring(mark, i))) } else if(cu_num && !in_num) { mark = i; in_num = true; } } if (in_num) num.push(parseInt(line.substring(mark))); return num; } var space = String.fromCharCode(10240); var spaces = { "hair" : String.fromCharCode(8202), // supposedly 1px wide "1/6" : String.fromCharCode(8198), "1/4" : String.fromCharCode(8197), "1/3" : String.fromCharCode(8196), "1/2" : String.fromCharCode(8192), "1" : String.fromCharCode(8193) }; function make_spaces(px) { var s = ""; for (var i = 0; i < px; i++) { s += spaces.hair; } return s; } cb.settings_choices = [ { name: 'board_data', type: 'str', required: false, defaultValue: '', label: "Board from data (priority)" },{ name: 'board_1', type: 'str', required: false, defaultValue: '11 22 33 22 11', label: "Board from numbers 1" },{ name: 'board_2', type: 'str', required: false, defaultValue: '22 33 44 33 22', label: "Board from numbers 2" },{ name: 'board_3', type: 'str', required: false, defaultValue: '33 44 55 44 33', label: "Board from numbers 3" },{ name: 'board_4', type: 'str', required: false, defaultValue: '22 33 44 33 22', label: "Board from numbers 4" },{ name: 'board_5', type: 'str', required: false, defaultValue: '11 22 33 22 11', label: "Board from numbers 5" },{ name: 'board_6', type: 'str', required: false, defaultValue: '', label: "Board from numbers 6" },{ name: 'board_7', type: 'str', required: false, defaultValue: '', label: "Board from numbers 7" },{ name: 'board_8', type: 'str', required: false, defaultValue: '', label: "Board from numbers 8" },{ name: 'board_9', type: 'str', required: false, defaultValue: '', label: "Board from numbers 9" },{ name: 'board_notify_interval', type: 'int', minValue: 0, defaultValue: 10, label: "Print the board every x minutes (0 to disable)" },{ name: 'notify_color', type: 'str', defaultValue: '#FF1493', label: "Bot color" },{ name: 'top_1', type: 'str', required: false, defaultValue: 'Throw darts at your screen to clear the numbers!', label: "Top line 1" },{ name: 'top_2', type: 'str', required: false, defaultValue: 'Every time you miss, be happy you still have a screen', label: "Top line 2" },{ name: 'bottom_1', type: 'str', required: false, defaultValue: 'If you get all the numbers, we will make this robot cum', label: "Bottom line 1" },{ name: 'bottom_2', type: 'str', required: false, defaultValue: '', label: "Bottom line 2" },{ name: 'number_cleared_msg', type: 'str', required: false, defaultValue: 'Sorry about your screen :(', label: "Message after a number is cleared from the board" },{ name: 'board_cleared_msg', type: 'str', required: false, defaultValue: 'Robots can\'t cum, can they?', label: "Message after board is cleared" },{ name: 'board_format', type: 'choice', choice1: 'Basic', choice2: 'Equalize', defaultValue: 'Basic', label: "Board formatting" },{ name: 'allow_uncensor', type: 'choice', choice1: 'Yes', choice2: 'No', choice3: 'Broadcaster only', defaultValue: 'Yes', label: "Allow /uncensor command" },{ name: 'allow_email', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', label: "Allow /email command" } ]; var board = []; function init() { if (isdef_str(cb.settings.board_data)) { board_set(cb.settings.board_data); } else { board_from_lines(); } board_spammer(); } function board_from_lines() { var lines = []; if (isdef_str(cb.settings.board_1)) lines.push(num_line(cb.settings.board_1)); if (isdef_str(cb.settings.board_2)) lines.push(num_line(cb.settings.board_2)); if (isdef_str(cb.settings.board_3)) lines.push(num_line(cb.settings.board_3)); if (isdef_str(cb.settings.board_4)) lines.push(num_line(cb.settings.board_4)); if (isdef_str(cb.settings.board_5)) lines.push(num_line(cb.settings.board_5)); if (isdef_str(cb.settings.board_6)) lines.push(num_line(cb.settings.board_6)); if (isdef_str(cb.settings.board_7)) lines.push(num_line(cb.settings.board_7)); if (isdef_str(cb.settings.board_8)) lines.push(num_line(cb.settings.board_8)); if (isdef_str(cb.settings.board_9)) lines.push(num_line(cb.settings.board_9)); if (lines.length > 0) { board = lines; broadcaster_notice("Board loaded from lines"); } else { broadcaster_notice("No board provided"); } } function board_tip(tip) { var clear = true; var cleared_number = false; for (var y = 0; y < board.length; y++) { for (var x = 0; x < board[y].length; x++) { if (tip.amount == board[y][x] && cleared_number == false) { board[y][x] = make_x(("" + board[y][x]).length); if (isdef_str(cb.settings.number_cleared_msg)) default_notice(cb.settings.number_cleared_msg); cleared_number = true; } if (Number.isInteger(board[y][x])) clear = false; } } if (clear && cleared_number) { if (board_spammer_id != undefined) cb.cancelTimeout(board_spammer_id); if (isdef_str(cb.settings.board_cleared_msg)) default_notice(cb.settings.board_cleared_msg); } } function format_board_basic() { var s = ""; for (var y = 0; y < board.length; y++) { s += space + space + space; for (var x = 0; x < board[y].length; x++) { s += board[y][x] + space + space; } if (y < board.length - 1) s += "\n" } return s; } function measure_board() { var measured_board = []; var measured_meta = {"line_widths":[], "max_width":0, "max_elements":0}; for (var y = 0; y < board.length; y++) { var line = board[y]; var measured_line = []; var line_width = 0; for (var x = 0; x < line.length; x++) { var el = { "val" : line[x], "width" : 0.0 }; if (Number.isInteger(line[x])) { el.width = ("" + line[x]).length * 6.5; } else { el.width = line[x].length * 6; } measured_line.push(el); line_width += el.width; } measured_meta.line_widths.push(line_width); measured_board.push(measured_line); if (line_width > measured_meta.max_width) measured_meta.max_width = line_width; if (line.length > measured_meta.max_elements) measured_meta.max_elements = line.length; } return { "board" : measured_board, "meta" : measured_meta }; } function equalize_line(line, width) { var a_width = width - (line[0].width + line[line.length - 1].width) / 2; var m_width = width / a_width; var min = 40; for (var i = 0; i < line.length; i++) { line[i].x = i / (line.length - 1) * m_width * width - line[i].width / 2 + min; } } function equalized_board() { var measured_board = measure_board(); var board = measured_board.board; var meta = measured_board.meta; var width = meta.max_elements * 30; for (var y = 0; y < board.length; y++) { equalize_line(board[y], width); } return board; } function render_board(board) { var s = ""; for (var y = 0; y < board.length; y++) { var line = board[y]; var px = 0; for (var x = 0; x < line.length; x++) { var bump = Math.round(Math.max(0, line[x].x - px)); s += make_spaces(bump); px += bump; s += line[x].val; px += line[x].width; } if (y < board.length - 1) s += "\n" } return s; } function format_board_equalize() { var board = equalized_board(); console.log(board); return render_board(board); } function board_notice() { var s = ""; if (isdef_str(cb.settings.top_1)) s += cb.settings.top_1 + "\n"; if (isdef_str(cb.settings.top_2)) s += cb.settings.top_2 + "\n"; if (cb.settings.board_format == "Basic") s += format_board_basic(); if (cb.settings.board_format == "Equalize") s += format_board_equalize(); if (isdef_str(cb.settings.bottom_1)) s += "\n" + cb.settings.bottom_1; if (isdef_str(cb.settings.bottom_2)) s += "\n" + cb.settings.bottom_2; default_notice(s); } function board_set(data_str) { try { board = JSON.parse(data_str); broadcaster_notice("Board loaded from status"); } catch (ex) { broadcaster_notice("Problem with setting board status (invalid formatting)"); } } function board_get() { broadcaster_notice(JSON.stringify(board)); } var board_spammer_id = undefined; function board_spammer() { if (board_spammer_id != undefined) cb.cancelTimeout(board_spammer_id); if (cb.settings.board_notify_interval > 0) { board_spammer_id = cb.setTimeout(board_spammer, cb.settings.board_notify_interval * 60 * 1000); } board_notice(); } cb.onTip(function (tip) { board_tip(tip); }); cb.onMessage(function (msg) { var is_broadcaster = msg.user == cb.room_slug; // commands if (msg.m.charAt(0) == '/') { var components = msg.m.split(' '); switch (components[0]) { case '/board': msg['X-Spam'] = true; board_notice(); break; case '/board_set': msg['X-Spam'] = true; if (!is_broadcaster) break; board_set(components[1]); board_spammer(); break; case '/board_data': msg['X-Spam'] = true; board_get(); break; case '/uncensor': msg['X-Spam'] = true; if (cb.settings.allow_uncensor == "No") break; if (cb.settings.allow_uncensor == "Broadcaster only" && !is_broadcaster) break; default_notice(msg.user + ": " + get_body(components)); break; case '/email': msg['X-Spam'] = true; if (cb.settings.allow_email == "No") break; broadcaster_notice(msg.user + ": " + get_body(components)); default_notice("Email delivered to broadcaster", msg.user); break; case '/link': msg['X-Spam'] = true; if (!is_broadcaster) break; default_notice(get_body(components, 2), components[1]); broadcaster_notice("Link delivered to user"); break; } } }); init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.