Bots Home
|
Create an App
C_Frame Testing
Author:
thmo_02
Description
Source Code
Launch Bot
Current Users
Created by:
Thmo_02
/** * c_frame - A simple CB bot framework * @version v0.0.1 * @author root202 * @link * @license Proprietary */ "use strict";var _this=void 0;function dynamicSort(n){var a=1;return"-"===n[0]&&(a=-1,n=n.substr(1)),function(e,t){return(e[n]<t[n]?-1:e[n]>t[n]?1:0)*a}}var frame={state:{},modules:[],settings:{},commands:{},global_alias_map:{},msg_pipeline:[],initial_top_levels:[{command:"help",alias:["?"],callback:function(e,t,n){cb.sendNotice("frame provides a framework for loading modules. To see the list of modules, use the /"+e.cmd_prefix+" list_modules command",n.user),cb.sendNotice("To see the list of top-level commands, use the '/"+e.cmd_prefix+" help' command",n.user)}},{command:"list_modules",alias:["list"],callback:function(e,t,n){var a=!0,r=!1,i=void 0;try{for(var l,o=e.modules[Symbol.iterator]();!(a=(l=o.next()).done);a=!0){var s=l.value;cb.sendNotice("The module "+s.name+" is loaded, to talk to it use '/"+e.cmd_prefix+" "+s.cmd_prefix+" <command_here>'",n.user)}}catch(e){r=!0,i=e}finally{try{a||null==o.return||o.return()}finally{if(r)throw i}}}}],initial_modules:[{name:"cb_hooks",cmd_prefix:null,event_listeners:[{event:"init",callback:function(m,e){2<arguments.length&&void 0!==arguments[2]&&arguments[2];cb.log("running callback for cb_hooks init event"),cb.onTip(function(e){m.event_bus.triggerEvent(m,"tip",{tip:e})}),cb.onMessage(function(e){if(cb.log("got message "+e.m),"/"===e.m[0]){cb.log(e.m+" starts with `/`");var t=e.m.split(" ");if(m.global_alias_map.hasOwnProperty(t[0])){cb.log(t[0]+" is a registered global alias, executing the command");var n=m.global_alias_map[t[0]].callback(m,t[0],e);return null!=n&&(e=n),e}if(e.m.substring(0,m.cmd_prefix.length+1)==="/"+m.cmd_prefix){if(!t[1]||""===t[1])return cb.log(t[0]+" doesn't have an associated module to look for, ejecting"),e;if(m.top_level_commands.hasOwnProperty(t[1])){cb.log(t[0]+t[1]+" is a registered top-level command, executing");var a=m.top_level_commands[t[1]].callback(m,t[1],e);return null!=a&&(e=a),e}if(!t[2]||""===t[2])return cb.log(e.m+" doesn't have a command for the specified module, ejecting..."),e;var r=m.cmd_prefix+"::"+t[1]+"::"+t[2];if(m.commands.hasOwnProperty(r)){cb.log(e.m+" is a registered module command, executing");var i=m.commands[r].callback(m,t[2],e);return null!=i&&(e=i),e}}}m.event_bus.triggerEvent(m,"message",{message:e}),cb.log(e.m+" is being passed through the message pipeline");var l=!0,o=!1,s=void 0;try{for(var c,d=m.msg_pipeline[Symbol.iterator]();!(l=(c=d.next()).done);l=!0){e=c.value.callback(m,e)}}catch(e){o=!0,s=e}finally{try{l||null==d.return||d.return()}finally{if(o)throw s}}return m.event_bus.triggerEvent(m,"message.post",{message:e}),e}),cb.onEnter(function(e){m.event_bus.triggerEvent(m,"enter",{user:e})}),cb.onLeave(function(e){m.event_bus.triggerEvent(m,"leave",{user:e})})}}],commands:[{command:"help",alias:["?"],callback:function(e,t,n){cb.sendNotice("The cb_hooks module does not have any commands",n.user)}}]}],event_bus:{event_listeners:{},triggerEvent:function(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(cb.log("event "+t+" triggered"),this.event_listeners.hasOwnProperty(t))for(var a in this.event_listeners[t]){var r=this.event_listeners[t][a];r.hasOwnProperty("callback")&&r.callback(e,t,n)}for(var i in this.event_listeners["*"]){var l=this.event_listeners["*"][i];l.hasOwnProperty("callback")&&l.callback(e,t,n)}},addEventListener:function(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,a=3<arguments.length&&void 0!==arguments[3]?arguments[3]:null;cb.log("event listener for "+e+" added"),this.event_listeners.hasOwnProperty(e)||(this.event_listeners[e]=[]),this.event_listeners[e].push({callback:t,priority:n,module:a}),this.event_listeners[e].sort(dynamicSort("-priority"))}},cmd_prefix:"frame",top_level_commands:{},addMessageHandler:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null;this.msg_pipeline.push({callback:e,priority:t,module:n}),cb.log("message handler added to pipeline"),this.msg_pipeline.sort(dynamicSort("-priority"))},addMessageHandlers:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null;return e.forEach(function(e){return _this.addMessageHandler(e,e.hasOwnProperty("priority")?e.priority:0,t)})},addModule:function(e){if(cb.log("module "+e.name+" added"),this.modules.push(e),e.hasOwnProperty("event_listeners")){var t=!0,n=!1,a=void 0;try{for(var r,i=e.event_listeners[Symbol.iterator]();!(t=(r=i.next()).done);t=!0){var l=r.value;this.event_bus.addEventListener(l.event,l.callback,l.hasOwnProperty("priority")?l.priority:0,e)}}catch(e){n=!0,a=e}finally{try{t||null==i.return||i.return()}finally{if(n)throw a}}}if(e.hasOwnProperty("cmd_prefix")&&null!==e.cmd_prefix||(e.cmd_prefix=e.name),e.hasOwnProperty("commands")){var o=!0,s=!1,c=void 0;try{for(var d,m=e.commands[Symbol.iterator]();!(o=(d=m.next()).done);o=!0){var u=d.value;u.module=e;var v=this.cmd_prefix+"::"+e.cmd_prefix+"::"+u.command;if(this.commands[v]=u,cb.log("command "+v+" added for module "+e.name),u.hasOwnProperty("alias")&&0<u.alias.length){var h=!0,g=!1,f=void 0;try{for(var p,_=u.alias[Symbol.iterator]();!(h=(p=_.next()).done);h=!0){var b=p.value,y=frame.cmd_prefix+"::"+e.cmd_prefix+"::"+b;this.commands[y]=u,cb.log(y+" added as an alias to "+v)}}catch(e){g=!0,f=e}finally{try{h||null==_.return||_.return()}finally{if(g)throw f}}}if(u.hasOwnProperty("global_alias")&&0<u.global_alias.length){var w=!0,x=!1,k=void 0;try{for(var O,P=u.global_alias[Symbol.iterator]();!(w=(O=P.next()).done);w=!0){var E=O.value;this.global_alias_map["/"+E]=u,cb.log(E+" added as a global alias to "+v)}}catch(e){x=!0,k=e}finally{try{w||null==P.return||P.return()}finally{if(x)throw k}}}}}catch(e){s=!0,c=e}finally{try{o||null==m.return||m.return()}finally{if(s)throw c}}}if(e.hasOwnProperty("settings")&&0<e.settings.length)for(var S in cb.hasOwnProperty("settings_choices")&&null!=cb.settings_choices&&void 0!==cb.settings_choices||(cb.settings_choices=[]),e.settings){var M=Object.assign({},e.settings[S]);M.name=e.name+"_"+e.settings[S].name,cb.settings_choices.push(M)}},addModules:function(){return(0<arguments.length&&void 0!==arguments[0]?arguments[0]:[]).forEach(function(e){return frame.addModule(e)})},addTopLevelCommand:function(e){if(this.top_level_commands[e.command]=e,cb.log(e.command+" added as a top level command"),e.hasOwnProperty("alias")&&0<e.alias.length){var t=!0,n=!1,a=void 0;try{for(var r,i=e.alias[Symbol.iterator]();!(t=(r=i.next()).done);t=!0){var l=r.value;this.top_level_commands[l]=e,cb.log(l+" added as an alias to top level command "+e.command)}}catch(e){n=!0,a=e}finally{try{t||null==i.return||i.return()}finally{if(n)throw a}}}},addTopLevelCommands:function(){return(0<arguments.length&&void 0!==arguments[0]?arguments[0]:[]).forEach(function(e){return frame.addTopLevelCommand(e)})},init:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[];this.addTopLevelCommands(this.initial_top_levels),this.addModules(this.initial_modules),this.addModules(e);var t=!0,n=!1,a=void 0;try{for(var r,i=this.modules[Symbol.iterator]();!(t=(r=i.next()).done);t=!0){var l=r.value;if(cb.hasOwnProperty("settings")&&l.hasOwnProperty("settings")&&0<l.settings.length){this.settings.hasOwnProperty(l.name)||(this.settings[l.name]={});var o=!0,s=!1,c=void 0;try{for(var d,m=l.settings[Symbol.iterator]();!(o=(d=m.next()).done);o=!0){var u=d.value;cb.log("Setting "+l.name+"_"+u.name+": "+cb.settings[l.name+"_"+u.name]),this.settings[l.name][u.name]=cb.settings[l.name+"_"+u.name]}}catch(e){s=!0,c=e}finally{try{o||null==m.return||m.return()}finally{if(s)throw c}}}}}catch(e){n=!0,a=e}finally{try{t||null==i.return||i.return()}finally{if(n)throw a}}this.event_bus.triggerEvent(this,"init")}}; /** * c_frame - A simple CB bot framework * @version v0.0.1 * @author root202 * @link * @license Proprietary */ "use strict";var demo_module={name:"demo_module",cmd_prefix:null,event_listeners:[{event:"init",callback:function(e,n){2<arguments.length&&void 0!==arguments[2]&&arguments[2]}}],commands:[{command:"help",alias:["?"],callback:function(e,n,l){}}]}; /** * c_frame - A simple CB bot framework * @version v0.0.1 * @author root202 * @link * @license Proprietary */ "use strict";var hightipper_highlight_module={name:"hightipper_highlight_module",cmd_prefix:null,settings:[{name:"highlight_color",type:"str",label:"Highlight Color for HT: #",minLength:6,maxLength:6,defaultValue:"88ffaa"}],event_listeners:[{event:"init",callback:function(e,t){2<arguments.length&&void 0!==arguments[2]&&arguments[2];cb.log("adding message pipeline command for tipper message highlight"),e.addMessageHandler(function(e,t){return e.state.hasOwnProperty(this.name)&&t.user==e.state[this.name].from_user&&(t.background="#"+e.settings[this.name].highlight_color),t},0)}},{event:"tip",callback:function(e,t){var i=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};cb.log("user "+i.tip.from_user+" tipped!"),(!e.state.hasOwnProperty("high_tipper")||i.tip.amount>e.state.high_tipper.amount)&&(cb.log("new high tiper!"),e.state.high_tipper=i.tip)}}],commands:[]}; /** * c_frame - A simple CB bot framework * @version v0.0.1 * @author root202 * @link * @license Proprietary */ "use strict";var ticker_module={name:"ticker_module",cmd_prefix:null,settings:[],event_listeners:[{event:"init",callback:function(t,e){var i=this;2<arguments.length&&void 0!==arguments[2]&&arguments[2];t.state[this.module.name]={};!function e(){t.event_bus.triggerEvent(t,"tick",{}),t.state[i.module.name].ticker=cb.setTimeout(e,1e3)}()}}],commands:[]}; /** * c_frame - A simple CB bot framework * @version v0.0.1 * @author root202 * @link * @license Proprietary */ "use strict";var tipper_data={name:"tipper_data",cmd_prefix:null,settings:[],event_listeners:[{event:"init",callback:function(t,e){2<arguments.length&&void 0!==arguments[2]&&arguments[2];t.state[tipper_data.name]={all_tippers:[],highest_tipper:null}}},{event:"tip",callback:function(t,e){var i=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},p=t.state[tipper_data.name],a=p.all_tippers.filter(function(t){return t.username===i.tip.from_user})[0];a&&null!=a&&void 0!==a||(cb.log("Adding new tipper ".concat(i.tip.from_user," to the database!")),a={username:i.tip.from_user},p.all_tippers.push(a)),a.hasOwnProperty("tip_total")?a.tip_total+=parseInt(i.tip.amount):a.tip_total=parseInt(i.tip.amount);var r=-1;a.hasOwnProperty("highest_tip")&&(r=a.highest_tip),a.highest_tip=Math.max(r,parseInt(i.tip.amount)),a.highest_tip>r&&cb.log("New High Tip for ".concat(i.tip.from_user)),(null==p.highest_tipper||a.highest_tip>p.highest_tipper.highest_tip||a===p.highest_tipper&&a.highest_tip>r)&&(p.highest_tipper=a,t.event_bus.triggerEvent(t,"high_tipper",{tipper:p.highest_tipper})),p.all_tippers.sort(dynamicSort("-tip_total"))}},{event:"high_tipper",callback:function(t,e){var i=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};cb.log("".concat(i.tipper.username," tipped ").concat(i.tipper.highest_tip," and became the new Highest Tipper!"))}}],commands:[]}; frame.addModule(demo_module); frame.addModule(hightipper_highlight_module); frame.addModule(ticker_module); frame.addModule(tipper_data) frame.init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.