Jump to content


Photo

Find one item by classid

node.js node-steam-tradeoffer-manager

  • Please log in to reply
3 replies to this topic

#1 PonyExpress

PonyExpress

    Member

  • Member
  • PipPip
  • 22 posts

Posted 06 February 2019 - 09:07 PM

I try to create code that will convert steamtradematcher.com URL and send trade offer.

steamtradematcher.com URL looks like:
 _ttps://www.steamtradematcher.com/action/startTradeOffer/239296914/2nqDtNKM/1935295573;2139754079/1930661303;2139726948
From this line I get all the data: Partner, Token and Items.

However, I think I'm doing something wrong. My method looks pretty complicated and doesn't work anyway.
My question is how can I find the first any item with classid="1935295573" to add it to the trade later? (One item)
 
            //  MSG = "STM https://www.steamtradematcher.com/action/startTradeOffer/239296914/2nqDtNKM/1935295573;2139754079/1930661303;2139726948"
            let stmUrl = MSG.split("/"),
                tradePartner = "[U:1:" + stmUrl[5] + "]",
                tradeToken = stmUrl[6],
                stmHisItems = stmUrl[8].split(";"),
                stmMyItems = stmUrl[7].split(";");
            if (stmHisItems.length != stmMyItems.length) {
                console.log("ERROR 1: Bad url");
            } else {
                let t = manager.createOffer(tradePartner, tradeToken);
                t.getUserDetails((ERR, ME, THEM) => {
                    if (ERR) {
                        console.log("ERROR 2: " + ERR);
                    } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
                        let hisItems = [],
                            myItems = [];
                        manager.getUserInventoryContents(tradePartner, 753, 6, true, (ERR, INV, CURR) => {
                            if (ERR) {
                                console.log("ERROR 3: " + ERR);
                            } else {
                                INV = INV.filter((ITEM) => ITEM.getTag("item_class").internal_name == "item_class_2"); // <<<<<<<<<<<<
                                for (let i = 0; i < INV.length; i++) {                // <<<<<<<<<<<<
                                    for (let j = 0; j < stmHisItems.length; j++) {    // <<<<<<<<<<<<
                                        if (stmHisItems[j] == INV[i].classid) {       // <<<<<<<<<<<<
                                            hisItems.push(INV[i]);                    // <<<<<<<<<<<<
                                            console.log("PUSH:" + i);                 // <<<<<<<<<<<<
                                            stmHisItems[j] = "need_only_one.";        // <<<<<<<<<<<<
                                        }
                                    }
                                }
                                // 2. find my items and 3. add his/my items in trade 4. send trade
                             }
                        });
                    }
                });
            }

 



#2 PonyExpress

PonyExpress

    Member

  • Member
  • PipPip
  • 22 posts

Posted 07 February 2019 - 12:36 PM

I think I found the solution myself

                                INV = INV.filter((ITEM) => ITEM.getTag("item_class").internal_name == "item_class_2");
                                for (let i = 0; i < stmHisItems.length; i++) {
                                    hisItems.push(    INV.find((ITEM) => ITEM.classid == stmHisItems[i])      );
                                }

_

 

Yes, it works great. Only I after a few trades, I began to receive an error:
 
TradeOffer.js:254
if (typeof details.appid === 'undefined' || typeof details.contextid === 'undefined' || (typeof details.assetid === 'undefined' && typeof details.id === 'undefined')) {
TypeError: Cannot read property 'appid' of undefined
 
I think I need to stop find and trade  if the at least 1 item is not found.

Do you think I should check my inventory first or partner's inventory? Or is there no difference?


Edited by PonyExpress, 07 February 2019 - 03:02 PM.


#3 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 2,038 posts

Posted 07 February 2019 - 07:53 PM

That error means you're calling addMyItem/addTheirItem with an undefined argument.

 

It doesn't matter which inventory you check first.



#4 PonyExpress

PonyExpress

    Member

  • Member
  • PipPip
  • 22 posts

Posted 28 February 2019 - 10:38 AM

Here is my finished code, maybe someone will need it.
Just copy STM-link from scan page, send to bot and the trade will be sent in a couple of seconds.
You can send offers with a very large amount cards, and you do not need to wait a few minutes until the inventory is loaded.

if (MSG.toUpperCase().indexOf("HTTPS://WWW.STEAMTRADEMATCHER.COM/ACTION/STARTTRADEOFFER/") >= 0) {
    let stmUrl = MSG.split("/"),
        tradePartner = "[U:1:" + stmUrl[5] + "]",
        tradeToken = stmUrl[6],
        stmHisItems = stmUrl[7].split(";"),
        stmBotItems = stmUrl[8].split(";");
    if (stmHisItems.length != stmBotItems.length) {
        console.log("Error: Invalid URL");
    } else {
        let trade = manager.createOffer(tradePartner, tradeToken);
        trade.getUserDetails((ERR, BotDetails, UserDetails) => {
            if (ERR) {
                console.log("An error occurred while getting trade holds: " + ERR);
            } else if (UserDetails.escrowDays == 0) {
                manager.getUserInventoryContents(tradePartner, 753, 6, true, (ERR, INV) => {
                    if (ERR) {
                        console.log("An error occurred while getting inventory: " + ERR);
                    } else {
                        let hisItems = [];
                        INV = INV.filter((ITEM) => ITEM.getTag("item_class").internal_name == "item_class_2");
                        for (let i = 0; i < stmHisItems.length; i++) {
                            hisItems.push(INV.find((ITEM) => ITEM.classid == stmHisItems[i]));
                        }
                        manager.getUserInventoryContents(client.steamID, 753, 6, true, (ERR, INV) => {
                            if (ERR) {
                                console.log("An error occurred while getting bot inventory: " + ERR);
                            } else {
                                let botItems = [];
                                INV = INV.filter((ITEM) => ITEM.getTag("item_class").internal_name == "item_class_2");
                                for (let i = 0; i < stmBotItems.length; i++) {
                                    botItems.push(INV.find((ITEM) => ITEM.classid == stmBotItems[i]));
                                }
                                if (hisItems.length != botItems.length) {
                                    console.log("Error: Unknown error");
                                } else {
                                    for (let i = 0; i < hisItems.length; i++) {
                                        if (hisItems[i] === undefined) {
                                            console.log("Error: Unknown partner item");
                                            return;
                                        }
                                    }
                                    for (let i = 0; i < botItems.length; i++) {
                                        if (botItems[i] === undefined) {
                                            console.log("Error: Unknown bot item");
                                            return;
                                        }
                                    }
                                    trade.addTheirItems(hisItems);
                                    trade.addMyItems(botItems);
                                    trade.setMessage("Steam Trade Matcher");
                                    trade.send((ERR) => {
                                        if (ERR) {
                                            console.log("An error occurred while sending trade: " + ERR);
                                        } else {
                                            console.log("Trade offer sent");
                                        }
                                    });
                                }
                            }
                        });
                    }
                });
            }
        });
    }
}
 






Also tagged with one or more of these keywords: node.js, node-steam-tradeoffer-manager

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users