Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var timer = null;
- var url = "http://www.insultgenerator.org/";
- print("insult script");
- function getSender()
- {
- var idents = [];
- Users.local(function (u)
- {
- idents.push(u.id);
- });
- if (idents.length == 0)
- return null;
- return user(idents[Math.floor(Math.random() * idents.length)]);
- }
- function getReceiver(sender)
- {
- var idents = [];
- Users.local(function (u)
- {
- if (u.id != sender.id)
- idents.push(u.id);
- });
- if (idents.length == 0)
- return null;
- return user(idents[Math.floor(Math.random() * idents.length)]);
- }
- function onLoad()
- {
- timer = new Timer();
- timer.interval = 10 * 60000;
- timer.oncomplete = timerTick;
- timer.start();
- doInsult(null);
- }
- function onJoin(userobj)
- {
- doInsult(userobj);
- }
- function timerTick()
- {
- timer.start();
- doInsult(null);
- }
- function doInsult(userobj)
- {
- var s = userobj;
- if (s == null)
- s = getSender();
- if (s != null)
- {
- var r = getReceiver(s);
- if (r != null)
- {
- var http = new HttpRequest();
- http.src = url;
- http.oncomplete = gotInsult;
- if (userobj != null)
- http.download(r.id + "\n" + s.id);
- else
- http.download(s.id + "\n" + r.id);
- }
- }
- }
- function gotInsult(e)
- {
- if (e)
- {
- var args = this.arg.split("\n");
- var s = user(parseInt(parseFloat(args[0])));
- var r = user(parseInt(parseFloat(args[1])));
- if (s != null && r != null)
- {
- var html = this.page.split("\n");
- var lines = [];
- var found = false;
- for (var i = 0; i < html.length; i++)
- {
- if (!found)
- {
- if (html[i].indexOf("\"wrap\"") > -1)
- found = true;
- }
- else
- {
- lines.push(html[i]);
- if (html[i].indexOf("</div>") > -1)
- break;
- }
- }
- for (var i = 0; i < lines.length; i++)
- if (lines[i].length > 0)
- s.sendText(r.name + ", " + Entities.decode(lines[i].replace(/<(?:.|\n)*?>/gm, "")));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement