Untitled

mail@pastecode.io avatar
unknown
javascript
7 months ago
3.5 kB
2
Indexable
Never
const SteamUser = require('steam-user');
const axios = require('axios');
const querystring = require('querystring'); // Для кодирования данных формы

const steamUsername = '';
const steamPassword = '';
const itemsToSend = [
    {
        appid: 570, // Идентификатор приложения для Dota 2
        contextid: '', // Контекст инвентаря для Dota 2
        assetid: '' // Пример ID предмета
    }
];
const client = new SteamUser();

let sessionID, cookies;

client.logOn({
    accountName: steamUsername,
    password: steamPassword
});

client.on('loggedOn', () => {
    console.log('Logged into Steam');
    client.setPersona(SteamUser.EPersonaState.Online);
});

client.on('webSession', (sid, cks) => {
    sessionID = sid;
    cookies = cks.join('; ');
    sendTradeOffer('partnerId', 'token', itemsToSend);
});

function sendTradeOffer(partnerSteamId, tradeOfferToken, itemsToSend) {
    // Организация данных для запроса

    const itemAsset = itemsToSend.map(item => ({
        "appid": item.appid,
        "contextid": item.contextid,
        "amount": "1",
        "assetid": item.assetid
    }));
 
    const jsonTradeOffer = {
        "newversion": true,
        "version": 4,
        "me": {
            "assets": itemAsset,
            "currency": [],
            "ready": false
        },
        "them": {
            "assets": [],
            "currency": [],
            "ready": false
        }
    };

    const data = {
        sessionid: sessionID,
        serverid: '1',
        partner: partnerSteamId,
        tradeoffermessage: 'Your trade offer message',
        json_tradeoffer: JSON.stringify(jsonTradeOffer),
        captcha: '',
        trade_offer_create_params: JSON.stringify({
            trade_offer_access_token: tradeOfferToken
        }),
        tradeofferid_countered: ''
    };

  
    console.log(cookies)

    const config = {
        headers: {
            'referer': `https://steamcommunity.com/tradeoffer/new/?partner=${partnerSteamId}&token=${tradeOfferToken}`,
            'Content-Type': 'application/x-www-form-urlencoded',
            'Cookie': cookies
        }
    };

    // Отправка запроса
    axios.post('https://steamcommunity.com/tradeoffer/new/send', querystring.stringify(data), config)
        .then(response => console.log('Trade offer sent successfully:', response.data))
        .catch(error => console.error('Error sending trade offer:', error));
}



// const express = require('express');
// const axios = require('axios');
// const app = express();
// const port = 3000;

// const apiKey = '';
// const steamId = '';

// app.get('/my-dota-items', async (req, res) => {
//     try {
//         const response = await axios.get(`http://api.steampowered.com/IEconItems_570/GetPlayerItems/v0001/?key=${apiKey}&steamid=${steamId}`);
//         const items = response.data.result.items;

//         const formattedItems = items.map(item => JSON.stringify(item, null, 4)).join('\n');

//         res.setHeader('Content-Type', 'application/json');
//         res.send(formattedItems);
//     } catch (error) {
//         console.error('Error fetching Dota 2 items:', error);
//         res.status(500).send('Error fetching items');
//     }
// });

// app.listen(port, () => {
//     console.log(`Server running on ${port}`);
// });
Leave a Comment