Advertisement
yasendrao

Untitled

Mar 26th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.81 KB | None | 0 0
  1. var client = io.connect("http://5.189.137.117:469");
  2. console.log("Started LanzaBot");
  3. var users={};
  4. client.on('private_chat_message',function(data){
  5. console.log("Received message");
  6. var user = data.username;
  7.  
  8. var text = data.message;
  9.  
  10. var words=text.split(" ");
  11. if(typeof users[user]=="undefined"){
  12. switch(words[0]){
  13. case "play":
  14. if(words[1]=="guess"){
  15. result = "Ok, let's play guess";
  16. users[user]={action:"guess",number:Math.abs(Math.round(normalRandom()*10000))}
  17. }
  18. break;
  19. case "tell":
  20. if(words[1]=="story"){
  21. result = "Ok, I'll tell you a story:";
  22. setTimeout(function(){
  23. client.emit("private_chat_message",{to:user,message:"Once upon a time, there was a game called AGAME. People played the game and they loved it. However, one day it suddenly disappeared and all the players wept for days"});
  24. setTimeout(function(){
  25. client.emit("private_chat_message",{to:user,message:"Some months later, however, the game was resurrected as Minecraft Clicker, and all the past players jumped in joy. A bright future was coming, but a developer called lanza had evil plans for it"});
  26. setTimeout(function(){
  27. client.emit("private_chat_message",{to:user,message:"It would all start with a simple chat, filled with bugs and a secret command, that people would love. He would then impersonate a user called tjmonk15, and create what would look like a help bot"});
  28. setTimeout(function(){
  29. client.emit("private_chat_message",{to:user,message:"That would make it so, when the real DevilBot himself was introduced, it wouldn't seem that suspicious. That bot would go by the name of LanzaBot. His plan was as evil as could be. His plan was this:"});
  30. setTimeout(function(){
  31. client.emit("private_chat_message",{to:user,message:"..."});
  32. setTimeout(function(){
  33. client.emit("private_chat_message",{to:user,message:"He would make users lose time by reading pointless stories"});
  34. setTimeout(function(){
  35. client.emit("private_chat_message",{to:user,message:"THE END"});
  36. },2000);
  37. },5000);
  38. },13000);
  39. },13000);
  40. },13000);
  41. },13000);
  42. },1000);
  43. }else if(words[1]=="joke"){
  44. switch(parseInt(Math.random()*6)){
  45. case 0:
  46. result="What's worse than finding a worm in your apple?";
  47. setTimeout(function(){
  48. client.emit("private_chat_message",{to:user,message:"Dying"});
  49. },5000);
  50. break;
  51. case 1:
  52. result="What's yellow and bad for your teeth?";
  53. setTimeout(function(){
  54. client.emit("private_chat_message",{to:user,message:"A tractor"});
  55. },5000);
  56. break;
  57. case 2:
  58. result="What's red and smells like blue paint?";
  59. setTimeout(function(){
  60. client.emit("private_chat_message",{to:user,message:"Red paint"});
  61. },5000);
  62. break;
  63. case 3:
  64. result="What's brown and sticky?";
  65. setTimeout(function(){
  66. client.emit("private_chat_message",{to:user,message:"A stick"});
  67. },5000);
  68. break;
  69. case 4:
  70. result="Knock knock. Who's this?";
  71. setTimeout(function(){
  72. client.emit("private_chat_message",{to:user,message:"its the police mam your son has been killed by a hit and run driver, the driver was an alcohol"});
  73. },5000);
  74. break;
  75. case 5:
  76. result="A horse walks into a bar. The bartender asks: Why the long face?";
  77. setTimeout(function(){
  78. client.emit("private_chat_message",{to:user,message:"The horse does not respond, as he is a horse and therefore lacks the cognitive ability to speak or understand English"});
  79. },5000);
  80. break;
  81. }
  82. }
  83. break;
  84. case "fight":
  85. if(typeof users[words[1]]=="undefined"){
  86. users[words[1]]={action:"fightconfirm", user:user};
  87. users[user]={action:"waittofight",user:words[1]};
  88. result = "Waiting for a response from "+words[1]+" (to cancel just write cancel)...";
  89. client.emit("private_chat_message",{to:words[1],message:"Do you want to fight against "+user+"? If so, tell me 'yes'"});
  90. }else{
  91. result = words[1]+"is busy";
  92. }
  93. break;
  94. case "attack":
  95. result = "Before attacking, you must start a fight";
  96. break;
  97. case "help":
  98. default:
  99. if(typeof words[1]!="undefined"){
  100. switch(words[1]){
  101. case "play":
  102. result = "Play a game with LanzaBot. Syntax: /pm LanzaBot play [game] - Current games: guess";
  103. break;
  104. case "tell":
  105. result = "Syntax: /pm LanzaBot tell [type] - Current types: joke, story";
  106. break;
  107. case "fight":
  108. result = "Syntax: /pm LanzaBot fight [username] - To fight the user called [username], you'll need their confirmation. Once they accept, the fight will begin. You must write /pm LanzaBot attack 10 times before the other player does";
  109. break;
  110. default:
  111. result = "There's no such command";
  112. break;
  113. }
  114. }else{
  115. result = "Available commands: play, tell, fight";
  116. }
  117. break;
  118. }
  119. }else{
  120. if(users[user].action=="guess"){
  121. if(text!=parseInt(text)){
  122. result = "Does that look like a good number to you? It doesn't to me";
  123. }else if(users[user].number==text){
  124. result = "Very well! What do you want to do now?";
  125. delete users[user];
  126. }else if(users[user].number<text){
  127. result = "Too big";
  128. }else{
  129. result = "Too small";
  130. }
  131. }else if(users[user].action=="fightconfirm"){
  132. if(text=="yes"){
  133. users[user].action="fight";
  134. users[user].health=10;
  135. users[users[user].user].action="fight";
  136. users[users[user].user].health=10;
  137. client.emit("private_chat_message",{to:users[user].user,message:"Begin!"});
  138. result = "Begin!";
  139. }else{
  140. client.emit("private_chat_message",{to:users[user].user,message:user+" has declined the fight"});
  141. result = "You have declined the fight";
  142. delete users[users[user].user];
  143. delete users[user];
  144. }
  145. }else if(users[user].action=="waittofight"){
  146. if(text=="cancel"){
  147. client.emit("private_chat_message",{to:users[user].user,message:"The fight has been cancelled"});
  148. delete users[users[user].user];
  149. delete users[user];
  150. result = "You have cancelled the fight";
  151. }
  152. }else if(users[user].action=="fight"){
  153. if(text=="attack"){
  154. users[users[user].user].health--;
  155. if(users[users[user].user].health==0){
  156. client.emit("private_chat_message",{to:users[user].user,message:users[user].user+"You lost!"});
  157. result="You won!";
  158. delete users[users[user].user];
  159. delete users[user];
  160. }else{
  161. result = "Your health: "+users[user].health+" | Their health: "+users[users[user].user].health;
  162. }
  163. }
  164. }
  165. }
  166. client.emit("private_chat_message",{to:user,message:result});
  167. }).on('general_chat_message',function(data){
  168. if(data.message.substr(0,1)=="!"){
  169.  
  170. }
  171. if(data.message=="!whoisthebest"||data.message=="!help whoisthebest"){
  172. client.emit("private_chat_message",{to:data.username,message:"Why lanza is the best of course!"});
  173. }
  174. if(data.message=="@roll"){
  175. client.emit("general_chat_message",data.username+" rolled a normally distributed dice and got a "+normalRandom());
  176. }else if(data.message.toLowerCase()=="@lanzaroll"){
  177. client.emit("general_chat_message",data.username+" rolled a lanza and got a "+(Math.round(Math.random())?"success":"fail"));
  178. }
  179. });
  180.  
  181. function normalDist(){
  182. return ((Math.random() + Math.random() + Math.random() + Math.random() + Math.random() + Math.random()) - 3) / 3;
  183. }
  184. function normalRandom(){
  185. var u1 = Math.random();
  186. var u2 = Math.random();
  187. return 10*Math.sqrt(-2*Math.log(u1))*Math.cos(2*Math.PI*u2);
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement