Advertisement
Shard

Auto Messager

May 1st, 2014
1,499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var msgs=["So whats up guys","How are you all","WAAZZAAAAPPPP"]; //default msgs, add as many as you like.
  2. var time=3600; //in seconds
  3. var timer;
  4. API.on(API.CHAT_COMMAND, command);
  5. API.chatLog("Running auto messager, user \'/settimermsg #\' to set how often in seconds a message is posted. This will start the program, use /pausemsg to stop it and /startmsg to start it (if no time set 1 hour interval used)",true);
  6.  
  7. function command(value) {
  8.     console.log("command called");
  9.     var commandfunction = "";
  10.    
  11.     if (value.indexOf(" ") == -1) {
  12.         var commandfunction = value.substring(value.indexOf("/")+1,value.length);
  13.     } else {
  14.         var commandfunction = value.substring(value.indexOf("/")+1,value.indexOf(" "));
  15.     }
  16.     var commandcontent =  value.substring(value.indexOf(" ")+1,value.length);
  17.    
  18.     console.log("commandfunction: " + commandfunction);
  19.     console.log("commandcontent: " + commandcontent);
  20.    
  21.     switch(commandfunction)
  22.     {
  23.         case "addmsg":
  24.             console.log("addmsg called");
  25.             msgs.push(commandcontent);
  26.             API.chatLog("Msg added: \'" + commandcontent + "\'", true);
  27.         break;
  28.         case "checkmsg":
  29.             console.log("checkmsg called");
  30.             API.chatLog("msg number "+ commandcontent + " is \'" + msgs[parseInt(commandcontent)-1] +"\'", true);
  31.         break;
  32.         case "countmsg":
  33.             console.log("countmsg called");
  34.             API.chatLog(msgs.length.toString() + " msgs in list", true);
  35.         break;
  36.         case "removemsg":
  37.             console.log("removemsg called");
  38.             msgs.splice(parseInt(commandcontent)-1,1);
  39.             API.chatLog("msg " + commandcontent + " was removed", true);
  40.         break;
  41.         case "pausemsg":
  42.             console.log("pausemsg called");
  43.             stoptimer();
  44.             API.chatLog("msgs no longer posting",true);
  45.         break;
  46.         case "startmsg":
  47.             console.log("startmsg called");
  48.             refreshtimer();
  49.             API.chatLog("msgs now posting",true);
  50.         break;
  51.         case "settimermsg":
  52.             console.log("settimermsg called");
  53.             time = parseInt(commandcontent);
  54.             API.chatLog("new post delay set to every " + commandcontent + " seconds. Also timer reset",true);
  55.             refreshtimer();
  56.         break;
  57.     }
  58. }
  59.  
  60. function postmsg() {
  61.     var random = Math.floor((Math.random() * msgs.length));
  62.     API.sendChat(msgs[random]);
  63. }
  64.  
  65. function refreshtimer() {
  66.     stoptimer(timer);
  67.     timer = window.setInterval(postmsg, time*1000);
  68. }
  69.  
  70. function stoptimer() {
  71.     window.clearInterval(timer);
  72.     timer = null;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement