Bots Home
|
Create an App
RoboCumBoardBot
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 try_parse_int(v, def) { v = "" + v; if (isdef_str(v) && !isNaN(v)) return parseInt(v); return def; } function num_line(line) { var num = []; var palette = "0123456789x"; 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; var ss = line.substring(mark, i); if (ss[0] == "x") { num.push(ss); } else { num.push(parseInt(ss)) } } else if(cu_num && !in_num) { mark = i; in_num = true; } } if (in_num) { var ss = line.substring(mark); if (ss[0] == "x") { num.push(ss); } else { num.push(parseInt(ss)) } } 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) { if (cb.settings.board_format == "Compatibility") return " "; var s = ""; for (var i = 0; i < px; i++) { s += spaces.hair; } return s; } function extract_email(s) { var at = s.indexOf("@"); if (at == -1) return ""; return s.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi); } 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', choice3: 'Compatibility', defaultValue: 'Equalize', label: "Board formatting" },{ name: 'board_offset', type: 'int', minValue: 0, defaultValue: 0, label: "Board offset from the left side (in pixels)" },{ name: 'board_space_width', type: 'int', minValue: 0, defaultValue: 10, label: "Width of spaces between board items (in pixels)" },{ 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" },{ name: 'track_tips', type: 'choice', choice1: 'Yes', choice2: 'No', choice3: 'Only higher than 1', defaultValue: 'Only higher than 1', label: "Track tips" },{ name: 'interval_message', type: 'str', required: false, defaultValue: 'Type /board for good luck and strong hair growth!', label: "Chat interval message" },{ name: 'interval_message_interval', type: 'int', minValue: 0, defaultValue: 40, label: "Number of lines between notifying the interval message" } ]; var chat_interval = 0; function check_chat_interval() { chat_interval++; if (isdef_str(cb.settings.interval_message) && cb.settings.interval_message_interval > 0) { if (chat_interval > cb.settings.interval_message_interval) { chat_interval = 0; default_notice(cb.settings.interval_message); } } } var emails_by_user = {}; function track_email(msg, usr) { var email = extract_email(msg); if (isdef_str(email)) emails_by_user[usr] = email; } var time_by_tipper_by_amount = {}; function track_tip(tip) { track_email(tip.message, tip.from_user); if (((cb.settings.track_tips == "Only higher than 1") && (tip.amount > 1)) || cb.settings.track_tips == "Yes") { if (!(tip.amount in time_by_tipper_by_amount)) time_by_tipper_by_amount[tip.amount] = {}; if (!(tip.from_user in time_by_tipper_by_amount[tip.amount])) time_by_tipper_by_amount[tip.amount][tip.from_user] = []; time_by_tipper_by_amount[tip.amount][tip.from_user].push(Date.now()); } } function get_tippers_since_time_ago_by_amount(amt, minutes_ago) { if (!(amt in time_by_tipper_by_amount)) return []; var time_by_tipper = time_by_tipper_by_amount[amt]; var now = Date.now(); var time_ago = 0; if (minutes_ago === undefined) { time_ago = now; } else { time_ago = minutes_ago * 60 * 1000; } var start_time = now - time_ago; var tippers = {}; for (var tipper in time_by_tipper) { var times = time_by_tipper[tipper]; for (var i = 0; i < times.length; i++) { if (times[i] >= start_time) { if (!(tipper in tippers)) { tippers[tipper] = 1; } else { tippers[tipper]++; } } } } return tippers; } function notice_tippers_by_amount(amt, minutes_ago) { var tippers = get_tippers_since_time_ago_by_amount(amt, minutes_ago); if (Object.keys(tippers).length == 0) { broadcaster_notice("No tippers for " + amt + " found"); return; } var s = "Users who tipped " + amt; if (minutes_ago === undefined) { s += " since bot started\n"; } else { s += " since " + minutes_ago + " minutes ago\n"; } var total = 0; for (var tipper in tippers) { var email = tipper in emails_by_user ? emails_by_user[tipper] : ""; s += tipper + " " + tippers[tipper] + "x " + email + "\n"; total += tippers[tipper]; } s += total + " tips of " + amt + " in total \n" broadcaster_notice(s); } 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 += make_spaces(cb.settings.board_offset); for (var x = 0; x < board[y].length; x++) { s += board[y][x] + make_spaces(cb.settings.board_space_width); } 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) { if (line.length < 1) return; var a_width = width - (line[0].width + line[line.length - 1].width) / 2; var m_width = width / a_width; var min = cb.settings.board_offset + 10; 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 * (7 + cb.settings.board_space_width); 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(); return render_board(board); } function board_notice(usr) { var s = ""; if (isdef_str(cb.settings.top_1)) s += make_spaces(cb.settings.board_offset) + cb.settings.top_1 + "\n"; if (isdef_str(cb.settings.top_2)) s += make_spaces(cb.settings.board_offset) + cb.settings.top_2 + "\n"; if (cb.settings.board_format == "Basic" || cb.settings.board_format == "Compatibility") s += format_board_basic(); if (cb.settings.board_format == "Equalize") s += format_board_equalize(); if (isdef_str(cb.settings.bottom_1)) s += "\n" + make_spaces(cb.settings.board_offset) + cb.settings.bottom_1; if (isdef_str(cb.settings.bottom_2)) s += "\n" + make_spaces(cb.settings.board_offset) + cb.settings.bottom_2; default_notice(s, usr); } 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); track_tip(tip); check_chat_interval(); }); 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].toLowerCase()) { case '/board': msg['X-Spam'] = true; var usr = undefined; if (!is_broadcaster) usr = msg.user; board_notice(usr); 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; track_email(get_body(components), msg.user); 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; case '/tippers': msg['X-Spam'] = true; if (!is_broadcaster) break; var amt = try_parse_int(components[1]); if (amt == undefined) { broadcaster_notice("Invalid tip amount specified"); break; } var minutes_ago = try_parse_int(components[2]); notice_tippers_by_amount(amt, minutes_ago); break; case '/tippers_reset': msg['X-Spam'] = true; if (!is_broadcaster) break; time_by_tipper_by_amount = {}; broadcaster_notice("Tip tracking has been reset"); break; case '/test': msg['X-Spam'] = true; default_notice("" + Date.now(), msg.user); break; } } else { check_chat_interval(); } }); init();
© Copyright Chaturbate 2011- 2026. All Rights Reserved.