Skip to content

Instantly share code, notes, and snippets.

@cymruu
Created May 8, 2017 16:41
Show Gist options
  • Save cymruu/5a377df3264890e5d44f7c08ef254e0b to your computer and use it in GitHub Desktop.
Save cymruu/5a377df3264890e5d44f7c08ef254e0b to your computer and use it in GitHub Desktop.
const WebSocket = require('ws');
const fs = require('fs');
var gameURL = 'ws://csgopoor.com:2052/socket.io/?EIO=3&transport=websocket'; //socket adress, can be checked in your browser (developer tools -> network -> websockets)
var depositURL = '';//csgopoor bot deposit url
var SteamCommunity = require('steamcommunity');
var SteamTotp = require('steam-totp');
var TradeOfferManager = require('steam-tradeoffer-manager');
var steam = new SteamCommunity();
var manager = new TradeOfferManager({
"language": "en", // We want English item descriptions
"pollInterval": 5000 // We want to poll every 5 seconds since we don't have Steam notifying us of offers
});
var logOnOptions = {
"accountName": "",//your bot login
"password": "",//your bot password
"twoFactorCode": SteamTotp.getAuthCode("//your bot identify")
};
function deposit(){
var offer = manager.createOffer(depositURL);
manager.getInventoryContents(730, 2, true, (err, inventory, currencies)=>{
if(err)return;
for (var i = 0; i < 5; i++) {
offer.addMyItem(inventory[i]);
}
offer.send((err, status)=>{
console.log(err, status);
lastDeposit = new Date();
lastOfferId = offer.id;
});
});
}
steam.login(logOnOptions, function(err, sessionID, cookies, steamguard) {
if (err) {
console.log("Steam login fail: " + err.message);
process.exit(1);
}
manager.setCookies(cookies, function(err) {
if (err) {
console.log(err);
process.exit(1); // Fatal error since we couldn't get our API key
return;
}
console.log("Got API key: " + manager.apiKey);
steam.chatLogon(5000);
steam.on('chatLoggedOn', ()=>{
steam.chatMessage(admin, 'Zalogowano');
});
deposit();
// deposit();
});
steam.startConfirmationChecker(5000, ""); //put your bot secret here
});
var client = new WebSocket(gameURL, {headers: {}});
client.on('open', function() {
console.log('connected');
client.send('42["auth",{"steamid":"76561198146332699"}]');//put your steamid there instead
setInterval(()=>{
client.send('2');
}, 14000);
});
client.on('message', function(message) {
handleMessage(message);
});
client.on('close', function (code, message) {
console.log(code, message);
});
client.on('error', function(err){
console.log(err);
});
var avgAcceptTime;
const admin = '76561198146332699'; //admin id
const botSteamId = '76561198274353984'; //bot id
var joined = false;
var lastDeposit;
var lastOfferId = 0;
var offerReceived = false;
function handleMessage(message){
try {
message = JSON.parse(message.substring(2));
} catch (e) {
return false;
}
switch (message[0]) {
case 'avgAcceptTime':
avgAcceptTime = message[1].avgAcceptTime;
break;
case 'winner':
fs.appendFile("./percentages.txt", message[1].seed+'|', function(err) {
if(err) {
return console.log(err);
}
});
deposit();
if(message[1].winner.steamid == botSteamId)steam.chatMessage(admin, 'WYGRAŁEŚ!!!111!');
joined = false;
lastOfferId = 0;
offerReceived = false;
break;
case 'offerStatus':
console.log(message);
var keys = Object.keys(message[1]);
if(keys.indexOf(lastOfferId)>-1){
switch (message[1][lastOfferId].status) {
case "ACCEPTED":
joined = true;
break;
case "STEAM_ERROR":
deposit();
break;
case "RECEIVED_OFFER":
offerReceived = true;
break;
}
}
break;
}
}
setInterval(()=>{
if(lastOfferId!==0 && offerReceived==false && !joined){
console.log('bot lost our offer, resending');
deposit();
}
}, 45000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment