Bots Home
|
Create an App
roll pink dice blah
Author:
fatkarl
Description
Source Code
Launch Bot
Current Users
Created by:
Fatkarl
// FRAME 1.1 // cb.settings_choices cb.settings_choices = []; function add_setting_str(name, label, default_value) { cb.settings_choices.push({ type:"str", name:name, label:label, defaultValue:default_value, required:false }); } function add_setting_int(name, label, default_value, opt_min, opt_max) { var sett = { type:"int", name:name, label:label, defaultValue:default_value }; if (opt_min !== undefined) sett.minValue = opt_min; if (opt_max !== undefined) sett.maxValue = opt_max; cb.settings_choices.push(sett); } function add_setting_choice(name, label, default_value, choices) { var sett = { type:"choice", name:name, label:label, defaultValue:default_value }; for (var i = 0; i < choices.length; i++) sett["choice" + (i + 1)] = choices[i]; cb.settings_choices.push(sett); } settings = cb.settings; // spam var _grey_messages = []; function _grey_spammer(msg) { if (msg.has_tokens) return false; var messages_in_last_10 = 0; var since = Date.now() - 10000; for (i = 0; i < _grey_messages.length; i++) { if (_grey_messages[i].user == msg.user) { if (_grey_messages[i].time > since) messages_in_last_10++; if (_grey_messages[i].immune) messages_in_last_10 = 0; } } _grey_messages.push({"msg" : msg.m, "user" : msg.user, "time" : Date.now(), "messages_in_last_10" : messages_in_last_10, "immune" : false}); if (_grey_messages.length > 50) _grey_messages.splice(0, 1); if (messages_in_last_10 > 5) { notice_broadcaster("Potential grey spammer: " + msg.user + " has sent over 5 messages in the last 10 seconds"); _grey_messages[_grey_messages.length - 1].immune = true; return true; } return false; } function _spam_check(msg) { if (_grey_spammer(msg)) return true; } // callbacks callback_enter_funcs = []; function listen_enter(callback) { callback_enter_funcs.push(callback); } if (cb.onEnter !== undefined) cb.onEnter(function(user) { for (var i = 0; i < callback_enter_funcs.length; i++) callback_enter_funcs[i].apply(this, arguments); }); callback_leave_funcs = []; function listen_leave(callback) { callback_leave_funcs.push(callback); } if (cb.onLeave !== undefined) cb.onLeave(function(user) { for (var i = 0; i < callback_leave_funcs.length; i++) callback_leave_funcs[i].apply(this, arguments); }); callback_message_funcs = []; function listen_message(callback) { callback_message_funcs.push(callback); } if (cb.onMessage !== undefined) cb.onMessage(function(message) { if (_spam_check(message)) { message["X-Spam"] = true; return message; }; for (var i = 0; i < callback_message_funcs.length; i++) callback_message_funcs[i].apply(this, arguments); return message; }); callback_tip_funcs = []; function listen_tip(callback) { callback_tip_funcs.push(callback); } if (cb.onTip !== undefined) cb.onTip(function(tip) { for (var i = 0; i < callback_tip_funcs.length; i++) callback_tip_funcs[i].apply(this, arguments); }); // panel _current_panel = {"template" : "3_rows_11_21_31", "row1_value" : "", "row2_value" : "", "row3_value" : ""}; if (cb.onDrawPanel !== undefined) cb.onDrawPanel(function(user){ return _current_panel; }); function draw_panel(row1, row2, row3) { _current_panel.row1_value = row1 === undefined ? "" : row1; _current_panel.row2_value = row2 === undefined ? "" : row2; _current_panel.row3_value = row3 === undefined ? "" : row3; cb.drawPanel(); } function modify_panel(row1, row2, row3) { if (row1 !== undefined) _current_panel.row1_value = row1; if (row2 !== undefined) _current_panel.row2_value = row2; if (row3 !== undefined) _current_panel.row3_value = row3; cb.drawPanel(); } function modify_panel_n(n, row) { if (n == 1) modify_panel(row, undefined, undefined); if (n == 2) modify_panel(undefined, row, undefined); if (n == 3) modify_panel(undefined, undefined, row); } // util settings_initialized = Object.keys(settings).length > 1; _notice_color = undefined; function set_notice_color(color) { _notice_color = color; } function notice(msg, user, color, background, weight) { cb.sendNotice(msg, user, background, color == undefined ? _notice_color : color, weight); } function notice_broadcaster(msg) { notice(msg, cb.room_slug, '#CD5C5C'); } function random_int(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } function parse_number(s, default_value, first_only) { if (first_only !== true) first_only = false; var ss = ""; var palette = "0123456789."; var in_number = false; for (var i = 0; i < s.length; i++) { if (palette.indexOf(s[i]) != -1) { ss += s[i]; in_number = true; } else { if (first_only && in_number) break; } } if (ss.length < 1 || isNaN(ss)) return default_value; return parseFloat(ss); } function rotator() { this.items = []; this.index = -1; this.next = function() { if (this.items.length == 0) return undefined; if (++this.index >= this.items.length) this.index = 0; return this.items[this.index]; }.bind(this); this.add = function(item) { this.items.push(item); }.bind(this); this.add_range = function(items) { for (var i = 0; i < items.length; i++) this.add(items[i]); } for (var i = 0; i < arguments.length; i++) { this.add(arguments[i]); } } function is_empty(str) { return ("" + str).replace(/ /g,'').length == 0; } // bot spam function repeat_forever(callback, interval_ms) { cb.setTimeout(function() { callback(); repeat_forever(callback, interval_ms); }, interval_ms); } _interval_callback_counter = 0; _interval_callbacks = []; function interval_callback(callback, interval, offset) { if (offset === undefined) offset = 0; _interval_callbacks.push({"callback" : callback, "interval" : interval, "offset" : offset}); } function _check_interval_callback(message) { for (var i = 0; i < _interval_callbacks.length; i++) { var item = _interval_callbacks[i]; item.offset++; if (item.offset >= item.interval) { item.offset = 0; item.callback(); } } } listen_message(_check_interval_callback); listen_tip(_check_interval_callback); // commands user_types = {broadcaster : 1, moderator : 2, guest : 4, all : 7, staff : 3}; _commands = {}; function add_command(name, argument_count, has_text, permitted_users, callback) { // has_text indicates that command and arguments are followed by plain text if (!(name in _commands)) _commands[name] = []; _commands[name].push({ argument_count:argument_count, has_text:has_text, permitted_users:permitted_users, callback:callback }); } function find_command_handlers(name, argument_count, user_type) { if (!(name in _commands)) return undefined; var handlers = _commands[name]; var found = []; for (var i = 0; i < handlers.length; i++) { if ((!handlers[i].has_text) && handlers[i].argument_count !== argument_count) continue; if (handlers[i].has_text && (handlers[i].argument_count + 1) > argument_count) continue; if ((handlers[i].permitted_users & user_type) === 0) continue; found.push(handlers[i]); } return found; } listen_message(function(msg) { if (msg.m.charAt(0) !== '/') return; // is command var args = msg.m.replace(/\s\s+/g, ' ').split(' '); // standardize and split if (args.length < 1) return; // sanity var command_name = args[0].substring(1).toLowerCase(); // strip slash and lower if (!(command_name in _commands)) return; // at least one callback is registered var user_type = user_types.guest; if (msg.is_mod === true) user_type = user_types.moderator; if (msg.user === cb.room_slug) user_type = user_types.broadcaster; args.splice(0, 1); // args var handlers = find_command_handlers(command_name, args.length, user_type); // find handlers if (handlers.length > 0) msg["X-Spam"] = true; for (var i = 0; i < handlers.length; i++) { var handler = handlers[i]; // execute handlers if (handler.has_text) { var args2 = [msg].concat(args.slice(0, handler.argument_count - 1)); args2.push(args.slice(handler.argument_count).join(" ")); handler.callback.apply(this, args2); } else { handler.callback.apply(this, [msg].concat(args)); } } }); // APP // colorizer add_setting_choice("use_colorizer", "Use colorizer", "Yes", ["Yes", "No"]); add_setting_choice("colorizer_broadcaster", "Apply colorizer to broadcaster", "Yes", ["Yes", "No"]); add_setting_choice("colorizer_color_commands", "Enable specific color commands (/red, etc.)", "Yes", ["Yes", "No"]); add_setting_choice("colorizer_mode", "Colorizer mode", "Try to give unique colors by usage", ["Random", "Try to give unique colors by assignment", "Try to give unique colors by usage"]); class colorizer { constructor() { this.hue_usage = {}; this.hue_assignments = {}; this.mode = "usage"; } generate() { var col; if (this.mode == "random") col = this.generate_readable_color(); if (this.mode == "assignment") col = this.generate_least_used_color(10, this.get_assignment.bind(this)); if (this.mode == "usage") col = this.generate_least_used_color(10, this.get_usage.bind(this)); this.register_assignment(col); this.register_usage(col); return col; } set_mode_random() { this.mode = "random"; } set_mode_assignment() { this.mode = "assignment"; } set_mode_usage() { this.mode = "usage"; } sample(hsv) { var el = document.createElement("div"); el.style.color = this.hsv_hex(hsv); document.body.appendChild(el); el.innerHTML = "SAMPLE try reading this"; } get_usage(hsv) { var total_usage = 0; for (var hue in this.hue_usage) { var fhue = parseFloat(hue); var hi = fhue > hsv.h ? fhue : hsv.h; var lo = fhue < hsv.h ? fhue : hsv.h; var dist_mul = Math.pow(1 - Math.min(hi - lo, lo + 1 - hi), 5); total_usage += dist_mul * this.hue_usage[hue]; } return total_usage; } register_usage(hsv) { if (!(hsv.h in this.hue_usage)) { this.hue_usage[hsv.h] = 1; } else { this.hue_usage[hsv.h]++; } } get_assignment(hsv) { var total_usage = 0; for (var hue in this.hue_assignments) { var fhue = parseFloat(hue); var hi = fhue > hsv.h ? fhue : hsv.h; var lo = fhue < hsv.h ? fhue : hsv.h; var dist_mul = Math.pow(1 - Math.min(hi - lo, lo + 1 - hi), 5); total_usage += dist_mul * this.hue_assignments[hue]; } return total_usage; } register_assignment(hsv) { if (!(hsv.h in this.hue_usage)) { this.hue_assignments[hsv.h] = 1; } else { this.hue_assignments[hsv.h]++; } } generate_readable_color() { var v_by_h = [[0, 1], [0.166, 0.65], [0.33, 0.7], [0.5, 0.75], [0.66, 1], [0.833, 1], [1, 1]]; var h = Math.random(); var s = 1 - Math.pow(Math.random() * 0.45, 2); var v = 0; for (var i = 0; i < v_by_h.length; i++) { if (v_by_h[i + 1][0] > h) { v = v_by_h[i][1] + (v_by_h[i + 1][1] - v_by_h[i][1]) * (h - v_by_h[i][0]) / (v_by_h[i + 1][0] - v_by_h[i][0]); v = v * s * s; return {"h" : h, "s" : s, "v" : v}; } } } generate_least_used_color(attempts, usage_func) { if (attempts === undefined) attempts = 10; var best = this.generate_readable_color(); var best_usage = usage_func(best); for (var i = 0; i < attempts; i++) { var potential = this.generate_readable_color(); var usage = usage_func(potential); if (usage < best_usage) { best = potential; best_usage = usage; } } return best; } rgb_hex(rgb) { var rh = rgb.r.toString(16); if (rh.length === 1) rh = "0" + rh; var gh = rgb.g.toString(16); if (gh.length === 1) gh = "0" + gh; var bh = rgb.b.toString(16); if (bh.length === 1) bh = "0" + bh; return "#" + rh + gh + bh; } hsv_rgb(hsv) { var h, s, v, r, g, b, i, f, p, q, t; s = hsv.s, v = hsv.v, h = hsv.h; i = Math.floor(h * 6); f = h * 6 - i; p = v * (1 - s); q = v * (1 - f * s); t = v * (1 - (1 - f) * s); switch (i % 6) { case 0: r = v, g = t, b = p; break; case 1: r = q, g = v, b = p; break; case 2: r = p, g = v, b = t; break; case 3: r = p, g = q, b = v; break; case 4: r = t, g = p, b = v; break; case 5: r = v, g = p, b = q; break; } return { r: Math.round(r * 255), g: Math.round(g * 255), b: Math.round(b * 255) }; } hex_rgb(hex) { var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16) } : undefined; } rgb_hsv(r, g, b) { if (arguments.length === 1) { g = r.g, b = r.b, r = r.r; } var max = Math.max(r, g, b), min = Math.min(r, g, b), d = max - min, h, s = (max === 0 ? 0 : d / max), v = max / 255; switch (max) { case min: h = 0; break; case r: h = (g - b) + d * (g < b ? 6: 0); h /= 6 * d; break; case g: h = (b - r) + d * 2; h /= 6 * d; break; case b: h = (r - g) + d * 4; h /= 6 * d; break; } return { h: h, s: s, v: v }; } hex_hsv(hex) { return this.rgb_hsv(this.hex_rgb(hex)); } hsv_hex(hsv) { return this.rgb_hex(this.hsv_rgb(hsv)); } } if (settings_initialized && settings.use_colorizer == "Yes") { var col = new colorizer(); if (settings.colorizer_mode == "Random") col.set_mode_random(); if (settings.colorizer_mode == "Try to give unique colors by assignment") col.set_mode_assignment(); if (settings.colorizer_mode == "Try to give unique colors by usage") col.set_mode_usage(); var color_by_user = {}; listen_message(function(msg) { if (settings.colorizer_broadcaster == "No" && msg.user == cb.room_slug) return; if (!(msg.user in color_by_user)) { color_by_user[msg.user] = col.generate(); } // hook #hex if (msg.m.charAt(0) == "/" && msg.m.charAt(1) == "#") { if (msg.m.length >= 8) { msg["X-Spam"] = true; try { var hex = msg.m.substring(2); var hsv = col.hex_hsv(hex); color_by_user[msg.user] = hsv; col.register_assignment(hsv); } catch(ex) { notice("Could not understand the color code, example usage: /#FF0000", msg.user); } } } col.register_usage(color_by_user[msg.user]); msg.c = col.hsv_hex(color_by_user[msg.user]); if (msg.c == "#f5c4c4") { msg['background'] = "#000000"; } }); add_command("color", 0, false, user_types.all, function(msg) { color_by_user[msg.user] = col.generate(); }); if (settings.colorizer_color_commands == "Yes") { var known_colors = { "red" : [0, 1, 1], "green" : [0.33, 1, 0.65], "blue" : [0.66, 1, 1], "purple" : [0.833, 1, 0.5], "black" : [0, 0, 0], "white" : [0, 0, 1], "orange" : [0.108, 1, 1], "yellow" : [0.166, 1, 1], "gold" : [0.141, 1, 1], "pink" : [0.916, 0.7, 1], "turquoise" : [0.486, 0.77, 0.84], "silver" : [0, 0, 0.75], "gray" : [0, 0, 0.5], "lime" : [0.33, 0.75, 0.8], "darkblue" : [0.66, 1, 0.55], "blacklikemysoul" : [0, 0.2, 0.96], "brown" : [0, 0.75, 0.65], "teal" : [0.5, 1, 0.5], "maroon" : [0, 1, 0.5], "cyan" : [0.5, 1, 1] }; for (let name in known_colors) { add_command(name, 0, false, user_types.all, function(msg) { color_by_user[msg.user] = {"h" : known_colors[name][0], "s" : known_colors[name][1], "v" : known_colors[name][2]}; }); } } } // fonts add_setting_choice("use_fonts", "Use fonts", "Yes", ["Yes", "No"]); add_setting_choice("fonts_broadcaster", "Apply fonts to broadcaster", "Yes", ["Yes", "No"]); var fonts = ["Tahoma", "Comic Sans MS", "Palatino Linotype", "Monospace"]; if (settings_initialized && settings.use_fonts == "Yes") { var font_by_user = {}; listen_message(function(msg) { if (settings.fonts_broadcaster == "No" && msg.user == cb.room_slug) return; if (!(msg.user in font_by_user)) font_by_user[msg.user] = fonts[random_int(1, fonts.length) - 1]; msg.f = font_by_user[msg.user]; }); add_command("font", 0, false, user_types.all, function(msg) { font_by_user[msg.user] = fonts[random_int(1, fonts.length) - 1]; }); var known_fonts = { "monospace" : "Monospace", "tahoma" : "Tahoma", "comic_sans" : "Comic Sans MS", "palatino" : "Palatino Linotype" } for (let font in known_fonts) { add_command(font, 0, false, user_types.all, function(msg) { font_by_user[msg.user] = known_fonts[font]; }); } } // tipmenu add_setting_choice("use_tipmenu", "Use tip menu", "Yes", ["Yes", "No"]); add_setting_str("tipmenu_color", "Tip menu color", "#FF1493"); add_setting_choice("tipmenu_weight", "Tip menu weight", "bold", ["normal", "bold", "bolder"]); add_setting_int("tipmenu_interval", "Tipmenu interval in lines of chat (0 to disable)", 60); add_setting_int("tipmenu_minutes", "Tipmenu interval in minutes (0 to disable)", 5); add_setting_int("tipmenu_panel_interval", "Tipmenu interval in the panel", 5, 1); add_setting_choice("tipmenu_separator", "Tipmenu separator", ":tinyflower2", [":tinyflower2", ":pixelglitter", ":heart2", ":bluebow", ":pixelheart", ":smile"]); add_setting_str("tipmenu_custom_separator", "Custom separator (overrides if used)", ""); add_setting_str("tipmenu_1", "Tip menu item 1", "25 Spank!"); add_setting_str("tipmenu_2", "Tip menu item 2", "50 2 Spanks!"); add_setting_str("tipmenu_3", "Tip menu item 3", ""); add_setting_str("tipmenu_4", "Tip menu item 4", ""); add_setting_str("tipmenu_5", "Tip menu item 5", ""); add_setting_str("tipmenu_6", "Tip menu item 6", ""); add_setting_str("tipmenu_7", "Tip menu item 7", ""); add_setting_str("tipmenu_8", "Tip menu item 8", ""); add_setting_str("tipmenu_9", "Tip menu item 9", ""); add_setting_str("tipmenu_10", "Tip menu item 10", ""); add_setting_str("tipmenu_11", "Tip menu item 11", ""); add_setting_str("tipmenu_12", "Tip menu item 12", ""); add_setting_str("tipmenu_13", "Tip menu item 13", ""); add_setting_str("tipmenu_14", "Tip menu item 14", ""); add_setting_str("tipmenu_15", "Tip menu item 15", ""); add_setting_str("tipmenu_16", "Tip menu item 16", ""); add_setting_str("tipmenu_17", "Tip menu item 17", ""); add_setting_str("tipmenu_18", "Tip menu item 18", ""); add_setting_str("tipmenu_19", "Tip menu item 19", ""); add_setting_str("tipmenu_20", "Tip menu item 20", ""); tipmenu = {}; function init_tipmenu() { for (var i = 1; i <= 20; i++) { var str = settings["tipmenu_" + i]; if (is_empty(str)) continue; var price = parse_number(str, -1, true); if (price === -1) continue; var item_idx = str.indexOf("" + price) + ("" + price).length; var item = str.substring(item_idx); tipmenu[price] = item; } } function notice_tipmenu(user_name) { var s = ""; var keys = Object.keys(tipmenu); var separator = settings.tipmenu_separator; if (settings.tipmenu_custom_separator != "") separator = settings.tipmenu_custom_separator; for (var i = 0; i < keys.length; i++) { s += tipmenu[keys[i]] + " (" + keys[i] + ") "; if (i < (keys.length - 1)) s += separator + " "; } notice(s, user_name, settings.tipmenu_color, undefined, settings.tipmenu_weight); } if (settings_initialized && settings.use_tipmenu == "Yes") { init_tipmenu(); add_command("tipmenu", 0, false, user_types.staff, function(msg) { notice_tipmenu(); }); add_command("tipmenu", 0, false, user_types.guest, function(msg) { notice_tipmenu(msg.user); }); if (settings.tipmenu_interval > 0) { interval_callback(function(){ notice_tipmenu(); }, settings.tipmenu_interval); } if (settings.tipmenu_minutes > 0) { repeat_forever(function() { notice_tipmenu(); }, settings.tipmenu_minutes * 1000 * 60); } var tipmenu_panels = []; if (settings.panel_row_1 == "Tipmenu") tipmenu_panels.push(0); if (settings.panel_row_2 == "Tipmenu") tipmenu_panels.push(1); if (settings.panel_row_3 == "Tipmenu") tipmenu_panels.push(2); if (tipmenu_panels.length > 0) { var rot = new rotator(); for (var price in tipmenu) { rot.add("Tipmenu: " + price + "tk for " + tipmenu[price]); } repeat_forever(function() { var args = [undefined, undefined, undefined]; for (var i = 0; i < tipmenu_panels.length; i++) { args[tipmenu_panels[i]] = rot.next(); } modify_panel(args[0], args[1], args[2]); }, settings.tipmenu_panel_interval * 1000); } } // notifier add_setting_choice("use_rotating", "Use rotating notifier", "Yes", ["Yes", "No"]); add_setting_str("rotating_color", "Rotating notifier color", "#FF1493"); add_setting_choice("rotating_weight", "Rotating notifier weight", "bold", ["normal", "bold", "bolder"]); add_setting_int("rotating_interval", "Rotating notifier interval in lines of chat (0 to disable)", 40); add_setting_int("rotating_minutes", "Rotating notifier interval in minutes (0 to disable)", 5); add_setting_str("rotating_1", "Rotating notifier 1", ""); add_setting_str("rotating_2", "Rotating notifier 2", ""); add_setting_str("rotating_3", "Rotating notifier 3", ""); add_setting_str("rotating_4", "Rotating notifier 4", ""); add_setting_str("rotating_5", "Rotating notifier 5", ""); add_setting_str("rotating_6", "Rotating notifier 6", ""); add_setting_str("rotating_7", "Rotating notifier 7", ""); add_setting_str("rotating_8", "Rotating notifier 8", ""); add_setting_str("rotating_9", "Rotating notifier 9", ""); add_setting_str("rotating_10", "Rotating notifier 10", ""); if (settings_initialized && settings.use_rotating == "Yes") { var rot = new rotator(); for (var i = 1; i <= 10; i++) { var str = settings["rotating_" + i]; if (is_empty(str)) continue; rot.add(str); } if (settings.rotating_interval > 0) { interval_callback(function(){ notice(rot.next(), undefined, settings.rotating_color, undefined, settings.rotating_weight); }, settings.rotating_interval); } if (settings.rotating_minutes > 0) { repeat_forever(function() { notice(rot.next(), undefined, settings.rotating_color, undefined, settings.rotating_weight); }, settings.rotating_minutes * 1000 * 60); } } // panel add_setting_choice("panel_row_1", "Panel row 1", "Tipmenu", ["Nothing", "Tipmenu"]); add_setting_choice("panel_row_2", "Panel row 2", "Nothing", ["Nothing", "Tipmenu"]); add_setting_choice("panel_row_3", "Panel row 3", "Nothing", ["Nothing", "Tipmenu"]); if (settings_initialized) { add_command("grey_messages", 0, false, user_types.all, function(msg) { var s = "Last 10 grey messages:\n"; for (var i = Math.max(0, _grey_messages.length - 10); i < _grey_messages.length; i++) { s += _grey_messages[i].user + ": " + _grey_messages[i].msg + "\n"; } notice(s, msg.user); }); }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.