Bots Home
|
Create an App
ivyBot v1
Author:
frits
Description
Source Code
Launch Bot
Current Users
Created by:
Frits
//Settings cb.settings_choices = [ {name: 'noticeOne', type: 'str', minLength: 0, maxLength: 1000, defaultValue: '', label: 'First notice.'}, {name: 'noticeTwo', type: 'str', minLength: 0, maxLength: 1000, defaultValue: '', label: 'Second notice'}, {name: 'notifierTime', type: 'int', minValue: 1, maxValue: 60, defaultValue: 5, label: 'Time between notices.'}, {name: 'waveTimeOut', type: 'int', minValue: 10, maxValue: 600, defaultValue: 60, label: 'Time until wave breaks in seconds.'}, {name: 'maxMsg', type: 'int', minValue: 1, maxValue: 1000, defaultValue: 3, label: 'Number of messages until wave breaks.'}, {name: 'waveTip', type: 'int', minValue: 1, maxValue: 10000, defaultValue: 15, label: 'Amount of tokens needed to start a wave or to keep it going.'}, {name: 'breakFans', type: 'choice', choice1: 'yes', choice2: 'no', defaultValue: 'yes', label: 'Can fans end waves?'}, {name: 'gagAuto', type: 'choice', defaultValue: 'no', choice1 : 'yes', choice2: 'no', label: 'Does the person that breaks a wave get gagged automatically?'}, {name: 'gagAutoTip', type: 'int', minvalue: 1, maxValue: 10000, defaultValue: 15, label: 'Amount of tokens needed to un-gag after being gagged for breaking a wave.'}, {name: 'whoGags', type: 'choice', choice1: 'neither', choice2: 'fans', choice3: 'mods', choice4: 'both', defaultValue: 'neither', label: 'Who else can gag users through gag commands?'}, {name: 'modT', type: 'int', minValue: 1, maxValue: 10000, defaultValue: 100, label: 'The maximum amount a mod can make a user tip to un-gag.'}, {name: 'fanT', type: 'int', minValue: 1, maxValue: 10000, defaultValue:100, label: 'The maximum amount a fan can make a user tip to un-gag.'}, {name: 'tipGag', type: 'choice', choice1: 'yes', choice2: 'no', defaultValue: 'no', label: 'Allow any user to gag another user by tipping.'}, {name: 'gagTip', type: 'int', minValue: 1, maxValue: 10000, defaultValue: 102, label: 'Amount of tokens needed to gag another user.'}, {name: 'ungagTip', type: 'int', minValue: 1, maxValue: 10000, defaultValue: 50, label: 'Amount of tokens needed to un-gag after being gagged by a tip.'}, {name: 'hideCommands', type: 'choice', choice1: 'yes', choice2: 'no', defaultValue: 'yes', label: 'Hide gag commands?'}, {name: 'foreColor', type: 'str', minLength: 7, maxLength: 7, defaultValue: '#8d91d1', label: 'Notice foreground color.'}, {name: 'backColor', type: 'str', minLength: 7, maxLength: 7, defaultValue: '#000000', label: 'Notice background color.'} ]; //Notice colors. const backClr = cb.settings.backColor; const foreClr = cb.settings.foreColor; //Notifier variables. let bowAmount = 0; const notice1 = cb.settings.noticeOne; const notice2 = cb.settings.noticeTwo; let noticeArray = []; let noticeIndex = 0; const noticeDelay = cb.settings.notifierTime * 1000; //fill up the noticeArray. if (!(notice1 === '')) {noticeArray.push(notice1)} if (!(notice2 === '')) {noticeArray.push(notice2)} //Global variables and constants for gagging. let gagList = []; const modGag = (cb.settings.whoGags === 'both' || cb.settings.whoGags === 'mods'); const fanGag = (cb.settings.whoGags === 'both' || cb.settings.whoGags === 'fans'); const tipToGag = (cb.settings.tipGag === 'yes'); const gagAmount = cb.settings.gagTip; const ungagAmount = cb.settings.ungagTip; const modLim = cb.settings.modT; const fanLim = cb.settings.fanT; const hide = (cb.settings.hideCommands === 'yes'); const charList = ['.', ',', '?', '!', ' ', ':', ';', `'`, `"`]; //Global variables and constants for bowing. let bowCount = 0; let waveInProgress = false; let wavers = []; let msgCount = 0; let timeOutId; const fansBreak = cb.settings.breakFans === 'yes'; const autoGag = cb.settings.gagAuto === 'yes'; const autoGagTip = cb.settings.gagAutoTip; const waveAmount = cb.settings.waveTip; let timeOut = (cb.settings.waveTimeOut * 1000); const msgLim = cb.settings.maxMsg; //Functions for gagging. function gag(userName, tipAmount) { cb.log(`gag function called. user: ${userName}, tip: ${tipAmount}.`); let inListIndex = inGagList(userName); if (inListIndex >= 0 && tipAmount === gagList[inListIndex][1]) { cb.sendNotice(`${capitalizer(userName)} is already gagged and can already un-gag for the same amount.`, '', backClr, foreClr, 'bold'); } else if (inListIndex >= 0) { gagList[inListIndex][1] = tipAmount; cb.sendNotice(`${capitalizer(userName)} is still gagged but can now un-gag for ${tipAmount} tokens.`, '', backClr, foreClr, 'bold'); } else { gagList.push([userName, tipAmount]); cb.sendNotice(`${capitalizer(userName)} is now gagged. ${tipAmount} tokens needed to un-gag`, '', backClr, foreClr, 'bold') } cb.log(gagList); } function inGagList(userName) { let userQuery = userName; let gagIndex = -1; cb.log(`inGagList called. user: ${userName}`); gagList.forEach((user, index) => { let gagName = user[0]; cb.log(`iteration ${index} of inGagList. user: ${user[0]}, tip: ${user[1]}`); if (userQuery === gagName) { gagIndex = index; } }); return gagIndex; } function unGag(i, tipAmount) { if (gagList[i][1] <= tipAmount) { let unGagged = gagList.splice(i, 1); cb.sendNotice(`${capitalizer(unGagged[0][0])} is now un-gagged.`, '', backClr, foreClr, 'bold'); } else { cb.sendNotice(`That's not enough, ${capitalizer(gagList[i][0])}!`, '', backClr, foreClr, 'bold'); } } function mmm(msgTxt) { let newMsgTxt = ''; for (let i = 0; i < msgTxt.length; i++) { if (charList.includes(msgTxt.charAt(i))) { newMsgTxt += msgTxt.charAt(i); } else if (/[A-Z]/.test(msgTxt.charAt(i))) { newMsgTxt += 'M'; } else { newMsgTxt += 'm'; } } return newMsgTxt; } function gagReader(msg) { let user = msg['user']; let msgTxt = msg['m']; if (msgTxt.slice(0, 4) === '!gag') { msg['X-Spam'] = hide; if (msgTxt.slice(0,8) === '!gaglist') { gagListPrinter(user); return; } if (msgTxt.slice(0.8) === '!gaghelp') { cb.sendNotice(`!gaglist: print a list of gagged users with the amount of tokens needed to un-gag.\n` + `!gag USERNAME TIP: gag a person. USERNAME is the user you want to gag and TIP is the` + `amount needed to un-gag. (authorized users only)\n!ungag USERNAME: un-gag a person.` + `USERNAME is the person you want to un-gag.` + `(broadcaster only)`, user, backClr, foreClr, 'bold'); return; } cb.log(msg); if (user === cb.room_slug || (msg['is_mod'] && modGag === true) || (msg['in_fanclub'] && fanGag === true)) { //Check if user is allowed to use the !gag command. let firstSpace = msgTxt.indexOf(' '); let secondSpace = msgTxt.indexOf(' ', firstSpace + 1); let userSlice = msgTxt.slice(firstSpace + 1, secondSpace); let tipAmount = parseInt(msgTxt.slice(secondSpace + 1)); cb.log(tipAmount); cb.log(userSlice); if (isNaN(tipAmount) || (firstSpace === -1) || (secondSpace === -1)) { //Check if command was formatted correctly. cb.sendNotice(`The command wasn't formatted correctly. Try '!gag USERNAME TIP', ` + `where USERNAME is the user you want to gag and TIP is the amount` + `of tokens needed to un-gag.`, user, backClr, foreClr, 'bold'); } else if (userSlice === cb.room_slug) { cb.sendNotice(`The Broadcaster can't be gagged!`, user, backClr, foreClr, 'bold'); } else if (msg['is_mod']) { if (tipAmount === 0) {tipAmount = 1;} if (tipAmount > modLim) {tipAmount = modLim;} gag(userSlice, tipAmount); } else if (msg['in_fanclub']) { if (tipAmount === 0) {tipAmount = 1;} if (tipAmount > fanLim) {tipAmount = fanLim;} gag(userSlice, tipAmount); } else { gag(userSlice, tipAmount); } } else { cb.sendNotice(`You're not authorized to use this command`, user, backClr, foreClr, 'bold'); } } else if (msgTxt.slice(0, 6) === '!ungag') { msg['X-Spam'] = hide; if (!(user === cb.room_slug)) { cb.sendNotice('Only the broadcaster can un-gag people!', user, backClr, foreClr, 'bold'); } else { let space = msgTxt.indexOf(' '); let userSlice = msgTxt.slice(space + 1); let index = inGagList(userSlice); cb.log(`gaglist index: ${index}, userSlice: ${userSlice}`); if (space === -1) { cb.sendNotice(`The command wasn't formatted correctly. Try '!ungag USERNAME', ` + `where USERNAME is the user you want to un-gag.`, user, backClr, foreClr, 'bold'); return; } if (index < 0) { cb.sendNotice('Either you specified an invalid username' + 'or the user you specified is currently not gagged.', user, backClr, foreClr, 'bold'); } else { unGag(index, gagList[index][1]); } } } } function gagTipReader(tip) { if (parseInt(tip['amount']) === gagAmount && tipToGag === true) { if (tip['message'] === cb.room_slug) { cb.sendNotice(`You can't gag the broadcaster!`, tip['from_user'], backClr, foreClr, 'bold'); } else if (tip['message'].length === 0) { cb.sendNotice('No username specified.', tip['from_user'], backClr, foreClr, 'bold'); } else { gag(tip['message'], ungagAmount); } } } function gagListPrinter(user) { if (gagList.length === 0) { cb.sendNotice('The gag list is currently empty.', user, backClr, foreClr, 'bold'); } else { let gagListNotice = ''; gagList.forEach((gaggedUser, index) => { gagListNotice +=`${capitalizer(gaggedUser[0])} needs ${gaggedUser[1]} tokens to un-gag.`; if (index !== gagList.length -1) { gagListNotice += '\n'; } }); cb.sendNotice(gagListNotice, user, backClr, foreClr, 'bold'); } } //Functions for bowing. function wave(tipAmount, user) { cb.log(`tip: ${tipAmount}, user: ${user}`) cb.log(timeOut); if (tipAmount === waveAmount) { wavers.push(user); bowAmount++; bowCount++; msgCount = 0; cb.log(bowCount); if (bowCount === 1) { timeOutId = cb.setTimeout(() => {bowCount = 0; wavers = [];}, timeOut); } else if (bowCount === 2) { cb.sendNotice(`${capitalizer(wavers[0])}'s bow started a wave and was followed by ` + `${capitalizer(wavers[1])}'s!`, '', backClr, foreClr, 'bold'); waveInProgress = true; cb.cancelTimeout(timeOutId); timeOutId = cb.setTimeout(() => {breakWave(true, ' ');}, timeOut); } else if (bowCount >= 3) { cb.sendNotice(`${capitalizer(user)} is keeping the wave going for ${bowCount} bows in a row!`, '', backClr, foreClr, 'bold'); cb.cancelTimeout(timeOutId); timeOutId = cb.setTimeout(() => {breakWave(true, ' ')}, timeOut); } } } function breakCheck(msg) { let user = msg['user']; if (!(wavers.includes(user) || (user === cb.room_slug) || msg['is_mod'] || (msg['in_fanclub'] && !fansBreak)) && waveInProgress) { msgCount++; if (msgCount >= msgLim) { breakWave(false, user); } } } function breakWave(byTime, userName) { if (byTime === true) { cb.sendNotice(`The wave slowly came halt after ${bowCount} bows. ` + `It ended with ${capitalizer(wavers[wavers.length -1])}'s bow.`, '', backClr, foreClr, 'bold'); } else { cb.sendNotice(`${capitalizer(userName)} did not respect the wave! ` + `It stopped after ${bowCount} bows and ended with ${capitalizer(wavers[wavers.length -1])}'s bow.`, '', backClr, foreClr, 'bold'); cb.cancelTimeout(timeOutId); if (autoGag === true) { gag(userName, autoGagTip); } } wavers = []; bowCount = 0; msgCount = 0; waveInProgress = false; } //Helper functions. function capitalizer(user) { return user[0].toUpperCase() + user.substring(1); } function notifier() { if (noticeIndex < noticeArray.length) { cb.sendNotice(noticeArray[noticeIndex], '', backClr, foreClr, 'bold'); } else if (noticeIndex === noticeArray.length) { cb.sendNotice(`There have been ${bowAmount} bows today!`); } noticeIndex++; if (noticeIndex > noticeArray.length) { noticeIndex = 0; } cb.setTimeout(() => {notifier()}, noticeDelay); } //Tip and message handlers. cb.onTip(function (tip) { let inList = inGagList(tip['from_user']); if (inList >= 0) { unGag(inList, parseInt(tip['amount'])); } wave(parseInt(tip['amount']), tip['from_user']); gagTipReader(tip); }); cb.onMessage(function (msg) { let inList = inGagList(msg['user']); breakCheck(msg); gagReader(msg); if (inList >= 0) { msg['m'] = mmm(msg['m']); } return msg; }); //Notifiers. cb.onEnter(function (user) { let userName = user['user']; let enterNotice = `IvyBot is active!\nWaves can be started by tipping ${waveAmount} tokens twice within ` + `${timeOut / 1000} seconds.\nWaves will end after ${msgLim} messages have been sent or ` + `${timeOut / 1000} seconds have passed since the last bow.\nWaves cant be ended by messages of: ` + `the broadcaster, mods${fansBreak ? ', fans' : ''} and people who've contributed to the wave.\n`; if (autoGag) { enterNotice += 'Users will be automatically gagged for ending a wave.\n'; } enterNotice += `These users can gag other users through gag commands: ` + `the broadcaster${fanGag ? ', fans' : ''}${modGag ? ', mods' : ''}.\n`; if (tipToGag) { enterNotice += `Users can gag other users by tipping ${gagAmount} tokens` + `and specifying a username in the tip-note.\n`; } enterNotice += `For available gag commands, type !gaghelp in chat.`; cb.sendNotice(enterNotice, userName, backClr, foreClr, 'bold'); }); cb.onStart(function() { notifier(); let enterNotice = `IvyBot is active!\nWaves can be started by tipping ${waveAmount} tokens twice within ` + `${timeOut / 1000} seconds.\nWaves will end after ${msgLim} messages have been sent or ` + `${timeOut / 1000} seconds have passed since the last bow.\nWaves cant be ended by messages of: ` + `the broadcaster, mods${fansBreak ? ', fans' : ''} and people who've contributed to the wave.\n`; if (autoGag) { enterNotice += 'Users will be automatically gagged for ending a wave.\n'; } enterNotice += `These users can gag other users through gag commands: ` + `the broadcaster${fanGag ? ', fans' : ''}${modGag ? ', mods' : ''}.\n`; if (tipToGag) { enterNotice += `Users can gag other users by tipping ${gagAmount} tokens` + `and specifying a username in the tip-note.\n`; } enterNotice += `For available gag commands, type !gaghelp in chat.`; cb.sendNotice(enterNotice, '', backClr, foreClr, 'bold'); })
© Copyright Chaturbate 2011- 2024. All Rights Reserved.