Advertisement
Guest User

Untitled

a guest
Oct 16th, 2015
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. // ==UserScript==
  2. // @name My Fancy New Userscript
  3. // @namespace http://your.homepage/
  4. // @version 0.1
  5. // @description enter something useful
  6. // @author You
  7. // @match http://chat.stackexchange.com/rooms/30332/beep-boop-maggot
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. function loadScript(url,callback){
  12. var head = document.getElementsByTagName('head')[0];
  13. var script = document.createElement('script');
  14. script.type = 'text/javascript';
  15. script.src = url;
  16. script.onreadystatechange = callback;
  17. script.onload = callback;
  18. head.appendChild(script);
  19. }
  20.  
  21. loadScript("http://mathjs.org/js/lib/math.js",function(){
  22. math.config({
  23. number: 'bignumber', // Default type of number:
  24. // 'number' (default), 'bignumber', or 'fraction'
  25. precision: 64 // Number of significant digits for BigNumbers
  26. });
  27. });
  28.  
  29. function obtainLastMessage(){
  30. message = $("div.monologue:last .content");
  31. messages = [];
  32. for(var i=0;i<message.length;i++){
  33. messages.push(message[i].innerHTML)
  34. }
  35. username = $("div.monologue:last .username")[0].innerHTML;
  36. return [username,"said",messages,$("div.monologue:last")]
  37. }
  38.  
  39. function send(msg,v){
  40. v = v || "<The Tin Soldier> ";
  41. t=document.createElement("textarea");
  42. t.innerHTML = msg;
  43. msg=t.value;
  44. $("#input")[0].value = v+msg;
  45. $("#sayit-button").click();
  46. }
  47.  
  48. function getCommand(x,a,b){
  49. if(commands[x] && Math.floor(new Date()/1000)-commandTimeout >= 10) {
  50. commands[x](a,b);
  51. commandTimeout = Math.floor(new Date()/1000);
  52. }
  53. }
  54.  
  55. mscope = {"alex":0.5,"geobits":"i","conor":true};
  56.  
  57. commands = {
  58. say: function(a,b){
  59. send(a,b);
  60. },
  61. time: function(a,b){
  62. send(new Date +"",b);
  63. },
  64. eval: function(a,b){
  65. try {
  66. xp=math.eval(a,mscope);
  67. send("`"+a+" => "+xp+"`",b);
  68. } catch(e){
  69. send(e,b)
  70. }
  71. },
  72. scope: function(a,b){
  73. a=a.split(" ");
  74. mscope[a[0]] = a[1];
  75. },
  76. alex: function(a,b){
  77. send(String.fromCharCode(3232)+"_"+String.fromCharCode(3232),b+" ["+String.fromCharCode(2063)+"](http://@AlexA.)");
  78. },
  79. help: function(a,b){
  80. send("Commands: "+Object.keys(commands).join("; ")+"\nNo docs yet.",b);
  81. },
  82. status: function(a,b){
  83. send("I am "+_name+" and have "+_status+" minute"+(status[1]==1?"":"s")+" left to live.");
  84. },
  85. stab: function(a,b){
  86. send("I am a soldier, maggot! Do you think that will hurt ME?!")
  87. },
  88. doorknob: function(a,b) {
  89. send("'OH GODS NO!! You can't leave us here with Doorknob! It'll be nethack everywhere!' -Geobits");
  90. }
  91. }
  92.  
  93.  
  94.  
  95. commands[String.fromCharCode(3232)+"_"+String.fromCharCode(3232)] = function(a,b){
  96. send("AlexA.",b);
  97. }
  98.  
  99. _status = Infinity;
  100. _name = "healthy";
  101.  
  102. commands["delete_self"] = function(a,b){
  103. name = b.replace("<The Tin Soldier> @","");
  104. send("\*"+name+" poisons The Tin Soldier\*\n<The Tin Soldier> No! W&ndash;Why would you do that, "+name+"?! I'm dying now. Slowly and inexorably. (Type `!status` to see how I am doing i.e. how much time I have left.)","");
  105. inf = _status == Infinity;
  106. _status = inf ? 5 : Math.floor(_status/2);
  107. _name = inf?"poisoned by "+name:_name+" and "+name;
  108. if(inf){
  109. setInterval(function(a){
  110. _status -= 1;
  111. if(_status<0){send("You killed me, "+a+". Now, I die.");clearInterval(intervalDude)}
  112. },60*1000,name);
  113. }
  114. }
  115.  
  116. commandTimeout = Math.floor(new Date()/1000)-10;
  117.  
  118. recentEl = null;
  119.  
  120. function checkSpoken(){
  121. if(typeof window.status=="string"){
  122. window.status = window.status.split(",");
  123. }
  124. lm = obtainLastMessage();
  125. if(lm[3]!=recentEl){
  126. content = lm[2];
  127. x = content.length - 1;
  128. content[x]=content[x].replace(/<a.+?><span.+?>(.+?)<\/span><\/a>/,"[tag:$1]");
  129. window.mostRecentMessage = lm;
  130. //for(var x=0;x<content.length;x++){
  131. if(content[x].search(/^!/g+1)){ // a command may be present!
  132. mid = content[x].indexOf(" ");
  133. mid = mid+1?mid:mid.length;
  134. command = content[x].slice(1,mid);
  135. argument = content[x].slice(mid,x.length).trim();
  136. getCommand(command,argument,"<The Tin Soldier> @"+username.replace(/ /g,"")+" ");
  137. }
  138. //}
  139. }
  140. recentEl = lm[3];
  141. }
  142.  
  143. intervalDude = setInterval(checkSpoken,1);
  144.  
  145.  
  146. send("Bot initiated. Type `!help` for help.");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement