Aluf

JavaScript Xat Bot v3

Jan 27th, 2015
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.29 KB | None | 0 0
  1. // ==UserScript==
  2. // @name           Aluf
  3. // @namespace      JSBot
  4. // @author         3nvisi0n
  5. // @version        1.3.3.7
  6. // @description Chat bot for H0rnet.
  7. // @include        http://m.xat.com:10049/*
  8. // @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js
  9. // @icon         https://mo-bot.googlecode.com/hg/icons/Mo-Bot.png
  10. // @icon64       https://mo-bot.googlecode.com/hg/icons/Mo-Bot.png
  11. // ==/UserScript==
  12.  
  13. //////////////////
  14. //---SETTINGS---//
  15. //////////////////
  16. var cmdChar = "!"; //Character that starts all commands
  17. var BUFFER_TIME = 3;//How long to wait before parsing messages(so we don't parse old ones)
  18.  
  19. window.unsafeWindow = window;
  20. AddMessB = unsafeWindow.AddMess;//don't change this is needed for overload
  21. var startTime = time(); //Used so we don't parse old messages
  22. var lastTab = 0;
  23. onload = autowelcome;
  24.  
  25. //Function stolen from somewhere I don't remember
  26. String.prototype.between = function(prefix, suffix) {
  27.   s = this;
  28.   var i = s.indexOf(prefix);
  29.   if (i >= 0) {
  30.     s = s.substring(i + prefix.length);
  31.   }
  32.   else {
  33.     return '';
  34.   }
  35.   if (suffix) {
  36.     i = s.indexOf(suffix);
  37.     if (i >= 0) {
  38.       s = s.substring(0, i);
  39.     }
  40.     else {
  41.       return '';
  42.     }
  43.   }
  44.   return s;
  45. }
  46. //grabs the unix timestamp
  47. function time() {
  48.     return Math.round((new Date()).getTime() / 1000);    
  49. }
  50. var lock = new Boolean();
  51. //Big switch for all cmd handling
  52. function handleCommand(cmd,argu,id) {
  53.     words = argu.split(" ");
  54.     var args = argu.split(" ");
  55.     if (id == "426474638") {
  56.     switch(cmd.toLowerCase()) {
  57.         //reboot
  58.         case "reboot": reb00t(); break;
  59.         case "botkill": shutdown(); break;
  60.         case "test": setTimeout( function() { respond("Up and running"); },1000); break;
  61.         case "autowelcome": autowelcome(id); break;
  62.         case "livebtcprice": setTimeout( function() { respond("http://preev.com"); },1000); break;
  63.         case "goto": gotoChat(argu); break;
  64.         case "spam": setInterval( function() { sendMessage(argu); },1); break;
  65.         case "adv": setInterval( function() { sendMessage(argu); },40000); break;
  66.         case "kick": kick(argu,"Because H0rnet decided so."); break;
  67.         case "ban": ban(argu,"Because H0rnet decided so.", args[1]); break;
  68.         case "member": member(argu);  break;
  69.         case "guest": guest(argu);  break;
  70.         case "mod": mod(argu);  break;
  71.         case "unban": unban(argu); break;
  72.     }
  73. }
  74.     switch(cmd.toLowerCase()) {
  75.         case "yell":
  76.         case "say": setTimeout( function() { respond("["+id+"] "+ argu); },1000); break;
  77.         case "pacmaninsult": setTimeout( function() { respond(argu + ", you eat more balls than pac man"); },1000); break;
  78.         case "repoot": setTimeout( function() { respond("Repooted "+argu+""); },1000); break;
  79.         case "quagmire": setTimeout( function() { respond("Giggity Giggity Goo!"); },1000); break;
  80.         //essay
  81.         case "essay": setTimeout( function() { respond("essaytyper.com"); },1000); break;
  82.         //Facts
  83.         case "funfact": setTimeout( function() { funfacts(); },1000); break;
  84.         //8ball
  85.         case "8ball": setTimeout( function() { eightBall(argu); },1000); break;
  86.         //Encryptions
  87.         case "md5": setTimeout( function() { crypto( argu, "MD5" ); },1000); break;
  88.         case "sha1": setTimeout( function() { crypto( argu, "SHA1" ); },1000); break;
  89.         case "sha256": setTimeout( function() { crypto( argu, "SHA256" ); },1000); break;
  90.         case "sha384": setTimeout( function() { crypto( argu, "SHA384" ); },1000); break;
  91.         case "sha512": setTimeout( function() { crypto( argu, "SHA512" ); },1000); break;
  92.         case "md2": setTimeout( function() { crypto( argu, "MD2" ); },1000); break;
  93.         //insult
  94.         case "insult": setTimeout( function() { insult( argu ); },1000); break;
  95.         //Time
  96.         case "time": time(); break;
  97.         case "date": datetime(); break;
  98.         //locking
  99.         case "lock":
  100.            if(id != "426474638"){
  101.              return;
  102.            }
  103.            lock = true;
  104.           setTimeout( function() {respond("Locking H0rnetBot") },1000);
  105.            break;
  106.        
  107.            case "unlock":
  108.            if(id != "426474638"){
  109.                 return;
  110.            }
  111.            lock = false;
  112.           setTimeout( function() { respond("Unlocking H0rnetBot"); },1000);
  113.            break;
  114.     }
  115. }
  116.  
  117. //Overloads display function
  118. unsafeWindow.AddMess = function AddMess(tab, s)
  119. {
  120. {
  121.     curTime = time();
  122.     last = s.between("(",")");
  123.     if(curTime >= startTime+BUFFER_TIME) { //Don't start parsing until BUFFER_TIME s has passed
  124.         var id = tab;
  125.         if(tab==0) id = s.between("(",")");
  126.         lastTab = tab;
  127.         if(s.indexOf("<B>")>=0) {
  128.             var msg = s.between("<B>","</B>")+" ";
  129.             if(msg.charAt(0) == cmdChar) {
  130.             if(lock && id != "426474638") {
  131.                           return;
  132.                         }
  133.                 var cmd = msg.substring(1,msg.indexOf(" "));
  134.                 handleCommand(cmd,msg.substring(msg.indexOf(" ")+1),id);
  135.             }
  136.             }
  137.         }
  138.     }
  139.     AddMessB(tab,s);
  140. }
  141. function autowelcome()
  142. {
  143. setTimeout( function() { sendMessage(" Bot is here!"); } ,2000);
  144. }
  145. function reb00t() {
  146. sendMessage("[Reboot]: Rebooting bot!");
  147. setTimeout(function() { history.go(-1) }, 2000);
  148. }
  149. function shutdown() {
  150. setTimeout( function() { sendMessage("Killing bot!"); } ,2000);
  151.   setTimeout(function() {
  152.   history.go(-5)
  153.   },1000);
  154. }
  155. ////////////////////////
  156. //MODERATION FUCNTIONS//
  157. ////////////////////////
  158. function kick(id,reason) {
  159.     unsafeWindow.DoMessage(id, '/k', reason);  
  160. }
  161. function ban(id,reason,time) {
  162.     unsafeWindow.DoMessage(id, '/g'+(time*3600), reason);  
  163. }
  164. function guest(id) {
  165.     unsafeWindow.DoMessage(id, '/r', '');    
  166. }
  167. function member(id) {
  168.     unsafeWindow.DoMessage(id, '/e', '');    
  169. }
  170. function mod(id) {
  171.     unsafeWindow.DoMessage(id, '/m', '');    
  172. }
  173. function owner(id) {
  174.     unsafeWindow.DoMessage(id, '/M', '');    
  175. }
  176. function gotoChat(argu) {
  177.     unsafeWindow.DoMessage('/go', argu);
  178. }
  179. //////////////////////
  180. //RESPONSE FUCNTIONS//
  181. //////////////////////
  182.  
  183. //Responds to whereever the message came from
  184. //in PC/PM(mobile doesn't differentiate) responds via PC
  185. //from main respond to main
  186. function respond(message) {
  187.     if(lastTab==0) {
  188.         sendMessage(message);    
  189.     } else {
  190.         sendPC(message,lastTab);
  191.     }
  192. }
  193.    
  194. //Simply sends a message to main chat
  195. function sendMessage(message) {
  196.     xmlHttp2 = unsafeWindow.getHTTPObject();
  197.     xmlHttp2.open('GET','/Post?m='+message,true);
  198.     xmlHttp2.setRequestHeader("Content-Type", "text/plain");
  199.     xmlHttp2.setRequestHeader("Connection", "close");
  200.     xmlHttp2.send(null);  
  201. }
  202. //Sends a message out to PC
  203. function sendPC(message,id) {
  204.     xmlHttp2 = unsafeWindow.getHTTPObject();
  205.     xmlHttp2.open('GET','/Post?u='+id+'&t='+message,true);
  206.     xmlHttp2.setRequestHeader("Content-Type", "text/plain");
  207.     xmlHttp2.setRequestHeader("Connection", "close");
  208.     xmlHttp2.send(null);      
  209. }
  210.     function datetime()         //date & time
  211.     {
  212.         var currentDate = new Date()            //reset date
  213.         var day = currentDate.getDate()         //dd
  214.         var month = currentDate.getMonth() + 1  //mm
  215.         var year = currentDate.getFullYear()    //yyyy
  216.         var hr = currentDate.getHours()         //hh
  217.         var min = currentDate.getMinutes()      //mm
  218.         var sec = currentDate.getSeconds()      //ss
  219.         sendMessage( "Date: " + day + "/" + month + "/" + year + " Time: " + hr + "h:" + min + "m:" + sec +"s" );
  220.     }
  221.     function eightBall( argu )
  222.         {
  223.                 var randomNumber = Math.floor( Math.random() * 4 ) + 1;
  224.                 if( randomNumber == 1 ) sendMessage(  "["+ argu +"] Certainly" );
  225.                 else if( randomNumber == 2 ) sendMessage( "["+ argu +"]  Yes" );
  226.                 else if( randomNumber == 3 ) sendMessage( "["+ argu +"]  Yes" );
  227.                 else if( randomNumber == 4 ) sendMessage( "["+ argu +"]  Yes" );
  228.             }
  229.             function crypto( arg, alg ) //encryption..
  230.     {
  231.             setTimeout( function() // unsafeWindow cannot call GM_cryptoHash()
  232.             {
  233.                     var hashed = GM_cryptoHash( arg, alg );
  234.                     if( alg == "SHA512" ) setTimeout( function() { sendMessage( hashed ); }, 1750 );
  235.                     else if( alg == "SHA384" || alg == "SHA256" ) setTimeout( function() { sendMessage(hashed ); }, 1500 );
  236.                     else setTimeout( function() { sendMessage( hashed ); }, 1000 );
  237.             }, 1);
  238.     }
  239.                    function insult( argu ) //I should of used var insult= [...] but I'm too lazy, by Twin, for some annoying people.
  240.             {
  241.                     var randomNumber = Math.floor( Math.random() * 35 ) + 1;
  242.                     if( randomNumber == 1 ) sendMessage( argu + ", get the fuck out of this chatroom, faggot." );
  243.                     else if( randomNumber == 2 ) sendMessage( argu + ", would you please shut the fuck up?" );
  244.                     else if( randomNumber == 3 ) sendMessage( argu + ", you are a retard." );
  245.                     else if( randomNumber == 4 ) sendMessage( argu + ", you are the worste skid I have ever seen." );
  246.                     else if( randomNumber == 5 ) sendMessage( argu + ", you are pathetic" );
  247.                     else if( randomNumber == 6 ) sendMessage( argu + ", since you have joined this room, our IQ have lowered by 3, I hope you are proud, and may God have mercy on you." );
  248.                     else if( randomNumber == 7 ) sendMessage( argu + ", even if you were twice as smart, you would still be stupid." );
  249.                     else if( randomNumber == 8 ) sendMessage( argu + ", fuck off." );
  250.                     else if( randomNumber == 9 ) sendMessage( argu + ", you are unwanted in this chat, please leave by clicking sign out." );
  251.                     else if( randomNumber == 11 ) sendMessage( argu + ", I would slap you, but that would be animal abuse." );
  252.                     else if( randomNumber == 12 ) sendMessage( argu + ", shock me, say something intelligent. " );
  253.                     else if( randomNumber == 13 ) sendMessage( argu + ", you are so fat that you download cheats for Wii Fit." );
  254.                     else if( randomNumber == 14 ) sendMessage( argu + ", you are the reason God created the middle finger." );
  255.                     else if( randomNumber == 15 ) sendMessage( argu + ", you are a cunt" );
  256.                     else if( randomNumber == 16 ) sendMessage( argu + ", yo momma is so poor, I saw her chasing the garbage truck with a shopping list." );
  257.                     else if( randomNumber == 17 ) sendMessage( argu + ", you are like a light switch, even a little kid can turn you on." );
  258.                     else if( randomNumber == 18 ) sendMessage( argu + ", you are a noob" );
  259.                     else if( randomNumber == 19 ) sendMessage( argu + ", insert insult here (redface)" );
  260.                     else if( randomNumber == 20 ) sendMessage( argu + ", nobody loves you" );
  261.                     else if( randomNumber == 21 ) sendMessage( argu + ", I could compare you to shit, but that would be an insult for the word shit." );
  262.                     else if( randomNumber == 22 ) sendMessage( argu + ", you are as smart as a plank" );
  263.                     else if( randomNumber == 23 ) sendMessage( argu + ", I hope a airplane crashes on you while you sleep." );
  264.                     else if( randomNumber == 24 ) sendMessage( argu + ", error is the only word I can use to define how nowhere you are." );
  265.                     else if( randomNumber == 25 ) sendMessage( argu + ", gtfo (d)" );
  266.                     else if( randomNumber == 26 ) sendMessage( argu + ", you are not cool :( " );
  267.                     else if( randomNumber == 27 ) sendMessage( argu + ", you are not smart." );
  268.                     else if( randomNumber == 28 ) sendMessage( argu + ", stfu please" );
  269.                     else if( randomNumber == 29 ) sendMessage( argu + ", you are a tool" );
  270.                     else if( randomNumber == 30 ) sendMessage( argu + ", I wish cancer on you and all your family." );
  271.                     else if( randomNumber == 31 ) sendMessage( argu + ", out of over 1,000,000 sperm, you were the fastest?" );
  272.                     else if( randomNumber == 32 ) sendMessage( argu + ", I would ask how old you are, but I know you cant count that high." );
  273.                     else if( randomNumber == 33 ) sendMessage( argu + ", you eat more balls than pac-man (xd)");
  274.                     else if( randomNumber == 34 ) sendMessage( argu + ", you eat more balls than pac-man (xd)");
  275.                     else if( randomNumber == 35 ) sendMessage( argu + ", you eat more balls than pac-man (xd)");
  276.             }
  277.             function funfacts() {
  278.             var randomNumber = Math.floor( Math.random() * 20 ) + 1;
  279.             if( randomNumber == 1 ) sendMessage("If you yelled for 8 years, 7 months and 6 days, you would have produced enough sound energy to heat one cup of coffee.");
  280.             else if( randomNumber == 2 ) sendMessage("The strongest muscle in proportion to its size in the human body is the tongue.");
  281.             else if( randomNumber == 3 ) sendMessage("Every time you lick a stamp, you're consuming 1/10 of a calorie.");
  282.             else if( randomNumber == 4 ) sendMessage("The human heart creates enough pressure when it pumps out to the body to squirt blood 30 feet.");
  283.             else if( randomNumber == 5 ) sendMessage("Banging your head against a wall uses 150 calories an hour.");
  284.             else if( randomNumber == 6 ) sendMessage("The average person falls asleep in seven minutes.");
  285.             else if( randomNumber == 7 ) sendMessage("Your stomach has to produce a new layer of mucus every two weeks otherwise it will digest itself");
  286.             else if( randomNumber == 8 ) sendMessage("Humans are the only primates that don't have pigment in the palms of their hands.");
  287.             else if( randomNumber == 9 ) sendMessage("Thirty-five percent of the people who use personal ads for dating are already married.");
  288.             else if( randomNumber == 10 ) sendMessage("It's possible to lead a cow upstairs...but not downstairs");
  289.             else if( randomNumber == 11 ) sendMessage("Dogs have four toes on their hind feet, and five on their front feet.");
  290.             else if( randomNumber == 12 ) sendMessage("Butterflies taste with their feet.");
  291.             else if( randomNumber == 13 ) sendMessage("A pregnant goldfish is called a twit.");
  292.             else if( randomNumber == 14 ) sendMessage("A cockroach will live nine days without it's head, before it starves to death.");
  293.             else if( randomNumber == 15 ) sendMessage("Elephants are the only mamals that can't jump.");
  294.             else if( randomNumber == 16 ) sendMessage("A duck's quack doesn't echo, and no one knows why.");
  295.             else if( randomNumber == 17 ) sendMessage("Snails can sleep for 3 years without eating");
  296.             else if( randomNumber == 18 ) sendMessage("Porcupines float in water.");
  297.             else if( randomNumber == 19 ) sendMessage("A giraffe can clean its ears with its 21-inch tongue!");
  298.             else if( randomNumber == 20 ) sendMessage("A Saudi Arabian woman can get a divorce if her husband doesn't give her coffee.");
  299.             }
Advertisement
Add Comment
Please, Sign In to add comment