Bots Home
|
Create an App
dthb
Author:
aasd_user
Description
Source Code
Launch Bot
Current Users
Created by:
Aasd_User
// BlazeFyre's club bot // author: asdfghjkl28 var OWNER_FLAG = 128; var MODERATOR_FLAG = 64; var FANCLUB_FLAG = 32; var TIPPED_RECENTLY_FLAG = 16; var TIPPED_ALOT_RECENTLY_FLAG = 8; var TIPPED_TONS_RECENTLY_FLAG = 4; var HAS_TOKENS_FLAG = 2; var GREY_FLAG = 1; var teamblaze = { commands: {}, registerCommand: function (command, helpText, owner, moderator, fanclub, recently, alot, tons, tokens, grey, method) { "use strict"; this.commands[command] = { method: method, helpText: helpText, perms: this.bool2Perm(owner, moderator, fanclub, recently, alot, tons, tokens, grey) }; }, checkCommand: function (msg) { "use strict"; var m = msg.m; var u = msg.user; if (m[0] === '/') { // don't print commands msg['X-Spam'] = true; // Remove trailing spaces m = m.replace(/\s+$/, ''); // Find command parameters var commandParts = m.split(/\s+/); var commandName = commandParts.shift(); // cb.log(u + ' issued command: ' + commandName); if (this.commands[commandName] && (this.commands[commandName].perms & this.msg2Perm(msg))) { // cb.log(u + " allowed to run command:" + commandName); msg = this.commands[commandName].method(msg, commandParts); // Only don't print if it is a command we handle return msg; } else if (this.canControlBot(msg)) { // Protect controllers from getting commands wrong return msg; } else { if (!this.canControlBot(msg)) { // cb.log(u + " NOT allowed to run command:" + commandName); } return false; } } else { return false; } }, bool2Perm: function (owner, moderator, fanclub, recently, alot, tons, tokens, grey) { "use strict"; var perms = 0; perms = owner ? perms | OWNER_FLAG : perms; perms = moderator ? perms | MODERATOR_FLAG : perms; perms = fanclub ? perms | FANCLUB_FLAG : perms; perms = recently ? perms | TIPPED_RECENTLY_FLAG : perms; perms = alot ? perms | TIPPED_ALOT_RECENTLY_FLAG : perms; perms = tons ? perms | TIPPED_TONS_RECENTLY_FLAG : perms; perms = tokens ? perms | HAS_TOKENS_FLAG : perms; perms = grey ? perms | GREY_FLAG : perms; return perms; }, msg2Perm: function (msg) { "use strict"; var perms = 0; perms = msg.user === cb.room_slug ? perms | OWNER_FLAG : perms; perms = msg.is_mod ? perms | MODERATOR_FLAG : perms; perms = msg.in_fanclub ? perms | FANCLUB_FLAG : perms; perms = msg.tipped_recently ? perms | TIPPED_RECENTLY_FLAG : perms; perms = msg.tipped_alot_recently ? perms | TIPPED_ALOT_RECENTLY_FLAG : perms; perms = msg.tipped_tons_recently ? perms | TIPPED_TONS_RECENTLY_FLAG : perms; perms = msg.has_tokens ? perms | HAS_TOKENS_FLAG : perms; perms = perms === 0 ? perms | GREY_FLAG : perms; return perms; }, actualBannedSWords: {}, haveBadSWords: false, actualBanList: "", totalMessagesBlocked: 0, // Useful globals wordBoundary: "(\\s|\\b)" }; // CB app settings cb.settings_choices = [ { name: 'doColoring', type: 'choice', label: 'Change text and background coloring for members (choose colours below)?', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes' }, { name: 'doText', type: 'choice', label: 'Add text labels in front of members\' messages (choose text below)?', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes' }, { name: 'fmText', label: 'Text to put in front of members messages (e.g. BF), the text will be put inside square brackets []', type: 'str', minLength: 0, maxLength: 10, required: false, defaultValue: 'Team Blaze' }, { name: 'fmTextColor', label: 'Members text color - HTML colour code without starting \'#\' e.g. (FFFFFF is white)', type: 'str', minLength: 0, maxLength: 6, required: false, defaultValue: '000000' }, { name: 'fmBGColor', label: 'Members background color - HTML colour code without starting \'#\' e.g. (000000 is black)', type: 'str', minLength: 0, maxLength: 6, required: false, defaultValue: 'FEA9F2' }, { name: 'badwords', label: 'List of bad words, separated by commas', type: 'str', minLength: 0, maxLength: 10240, required: false, defaultValue: '' } ]; var customText = {}; customText['bookerdewitt'] = "Team Balze"; customText['teck1234'] = "Team Unmod Teck"; customText['tcollins092'] = "Team Bae"; customText['tits_mcgee9393'] = "Team grey"; customText['tstonewow'] = "Team Fridge"; customText['danimusprime'] = "Team Salad: Going From Medium to Small"; customText['studsmcduff'] = "Team Tay Tay"; customText['asdfghjkl28'] = "Team Leader"; customText['shapman88'] = "The Token Jew"; customText['weetimmi'] = "Team Riley"; customText['walterjp20'] = "Team Spoil"; customText['walterjp22'] = "Team Spoil"; customText['tatsuro'] = "Team gachiGASM"; customText['evilsevadus'] = "Team Butts"; customText['andrew83b'] = "Team Booty"; cb.onMessage(function (msg) { "use strict"; return teamblaze.onMessage(msg); }); teamblaze.addCustomLabel = function (user, label) { customText[user] = label; }; teamblaze.removeCustomLabel = function (user) { delete customText[user]; }; teamblaze.onMessage = function (msg) { // checkCommand will check if this is a registered command and run the command if it is. It returns a message object if it ran so we can exit early. // it returns false if it did not run so we can do more processing if we want var newMsg = teamblaze.checkCommand(msg); if (newMsg) { return newMsg; } // If we get to here it isn't a command so do normal processing // vars for ease of use var u = msg['user']; // Process bad words var bannedWord = teamblaze.hasBannedSWord(msg.m); if (bannedWord) { msg['X-Spam'] = true; teamblaze.totalMessagesBlocked++; return msg; } // Add label if (msg.in_fanclub || msg.is_mod || u === 'asdfghjkl28' || u === 'weetimmi') { msg['background'] = '#' + cb.settings.fmBGColor; msg['c'] = '#' + cb.settings.fmTextColor; if (customText[u]) { msg['m'] = "[" + customText[u] + "] " + msg['m']; } else { msg['m'] = "[" + cb.settings.fmText + "] " + msg['m']; } } // Block stupid emote if (u != 'bookerdewitt') { msg['m'] = msg['m'].replace(/:dolph.*cum/gi, ":chickenhug"); } return msg; }; teamblaze.canControlBot = function (msg) { "use strict"; return ((msg.user === cb.room_slug) || msg.is_mod); }; teamblaze.addToActualSBanList = function (item) { "use strict"; var lengthBefore = Object.keys(teamblaze.actualBannedSWords).length; //cb.log("lengthBefore " + lengthBefore); teamblaze.actualBannedSWords[item] = {u: 1}; //cb.log("lengthAfter " + Object.keys(teamblaze.actualBannedSWords).length); var diff = Object.keys(teamblaze.actualBannedSWords).length - lengthBefore; if (diff > 0) { return true; } return false; }; teamblaze.removeFromActualSBanList = function (item) { "use strict"; var lengthBefore = Object.keys(teamblaze.actualBannedSWords).length; delete teamblaze.actualBannedSWords[item]; var diff = Object.keys(teamblaze.actualBannedSWords).length - lengthBefore; if (diff < 0) { return true; } return false; }; teamblaze.buildBanLists = function () { "use strict"; teamblaze.actualBanList = ""; var maxLineLength = 60; var currentLineLength = 0; if (Object.keys(teamblaze.actualBannedSWords).length > 0) { // cb.log("have banned words"); teamblaze.haveBadSWords = true; var localBadSWordPattern = '(' + Object.keys(teamblaze.actualBannedSWords).join('|') + ')'; // cb.log("Builder: " + localBadSWordPattern); teamblaze.SwordPatternStart = new RegExp('^' + localBadSWordPattern + '' + teamblaze.wordBoundary, 'ig'); teamblaze.SwordPatternEnd = new RegExp(teamblaze.wordBoundary + localBadSWordPattern + '$', 'ig'); teamblaze.SwordPatternMiddle = new RegExp(teamblaze.wordBoundary + localBadSWordPattern + teamblaze.wordBoundary, 'ig'); // teamblaze.actualBanList += localBadWordPattern; for (var word in teamblaze.actualBannedSWords) { // cb.log("Word: " + word); if (currentLineLength === 0) { teamblaze.actualBanList += word; currentLineLength = word.length; } else if ((currentLineLength + word.length) > maxLineLength) { teamblaze.actualBanList += '\n' + word; currentLineLength = word.length; } else { teamblaze.actualBanList += ',' + word; currentLineLength += word.length; } } } }; teamblaze.hasBannedSWord = function (text) { "use strict"; if (!teamblaze.haveBadSWords) { // No S banned words // cb.log("Don't have any bad words") return false; } else { var match; while (match = teamblaze.SwordPatternStart.exec(text)) { if (match[1] !== cb.room_slug) { teamblaze.SwordPatternStart.lastIndex = 0; return match[1]; } } while (match = teamblaze.SwordPatternEnd.exec(text)) { if (match[2] !== cb.room_slug) { teamblaze.SwordPatternEnd.lastIndex = 0; return match[2]; } } while (match = teamblaze.SwordPatternMiddle.exec(text)) { if (match[2] !== cb.room_slug) { teamblaze.SwordPatternMiddle.lastIndex = 0; return match[2]; } } } return false; }; teamblaze.printBannedItemsMessage = function (user) { "use strict"; var outMessage = ""; outMessage += 'Messages blocked this session: ' + teamblaze.totalMessagesBlocked + '\n'; outMessage += 'Banned words and phrases: ' + teamblaze.actualBanList + '\n'; cb.sendNotice(outMessage,user); }; teamblaze.grabSettings = function () { // cb.log("starting grabbing settings"); if (cb.settings.badwords) { var badWordsSettings = cb.settings.badwords.split(','); for (var ii = 0; ii < badWordsSettings.length; ii++) { // Trim leading and following spaces var clean = badWordsSettings[ii].replace(/^\s+/, ""); clean = clean.replace(/\s+$/, ""); // Check still something left to add! if (clean.length > 1) { teamblaze.addToActualSBanList(clean); } else { cb.sendNotice("WARNING: This word was too short (must be at least 2 letters long), didn't add to list: " + clean, cb.room_slug); } } teamblaze.buildBanLists(); } // cb.log("finished grabbing settings"); }; teamblaze.usage = function (msg) { "use strict"; var u = msg.user; var helpMessage = 'Available commands for Team Blaze bot:\n'; var msgPerms = teamblaze.msg2Perm(msg); for (var key in teamblaze.commands) { if (teamblaze.commands[key].perms & msgPerms) { // Command allowed for this user helpMessage += key + teamblaze.commands[key].helpText + "\n"; } } cb.sendNotice(helpMessage, u); }; teamblaze.init = function () { "use strict"; teamblaze.grabSettings(); // register commands // addLabel - only for owner and moderators teamblaze.registerCommand('/addLabel', ' - set custom label for a fan club member for this session', true, true, false, false, false, false, false, false, function (msg, commandParts) { var u = msg.user; var theuser = commandParts.shift(); if (commandParts.length > 0) { var thelabel = commandParts.join(' '); teamblaze.addCustomLabel(theuser, thelabel); cb.sendNotice("Added label " + thelabel + " to user " + theuser, u, '#F2C7EF', '#000000', 'normal'); if (u !== cb.room_slug) { cb.sendNotice(u + " added label " + thelabel + " to user " + theuser, cb.room_slug, '#F2C7EF', '#000000', 'normal'); } } else { cb.sendNotice("You forgot to specify a new label", u, '#F2C7EF', '#000000', 'normal'); } return msg; }); // removeLabel - only for owner and moderators teamblaze.registerCommand('/removeLabel', ' - remove custom label for a fan club member for this session', true, true, false, false, false, false, false, false, function (msg, commandParts) { var u = msg.user; if (commandParts.length === 1) { var theuser = commandParts.shift(); teamblaze.removeCustomLabel(theuser); cb.sendNotice("Removed custom label from user " + theuser, u, '#F2C7EF', '#000000', 'normal'); if (u !== cb.room_slug) { cb.sendNotice(u + " removed custom label from user " + theuser, cb.room_slug, '#F2C7EF', '#000000', 'normal'); } } else { cb.sendNotice("You gave too many parameters, I'm going to ignore this command", u, '#F2C7EF', '#000000', 'normal'); } return msg; }); // addbadword - only for owner and moderators teamblaze.registerCommand('/addbadword', ' - add a new bad word for this session', true, true, false, false, false, false, false, false, function (msg, commandParts) { var u = msg.user; if (commandParts.length === 1) { var badword = commandParts[0]; // cb.log("bad word: " + badword); if (teamblaze.addToActualSBanList(badword)) { teamblaze.buildBanLists(); cb.sendNotice("Added badword " + badword + " to list", u, '#F2C7EF', '#000000', 'normal'); if (u !== cb.room_slug) { cb.sendNotice(u + " added badword " + badword + " to list", cb.room_slug, '#F2C7EF', '#000000', 'normal'); } } else { cb.sendNotice("badword " + badword + " not added to list (it is already on the list)", u, '#F2C7EF', '#000000', 'normal'); } } else { cb.sendNotice("You forgot to specify a badword or specified more than one", u, '#F2C7EF', '#000000', 'normal'); } return msg; }); // delbadword - only for owner and moderators teamblaze.registerCommand('/delbadword', ' - delete a bad word for this session', true, true, false, false, false, false, false, false, function (msg, commandParts) { var u = msg.user; if (commandParts.length === 1) { var badword = commandParts[0]; if (teamblaze.removeFromActualSBanList(badword)) { teamblaze.buildBanLists(); cb.sendNotice("Removed badword " + badword + " from list", u, '#F2C7EF', '#000000', 'normal'); if (u !== cb.room_slug) { cb.sendNotice(u + " removed badword " + badword + " from list", cb.room_slug, '#F2C7EF', '#000000', 'normal'); } } else { cb.sendNotice("badword " + badword + " not removed from list (it isn't on the list)", u, '#F2C7EF', '#000000', 'normal'); } } else { cb.sendNotice("You forgot to specify a badword or specified more than one", u, '#F2C7EF', '#000000', 'normal'); } return msg; }); // listbadwords - only for owner and moderators teamblaze.registerCommand('/listbadwords', ' - list bad words for this session', true, true, false, false, false, false, false, false, function (msg, commandParts) { var u = msg.user; teamblaze.printBannedItemsMessage(u); return msg; }); // usage - only for owner and moderators this.registerCommand('/help', ' - show this help message', true, true, false, false, false, false, false, false, function (msg, commandParts) { teamblaze.usage(msg); return msg; }); }; teamblaze.init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.