Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp');
const SteamCommunity = require('steamcommunity');
const TradeOfferManager = require('steam-tradeoffer-manager');
const Prices = require('./prices.json');
const config = require('./config.json');
const client = new SteamUser();
const community = new SteamCommunity();
const manager = new TradeOfferManager ({
steam: client,
community: community,
language: 'en'
});
const logOnOptions = {
accountName: config.username,
password: config.password,
twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
};
client.logOn(logOnOptions);
client.on('loggedOn', () => {
console.log('succesfully logged on.');
client.setPersona(SteamUser.Steam.EPersonaState.Online);
client.gamesPlayed([440]);
});
client.on('friendRelationship', (steamid, relationship) => {
if (relationship === 2) {
client.addFriend(steamid);
client.chatMessage(steamid, 'Hello there! Thanks for adding me.');
}
});
client.on("friendMessage", function(steamID, message) {
if (message == "hey") {
client.chatMessage(steamID, "Hello, type !help to continue.");
}
});
client.on("friendMessage", function(steamID, message) {
if (message == "Hello") {
client.chatMessage(steamID, "Hello, type !help to continue.");
}
});
client.on("friendMessage", function(steamID, message) {
if (message == "Greetings!") {
client.chatMessage(steamID, "Hello, type !help to continue.");
}
});
client.on("friendMessage", function(steamID, message) {
if (message == "Good Morning!") {
client.chatMessage(steamID, "Hello, type !help to continue.");
}
});
client.on("friendMessage", function(steamID, message) {
if (message == "Afternoon!") {
client.chatMessage(steamID, "Hello, type !help to continue.");
}
});
client.on("friendMessage", function(steamID, message) {
if (message == "Evening!") {
client.chatMessage(steamID, "Hello, type !help to continue.");
}
});
client.on("friendMessage", function(steamID, message) {
if (message == "Salutations!") {
client.chatMessage(steamID, "Hello, type !help to continue.");
}
});
client.on("friendMessage", function(steamID, message) {
if (message == "Good Day!") {
client.chatMessage(steamID, "Hello, type !help to continue.");
}
});
client.on("friendMessage", function(steamID, message) {
if (message == "hi") {
client.chatMessage(steamID, "Hello, type !help to continue.");
}
});
client.on("friendMessage", function(steamID, message) {
if (message == "Hi!") {
client.chatMessage(steamID, "Hello, type !help to continue.");
}
});
client.on("friendMessage", function(steamID, message) {
if (message == "Hey") {
client.chatMessage(steamID, "Hello, type !help to continue.");
}
});
client.on("friendMessage", function(steamID, message) {
if (message == "你 好!") {
client.chatMessage(steamID, "Hello, type !help to continue.");
}
});
client.on("friendMessage", function(steamID, message) {
if (message == "howdy") {
client.chatMessage(steamID, "Hello, type !help to continue.");
}
});
client.on("friendMessage", function(steamID, message) {
if (message == "!help") {
client.chatMessage(steamID, "Check what i am selling with !selling.");
}
});
client.on("friendMessage", function(steamID, message) {
if (message == "!help") {
client.chatMessage(steamID, "Check what i am buying with !buying.");
}
});
client.on('webSession', (sessionid, cookies) => {
manager.setCookies(cookies);
community.setCookies(cookies);
community.startConfirmationChecker(20000, config.identitySecret);
});
function acceptOffer(offer) {
offer.accept((err) => {
community.checkConfirmations();
console.log("We Accepted an offer");
if (err) console.log("There was an error declining the offer.");
});
}
function declineOffer(offer) {
offer.decline((err) => {
console.log("We Declined an offer");
if (err) console.log("There was an error declining the offer.");
});
}
function processOffer(offer) {
if (offer.isGlitched() || offer.state === 11) {
console.log("Offer was glitched, declining.");
declineOffer(offer);
} else if (offer.partner.getSteamID64() === config.ownerID) {
acceptOffer(offer);
} else {
var ourItems = offer.itemsToGive;
var theirItems = offer.itemsToReceive;
var ourValue = 0;
var theirValue = 0;
for (var i in ourItems) {
var item = ourItems[i].market_name;
if(Prices[item]) {
ourValue += Prices[item].sell;
} else {
console.log("Invalid Value.");
ourValue += 99999;
}
}
for(var i in theirItems) {
var item= theirItems[i].market_name;
if(Prices[item]) {
theirValue += Prices[item].buy;
} else {
console.log("Their value was different.")
}
}
}
console.log("Our value: "+ourValue);
console.log("Their value: "+theirValue);
if (ourValue <= theirValue) {
acceptOffer(offer);
} else {
declineOffer(offer);
}
}
client.setOption("promptSteamGuardCode", false);
manager.on('newOffer', (offer) => {
processOffer(offer);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.