Advertisement
3nvisi0n

JS Xat Bot (no power needed)

Nov 14th, 2011
1,471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           JSXatBot
  3. // @namespace      JSBot
  4. // @author         3nvisi0n
  5. // @include        http://m.xat.com:10049/*
  6. // ==/UserScript==
  7. //DO NOT FOR ANY REASON WHAT SO EVER THINK TO COME FIND ME FOR HELP
  8. //DO NOT FOR ANY REASON WHAT SO EVER THINK TO COME FIND ME FOR HELP
  9. //DO NOT FOR ANY REASON WHAT SO EVER THINK TO COME FIND ME FOR HELP
  10. //DO NOT FOR ANY REASON WHAT SO EVER THINK TO COME FIND ME FOR HELP
  11. //DO NOT FOR ANY REASON WHAT SO EVER THINK TO COME FIND ME FOR HELP
  12. //DO NOT FOR ANY REASON WHAT SO EVER THINK TO COME FIND ME FOR HELP
  13.  
  14. /* Script is free to use edit and modify, heck that is the point
  15. of this release, I have no intention to maintain the code just put
  16. it out so you guys can use it and modify it to fit your needs. Do
  17. not ask me to add stuff, DO NOT ask me HOW to do stuff, read the
  18. code all the basics you need are here, if you need more do it your
  19. self.
  20.  
  21. Runs on m.xat.com not normal Xat pages.*/
  22.  
  23. //////////////////
  24. //---SETTINGS---//
  25. //////////////////
  26. var cmdChar = "!"; //Character that starts all commands
  27. var BUFFER_TIME = 3;//How long to wait before parsing messages(so we don't parse old ones)
  28.  
  29.  
  30. AddMessB = unsafeWindow.AddMess;//don't change this is needed for overload
  31. var startTime = time(); //Used so we don't parse old messages
  32. var lastTab = 0;
  33.  
  34. //Function stolen from somewhere I don't remember
  35. String.prototype.between = function(prefix, suffix) {
  36.   s = this;
  37.   var i = s.indexOf(prefix);
  38.   if (i >= 0) {
  39.     s = s.substring(i + prefix.length);
  40.   }
  41.   else {
  42.     return '';
  43.   }
  44.   if (suffix) {
  45.     i = s.indexOf(suffix);
  46.     if (i >= 0) {
  47.       s = s.substring(0, i);
  48.     }
  49.     else {
  50.       return '';
  51.     }
  52.   }
  53.   return s;
  54. }
  55. //grabs the unix timestamp
  56. function time() {
  57.     return Math.round((new Date()).getTime() / 1000);    
  58. }
  59.  
  60. //Big switch for all cmd handling
  61. function handleCommand(cmd,argu,id) {
  62.     words = argu.split(" ");
  63.     switch(cmd.toLowerCase()) {
  64.         case "yell":
  65.         case "say": respond(argu); break;
  66.         case "kick": kick(id,"Requested.");  break;
  67.         case "ban": ban(id,"Requested", argu[1]);
  68.         case "member": member(id);  break;
  69.         case "guest": guest(id);  break;
  70.         case "mod": mod(id);   break;
  71.     }
  72. }
  73.  
  74. //Overloads display function
  75. unsafeWindow.AddMess = function AddMess(tab, s)
  76. {
  77.     curTime = time();
  78.     last = s.between("(",")");
  79.     if(curTime >= startTime+BUFFER_TIME) { //Don't start parsing until BUFFER_TIME s has passed
  80.         var id = tab;
  81.         if(tab==0) id = s.between("(",")");
  82.         lastTab = tab;
  83.         if(s.indexOf("<B>")>=0) {
  84.             var msg = s.between("<B>","</B>")+" ";
  85.             if(msg.charAt(0) == cmdChar) {
  86.                 var cmd = msg.substring(1,msg.indexOf(" "));
  87.                 handleCommand(cmd,msg.substring(msg.indexOf(" ")+1),id);
  88.             }
  89.         }
  90.     }
  91.     AddMessB(tab,s);
  92. }
  93.  
  94. ////////////////////////
  95. //MODERATION FUCNTIONS//
  96. ////////////////////////
  97. function kick(id,reason) {
  98.     unsafeWindow.DoMessage(id, '/k', reason);  
  99. }
  100. function ban(id,reason,time) {
  101.     unsafeWindow.DoMessage(id, '/g'+(time*3600), reason);  
  102. }
  103. function guest(id) {
  104.     unsafeWindow.DoMessage(id, '/r', '');    
  105. }
  106. function member(id) {
  107.     unsafeWindow.DoMessage(id, '/e', '');    
  108. }
  109. function mod(id) {
  110.     unsafeWindow.DoMessage(id, '/m', '');    
  111. }
  112. function owner(id) {
  113.     unsafeWindow.DoMessage(id, '/M', '');    
  114. }
  115. //////////////////////
  116. //RESPONSE FUCNTIONS//
  117. //////////////////////
  118.  
  119. //Responds to whereever the message came from
  120. //in PC/PM(mobile doesn't differentiate) responds via PC
  121. //from main respond to main
  122. function respond(message) {
  123.     if(lastTab==0) {
  124.         sendMessage(message);    
  125.     } else {
  126.         sendPC(message,lastTab);
  127.     }
  128. }
  129.    
  130. //Simply sends a message to main chat
  131. function sendMessage(message) {
  132.     xmlHttp2 = unsafeWindow.getHTTPObject();
  133.     xmlHttp2.open('GET','/Post?m='+message,true);
  134.     xmlHttp2.setRequestHeader("Content-Type", "text/plain");
  135.     xmlHttp2.setRequestHeader("Connection", "close");
  136.     xmlHttp2.send(null);  
  137. }
  138. //Sends a message out to PC
  139. function sendPC(message,id) {
  140.     xmlHttp2 = unsafeWindow.getHTTPObject();
  141.     xmlHttp2.open('GET','/Post?u='+id+'&t='+message,true);
  142.     xmlHttp2.setRequestHeader("Content-Type", "text/plain");
  143.     xmlHttp2.setRequestHeader("Connection", "close");
  144.     xmlHttp2.send(null);      
  145. }
  146.  
  147. //If you want youtube, google and stuff for commands use GM_xmlhttpRequest to make the GET/POST out to whereever
  148. //Documentation: http://wiki.greasespot.net/GM_xmlhttpRequest
  149. //DO NOT FOR ANY REASON WHAT SO EVER THINK TO COME FIND ME FOR HELP
  150. //DO NOT FOR ANY REASON WHAT SO EVER THINK TO COME FIND ME FOR HELP
  151. //DO NOT FOR ANY REASON WHAT SO EVER THINK TO COME FIND ME FOR HELP
  152. //DO NOT FOR ANY REASON WHAT SO EVER THINK TO COME FIND ME FOR HELP
  153. //DO NOT FOR ANY REASON WHAT SO EVER THINK TO COME FIND ME FOR HELP
  154. //DO NOT FOR ANY REASON WHAT SO EVER THINK TO COME FIND ME FOR HELP
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement