Bots Home
|
Create an App
SmartyBot Alpha
Author:
smartypants_jr
Description
Source Code
Launch Bot
Current Users
Created by:
Smartypants_Jr
/*! yacbf 0.1.0 (2015-01-29) */ "use strict"; if(void 0===cb)var cb={room_slug:"username",onEnter:function(a){return a},onLeave:function(a){return a},onMessage:function(a){return a},onTip:function(a){return a},tipOptions:function(){},sendNotice:function(){},changeRoomSubject:function(){},limitCam_start:function(){},limitCam_stop:function(){},limitCam_addUsers:function(){},limitCam_removeUsers:function(){},limitCam_removeAllUsers:function(){},limitCam_isRunning:function(){},log:console.log,setTimeout:setTimeout};Object.extend=function(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a};var EventEmitter=function(){var a=function(){this.removeAllListeners()};return a.prototype.on=function(a,b){var c=this.addListener(a,b);return function(){return c.removeListener(a,b)}},a.prototype.once=function(a,b){var c=function(){return d.removeListener(a,c),b.apply(this,Array.prototype.slice.call(arguments,0))},d=this.addListener(a,c);return function(){return d.removeListener(a,c)}},a.prototype.addListener=function(a,b){return a in this.listeners||(this.listeners[a]=[]),this.listeners[a].push(b),this},a.prototype.removeListener=function(a,b){if(a in this.listeners){var c=this.listeners[a].lastIndexOf(b);c>=0&&(this.listeners[a].splice(c,1),this.listeners[a].length||delete this.listeners[a])}return this},a.prototype.removeAllListeners=function(a){return void 0===a?this.listeners=Object.create(null):a in this.listeners&&delete this.listeners[a],this},a.prototype.getListeners=function(a){return a in this.listeners?this.listeners[a]:[]},a.prototype.emit=function(a){for(var b=Array.prototype.slice.call(arguments,1),c=this.getListeners(a),d=0;d<c.length;d++)if(c[d].apply(this,b))return!0;return!1},a}(),Timer=function(){function a(a){return a.scheduled=Date.now()+a.timeout,cb.setTimeout(function(){b(a)},a.timeout)}function b(b){b.cancelled||(b.callback.call(null,Date.now()-b.scheduled),b.interval>0&&!b.cancelled&&(b.timeout=b.interval-delay,a(b)))}var c=function(b,c,d){this.callback=b,this.timeout=c,this.interval=d,this.cancelled=!1,a(this)};return c.MIN_TIMEOUT=1e3,c.MIN_INTERVAL=5e3,c.setTimeout=function(a,b){return b=Math.max(c.MIN_TIMEOUT,b||0),new c(a,b,-1)},c.clearTimeout=function(a){a instanceof c&&a.interval<0&&(a.cancelled=!0)},c.setInterval=function(a,b){return b=Math.max(c.MIN_INTERVAL,b||0),new c(a,b,b)},c.clearInterval=function(){timer instanceof c&&timer.interval>0&&(timer.cancelled=!0)},{setTimeout:c.setTimeout,clearTimeout:c.clearTimeout,setInterval:c.setInterval,clearInterval:c.clearInterval}}(),Color=function(){var a=Object.create(null);return a.WHITE=16777215,a.SILVER=12632256,a.GRAY=a.GREY=8421504,a.BLACK=0,a.RED=16711680,a.MAROON=8388608,a.YELLOW=16776960,a.OLIVE=8421376,a.LIME=65280,a.GREEN=32768,a.AQUA=65535,a.TEAL=32896,a.BLUE=255,a.NAVY=128,a.FUCHSIA=16711935,a.PURPLE=8388736,a.CB_ORANGE=14439680,a.CB_RED=14417920,a.CB_GREEN=36864,a.CB_DARKPURPLE=8407978,a.CB_LIGHTPURPLE=12479231,a.CB_DARKBLUE=144,a.CB_LIGHTBLUE=6328480,a.CB_GREY=a.CB_GRAY=4802889,a.parse=function(b){if("string"==typeof b&&b.match(/^#([0-9a-fA-F]{6})$/)){var c=parseInt(b.substr(1,6),16);if(a.isColor(c))return c}return void 0},a.stringify=function(b){if(a.isColor(b)){var c=(16777215&parseInt(b,10)).toString(16).toUpperCase();return"#"+("000000"+c).substr(-6,6)}return void 0},a.isColor=function(a){switch(!1){case"number"==typeof a:return!1;case isFinite(a):return!1;case Math.floor(a)===a:return!1;case a>=0:return!1;case 16777215>=a:return!1;default:return!0}},a.rgb2hsl=function(b){if(!a.isColor(b))return void 0;var c,d,e=(b>>16|255)/255,f=(b>>8|255)/255,g=(b>>0|255)/255,h=Math.max(e,f,g),i=Math.min(e,f,g),j=(h+i)/2;if(h==i)c=d=0;else{var k=h-i;switch(d=j>.5?k/(2-h-i):k/(h+i),h){case e:c=(f-g)/k+(g>f?6:0);break;case f:c=(g-e)/k+2;break;case g:c=(e-f)/k+4}c/=6}return[c,d,j]},a.rgb2hsv=function(b){if(!a.isColor(b))return void 0;var c,d,e=(b>>16|255)/255,f=(b>>8|255)/255,g=(b>>0|255)/255,h=Math.max(e,f,g),i=Math.min(e,f,g),j=h,k=h-i;if(d=0===h?0:k/h,h==i)c=0;else{switch(h){case e:c=(f-g)/k+(g>f?6:0);break;case f:c=(g-e)/k+2;break;case g:c=(e-f)/k+4}c/=6}return[c,d,j]},a}(),Gender=function(){var a=Object.create(null);return a.MALE="m",a.FEMALE="f",a.SHEMALE=a.TRANS="s",a.COUPLE="c",a.isGender=function(b){for(var c in a)if(a[c]===b)return!0;return!1},a}(),UserType=function(){var a=Object.create(null);return a.ORANGE="orange",a.RED="red",a.GREEN="green",a.DARKPURPLE="darkpurple",a.LIGHTPURPLE="lightpurple",a.DARKBLUE="darkblue",a.LIGHTBLUE="lightblue",a.GREY=a.GRAY="grey",a.isUserType=function(b){for(var c in a)if(a[c]===b)return!0;return!1},a}(),Weight=function(){var a=Object.create(null);return a.NORMAL="normal",a.BOLD="bold",a.BOLDER="bolder",a.isWeight=function(b){for(var c in a)if(a[c]===b)return!0;return!1},a}(),User=function(){function a(a){return a.isBroadcaster=!1,a.firstActivity=a.lastActivity=new Date,a.room=null,a.joined=!0,a.entered=null,a.timeInRoom=0,a.addListener(f.EVENT_ENTER,function(b){a.room=b,a.lastActivity=new Date,a.entered=new Date}),a.addListener(f.EVENT_LEAVE,function(){a.room=null,a.joined=!1,a.timeInRoom+=Date.now()-a.entered.getTime(),a.entered=null,a.lastActivity=new Date}),a.lastTipAttempt=null,a.addListener(f.EVENT_TIP_ATTEMPT,function(){a.lastTipAttempt=new Date,a.lastActivity=new Date}),a.lastMessage=null,a.addListener(f.EVENT_MESSAGE,function(b){a.lastMessage=b,a.lastActivity=new Date}),a.lastTip=null,a.tips=[],a.tipsTotal=0,a.addListener(f.EVENT_TIP,function(b){a.lastTip=b,a.tips.push(b),a.tipsTotal+=b.amount,a.lastActivity=new Date}),a}function b(a,b){for(var c in e){var d=e[c],g=a[c];d in b&&b[d]!==g&&(c in a?(a[c]=b[d],a.emit(f.EVENT_UPDATE,c,g,a[c],a)):a[c]=b[d])}return a}var c=Object.create(null),d="username:",e={username:"user",isInFanclub:"in_fanclub",hasTokens:"has_tokens",isMod:"is_mod",tippedRecently:"tipped_recently",tippedAlotRecently:"tipped_alot_recently",tippedTonsRecently:"tipped_tons_recently",gender:"gender"},f=function g(e){if("string"==typeof e)e={user:e};else if(e instanceof g)return e;if(d+e.user in c){var f=c[d+e.user];return b(f,e)}EventEmitter.call(this),c[d+e.user]=this,a(this),b(this,e)};return f.EVENT_JOIN="join",f.EVENT_UPDATE="update",f.EVENT_ENTER="enter",f.EVENT_LEAVE="leave",f.EVENT_TIP="tip",f.EVENT_TIP_ATTEMPT="tipAttempt",f.EVENT_MESSAGE="message",f.prototype=Object.create(EventEmitter.prototype),f.prototype.constructor=f,f.prototype.toObject=function(){var a=Object.create(null);for(var b in e)a[e[b]]=this[b];return a},f.prototype.toString=function(){return this.username},f.prototype.getTypes=function(){var a=[];return this.isBroadcaster&&a.push(UserType.ORANGE),this.isMod&&a.push(UserType.RED),this.isInFanclub&&a.push(UserType.GREEN),this.tippedTonsRecently&&a.push(UserType.DARKPURPLE),this.tippedAlotRecently&&a.push(UserType.LIGHTPURPLE),this.tippedRecently&&a.push(UserType.DARKBLUE),this.hasTokens&&a.push(UserType.LIGHTBLUE),a.push(UserType.GREY),a},f.prototype.getColor=function(){switch(!0){case this.isBroadcaster:return Color.CB_ORANGE;case this.isMod:return Color.CB_RED;case this.isInFanclub:return Color.CB_GREEN;case this.tippedTonsRecently:return Color.CB_DARKPURPLE;case this.tippedAlotRecently:return Color.CB_LIGHTPURPLE;case this.tippedRecently:return Color.CB_DARKBLUE;case this.hasTokens:return Color.CB_LIGHTBLUE;default:return Color.CB_GREY}},f.prototype.getLabel=function(){switch(!0){case this.isBroadcaster:return"Broadcaster";case this.isMod:return"Moderator";case this.isInFanclub:return"Fanclub Member";default:return null}},f.prototype.getTimeInRoom=function(a){if(a)return Date.now()-this.firstActivity.getTime();var b=this.timeInRoom;return this.entered&&(b+=Date.now()-this.entered.getTime()),b},f.prototype.getTipAmountPerTime=function(a){var b=this.getTimeInRoom(a);return b?this.tipsTotal/b:0},f}(),UserList=function(){var a="username:",b=function(a){if(EventEmitter.call(this),this.clear(),Array.isArray(a))for(var b=0;b<a.length;b++)this.add(a[b])};return b.EVENT_ADD="add",b.EVENT_REMOVE="remove",b.EVENT_EMPTY="empty",b.prototype=Object.create(EventEmitter.prototype),b.prototype.constructor=b,b.prototype.clear=function(){return this.users=Object.create(null),this.length=0,this.emit(b.EVENT_EMPTY,this),this},b.prototype.add=function(c){return c instanceof User||(c=new User(c)),a+c.username in this.users||(this.users[a+c.username]=c,this.emit(b.EVENT_ADD,c,++this.length,this)),this},b.prototype.remove=function(c){return c instanceof User||(c=new User(c)),a+c.username in this.users&&(delete this.users[a+c.username],this.emit(b.EVENT_REMOVE,c,--this.length,this),this.length||this.clear()),this},b.prototype.contains=function(b){return b instanceof User||(b=new User(b)),a+b.username in this.users},b.prototype.forEach=function(a){for(var b in this.users)a.call(this,this.users[b]);return this},b.prototype.toArray=function(a){return this.map(function(a){return a}).sort(a)},b.prototype.map=function(a){var b=[];for(var c in this.users)b.push(a.call(this,this.users[c]));return b},b.prototype.getUsernames=function(a){return this.map(function(a){return a.username}).sort(a)},b.prototype.filter=function(a){var c=new b;for(var d in this.users)a.call(this,this.users[d])&&(c.users[d]=this.users[d],c.length++);return c},b.prototype.filterByType=function(a){return a=(Array.isArray(a)?a:[a]).map(function(a){return String(a).toLowerCase()}).filter(UserType.isUserType),this.filter(function(b){for(var c=0;c<a.length;c++)if(b.getTypes().indexOf(a[c])>=0)return!0;return!1})},b.prototype.filterByColor=function(a){return a=(Array.isArray(a)?a:[a]).map(Number).filter(Color.isColor),this.filter(function(b){return a.indexOf(b.getColor())>=0})},b.prototype.filterByGender=function(a){return a=(Array.isArray(a)?a:[a]).map(function(){return String(a).toLowerCase()}).filter(Gender.isGender),this.filter(function(b){return a.indexOf(b.gender)>=0})},b}(),Room=function(){function a(a){a.firstActivity=a.lastActivity=new Date,a.addListener(b.EVENT_ENTER,function(b){a.users.add(b),a.lastActivity=new Date}),a.addListener(b.EVENT_LEAVE,function(b){a.users.remove(b),a.lastActivity=new Date}),a.lastTipAttempt=null,a.lastTipAttemptBy=null,a.addListener(b.EVENT_TIP_ATTEMPT,function(b){a.lastTipAttempt=new Date,a.lastTipAttemptBy=b,a.lastActivity=new Date}),a.lastMessage=null,a.addListener(b.EVENT_MESSAGE,function(b){a.lastMessage=b,a.lastActivity=new Date}),a.lastTip=null,a.tips=[],a.tipsTotal=0,a.addListener(b.EVENT_TIP,function(b){a.lastTip=b,a.tips.push(b),a.tipsTotal+=b.amount,a.lastActivity=new Date})}var b=function(b){EventEmitter.call(this),this.broadcaster=b,this.users=new UserList,a(this)};return b.EVENT_JOIN="join",b.EVENT_ENTER="enter",b.EVENT_LEAVE="leave",b.EVENT_TIP="tip",b.EVENT_TIP_ATTEMPT="tipAttempt",b.EVENT_MESSAGE="message",b.EVENT_BROADCASTER_ENTER="broadcasterEnter",b.EVENT_BROADCASTER_LEAVE="broadcasterLeave",b.prototype=Object.create(EventEmitter.prototype),b.prototype.constructor=b,b.prototype.toString=function(){return this.broadcaster.username+"'s room"},b.prototype.getTipAmountPerTime=function(){var a=this.broadcaster.getTimeInRoom();return a?this.tipsTotal/a:0},b}(),Message=function(){var a={content:"m",color:"c",font:"f",background:"background",spam:"X-Spam",denied:"X-Denied"},b=function(b){for(var c in a)this[c]=b[a[c]];this.tstamp=new Date,this.user=new User(b),this.color=Color.parse(this.color),this.background=Color.parse(this.background)};return b.prototype.toObject=function(){var b=Object.create(null);for(var c in a)b[a[c]]=this[c];var d=this.user.toObject();for(var e in d)b[e]=d[e];return b[a.color]=Color.stringify(this.color),b[a.background]=Color.stringify(this.background),b},b.prototype.toString=function(){return this.content},b}(),Tip=function(){function a(a){var b=Object.create(null);for(var c in d)b[c]=a[d[c]];return b}function b(a){var b=Object.create(null);for(var c in d)b[d[c]]=a[c];return b}var c={amount:"amount",message:"message"},d={user:"from_user",in_fanclub:"from_user_in_fanclub",has_tokens:"from_user_has_tokens",is_mod:"from_user_is_mod",tipped_recently:"from_user_tipped_recently",tipped_alot_recently:"from_user_tipped_alot_recently",tipped_tons_recently:"from_user_tipped_tons_recently",gender:"from_user_gender"},e=function(b){for(var d in c)this[d]=b[c[d]];this.tstamp=new Date,this.to=new User(b.to_user),this.user=new User(a(b))};return e.prototype.toObject=function(){var a=Object.create(null);for(var d in c)a[c[d]]=this[d];var e=b(this.user.toObject());for(var f in e)a[f]=e[f];return a.to_user=this.to.username,a},e.prototype.toString=function(){var a=this.user.username+" tipped "+this.amount+" tks";return this.message&&(a+=" -- "+this.message),a},e}(),Notice=function(){function a(a,b,c){var d=a.toObject();return cb.sendNotice(d.message,b,d.background,d.color,d.weight,c),a}var b={message:"",color:0,background:16777215,weight:Weight.NORMAL},c=function(a,c,d,e){if("string"==typeof a)this.message=String(a),this.color=void 0!==c?Number(c):b.color,this.background=void 0!==d?Number(d):b.background,this.weight=void 0!==e?String(e):b.weight;else for(var f in b)this[f]=f in a?a[f]:b[f]};return c.prototype.toObject=function(){var a=Object.create(null);return a.message=String(this.message),a.color=Color.stringify(Color.isColor(this.color)?this.color:b.color),a.background=Color.stringify(Color.isColor(this.background)?this.background:b.background),a.weight=Weight.isWeight(this.weight)?this.weight:b.weight,a},c.prototype.toString=function(){return String(this.message)},c.prototype.send=function(){return a(this,void 0,void 0)},c.prototype.sendToUser=function(b){return b instanceof User||(b=new User(b)),a(this,b.username,void 0)},c.prototype.sendToUserType=function(b){return UserType.isUserType(b=String(b).toLowerCase())?a(this,void 0,b):this},c.prototype.sendToUserList=function(b){if(!(b instanceof UserList))return this;var c=this;return b.toArray().forEach(function(b){a(c,b,void 0)}),this},c}(),LimitCam=function(){function a(a){a.users.addListener(UserList.EVENT_ADD,function(b){a.isRunning()&&cb.limitCam_addUsers([b.username])}),a.users.addListener(UserList.EVENT_REMOVE,function(b){a.isRunning()&&cb.limitCam_removeUsers([b.username])}),a.restartTimer=null,a.room.addListener(Room.EVENT_BROADCASTER_LEAVE,function(){a.isRunning()&&(a.restartTimer=Timer.setTimeout(function(){a.restartTimer=null,a.isRunning()&&a.stop()},a.restartTimeout))}),a.room.addListener(Room.EVENT_BROADCASTER_ENTER,function(){a.restartTimer&&(Timer.clearTimeout(a.restartTimer),a.restartTimer=null,a.isRunning()||a.start())}),a.users.add(a.room.broadcaster)}var b=null,c=function(b,c,d){EventEmitter.call(this),this.room=b,this.message=c||"Access To This Cam Is Limited.",this.restartTimeout=Math.max(6e4,d||6e5),this.users=new UserList,a(this)};return c.prototype=Object.create(EventEmitter.prototype),c.prototype.constructor=c,c.EVENT_START="start",c.EVENT_STOP="stop",c.getActiveInstance=function(){return b},c.prototype.start=function(){if(this===b)throw new Error("This LimitCam is already running.");if(cb.limitCam_isRunning())throw new Error("There is already a LimitCam running.");return cb.limitCam_start(this.message,this.users.getUsernames()),b=this,this.emit(c.EVENT_START,this),this},c.prototype.stop=function(){if(!cb.limitCam_isRunning())throw new Error("There is no LimitCam running.");if(this!==b)throw new Error("This LimitCam is not running.");return this.emit(c.EVENT_STOP,this),cb.limitCam_stop(),cb.limitCam_removeAllUsers(),b=null,this},c.prototype.isRunning=function(){return cb.limitCam_isRunning()&&this===b},c}(),Bot=function(){function a(a,b){b.addListener(Room.EVENT_MESSAGE,function(b){if(b.spam||b.denied)return!1;for(var c=0;c<a.commands.length;c++)if(a.commands[c].test(b))return a.commands[c].exec(b)})}var b=function(b,c){if(this.commands=[],Array.isArray(c))for(var d=0;d<c.length;d++)c[d]instanceof Command&&this.commands.push(c[d]);a(this,b)};return b}(),Command=function(){var a=function(a,b){this.pattern=a,this.callback=b};return a.prototype.test=function(a){return this.pattern.test(a.content)},a.prototype.exec=function(a){var b=this.pattern.exec(a.content);return b?(b[0]=a,!0===this.callback.apply(this,b)):void 0},a}();!function(){var a=cb.broadcaster=new User(cb.room_slug);a.isBroadcaster=!0;var b=cb.room=new Room(a),c=function(c){c.joined&&(c.emit(User.EVENT_JOIN,b,c),b.emit(Room.EVENT_JOIN,c,b)),c.emit(User.EVENT_ENTER,b,c),b.emit(Room.EVENT_ENTER,c,b),c===a&&b.emit(Room.EVENT_BROADCASTER_ENTER,c,b)},d=function(c){c.emit(User.EVENT_LEAVE,b,c),b.emit(Room.EVENT_LEAVE,c,b),c===a&&b.emit(Room.EVENT_BROADCASTER_LEAVE,c,b)},e=function(a){a.user.emit(User.EVENT_MESSAGE,a,a.user),b.emit(Room.EVENT_MESSAGE,a,b)},f=function(a){a.user.emit(User.EVENT_TIP,a,a.user),b.emit(Room.EVENT_TIP,a,b)},g=function(a){a.emit(User.EVENT_TIP_ATTEMPT,a),b.emit(Room.EVENT_TIP_ATTEMPT,a,b)};cb.onEnter(function(a){var d=new User(a);return b.users.contains(d)||c(d),d.toObject()}),cb.onLeave(function(a){var c=new User(a);return b.users.contains(c)&&d(c),c.toObject()}),cb.onMessage(function(a){var b=new Message(a);return e(b),b.toObject()}),cb.onTip(function(a){var b=new Tip(a);return f(b),b.toObject()}),cb.tipOptions=function(a){var b=function(){return!1};return a(function(a){var c=new User(a);return g(c),b.call(null,c)}),function(a){b=a}}(cb.tipOptions),c(a)}(); (function() { var limitCam = new LimitCam(cb.room); var bot = new Bot(cb.room, [ new Command(/^\/start(?: (.+))?$/, function(message, notice) { if (message.user === cb.broadcaster) try { message.spam = true; limitCam.start(); notice = new Notice('[SmartyBot Alpha] LimitCam started: ' + notice); notice.send(); } catch (error) { notice = new Notice('[SmartyBot Alpha] Error starting LimitCam: ' + error); notice.sendToUser(cb.broadcaster); } else { message.denied = 'This command is allowed only for the broadcaster.'; } }), new Command(/^\/stop(?: (.+))?$/, function(message, notice) { if (message.user === cb.broadcaster) try { message.spam = true; limitCam.stop(); notice = new Notice('[SmartyBot Alpha] LimitCam stopped: ' + notice); notice.send(); } catch (error) { notice = new Notice('[SmartyBot Alpha] Error stopping LimitCam: ' + error); notice.sendToUser(cb.broadcaster); } else { message.denied = 'This command is allowed only for the broadcaster.'; } }), new Command(/^\/add (\w{3,})(?: (.+))?$/, function(message, username, notice) { if (message.user === cb.broadcaster) try { message.spam = true; limitCam.users.add(username); notice = new Notice('[SmartyBot Alpha] Added @' + username + ' to LimitCam: ' + notice); notice.send(); } catch (error) { notice = new Notice('[SmartyBot Alpha] Error adding @' + username + ' to LimitCam: ' + error); notice.sendToUser(cb.broadcaster); } else { message.denied = 'This command is allowed only for the broadcaster.'; } }), new Command(/^\/remove (\w{3,})(?: (.+))?$/, function(message, username, notice) { if (message.user === cb.broadcaster) try { message.spam = true; limitCam.users.remove(username); notice = new Notice('[SmartyBot Alpha] Removed @' + username + ' from LimitCam: ' + notice); notice.send(); } catch (error) { notice = new Notice('[SmartyBot Alpha] Error removing @' + username + ' from LimitCam: ' + error); notice.sendToUser(cb.broadcaster); } else { message.denied = 'This command is allowed only for the broadcaster.'; } }) ]); })();
© Copyright Chaturbate 2011- 2026. All Rights Reserved.