var io = require('socket.io-client'); socket = io.connect("http://192.155.86.153:8888"); var username = "LuckBot"; var outputBuffer = []; socket.on('connect', function(){ //Your session key (aka API key) //Get this from your browser's cookies. socket.emit('login', {session: "Mlbyf1xY6Qq0STt9FlFZBFajlcJV02GtYOHdfhvLszDPrwvRXb4mZMbKG8KvUz7F"}); socket.on('loggedin', function(data){ username = data.username; setTimeout(function(){ socket.emit("getcolors", {}); socket.on('chat', function(data){ if(contains(data.message, ["!gettip"]) && data.user == "highonquack"){ socket.emit("tip", {user: "Tripy998", room: "feelinglucky", tip: 0.3, message: "You'll need it!"}); } if(contains(data.message, ["!help"])){ 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).'}); } if(contains(data.message, ["hi", username])){ outputBuffer.push({room: data.room, color: "000", message: 'Feeling Lucky? Tip me!'}); } if(contains(data.message, ["has tipped " + username, "donation"])){ outputBuffer.push({room: data.room, color: "000", message: "Thank you for the tip, " + data.user + "!"}) } if(contains(data.message, ["slaps", "ccbot"])){ outputBuffer.push({room: data.room, color: "000", message: "/me slaps " + data.user + " around a bit with a large trout."}); } if(contains(data.message, ["has tipped " + username]) && !contains(data.message, ["donation"])){ var amount = data.message.split("has tipped " + username + " ")[1].split(" ")[0]; var random = Math.ceil(Math.random() * 100); if(random > 50) { var randomtwo = Math.ceil(Math.random() * 3); var earned = 2 * amount if(randomtwo == 1){ 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"}); } if(randomtwo == 2){ 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"}); } if(randomtwo == 3){ 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"}); } socket.emit("tip", {user: data.user, room: "feelinglucky", tip: earned, message: "You're a lucky man!"}); } if(random < 51) { var randomtwo = Math.ceil(Math.random() * 2); if(randomtwo == 1){ outputBuffer.push({room: "feelinglucky", color: "000", message: data.user + " Tried to shoot the deal but his gun backfired! " + data.user + " });loses! " + random + "/100"}); } if(randomtwo == 2){ outputBuffer.push({room: "feelinglucky", color: "000", message: data.user + " placed his bet, but the dealer shot " + data.user + "! " + data.user + " is dead. " + random + "/100"}); } } } if(contains(data.message, ["!flip"])){ var res = (Math.random() > 0.5 ? "heads" : "tails"); socket.emit("chat", {room: data.room, message: "Flipping coin: " + res + "!", color: "000"}); } }); }, 1000); setInterval(function(){ //CoinChat has a 550ms anti spam prevention. You can't send a chat message more than once every 550ms. if(outputBuffer.length > 0){ var chat = outputBuffer.splice(0,1)[0]; socket.emit("chat", {room: chat.room, color: "000", message: chat.message}); } }, 600); }); socket.on('disconnect', function(){}); }); function contains(string, terms){ for(var i=0; i