Bots Home
|
Create an App
ivyBot
Author:
henk
Description
Source Code
Launch Bot
Current Users
Created by:
Henk
//Global variables for gagging. let gagList = []; let modGag = false; let fanGag = false; let modLim = 100; let fanLim = 100; const charList = ['.', ',', '?', '!', ' ']; //Global variables for bowing. let bowCount = 0; let waveInProgress = false; let wavers = []; let timeOut = 60000; let msgCount = 0; let timeOutId; const msgLim = 3; //Functions for gagging. function gag(userName, tipAmount) { gagList.forEach(user => { if (userName === user[0] && tipAmount === user[1]) { cb.sendNotice(`${capitalizer(userName)} is already gagged and can already un-gag for the same amount.`); } else if (userName === user[0]) { user[1] = tipAmount; cb.sendNotice(`${capitalizer(userName)} is still gagged but can now un-gag for ${tipAmount} tokens.`); } else { gagList.push([userName, tipAmount]); cb.sendNotice(`${capitalizer(userName)} is now gagged and can un-gag for ${tipAmount} tokens.`); } }); } function checkIfGagged(userName) { gagList.forEach((user, index) => { if (user[0] === userName) {return index} }); return -1 } function unGag(i, tipAmount) { if (i >= 0 && gagList[i][0] > tipAmount) { let unGagged = gagList.splice(i, 1); cb.sendNotice(`${capitalizer(unGagged[0][0])} is now un-gagged.`); } else { cb.sendNotice(`You didn't specify a valid username or the user isn't gagged.`, cb.room_slug) } } function mmm(userName, msgTxt) { let newMsgTxt = msgTxt; gagList.forEach(user => { if (user[0] === userName) { newMsgTxt = ''; for (let i = 0; i < msgTxt.length; i++) { if ((!charList.includes(msgTxt[i])) && (msgTxt[i] === msgTxt[i].toUpperCase)) { newMsgTxt += 'M'; } else if (!charList.includes(msgTxt[i])) { newMsgTxt += 'm'; } else { newMsgTxt += msgTxt[i]; } } } }); return newMsgTxt; } function gagReader(msg) { if (msg['m'].slice(0, 4) === '!gag') { msg['X-spam'] = true; if (msg['user'] === cb.room_slug || (msg['is_mod'] && modGag === true) || (msg['in_fanclub'] && fanGag === true)) { let opener = msg['m'].indexOf('('); let comma = msg['m'].indexOf(','); let closer = msg['m'].indexOf(')'); let userSlice = msg['m'].slice(opener, comma); let tipAmount = Number.parseInt(msg['m'].slice(comma + 2, closer)); if (isNaN(tipAmount) || (opener === -1) || (comma === -1) || (closer === -1)) { cb.sendNotice(`The command was not formatted correctly. Try '!gag(USERNAME, TIPAMOUNT)'` + `where USERNAME is the user you want to gag and TIPAMOUNT is the amount of tokens needed to un-gag.`, msg['user']); return; } else if (userSlice === cb.room_slug) { cb.sendNotice(`The Broadcaster can't be gagged!`, msg['user']); return; } else if (msg['is_mod']) { if (tipAmount === 0) {tipAmount = 1} if (tipAmount > modLim) {tipAmount = modLim} gag(userSlice, tipAmount); return; } else if (msg['in_fanclub']) { if (tipAmount === 0) {tipAmount = 1} if (tipAmount > fanLim) {tipAmount = fanLim} gag(userSlice, tipAmount); return; } else { gag(userSlice, tipAmount); return; } } else { cb.sendNotice(`You're not authorized to use this command`, msg['user']); } } else if (msg['m'].slice(0, 6) === '!ungag') { msg['X-spam'] = true; if (!(msg['user'] === cb.room_slug)) { cb.sendNotice('Only the broadcaster can un-gag people!', msg['user']); return; } else { let opener = msg['m'].indexOf('('); let closer = msg['m'].indexOf(')'); if ((opener === -1) || (closer === -1)) { cb.sendNotice(`The command wasn't formatted correctly. Try '!ungag(USERNAME), where USERNAME is the user you want to un-gag.'`); return; } let userSlice = msg['m'].slice(opener + 1, closer); let index = checkIfGagged(userSlice); unGag(index, gagList[index][1]); return; } } } //Functions for bowing. function wave(tipAmount, user) { if (tipAmount === 15) { wavers.push(user); bowCount++; } if (bowCount === 2) { cb.sendNotice(`${capitalizer(wavers[0])} started a wave and was followed by ${capitalizer(wavers[1])}!`); 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!`); cb.cancelTimeout(timeOutId); timeOutId = cb.setTimeout(breakWave(true, ''), timeOut); } } function breakCheck(msg) { msgCount++; if (msgCount <= msgLim && waveInProgress && !wavers.includes(msg['user']) && !(msg['user'] === cb.room_slug || msg['is_mod'])) { breakWave(false, msg['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.`) } 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.`) cb.cancelTimeout(timeOutId); } wavers = []; bowCount = 0; msgCount = 0; waveInProgress = false; } //Helper functions. function tipHandler(tip) { unGag(checkIfGagged(tip['from_user']), Number.parseInt(tip['amount'])); wave(tip['from_user'], tip['amount']); } function msgHandler(msg) { breakCheck(msg); gagReader(msg); msg['m'] = mmm(msg['user'], msg['m']); return msg; } function capitalizer(user) { let newName = user; newName[0] = newName[0].toUpperCase(); return newName; } cb.onTip(function (tip) { tipHandler(tip); }); cb.onMessage(function (msg) { msgHandler(msg); });
© Copyright Chaturbate 2011- 2024. All Rights Reserved.