Bots Home
|
Create an App
gbgffdg
Author:
masta_shake
Description
Source Code
Launch Bot
Current Users
Created by:
Masta_Shake
var subs = {}; var badwords = []; var choice; cb.settings_choices = [{name:"timer", type:"int", label:"Number of seconds greys are prevented from chatting", defaultValue:10, minValue:1}, {name:"custom_subs", type:"str", label:"Custom word replacements", defaultValue:"baby|bb|babe = " + cb.room_slug + " , big|large|huge = small"}, {name:"which_users", type:"choice", label:"Which users?", choice1:"Greys", choice2:"Greys and Blues", defaultValue:"Greys and Blues"}]; var timeBlocked = cb.settings.timer; var room = {inRoom:function(user) { return user in room.users; }, addUser:function(name) { room.users[name] = {msgs:[], timeEntered:Date.now()}; }, checkSpam:function(sendTo) { for (var username in room.users) { if (room.users.hasOwnProperty(username)) { room.users[username].msgs.forEach(function(message) { cb.sendNotice(username + ":" + message, sendTo); }); } } }, getCmd:function(str) { return str.split(" ")[0].substring(1); }, getArgs:function(str) { var array = str.match(/[#a-z0-9]+/gi); room.arrayRemove(array, array[0]); return array; }, arrayRemove:function(array, item) { var i = array.indexOf(item); while (i > -1) { array.splice(i, 1); i = array.indexOf(item); } }, changeTimer:function(str) { var num = str.match(/\d+/g); if (num !== null) { return parseInt(num.toString().replace(/,*/g, "")); } return false; }, users:{}}; cb.onEnter(function(chat) { var user = chat.user; var isHost = user == cb.room_slug; var isMod = chat.is_mod; var isFan = chat.in_fanclub; var isBlue = chat.has_tokens; var isGrey = !isBlue && !isFan && !isMod && !isHost; if (isGrey && !room.inRoom(user)) { room.addUser(user); } }); cb.onMessage(function(msg) { var user = msg.user; var isHost = user == cb.room_slug; var isMod = msg.is_mod; var isFan = msg.in_fanclub; var isBlue = msg.has_tokens; var isGrey = !isBlue && !isFan && !isMod && !isHost; var isDev = user == "i0_ol"; var m = msg.m.replace(/\s+/g, " ").trim().toLowerCase(); var command = false; if (isGrey) { if (!room.inRoom(user)) { room.addUser(user); } var timeElapsed = (Date.now() - room.users[user].timeEntered) / 1000; var timeLeft = timeBlocked - timeElapsed; if (timeLeft > 0) { msg["X-Spam"] = true; room.users[user].msgs.unshift(msg.m); cb.sendNotice("To prevent spam, your messages are blocked for " + Math.round(timeLeft) + " more seconds", user); } } if (choice === "Greys" && isGrey) { msg.m = wordReplace(m); } else { if (!isMod && !isFan && !isHost) { msg.m = wordReplace(m); } } if (isHost || isMod || isDev) { if (m.charAt(0) === "/") { command = true; msg["X-Spam"] = true; } if (command) { var cmd = room.getCmd(m); var arg = room.getArgs(m)[0]; if (cmd === "list") { badwords.forEach(function(word) { cb.sendNotice(word, user); }); } if (cmd === "spam") { room.checkSpam(user); } if (cmd === "timeout") { if (arg && /\d+/.test(arg)) { timeBlocked = room.changeTimer(arg); cb.sendNotice("AntiBot timeout set to " + timeBlocked + " seconds", user); } else { cb.sendNotice("Current timeout is set to " + timeBlocked + " seconds", user); } } } } return msg; }); function setup() { if (!isBlank(cb.settings.custom_subs)) { subs = setupSubs(cb.settings.custom_subs); } choice = cb.settings.which_users; } function setupSubs(setting) { var arr = setting.split(","); var obj = {}; var arr2 = []; arr.forEach(function(item) { arr2.push(item.split("=")); }); arr2.forEach(function(item, i) { var str = ""; if (!isBlank(arr2[i][0])) { if (!isBlank(arr2[i][1])) { var good = arr2[i][1].trim(); var bad = arr2[i][0].trim(); bad.split("|").forEach(function(word) { if (!badwords.includes(word)) { badwords.push(word); } }); bad = "\\b" + bad.replace(/\|/g, "\\b|\\b") + "\\b"; var arr3 = Array.from(bad); arr3.forEach(function(letter, index) { if (/\w/g.test(letter) && arr3[index - 1] !== "\\") { str += letter + "+"; } else { str += letter; } }); str = str.replace(/\s*\|\s*/g, "|").replace(/\s+/g, "\\s*"); obj[good] = new RegExp(str, "gi"); } } }); return obj; } function wordReplace(message) { for (var re in subs) { var regex = subs[re]; if (regex.test(message)) { message.match(regex).forEach(function(str) { message = message.replace(str, re); }); } } return message; } function isBlank(str) { return str === undefined || str === null || str === ""; } setup();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.