Apps Home
|
Create an App
msg test
Author:
bob
Description
Source Code
Launch App
Current Users
Created by:
Bob
var botName="testbot"; //this needs to be a unique name for your app/bot, it will also be the name used to save data under //and the bot name in the data sent out by the API program var botMsgCounter=0;// counter to differentiate msgs function sendBotMsg(request,name,ob,id){//msg sending function if(request===undefined) {return;} if(ob===undefined){return;} if(name===undefined){return;} if(id===undefined){id="";} var bmsg={"request":request,"name":name,"id":id,"data":ob}; var msgJSON=JSON.stringify(bmsg); var len=msgJSON.length; var len2=Math.ceil(len/100); var obj=[]; var d=botName+'-'+botMsgCounter; botMsgCounter++; for(let i=0;i<len2;i++){ let subEnd=100; let txt=msgJSON.slice(0,subEnd); msgJSON=msgJSON.slice(subEnd); obj[i]='#$& '+d+' '+(i+1)+' of '+len2+' '+'|'+txt; } for(let i=0;i<obj.length;i++){ cb.setTimeout(function(){cb.sendNotice(obj[i], cb.room_slug,"#ff0000");},i*1); } } // to send a msg call sendBotMsg(request,name,ob,id) where ob is an object you want to send to the API program and request is either // "save" var botMsgList=[]; cb.onMessage(function (message) { if(message.user==cb.room_slug){ if(message.m.charAt(0)=='#'){ if(message.m.charAt(1)=='$'){ if(message.m.charAt(2)=='&'){ message['X-Spam'] = true; parseBotMsg(message.m); } } } } return message; }); function botMsg(name,id,index,total,msg){ this.id=id; this.name=name; this.index=index; this.total=total; this.msg=msg; this.type='botmsg'; } function parseBotMsg(msg){ var bm=msg.split(' '); var ids=bm[1].split('-'); if(ids[0]!=botName){return;} var botJSONStart=msg.indexOf('|')+1; var botJSON=msg.substr(botJSONStart); var bmOb=new botMsg(ids[0],ids[1],bm[2],bm[4],botJSON); if(bmOb.total==1){ onBotMsg(bmOb.msg); }else if(bmOb.total>1){ checkBotMsgList(bmOb); } } function checkBotMsgList(ob){ if(botMsgList.length>0){ for(let i=0;i<botMsgList.length;j++){ if(botMsgList[i].id==ob.id){ for(let j=0;j<botMsgList[i].list.length;j++){ if(botMsgList[i].list[j].index==ob.index){ return; } } botMsgList[i].list[botMsgList[i].list.length]=ob; if(botMsgList[i].list.length==ob.total){ botMsgList[i].list.sort(function(a,b){return a.index-b.index}); var x=botMsgList[i].list[0]; for(let k=1;k<botMsgList[i].list.length;k++){ x.msg+=botMsgList[i].list[k].msg; } onBotMsg(x.msg); } return; } } botMsgList[i].list[botMsgList[i].list.length]={id:ob.id,list:[ob]}; return; }else{ botMsgList[0]={id:ob.id,list:[ob]}; } } function onBotMsg(msg){ cb.sendNotice(msg,cb.room_slug,"#3399ff"); } var idcount=0; function sn(){ sendBotMsg("msg","testbot.txt",{name:100}, idcount); //sendBotMsg("write","testbot.txt",{name:100}, idcount); //sendBotMsg("append","testbot.txt",{name:100}, idcount); //sendBotMsg("load","testbot.txt",{}, idcount); idcount++; } cb.setTimeout(sn,2000);
© Copyright Chaturbate 2011- 2025. All Rights Reserved.