Advertisement
Tripy998

CoinChat Bot

Jul 26th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.09 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 = "LuckBot";
  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: "Mlbyf1xY6Qq0STt9FlFZBFajlcJV02GtYOHdfhvLszDPrwvRXb4mZMbKG8KvUz7F"});
  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 == "highonquack"){
  18. socket.emit("tip", {user: "Tripy998", room: "feelinglucky", tip: 0.3, message: "You'll need it!"});
  19. }
  20. if(contains(data.message, ["!help"])){
  21. outputBuffer.push({room: "feelinglucky", color: "000", message: 'Tip LuckBot to gamble, there is a 50/50 chance you will win 2x your payment! You can also donate, by tipping LuckBot with the message donation (/tip LuckBot 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", "ccbot"])){
  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, ["<span class='label label-success'>has tipped " + username]) && !contains(data.message, ["donation"])){
  33. var amount = data.message.split("<span class='label label-success'>has tipped " + username + " ")[1].split(" ")[0];
  34.  
  35. var random = Math.ceil(Math.random() * 100);
  36. if(random > 50) {
  37. var randomtwo = Math.ceil(Math.random() * 3);
  38. var earned = 2 * amount
  39.  
  40. if(randomtwo == 1){
  41. outputBuffer.push({room: "feelinglucky", color: "000", message: data.user + " placed his/her bet and just as he was about to lose luck smiled over him! " + data.user + " wins 2 times his bet! (2 * " + amount + " = " + earned + ")! " + random + "/100"});
  42. }
  43.  
  44. if(randomtwo == 2){
  45. outputBuffer.push({room: "feelinglucky", color: "000", message: data.user + " placed his bet bet and just at the right time his luck decided to show up. " + data.user + " wins 2 times his bet! (2 * " + amount + " = " + earned + ")! " + random + "/100"});
  46. }
  47.  
  48. if(randomtwo == 3){
  49. outputBuffer.push({room: "feelinglucky", color: "000", message: data.user + " has rigged this to win! Well he wins! " + data.user + " wins 2 times his bet! (2 * " + amount + " = " + earned + ")! " + random + "/100"});
  50. }
  51. socket.emit("tip", {user: data.user, room: "feelinglucky", tip: earned, message: "You're a lucky man!"});
  52. }
  53. if(random < 51) {
  54. var randomtwo = Math.ceil(Math.random() * 2);
  55.  
  56. if(randomtwo == 1){
  57. outputBuffer.push({room: "feelinglucky", color: "000", message: data.user + " Tried to shoot the deal but his gun backfired! " + data.user + " });loses! " + random + "/100"});
  58. }
  59.  
  60. if(randomtwo == 2){
  61. outputBuffer.push({room: "feelinglucky", color: "000", message: data.user + " placed his bet, but the dealer shot " + data.user + "! " + data.user + " is dead. " + random + "/100"});
  62. }
  63. }
  64. }
  65. if(contains(data.message, ["!flip"])){
  66. var res = (Math.random() > 0.5 ? "heads" : "tails");
  67. socket.emit("chat", {room: data.room, message: "Flipping coin: " + res + "!", color: "000"});
  68. }
  69. });
  70.  
  71. }, 1000);
  72. setInterval(function(){
  73. //CoinChat has a 550ms anti spam prevention. You can't send a chat message more than once every 550ms.
  74. if(outputBuffer.length > 0){
  75. var chat = outputBuffer.splice(0,1)[0];
  76. socket.emit("chat", {room: chat.room, color: "000", message: chat.message});
  77. }
  78. }, 600);
  79. });
  80. socket.on('disconnect', function(){});
  81. });
  82.  
  83. function contains(string, terms){
  84. for(var i=0; i<terms.length; i++){
  85. if(string.toLowerCase().indexOf(terms[i].toLowerCase()) == -1){
  86. return false;
  87. }
  88. }
  89. return true;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement