Advertisement
Guest User

vampire

a guest
Apr 25th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var timer = null;
  2. var url = "http://www.insultgenerator.org/";
  3.  
  4. print("insult script");
  5.  
  6. function getSender()
  7. {
  8.     var idents = [];
  9.  
  10.     Users.local(function (u)
  11.     {
  12.         idents.push(u.id);
  13.     });
  14.  
  15.     if (idents.length == 0)
  16.         return null;
  17.  
  18.     return user(idents[Math.floor(Math.random() * idents.length)]);
  19. }
  20.  
  21. function getReceiver(sender)
  22. {
  23.     var idents = [];
  24.  
  25.     Users.local(function (u)
  26.     {
  27.         if (u.id != sender.id)
  28.             idents.push(u.id);
  29.     });
  30.  
  31.     if (idents.length == 0)
  32.         return null;
  33.  
  34.     return user(idents[Math.floor(Math.random() * idents.length)]);
  35. }
  36.  
  37. function onLoad()
  38. {
  39.     timer = new Timer();
  40.     timer.interval = 10 * 60000;
  41.     timer.oncomplete = timerTick;
  42.     timer.start();
  43.     doInsult(null);
  44. }
  45.  
  46. function onJoin(userobj)
  47. {
  48.     doInsult(userobj);
  49. }
  50.  
  51. function timerTick()
  52. {
  53.     timer.start();
  54.     doInsult(null);
  55. }
  56.  
  57. function doInsult(userobj)
  58. {
  59.     var s = userobj;
  60.  
  61.     if (s == null)
  62.         s = getSender();
  63.  
  64.     if (s != null)
  65.     {
  66.         var r = getReceiver(s);
  67.  
  68.         if (r != null)
  69.         {
  70.             var http = new HttpRequest();
  71.             http.src = url;
  72.             http.oncomplete = gotInsult;
  73.  
  74.             if (userobj != null)
  75.                 http.download(r.id + "\n" + s.id);
  76.             else
  77.                 http.download(s.id + "\n" + r.id);
  78.         }
  79.     }
  80. }
  81.  
  82. function gotInsult(e)
  83. {
  84.     if (e)
  85.     {
  86.         var args = this.arg.split("\n");
  87.         var s = user(parseInt(parseFloat(args[0])));
  88.         var r = user(parseInt(parseFloat(args[1])));
  89.  
  90.         if (s != null && r != null)
  91.         {
  92.             var html = this.page.split("\n");
  93.             var lines = [];
  94.             var found = false;
  95.  
  96.             for (var i = 0; i < html.length; i++)
  97.             {
  98.                 if (!found)
  99.                 {
  100.                     if (html[i].indexOf("\"wrap\"") > -1)
  101.                         found = true;
  102.                 }
  103.                 else
  104.                 {
  105.                     lines.push(html[i]);
  106.  
  107.                     if (html[i].indexOf("</div>") > -1)
  108.                         break;
  109.                 }
  110.             }
  111.  
  112.             for (var i = 0; i < lines.length; i++)
  113.                 if (lines[i].length > 0)
  114.                     s.sendText(r.name + ", " + Entities.decode(lines[i].replace(/<(?:.|\n)*?>/gm, "")));
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement