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();
- var ownerID = config.ownerID
- // 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('Succesfully logged on.');
- client.chatMessage(ownerID, "Succesfully logged on.")
- client.setPersona(SteamUser.Steam.EPersonaState.Online);
- client.gamesPlayed([440]); // Custom game name HÄÄÄÄÄÄR!
- });
- client.on('accountInfo', function(name, country) {});
- //SKIT
- // FRIEND MESSAGES ------------------------------------------------------------------------------------------------------------------------------------------- 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.chatMessage(steamID, "!donate to donate (wip)")
- client.chatMessage(steamID, "!tradelink to get my tradelink")
- client.chatMessage(steamID, "!donators to see all my donators.")
- client.getPersonas([steamID], function(personas) {
- var persona = personas[steamID.getSteamID64()];
- var name = persona ? persona.player_name : (`['${steamID.getSteamID64()}']`); {
- console.log(`${name} (${steamID.getSteamID64()}) Skrev !commands`);
- }
- });
- }
- 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 "),
- client.chatMessage(steamID, "Mann Co.Supply Crate Keys:", keys),
- client.chatMessage(steamID, "Refined:", refined),
- client.chatMessage(steamID, "Reclaimed:", reclaimed),
- client.chatMessage(steamID, "Scrap:", 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.match("!play") && steamID == config.ownerID) { // TITTA HÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄR
- message = message.replace("!play ", "");
- console.log(message);
- client.gamesPlayed([message, 440])
- } else if(message.match("!tf2") && steamID == config.ownerID) {
- console.log(message);
- client.gamesPlayed([440])
- } else if (message.match("!online") && steamID == ownerID) {
- client.gamesPlayed([])
- client.setPersona(SteamUser.Steam.EPersonaState.Online);
- } else if (message.match("!busy") && steamID == ownerID) {
- client.gamesPlayed([])
- client.setPersona(SteamUser.Steam.EPersonaState.Busy);
- } else if (message.match("!away") && steamID == ownerID) {
- client.gamesPlayed([])
- client.setPersona(SteamUser.Steam.EPersonaState.Away);
- } else if (message.match("!ocommands") && steamID == ownerID) {
- client.chatMessage(ownerID, "My owner commands are:")
- client.chatMessage(ownerID, "!play to choose what the bot should play")
- client.chatMessage(ownerID, "!tf2 to play tf2")
- client.chatMessage(ownerID, "!online to only go online and not play tf2")
- client.chatMessage(ownerID, "!busy to go busy and not play tf2")
- client.chatMessage(ownerID, "!away to go away and not play tf2")
- client.chatMessage(ownerID, "!tradelink not owner command only but...")
- } else if (message.match("!donate")) {
- client.chatMessage(steamID, "If you want to donate just trade me with nothing on my side! Put a message with the following text: DONATION")
- } else if (message == "!tradelink") {
- client.chatMessage(steamID, "https://steamcommunity.com/tradeoffer/new/?partner=886523840&token=Y-s4Jvor")
- } else if (message.match("!donators")) {
- client.chatMessage(steamID, "I haven't recieved any donations yet. Do you want to be on this list, simply donate! Doesnt matter how much!")
- } else {
- client.chatMessage(steamID, "Sorry i couldn't understand that type !commands to get further information about what i can do.")
- }
- });
- // FRIEND MESSAGES ------------------------------------------------------------------------------------------------------------------------------------------- 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("Succesfully accepted a trade!");
- client.chatMessage(ownerID, "Succesfully accepted a trade!")
- if (err) console.log("There was an error accepting the offer."), client.chamessage(ownerID, "There was an error accepting the offer.");
- });
- }
- function declineOffer(offer) {
- offer.decline((err) => {
- console.log("Declined an offer");
- client.chatMessage(ownerID, "Declined an 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("A trade offer was glitched declining.");
- client.chatMessage(ownerID, "A trade offer was glitched declining.")
- declineOffer(offer);
- } else if (offer.partner.getSteamID64() === 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.")
- client.chatMessage(ownerID, "I got a trade offer but i declined it because their value was different:")
- }
- }
- }
- console.log("Our value: "+ourValue);
- console.log("Their Value: "+theirValue);
- console.log("These were the items i offered: "+itemsToGive);
- console.log("These were the items he offered: "+itemstoReceive);
- client.chatMessage(ownerID, "Our value: "+ourValue);
- client.chatMessage(ownerID, "Their Value:"+theirValue)
- client.chatMessage(ownerID, "These were the items i offered: "+itemsToGive);
- client.chatMessage(ownerID, "These were the items they offered: "+itemstoReceive);
- 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