Advertisement
Tripy998

Code

Jul 26th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.34 KB | None | 0 0
  1. var io = require('socket.io-client');
  2. socket = io.connect("http://192.155.86.153:8888");
  3.  
  4. var username = "devdicebot";
  5. var outputBuffer = [];
  6.  
  7. socket.on('connect', function(){
  8. //Your session key (aka API key)
  9. //Get this from your browser's cookies.
  10. socket.emit('login', {session: "################################################################"});
  11. socket.on('loggedin', function(data){
  12. username = data.username;
  13. setTimeout(function(){
  14. socket.emit("getcolors", {});
  15.  
  16. socket.on('chat', function(data){
  17. if(contains(data.message, ["!gettip"]) && data.user == "Tripy998"){
  18. socket.emit("tip", {user: "Tripy998", room: "lottery", tip: 0.3, message: "You'll need it!"});
  19. }
  20. if(contains(data.message, ["!help"])){
  21. outputBuffer.push({room: "lottery", color: "000", message: 'Tip DevDiceBot to roll the dice, there is a 50/50 chance you will win 2x your payment! You can also donate, by tipping devdicebot with the message donation (/tip devdicebot amount donation).'});
  22. }
  23. if(contains(data.message, ["hi", username])){
  24. outputBuffer.push({room: data.room, color: "000", message: 'Feeling Lucky? Tip me!'});
  25. }
  26. if(contains(data.message, ["<span class='label label-success'>has tipped " + username, "donation"])){
  27. outputBuffer.push({room: data.room, color: "000", message: "Thank you for the tip, " + data.user + "!"})
  28. }
  29. if(contains(data.message, ["slaps", "devdicebot"])){
  30. outputBuffer.push({room: data.room, color: "000", message: "/me slaps " + data.user + " around a bit with a large trout."});
  31. }
  32. if(contains(data.message, ["who", "devdicebot"])){
  33. outputBuffer.push({room: data.room, color: "000", message: "/me slaps " + data.user + " around a bit with a large trout."});
  34. }
  35. if(contains(data.message, ["<span class='label label-success'>has tipped " + username]) && !contains(data.message, ["donation"])){
  36. var amount = data.message.split("<span class='label label-success'>has tipped " + username + " ")[1].split(" ")[0];
  37.  
  38. var random = Math.ceil(Math.random() * 100);
  39. if(random > 50) {
  40. var randomtwo = Math.ceil(Math.random() * 3);
  41. var earned = 2 * amount
  42.  
  43. if(randomtwo == 1){
  44. outputBuffer.push({room: "lottery", color: "000", message: data.user + " has rolled the dice and landed on 4, " + data.user + " wins 2 times his bet! (2 * " + amount + " = " + earned + ")! " + random + "/100"});
  45. }
  46.  
  47. if(randomtwo == 2){
  48. outputBuffer.push({room: "lottery", color: "000", message: data.user + " has rolled the dice and landed on 6, " + data.user + " wins 2 times his bet! (2 * " + amount + " = " + earned + ")! " + random + "/100"});
  49. }
  50.  
  51. if(randomtwo == 3){
  52. outputBuffer.push({room: "lottery", color: "000", message: data.user + " has rolled the dice and landed on 5, " + data.user + " wins 2 times his bet! (2 * " + amount + " = " + earned + ")! " + random + "/100"});
  53. }
  54. socket.emit("tip", {user: data.user, room: "lottery", tip: earned, message: "You're a lucky man!"});
  55. }
  56. if(random < 51) {
  57. var randomtwo = Math.ceil(Math.random() * 2);
  58.  
  59. if(randomtwo == 1){
  60. outputBuffer.push({room: "lottery", color: "000", message: data.user + " has rolled the dice and landed on 3, " + data.user + " });loses! " + random + "/100"});
  61. }
  62.  
  63. if(randomtwo == 2){
  64. outputBuffer.push({room: "lottery", color: "000", message: data.user + " has rolled, but the dealer shot " + data.user + "! " + data.user + " is dead. " + random + "/100"});
  65. }
  66. }
  67. }
  68. if(contains(data.message, ["!flip"])){
  69. var res = (Math.random() > 0.5 ? "heads" : "tails");
  70. socket.emit("chat", {room: data.room, message: "Flipping coin: " + res + "!", color: "000"});
  71. }
  72. });
  73.  
  74. }, 1000);
  75. setInterval(function(){
  76. //CoinChat has a 550ms anti spam prevention. You can't send a chat message more than once every 550ms.
  77. if(outputBuffer.length > 0){
  78. var chat = outputBuffer.splice(0,1)[0];
  79. socket.emit("chat", {room: chat.room, color: "000", message: chat.message});
  80. }
  81. }, 600);
  82. });
  83. socket.on('disconnect', function(){});
  84. });
  85.  
  86. function contains(string, terms){
  87. for(var i=0; i<terms.length; i++){
  88. if(string.toLowerCase().indexOf(terms[i].toLowerCase()) == -1){
  89. return false;
  90. }
  91. }
  92. return true;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement