Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CONST
- const SteamUser = require('steam-user');
- const SteamTotp = require('steam-totp');
- const SteamCommunity = require('steamcommunity');
- const TradeOfferManager = require('steam-tradeoffer-manager');
- const config = require('./config.json');
- const TeamFortress2 = require ('tf2');
- const Prices = require('./prices.json');
- const client = new SteamUser();
- const tf2 = new TeamFortress2(client);
- const community = new SteamCommunity();
- // CONST
- //SKIT
- 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('Inloggad.');
- client.chatMessage(config.ownerID, "Inloggad");
- client.setPersona(SteamUser.Steam.EPersonaState.Online);
- client.gamesPlayed(["Grinch is da bezt", 440]); // Custom game name HÄÄÄÄÄÄR!
- });
- client.on('accountInfo', function(name, country) {});
- //SKIT
- // FRIEND MESSAGES
- client.on("friendMessage", function(steamID, message) {
- if (message == "!commands") {
- client.chatMessage(steamID, "My commands are:");
- client.chatMessage(steamID, "!stock to get my current stock");
- client.chatMessage(steamID, "!owner to know who my owner is.");
- client.chatMessage(steamID, "!how2trade to know how to trade with me")
- client.getPersonas([steamID], function(personas) {
- var persona = personas[steamID.getSteamID64()];
- var name = persona ? persona.player_name : (`['${steamID.getSteamID64()}']`); {
- console.log(`${name} (${steamID.getSteamID64()}) Skrev help`);
- }
- });
- }
- else if (message == "!stock") {
- manager.getInventoryContents(440, 2, true, function (err, inventory) {
- if (err) {
- client.chatMessage(steamID, "Oooopsi daisy that didn't work.")
- return;
- }
- var refined, reclaimed, scrap, keys = 0;
- for (var i = 0; i < inventory.length; i++) {
- var item = inventory [i];
- var name = item.market_hash_name;
- if (name == "Refined Metal") {
- refined++;
- } else if (name == "Reclaimed Metal") {
- reclaimed++;
- } else if (name == "Scrap Metal") {
- scrap++
- } else if (name == "Mann Co.Supply Crate Key") {
- keys++
- }
- }
- client.chatMessage(steamID, "Stock is ", keys, refined, reclaimed, scrap)
- })
- } else if (message == "!how2trade") {
- client.chatMessage(steamID, "You basically send a trade offer with the correct amount, you can check my listings here https://backpack.tf/classifieds?steamid=76561198846789568")
- } else if (message == "!owner") {
- client.chatMessage(steamID, "I am coded by Aethez you can find his profile in my comments on my profile.")
- } else if (message == "!play" && steamID == config.ownerID) {
- message = message.replace("!play", "");
- client.gamesPlayed([message, 440])
- }
- });
- //FRIEND MESSAGES
- // TRADING
- 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("Jag accade ett trade offer");
- client.chatMessage(76561198403256399, "Jag gjorde ett trade!")
- if (err) console.log("There was an error accepting the offer.");
- });
- }
- function declineOffer(offer) {
- offer.decline((err) => {
- console.log("Jag declinade ett trade offer");
- if (err) console.log("There was an error declining the offer.");
- });
- }
- client.setOption("promptSteamGuardCode", false);
- function processOffer(offer) {
- if (offer.isGlitched() || offer.state === 11) {
- console.log("Ett Trade offer var glitchad declinar traden på momangen.");
- 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);
- }
- }
- manager.on('newOffer', (offer) => {
- processOffer(offer);
- });
- //TRADING
- //Friends!!!
- client.on('friendRelationship', function(sid, relationship) {
- if (relationship == SteamUser.EFriendRelationship.RequestRecipient) {
- console.log("We recieved a friend request from "+sid);
- client.addFriend(sid, function (err, name) {
- if (err) {
- console.log(err);
- return;
- } else {
- console.log("Accepted user with the name of "+name);
- client.chatMessage(config.ownerID, "Added 1 person, their name is: " +name);
- client.chatMessage(sid, "Hi thanks for adding me, type !commands to get my command list.");
- }
- });
- }
- });
- //FRIENDS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement