Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const SteamUser = require('steam-user');
- const SteamTotp = require('steam-totp');
- const SteamCommunity = require('steamcommunity');
- const TradeOdderManager = require('steam-tradeoffer-manager');
- const TeamFortress2 = require('tf2');
- const Prices = require('./prices.json');
- const config = require('./config.json');
- const client = new SteamUser();
- const tf2 = new TeamFortress2(client);
- const commuinty = new SteamCommunity();
- const manager = new TradeOdderManager({
- steam: client,
- commuinty: commuinty,
- language: 'en'
- });
- const logOnOptions = {
- accountName: config.username,
- password: config.password,
- twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
- };
- client.logOn(logOnOptions);
- client.on('loggedOn', () => {
- console.log('Logged on.');
- client.setPersona(SteamUser.Steam.EPersonaState.Online);
- client.gamesPlayed(["Oi",440]);
- });
- client.on("friendMessage", function(steamID, message) {
- if (message == "hi") {
- client.chatMessage(steamID, "hello, this works.");
- }
- });
- client.on('webSession', (sessionid, cookies) => {
- manager.setCookies(cookies);
- commuinty.setCookies(cookies);
- commuinty.startConfirmationChecker(20000, config.identitySecret);
- });
- function acceptOffer(offer) {
- offer.accept((err) => {
- commuinty.checkConfirmations();
- console.log("We accept an offer.")
- if (err) console.log("There was a error.");
- });
- }
- function declineOffer(offer) {
- offer.decline((err) => {
- console.log("We declined an offer.")
- if (err) console.log("There was a error.");
- });
- }
- 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("promtSteamGuardCode", false);
- manager.on('newOffer', (offer) => {
- processOffer(offer);
- });
- client.on('friendRelationship', function(sid, relationship) {
- if (relationship == SteamUser.EFriendRelationship.RequestRecipient) {
- console.log("We got a request from "+sid);
- client.addFriend(sid, function (err, name) {
- if (err) {
- console.log(err);
- return;
- }
- console.log("Accepted user with the name of "+name)
- })
- }
- })
- client.on('groupRelationship', function(sid, relationship) {
- if (relationship == SteamUser.EClanRelationship.Invited) {
- console.log("Clan #"+sid);
- client.respondToGroupInvite(sid, true);
- }
- })
- client.on('friendsList', function() {
- for (var sid in client.myFriends);
- var relationship = client.myFriends[sid]
- if (relationship == SteamUser.EFriendRelationship.RequestRecipient) {
- console.log("We got a request from"+sid);
- client.addFriend(sid, function (err, name) {
- if (err) {
- console.log(err);
- return;
- }
- console.log("Accepted user with the name of "+name)
- })
- }
- })
- client.on('groupList', function() {
- for (var sid in client.myGroups);
- var relationship = client.myGroups[sid]
- if (relationship == SteamUser.EClanRelationship.Invited) {
- console.log("Clan #"+sid);
- client.respondToGroupInvite(sid, true);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement