Bots Home
|
Create an App
Pirate Filter
Author:
lactose_intolerant
Description
Source Code
Launch Bot
Current Users
Created by:
Lactose_Intolerant
var util = new (function( ) { var secondsInAMinute = 60; var secondsInAnHour = 60 * secondsInAMinute; var splitSeconds = function( seconds ) { var hours = 0; var minutes = 0; if (seconds >= secondsInAnHour) hours = Math.floor( seconds / secondsInAnHour ); seconds = seconds - hours * secondsInAnHour; if (seconds >= secondsInAMinute) minutes = Math.floor( seconds / secondsInAMinute ); seconds = Math.floor( seconds - minutes * secondsInAMinute ); return { 'seconds' : seconds, 'minutes' : minutes, 'hours' : hours }; } this.createReadableDuration = function( seconds ) { parts = splitSeconds( seconds ); var components = []; if (parts.hours > 0) components.push( parts.hours + ":" ); components.push( parts.minutes + ":" ); components.push( parts.seconds ); return components.join( "" ); } this.createReadableDuration2 = function( seconds ) { parts = splitSeconds( seconds ); var components = []; if (parts.hours > 0) components.push( parts.hours + " hours" ); if (parts.minutes > 0) components.push( parts.minutes + " minutes" ); if (components.length == 0 || parts.seconds > 0) components.push( parts.seconds + " seconds" ); return components.join( ", " ); } this.parseDurationString = function( str ) { var match = /(?:(\d+)h)?\s*(?:(\d+)m)?\s*(?:(\d+)s)?/.exec( str ); if (match == null) return null; if (match[1] == null && match[2] == null && match[3] == null) return null; var seconds = 0; if (match[1] != null) seconds += parseInt( match[1] ) * secondsInAnHour; if (match[2] != null) seconds += parseInt( match[2] ) * secondsInAMinute; if (match[3] != null) seconds += parseInt( match[3] ); return seconds; } this.getTimeSinceEpochInSeconds = function( ) { return (new Date( )).valueOf( ) / 1000.0; } this.mergeObjects = function( a, b ) { var result = {}; for (k in a) result[k] = a[k]; for (k in b) result[k] = b[k]; return result; } this.randomArrayItem = function( array ) { var i = Math.floor( Math.random( ) * array.length ); return array[i]; } })( ); var Events = function( names ) { var handlers = {}; var init = function( ) { for (var i = 0; i < names.length; ++i) handlers[names[i]] = []; } this.add = function( event, handler ) { handlers[event].push( handler ); } this.raise = function( event /*, *args */ ) { var raiseArgs = Array.prototype.slice.call( arguments, 1 ); var rval; for (var i = 0; i < handlers[event].length; ++i) rval = handlers[event][i].apply( null, raiseArgs ); return rval; } init( ); }; var platform = new (function( ) { var events = new Events( ["onMessage", "onEnter", "onLeave", "onTip", "onDrawPanel"] ); var isOnMockPlatform = !!cb.cbUsers; var init = function( ) { cb.onMessage( cbOnMessage ); cb.onDrawPanel( cbOnDrawPanel ); cb.onTip( cbOnTip ); if (!isOnMockPlatform) { cb.onEnter( cbOnEnter ); cb.onLeave( cbOnLeave ); } } this.room_slug = cb.room_slug; this.onMessage = function( handler ) { events.add( "onMessage", handler ); } this.onEnter = function( handler ) { events.add( "onEnter", handler ); } this.onLeave = function( handler ) { events.add( "onLeave", handler ); } this.onDrawPanel = function( handler ) { events.add( "onDrawPanel", handler ); } this.onTip = function( handler ) { events.add( "onTip", handler ); } this.fakeLeave = function( usernameOrObj ) { var cbUser = usernameOrObj; if (typeof usernameOrObj == "string") cbUser = createFakeUserObj( usernameOrObj ); events.raise( "onLeave", cbUser ); } this.fakeEnter = function( usernameOrObj ) { var cbUser = usernameOrObj; if (typeof usernameOrObj == "string") cbUser = createFakeUserObj( usernameOrObj ); events.raise( "onEnter", cbUser ); } this.drawPanel = function( ) { cb.drawPanel( ); } this.chatNotice = function( msg, to, fore, back, bold ) { cb.chatNotice( msg, to, fore, back, bold ); } this.changeRoomSubject = function( subj ) { cb.changeRoomSubject( subj ); } this.setTimeout = function( func, timeout ) { cb.setTimeout( func, timeout ); } this.setInterval = function( func, timeout ) { cb.setTimeout( function( ) { cb.setTimeout( arguments.callee, timeout ); func( ); }, timeout ); } var createFakeUserObj = function( name ) { return { "user" : name, "in_fanclub" : false, "has_tokens" : 0, "is_mod" : false, "tipped_recently" : false, "gender" : "m" }; } var cbOnMessage = function( cbMsg ) { events.raise( "onMessage", cbMsg ); return cbMsg; } var cbOnEnter = function( cbUser ) { events.raise( "onEnter", cbUser ); } var cbOnLeave = function( cbUser ) { events.raise( "onLeave", cbUser ); } var cbOnTip = function( cbTip ) { events.raise( "onTip", cbTip ); } var cbOnDrawPanel = function( cbUser ) { return events.raise( "onDrawPanel", cbUser ); } init( ); })( ); var TipRankings = function( ) { var Tipper = function( username, gender ) { this.username = username; this.totalTips = 0; this.gender = gender; this.firstSeen = util.getTimeSinceEpochInSeconds( ); this.isPresent = true; this.leftAt = 0; this.lastTipTime = 0; } var _this = this; var handlers = new Events( [ 'onTipLeaderOvertaken', 'onTipLeaderChange', 'onTip', 'onTipperLeave', 'onTipperEnter' ] ); var tippers = []; this.totalTips = 0; this.leaderMustBePresent = true; this.leader = null; var init = function( ) { platform.onTip( cbOnTip ); platform.onEnter( cbOnEnter ); platform.onLeave( cbOnLeave ); } var cbOnEnter = function( cbUser ) { var tipper = _this.findTipper( cbUser.user ); if (tipper != null && !tipper.isPresent) { tipper.isPresent = true; handlers.raise( 'onTipperEnter', tipper ); updateRankings( ); } } this.findTipper = function( username ) { for (var i = 0; i < tippers.length; ++i) { var tipper = tippers[i]; if (tipper.username == username) return tipper; } return null; } var createNewUser = function( username, opt_gender ) { var user = new User( username, opt_gender == undefined ? "m" : opt_gender ); users.push( user ); return user; } var cbOnLeave = function( cbUser ) { var tipper = _this.findTipper( cbUser.user ); if (tipper != null && tipper.isPresent) { tipper.isPresent = false; tipper.leftAt = util.getTimeSinceEpochInSeconds( ); handlers.raise( 'onTipperLeave', tipper ); updateRankings( ); } } var cbOnTip = function( cbTip ) { var tipper = createTipper( cbTip.from_user, cbTip.from_user_gender ); tipper.lastTipTime = util.getTimeSinceEpochInSeconds( ); var amount = parseInt( cbTip.amount ); tipper.totalTips += amount; _this.totalTips += amount; var oldLeader = _this.leader; updateRankings( ); if (_this.leader && oldLeader !== _this.leader && _this.leader.username == cbTip.from_user) handlers.raise( "onTipLeaderOvertaken", _this.leader, oldLeader ); handlers.raise( 'onTip', tipper, amount ); } var createTipper = function( username, gender ) { var tipper = _this.findTipper( username ); if (tipper != null) return tipper; tipper = new Tipper( username, gender ); tippers.push( tipper ); return tipper; } var updateRankings = function( ) { var oldLeader = _this.leader; _this.leader = findNewLeader( ); if (oldLeader !== _this.leader) handlers.raise( "onTipLeaderChange", _this.leader ); } var findNewLeader = function( ) { if (tippers.length == 0) return null; var currentLeader = null; for (var i = 0; i < tippers.length; ++i) { var tipper = tippers[i]; if (tipper.isPresent || !_this.leaderMustBePresent) { if (currentLeader == null) currentLeader = tipper; else { var d = tipper.totalTips - currentLeader.totalTips; if (d > 0 || (d == 0 && tipper.lastTipTime < currentLeader.lastTipTime)) currentLeader = tipper; } } } return currentLeader; } this.subscribe = function( event, handler ) { handlers.add( event, handler ); } this.getRankedTippers = function( ) { var top = tippers.slice( 0 ); top.sort( function( a, b ) { if (_this.leaderMustBePresent) { if (!a.isPresent) return 1; if (!b.isPresent) return -1; } var d = b.totalTips - a.totalTips; if (d != 0) return d; return a.lastTipTime - b.lastTipTime; } ); return top; } this.isLeader = function( username ) { return _this.leader != null && _this.leader.username == username; } init( ); } var Substitution = function( regex, replacements ) { this.regex = regex; this.replacements = replacements; this.apply = function( text ) { // HACK: poorly chosen substitutions can go in infinitely so only loop 25 times. for (var i = 0; i < 25; ++i) { if (!this.regex.test( text )) break; var repl = Array.isArray( this.replacements ) ? util.randomArrayItem( this.replacements ) : this.replacements; text = text.replace( this.regex, repl ); } return text; } } var PirateFilter = function( ) { var Decoration = function( text, probability ) { this.text = text; this.probability = probability; } var canonicalSubs = [ new Substitution( /\bu\b/i, "you" ), new Substitution( /\bur\b/i, "you're" ), new Substitution( /\bn\b/i, "and" ), new Substitution( /\bl8r\b/i, "later" ), new Substitution( /\bbb\b/i, "baby" ), new Substitution( /\br\b/i, "are" ), new Substitution( /\bteh\b/i, "the" ), new Substitution( /\bda\b/i, "the" ), new Substitution( /\bfuk\b/i, "fuck" ), new Substitution( /\bfukd\b/i, "fucked" ), new Substitution( /\bjizz\b/i, "cum" ), new Substitution( /\bcock\b/i, "penis" ), new Substitution( /\bcocks\b/i, "penises" ), new Substitution( /\bdick\b/i, "penis" ), new Substitution( /\bdicks\b/i, "penises" ), new Substitution( /\bwinky\b/i, "penis" ), new Substitution( /\bwinkies\b/i, "penises" ), new Substitution( /\bpussy\b/i, "vagina" ), new Substitution( /\bcunt\b/i, "vagina" ), new Substitution( /\bass\b/i, "butt" ), new Substitution( /\bboob(s?)\b/i, "breast$1" ), new Substitution( /\btit(s?)\b/i, "breast$1" ), new Substitution( /\bhey\b/i, "hello" ), new Substitution( /\bsup\b/i, "hello" ), new Substitution( /\bhi\b/i, "hello" ), new Substitution( /\bwhat'?s up\b/i, "hello" ), new Substitution( /\bbuddy\b/i, "friend" ), new Substitution( /\bbuddies\b/i, "friends" ), new Substitution( /\bshorts\b/i, "pants" ), new Substitution( /\bunderwears?\b/i, "briefs" ), new Substitution( /\bpanties\b/i, "briefs" ), new Substitution( /\bboxers\b/i, "briefs" ), new Substitution( /\bthongs?\b/i, "briefs" ), new Substitution( /\bpimp(s?)\b/i, "leader$1" ), new Substitution( /\bpl[sz]\b/i, "please" ), new Substitution( /\bbitches\b/i, "whores" ), new Substitution( /\bhooker(s?)\b/i, "whore$1" ), new Substitution( /\bslut(s?)\b/i, "whore$1" ), new Substitution( /\bbitch\b/i, "whore" ), new Substitution( /\bfucker(s?)\b/i, "loser" ), new Substitution( /\bloser(s?)\b/i, "loser" ), new Substitution( /\bgorgeous\b/i, "beautiful" ), new Substitution( /\bhaha(ha)+h?\b/i, "haha" ), new Substitution( /\blol\b/i, "haha" ), new Substitution( /\bgoodbye\b/i, "bye" ), new Substitution( /\bso long\b/i, "bye" ), new Substitution( /\bevil\b/i, "bad" ), new Substitution( /\bugly\b/i, "bad" ), new Substitution( /\bgross\b/i, "bad" ), new Substitution( /\bdisgusting\b/i, "bad" ), new Substitution( /\bball(s?)\b/i, "testicle$1" ), new Substitution( /\bnut(s?)\b/i, "testicle$1" ), new Substitution( /\basshole\b/i, "anus" ), new Substitution( /\bbutthole\b/i, "anus" ), new Substitution( /\bhole\b/i, "anus" ), new Substitution( /\bboner\b/i, "erection" ), new Substitution( /\bhard[ -]*on\b/i, "erection" ), new Substitution( /\bjerk it\b/i, "jack off" ), new Substitution( /\bjack itb/i, "jack off" ), new Substitution( /\bjerk off\b/i, "jack off" ), new Substitution( /\bstroke it\b/i, "jack off" ), new Substitution( /\bx+[ -]?mas+\b/i, "christmas" ), new Substitution( /\bch?rist?mas+\b/i, "christmas" ), new Substitution( /\bnope\b/i, "no" ), new Substitution( /\bnah\b/i, "no" ), new Substitution( /\byeah\b/i, "yes" ), new Substitution( /\byup\b/i, "yes" ) ]; var subs = [ new Substitution( /\byes\b/i, "aye" ), new Substitution( /\bno\b/i, "nay" ), new Substitution( /\bin love\b/i, "smitten" ), new Substitution( /\boh my god\b/i, "saints be praised" ), new Substitution( /\bomg\b/i, "saints be praised" ), new Substitution( /\bwow\b/i, "saints be praised" ), new Substitution( /\bmy god\b/i, "saints be praised" ), new Substitution( /\bhaha\b/i, "'ar-dee-'ar" ), new Substitution( /\bplease\b/i, "if ye be so inclined" ), new Substitution( /\bhe (is|was) (\w+ )talking\b/i, "$1 waggin' 'ims beard" ), new Substitution( /\bshe (is|was) (\w+ )talking\b/i, "$1 waggin' 'er beard" ), new Substitution( /\b(you) (\w+ )talking\b/i, "$1 waggin' yer beards" ), new Substitution( /\b(we('?re)) talking\b/i, "$1 waggin' our beards" ), new Substitution( /\b(he's) talking\b/i, "$1 waggin' 'ims beard" ), new Substitution( /\b(she's) talking\b/i, "$1 waggin' 'er beard" ), new Substitution( /\b(they('?re)) talking\b/i, "$1 waggin' thems beards" ), new Substitution( /\b(you)? talking\b/i, "$1 waggin' yer beard" ), new Substitution( /\bfriend(s?)b/i, "matey$1" ), new Substitution( /\bbetween\b/i, "twixt" ), new Substitution( /\bbutt\b/i, "booty" ), new Substitution( /\bfuck(\w*)\b/i, "plunder$1" ), new Substitution( /\bcum(\w*)\b/i, "blast$1" ), new Substitution( /\bhello\b/i, ["ahoy","avast"] ), new Substitution( /\bbreast(\w*)/i, "bosom$1" ), new Substitution( /\bpenis/i, "sword" ), new Substitution( /\bpenises/i, "swords" ), new Substitution( /\bvagina(s?)/i, "mossy pit$1" ), new Substitution( /\byou're\b/i, "yer" ), new Substitution( /\byour\b/i, "yer'n" ), new Substitution( /\byours\b/i, "yers" ), new Substitution( /\byou\b/i, "ye" ), new Substitution( /\bmy\b/i, "me" ), new Substitution( /\bhis\b/i, "'ims" ), new Substitution( /\bhers\b/i, "'ers" ), new Substitution( /\bthere(s?)\b/i, "thar$1" ), new Substitution( /\bthem\b/i, "thems" ), new Substitution( /\btheirs?\b/i, "thems" ), new Substitution( /\bwhen\b/i, "whence" ), new Substitution( /\bwith\b/i, "wit'" ), new Substitution( /\bhe'?(s?)\b/i, "'im$1" ), new Substitution( /\bis\b/i, "be" ), new Substitution( /\bwas\b/i, "were" ), new Substitution( /\bare\b/i, "be" ), new Substitution( /\bfor\b/i, "fer" ), new Substitution( /\bpants\b/i, "breeches" ), new Substitution( /\bbriefs\b/i, "knickers" ), new Substitution( /\bfeet\b/i, "paddles" ), new Substitution( /\bfoot\b/i, "paddle" ), new Substitution( /\bcar\b/i, "ship" ), new Substitution( /\bleader\b/i, "captain" ), new Substitution( /\bboss\b/i, "captain" ), new Substitution( /\bwhore(s?)\b/i, "harlot$1" ), new Substitution( /\bbeautiful\b/i, "captivatin'" ), new Substitution( /\bhot\b/i, "blisterin'" ), new Substitution( /\bsexy\b/i, "blisterin'" ), new Substitution( /\bbye\b/i, "fare thee well" ), new Substitution( /\bbad\b/i, "vile" ), new Substitution( /\btoken(s?)\b/i, "treasure$1" ), new Substitution( /\btip(s?)\b/i, "treasure$1" ), new Substitution( /\bbaby\b/i, "me hearty" ), new Substitution( /\bh(\w+)/i, "'$1" ), new Substitution( /(\w+)ing\b/i, "$1in'" ), new Substitution( /\bfine\b/i, "dandy" ), new Substitution( /\bwtf\b/i, "shiver me timbers" ), new Substitution( /\bget\b/i, "gets" ), new Substitution( /\binto\b/i, "inter" ), new Substitution( /\bdon'?t know\b/i, "couldn't fathom" ), new Substitution( /\bpretty\b/i, "purdy" ), new Substitution( /\bshirt\b/i, "frock" ), new Substitution( /\bunder/i, "unner" ), new Substitution( /\bweird\b/i, "unnatural" ), new Substitution( /\bnice\b/i, "mighty ripe" ), new Substitution( /\bloser(s?)\b/i, "landlubber$1" ), new Substitution( /\banus\b/i, "starfish" ), new Substitution( /\btesticle(s?)\b/i, "barnacle$1" ), new Substitution( /\bover\b/i, "o'er" ), new Substitution( /\bmyself\b/i, "meself" ), new Substitution( /\berection\b/i, "driftwood" ), new Substitution( /\bfilipino(s?)\b/i, "savage$1" ), new Substitution( /\bcut\b/i, "unsheathed" ), new Substitution( /\buncut\b/i, "sheathed" ), new Substitution( /\bto\b/i, "ter" ), new Substitution( /\bcute\b/i, "purdy" ), new Substitution( /\bsee\b/i, "sees" ), new Substitution( /\bforeskin\b/i, "jib" ), new Substitution( /\bjack off\b/i, "walk the plank" ), new Substitution( /\bchristmas\b/i, "THE HOLIDAY THAT SHALL NOT BE NAMED" ) ]; var decorations = [ new Decoration( "arrr!", 0.1 ), new Decoration( "shiver me timbers!", 0.025 ) ]; var _this = this; var exceptions = []; this.enabled = false; var init = function( ) { platform.onMessage( cbOnMessage ); } this.addException = function( username ) { exceptions.push( username ); } this.clearExceptions = function( ) { exceptions = []; } this.toggleException = function( username ) { for (var i = 0; i < exceptions.length; ++i) { if (exceptions[i] == username) { exceptions.splice( i, 1 ); return; } } exceptions.push( username ); } var cbOnMessage = function( cbMsg ) { if (_this.enabled) { if (_this.isExempt( cbMsg.user )) return; cbMsg.m = toPirate( canonicalize( cbMsg.m ) ); } } this.isExempt = function( username ) { if (username == platform.room_slug) return true; for (var i = 0; i < exceptions.length; ++i) { if (exceptions[i] == username) return true; } return false; } var canonicalize = function( text ) { for (var i = 0; i < canonicalSubs.length; ++i) { var sub = canonicalSubs[i]; text = sub.apply( text ); } return text; } var toPirate = function( text ) { for (var i = 0; i < subs.length; ++i) { var sub = subs[i]; text = sub.apply( text ); } return decoratePirate( text ); } var decoratePirate = function( text ) { for (var i = 0; i < decorations.length; ++i) { var decor = decorations[i]; if (Math.random( ) < decor.probability) { if (Math.random( ) > 0.5) text = text + " " + decor.text; else text = decor.text + " " + text; break; } } return text; } init( ); } var CommandParser = function( ) { var events; var init = function( ) { model = platform.room_slug; events = new Events( [ "onCommandError", "onPirateCommand" ] ); platform.onMessage( cbOnMessage ); } this.subscribe = function( event, handler ) { events.add( event, handler ); } var cbOnMessage = function( cbMessage ) { if (parseMessage( cbMessage.user, cbMessage.m )) cbMessage['X-Spam'] = true; } var parseMessage = function( username, msg ) { if (msg.indexOf( "/" ) == 0) { msg = msg.substr( 1 ); return parseCommand( username, msg ); } } var parseCommand = function( username, msg ) { var cmd = getCommandAndPayload( msg ); if (cmd == null) return false; switch (cmd.cmd) { case "pirate": parsePirateCommand( username, cmd.payload ); return true; default: return false; } } var getCommandAndPayload = function( msg ) { var match = /^(\S+)(?:\s+(\S.*))?/.exec( msg ); if (match == null) return null; return { 'cmd' : match[1], 'payload' : typeof match[2] == "string" ? match[2] : "" }; } var parsePirateCommand = function( username, payload ) { events.raise( "onPirateCommand", username ); } init( ); } new (function( ) { var commandParser = new CommandParser( ); var pirateFilter = new PirateFilter( ); var tipRankings = new TipRankings( ); var init = function( ) { commandParser.subscribe( "onPirateCommand", onPirateCommand ); tipRankings.subscribe( "onTipLeaderChange", onTipLeaderChange ); pirateFilter.enabled = true; } var onPirateCommand = function( username ) { if (username == platform.room_slug) togglePirateFilter( ); else if (tipRankings.isLeader( username )) togglePirateException( username ); } var onTipLeaderChange = function( tipper ) { pirateFilter.clearExceptions( ); if (tipper) { pirateFilter.addException( tipper.username ); notify( tipper.username, "As first mate, you are automatically exempt from the pirate filter." + " Type /pirate to opt in." ); } } var togglePirateFilter = function( ) { pirateFilter.enabled = !pirateFilter.enabled; if (pirateFilter.enabled) announce( "Pirate filter enabled." ); else announce( "Pirate filter disabled." ); } var togglePirateException = function( username ) { pirateFilter.toggleException( username ); if (pirateFilter.isExempt( username )) notify( username, "You are now exempt from the pirate filter." ); else notify( username, "You have opted back in to the pirate filter." ); } var announce = function( msg ) { if (msg.length > 0) platform.chatNotice( msg, '', '#FFFFFF', '#000000', 'bold' ); } var notify = function( username, msg ) { if (msg.length > 0) platform.chatNotice( msg, username, '#000000', '#FFFFFF', 'bold' ); } init( ); })( );
© Copyright Freesexcam 2011- 2024. All Rights Reserved.