Bots Home
|
Create an App
fdbn fsghjg
Author:
mistressadelle
Description
Source Code
Launch Bot
Current Users
Created by:
Mistressadelle
// FRAME 1.2 // testbed compatibility if (cb.cancelTimeout === undefined) { cb.cancelTimeout = function(id) { notice("Timeout #" + id + " has been ordered to cancel but the platform doesn't support this command"); } } // 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 format(text, args) { if (typeof args !== "object") return; for (var key in args) text = text.split(key).join(args[key]); return text; } 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 class timer { constructor(callback, interval_ms) { this.callback = callback; this.interval_ms = interval_ms; this.timer_id = cb.setTimeout(this.tick.bind(this), this.interval_ms); this.trigger_callback = function() {}; } tick() { if (this.interval_ms == 0) return; this.callback(); this.trigger_callback(); this.timer_id = cb.setTimeout(this.tick.bind(this), this.interval_ms); } reset() { if (this.interval_ms == 0) return; cb.cancelTimeout(this.timer_id); this.timer_id = cb.setTimeout(this.tick.bind(this), this.interval_ms); } } class counter { constructor(callback, interval_lines, offset) { this.callback = callback; this.interval_lines = interval_lines; this.offset = offset || 0; this.trigger_callback = function() {}; listen_message(this.check.bind(this)); listen_tip(this.check.bind(this)); } check(msg) { if (this.interval_lines == 0) return; this.offset++; if (this.offset >= this.interval_lines) { this.offset = 0; this.callback(); this.trigger_callback(); } } reset() { this.offset = 0; } } class timer_counter { constructor(callback, interval_ms, interval_lines) { this._callback = callback; this._timer = new timer(callback, interval_ms); this._timer.trigger_callback = function() { this._counter.reset(); }.bind(this); this._counter = new counter(callback, interval_lines); this._counter.trigger_callback = function() { this._timer.reset(); }.bind(this); } reset() { this._timer.reset(); this._counter.reset(); } trigger() { this._callback(); this.reset(); } } // 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 add_setting_str("bot_color", "Bot color", "#FF1493"); add_setting_str("prize_name", "Name of the prize", "Aaaargh!! (╯°□°)╯︵( .O.)"); add_setting_str("win_message", "Raffle end message", "Wew! $user with his mighty $tickets has won $prize!! :fireworksjizz"); add_setting_choice("stats_public", "Display /raffle_stats publicly", "No", ["Yes", "No"]); add_setting_int("ticket_price", "Ticket price", 5); add_setting_choice("allow_multiples", "Allow multiplied tips", "Yes", ["Yes", "No"]); add_setting_str("purchase_message", "Purchase message (empty to disable)", "$user has bought $tickets for a chance to win $prize!"); add_setting_str("advertisement_message", "Advertisement message", "Tip $price to join the raffle for $prize!"); add_setting_int("advertisement_interval", "Advertisement interval in lines of chat (0 to disable)", 60); add_setting_int("advertisement_minutes", "Advertisement interval in minutes (0 to disable)", 5); if (settings_initialized) { var tickets = {}; var tickets_total = 0; var raffle_over = false; function pick_winner() { raffle_over = true; var winning_ticket = random_int(0, tickets_total - 1); var tickets_counted = 0; for (var user in tickets) { tickets_counted += tickets[user]; if (tickets_counted > winning_ticket) return user; } } listen_tip(function(tip) { if (raffle_over) return; if ((tip.amount % settings.ticket_price) != 0) return; if (settings.allow_multiples == "No" && tip.amount != settings.ticket_price) return; if (!(tip.from_user in tickets)) tickets[tip.from_user] = 0; var n = tip.amount / settings.ticket_price; tickets[tip.from_user] += n; tickets_total += n; if (!is_empty(settings.purchase_message)) { var $tickets = n == 1 ? "1 ticket" : n + " tickets"; var pmsg = format(settings.purchase_message, {"$user":tip.from_user, "$tickets":$tickets, "$prize":settings.prize_name, "$price":settings.ticket_price}); notice(pmsg, undefined, settings.bot_color); } }); var tc = new timer_counter(function() { if (raffle_over) return; notice(format(settings.advertisement_message, {"$prize":settings.prize_name, "$price":settings.ticket_price}), undefined, settings.bot_color); }, settings.advertisement_minutes * 1000 * 60, settings.advertisement_interval); add_command("raffle", 0, false, user_types.broadcaster, function(msg) { tc.trigger(); }); add_command("raffle", 0, false, user_types.guest, function(msg) { if (msg.user in tickets) { notice("You have " + tickets[msg.user] + " tickets, good luck!", msg.user, settings.bot_color); } else { notice("You don't have any tickets yet! Tip " + settings.ticket_price + " for a chance to win " + settings.prize_name, msg.user, settings.bot_color); } }); add_command("raffle_end", 0, false, user_types.broadcaster, function(msg) { if (tickets_total == 0) return notice_broadcaster("No raffle tickets have been bought yet!"); var winner = pick_winner(); var $tickets = tickets[winner] == 1 ? "1 ticket" : tickets[winner] + " tickets"; notice(format(settings.win_message, {"$user":winner, "$tickets":$tickets, "$prize":settings.prize_name, "$price":settings.ticket_price}), undefined, settings.bot_color); }); add_command("raffle_stats", 0, false, user_types.broadcaster, function(msg) { var ticket_owners = []; for (var user in tickets) ticket_owners.push({"user":user, "amt":tickets[user]}); ticket_owners.sort(function(a, b) {return b.amt - a.amt;}); var msg = "Total raffle tickets: " + tickets_total; for (var i = 0; i < ticket_owners.length; i++) { msg += "\n" + ticket_owners[i].user + ": " + ticket_owners[i].amt; } if (settings.stats_public == "Yes") { notice(msg, undefined, settings.bot_color); } else { notice_broadcaster(msg); } }); add_command("raffle_restart", 0, false, user_types.broadcaster, function(msg) { tickets = {}; tickets_total = 0; raffle_over = false; notice_broadcaster("Raffle has been restarted"); tc.trigger(); }); add_command("help", 0, false, user_types.all, function(msg) { notice("List of commands for ROFL Raffle:\n/raffle - display advertisement message\n/raffle_end - (broadcaster only) pick a winner and end the raffle\n/raffle_stats - (broadcaster only) display who has bought how many tickets\n/raffle_restart - (broadcaster only) restarts the raffle", msg.user); }); notice("ROFL Raffle has been started!", undefined, settings.bot_color); tc.trigger(); }
© Copyright Chaturbate 2011- 2025. All Rights Reserved.