Bots Home
|
Create an App
Olivia's Gatekeeper
Author:
oliviaoncam
Description
Source Code
Launch Bot
Current Users
Created by:
Oliviaoncam
const isMessageByHuman = (function(trustTippers) { function randomInteger(min, max) { return min + Math.floor(Math.random() * (max - min + 1)); } class Challenge { constructor(description, expectedResponse) { this.description = description; this.expectedResponse = String(expectedResponse).trim(); } isValidResponse(response) { return String(response).trim() == this.expectedResponse; } toString() { return this.description; } } class MathChallenge extends Challenge { static createRandomAddition() { const a = randomInteger(1, 50), b = randomInteger(1, 50), aPlusB = a + b; return new MathChallenge(`${a} + ${b} = ?`, aPlusB); } static createRandomSubtraction() { const a = randomInteger(1, 50), b = randomInteger(1, 50), aPlusB = a + b; return new MathChallenge(`${aPlusB} - ${b} = ?`, a); } constructor(description, expectedResponse) { super(description, parseInt(expectedResponse, 10)); } isValidResponse(response) { return super.isValidResponse(parseInt(response, 10)); } } const challengeFactories = [ MathChallenge.createRandomAddition, MathChallenge.createRandomSubtraction ]; function createRandomChallenge() { return challengeFactories[Math.floor(Math.random() * challengeFactories.length)].call(null); } const whitelist = new Set([ cb.room_slug ]); // add the broadcaster to whitelist right away const userChallenges = new Map(); function addToWhitelist(username) { whitelist.add(username); userChallenges.delete(username); return true; } return function(message) { if (whitelist.has(message.user)) { return true; } else if (message.in_fanclub || message.is_mod) { return addToWhitelist(message.user); } else if (trustTippers && (message.tipped_recently || message.tipped_alot_recently || message.tipped_tons_recently)) { return addToWhitelist(message.user); } else { let challenge = userChallenges.get(message.user); if (challenge && challenge.isValidResponse(message.m)) { addToWhitelist(message.user); message['X-Spam'] = true; message.m = '[CAPTCHA] Your solution is correct, you are now allowed to chat.'; return false; } else { if (!challenge) userChallenges.set(message.user, challenge = createRandomChallenge()); message['X-Spam'] = true; message.m = '[CAPTCHA] Your message has been blocked. Please prove that you are not a spam robot by solving this captcha challenge and typing the solution to public chat: ' + challenge.toString().replace(/ /g, '\u00A0'); return false; } } }; })(cb.settings.trustTippers == 'true'); cb.onMessage((message) => { if (!isMessageByHuman(message)) { // stop processing the message return message; } // otherwise do your things // and in the end, as always, return the message return message; });
© Copyright Chaturbate 2011- 2024. All Rights Reserved.