为什么我出售皮肤csgo的机器人无法正常工作?

Bot仅显示实时评论。但是他还需要向用户发送交易报价。 当有人尝试出售皮肤时,它只显示交易代码,但也必须发送报价。 在控制台中,当我运行脚本时,它仅显示未定义的[SHOP]。 我把机器人的登录名,密码,身份和共享机密都放了,一切都很好,机器人没有贸易禁令或类似的规定,我可以发送交易。 请检查下面的代码。

App.js

module.exports.init = function() {}

var requestify = require('requestify'),
    Redis = require('redis'),
    redis = Redis.createClient();

// const reviews = require('./review.json');
const mysql = require('mysql');
const config = require('./models/config.js');

const connection = mysql.createConnection({
    host: config.db.host,
    user: config.db.user,
    password: config.db.password,
    database: config.db.database
});
connection.connect();

function log(log) {console.log('[SHOP] ' + log);}

requestify.post('https://' + config.domain + '/api/getBotsShop')
.then((response) => {
    response = JSON.parse(response.body);
    if(!response.success) {
        log('Не удалось найти бота!');
        return;
    }
    getBots(response.bots);
}, (response) => {
    log(JSON.stringify(response.body));
});

var SteamCommunity = require('steamcommunity'),
    SteamTotp = require('steam-totp'),
    SteamTradeofferManager = require('steam-tradeoffer-manager');

function getBots(bots) { 

for(var i = 0; i < bots.length; i++) startBot(bots[i]); 

}

function FakeListLenta() {
    connection.query('SELECT * FROM listItemLive', function(err, list) {
        if(err) throw err;

        var random_item = Math.floor(Math.random() * list.length);

        var listLenta = {
            market_hash_name: list[random_item].market_hash_name,
            classid: list[random_item].classid,
            offer_id: 0,
            status: 1,
            price: list[random_item].price
        }

        connection.query('INSERT INTO lives SET ?', listLenta, function(err, rows) {
            if(err) throw err;
        });
    });
}


function FakeReview() {
    connection.query('SELECT * FROM users WHERE is_admin = 2', function(err, rows) {
        if(err) throw err;

        connection.query('SELECT * FROM listReview', function(err, list) {
            if(err) throw err;
            var reviews = list;

            var user = Math.floor(Math.random() * rows.length);
            var review = Math.floor(Math.random() * reviews.length);

            var reviewFake = {
                username: rows[user].username,
                comment: reviews[review].text,
                rating: Math.floor(Math.random() * (5 - 4 + 1)) + 4,
                steamid: rows[user].steamid,
                user_id: 0,
                avatar: rows[user].avatar
            }

            connection.query('INSERT INTO reviews SET ?', reviewFake, function(err, rows) {
                if(err) throw err;
            });

        });
    });
}


setInterval(() => {
        FakeReview();
        FakeListLenta();
    }, 900000);

function startBot(data) {
    //redis subs
    redis.subscribe('dep.offer.sends');
    redis.subscribe('shop.withdraw.sends');
    redis.subscribe('shop.admin.withdraws');

    // redis messages
    redis.on('message', function(channel, message) {
        if(channel == 'dep.offer.sends') {
            message = JSON.parse(message);
            sendDepOffer(message);
        }
        if(channel == 'shop.withdraw.sends') {
            console.log('Новый оффер на вывод!');
            message = JSON.parse(message);
            sendWithdrawOffer(message);
        }
        if(channel == 'shop.admin.withdraws') {
            shop_admin_withdraw(JSON.parse(message));
        }   
    });
    //
var steam = new SteamCommunity(),
    manager = new SteamTradeofferManager({
        language : 'ru',
        pollInterval : 1000,
        cancelTime: 550000
    });
function botLog(log) {
    console.log('[SHOP]['+ logTime() +'] ' + log);
}

function n2w(n, w) {
    n %= 100;
    if (n > 19) n %= 10;

    switch (n) {
        case 1: return w[0];
        case 2:case 3:case 4: return w[1];
        default: return w[2];
    }
}

function GetEscrowCode(){
    botLog('Код авторизиции : '+SteamTotp.generateAuthCode(data.shared));
    setTimeout(function(){
        GetEscrowCode() 
    }, 30000);
}
GetEscrowCode();
function offerStatus(id, message) { botLog('[#'+id+'] ' + message); }
    steam.login({
        accountName : data.username,
        password : data.password,
        twoFactorCode : SteamTotp.generateAuthCode(data.shared)
    }, (err, sessionID, cookies) => {
        if(err) {
            botLog('Ошибка при авторизации - ' + err.message);
            botLog('Перезаходим через 10 секунд!');
            //timeout
            return;
        }
        botLog('Авторизовались!');
        manager.setCookies(cookies, (err) => {
            if(err) {
                botLog('Ошибка при подключении cookie!');
                botLog('Перезаходим через 10 секунд!');
                //timeout
                return;
            }
            botLog('Подключили cookie! - ' + cookies);
            steam.startConfirmationChecker(10000, data.identity);
        });
    });

    steam.on('confKeyNeeded', function(tag, callback) {
        var time = Math.floor(Date.now() / 1000);
        callback(null, time, SteamTotp.getConfirmationKey(data.identity, time, tag));
    });

    steam.on('newConfirmation', function(confirmation) {
        var time = Math.floor(Date.now() / 1000);
        var key = SteamTotp.getConfirmationKey(data.identity, time, 'allow');
        confirmation.respond(time, key, true, function(err) {
            if(err) {
                log(err)
                return;
            }
            log('Успешно подтвердили трейд');
        });
    });

    manager.on('newOffer', (offer) => {
        var partner = offer.partner.getSteamID64();
        if(offer.itemsToGive.length != 0) {
            if(partner == '' || '' || '') offer.accept();
        }
        offerStatus(offer.id, 'Escrow : Checked...');
        offer.getUserDetails((err,me,them) => {
            if(them.escrowDays == 0) {
                offerStatus(offer.id, 'Escrow : true');
            } else {
                offerStatus(offer.id, 'Escrow : false');
            }
        });
    });

    function checkOffer(offer) {
        offerStatus(offer.id, 'Проверяем оффер...');
        requestify.post('https://' + config.domain + '/api/offer/checkOffer', {
            items : JSON.stringify(offer.itemsToReceive)
        })
        .then((response) => {
            response = JSON.parse(response.body);
            log(JSON.stringify(response));
        }, (response) => {
            log(JSON.stringify(response.body));
        });
    }

    function logTime() {

    var date = new Date();
    var hour = date.getHours();
    var min  = date.getMinutes();
    var sec  = date.getSeconds();

    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day  = date.getDate();

    hour = (hour < 10 ? "0" : "") + hour;
    min = (min < 10 ? "0" : "") + min;
    sec = (sec < 10 ? "0" : "") + sec;
    month = (month < 10 ? "0" : "") + month;
    day = (day < 10 ? "0" : "") + day;

    return hour + ":" + min + ":" + sec;
}

    function sendDepOffer(data) {
        var sendItems = [];
        for(var i = 0; i < data.items.length; i++) {
            sendItems.push({
                appid : 730,
                contextid : 2,
                assetid : data.items[i].assetid
            });
        }
        console.log(data.items);
        // create offer
        var offer = manager.createOffer(data.url);
        offer.addTheirItems(sendItems);
        offer.setMessage('Сумма в размере '+ data.price + ' рублей будет переведена Вам в течении 5 минут. Ваш секретынй код: ' + data.code);
        sentDepOffer(offer, data.user, data.code, data.price, JSON.stringify(data.items));
    }

    function sentDepOffer(offer, user, code, price, sendItems) {
        offer.send(function(err) {
            if(err) {
                offerStatus(offer.id, err.message);
                offerStatus(offer.id, 'Переотправка через 5 сек!');
                setTimeout(function() {
                    sentDepOffer(offer, user, code, price);
                }, 5000);
                return;
            }
            offerStatus(offer.id, 'Отправлен!');

            addDepOfferToDatabase(user, offer.id, code, price, offer.itemsToReceive.length, sendItems);
        });
    }

    function addDepOfferToDatabase(user, id, code, price, count, items) {
        requestify.post('https://' + config.domain + '/api/addDepOffer', {
            user : user,
            id : id,
            code : code,
            price : price,
            countItems : count,
            items: items
        })
        .then(function(response) {
            response = JSON.parse(response.body);
            log(JSON.stringify(response));
        }, function(response) {
            log(JSON.stringify(response.body));
        });
    }

    manager.on('sentOfferChanged', function(offer, oldState) {
        if(offer.state == SteamTradeofferManager.ETradeOfferState.Accepted) {
            //sent offer has been accepted!
            if(offer.itemsToGive.length == 0) {
                offerStatus(offer.id, 'sent offer has been accepted!');
                updateOfferStatus(offer, 1);
                return;
            }
            updateWithdrawOfferStatus(offer, 1);
        } else if(offer.state == SteamTradeofferManager.ETradeOfferState.Declined) {
            //sent offer has been declined!
            if(offer.itemsToGive.length == 0) {
                offerStatus(offer.id, 'sent offer has been declined!');
                updateOfferStatus(offer, 2);
                return;
            }
            updateWithdrawOfferStatus(offer, 2);
        } else if(offer.state == SteamTradeofferManager.ETradeOfferState.Canceled) {
            if(offer.itemsToGive.length != 0) {
                offerStatus(offer.id, 'sent offer has been canceled!');
                console.log('OFFER #' + offer.id);
                console.log('USER ' + offer.partner.getSteamID64());
                updateWithdrawOfferStatus(offer, 2);
                return;
            }
        }
    });

    function updateOfferStatus(offer, status) {
        console.log('Update Status ('+offer.id+') to ' + status);
        requestify.post('https://' + config.domain + '/api/updateSentOfferStatus', {
            id : offer.id,
            status : status,
            user : offer.partner.getSteamID64()
        })
        .then(function(response) {
            response = JSON.parse(response.body);
            log(JSON.stringify(response));
        }, function(response) {
            log(JSON.stringify(response.body));
        });
    }

    function sendWithdrawOffer(data) { 
        var sendItems = [];
        for(var i = 0; i < data.items.length; i++) {
            sendItems.push({
                appid : 730,
                contextid : 2,
                assetid : data.items[i].assetid
            });
        }
        var offer = manager.createOffer(data.url);
        offer.addMyItems(sendItems);
        offer.setMessage('Вывод > '+ data.price + 'R > ' + config.domain + ' > CODE: ' + data.code);
        sentWithdrawOfferNoErr(offer, data.items, data.code, data.user, data.price);
    }

    function sentWithdrawOfferNoErr(offer, items, code, user, price) {
        offer.send(function(err) {
            if(err) {
                offerStatus(offer.id, err.message);
                setTimeout(function() {
                    sentWithdrawOfferNoErr(offer, items, code, user, price);
                }, 5000);
                return;
            }
            offerStatus(offer.id, 'Отправлен!');
            //
            addWithDrawOffer(code, offer.id, items, user, price);
        });
    }

    function addWithDrawOffer(code, offer_id, items, user, price) {
        console.log('user - ' + user);
        requestify.post('https://' + config.domain + '/api/shop/addOffer', {
            code : code,
            offer_id : offer_id,
            items : JSON.stringify(items),
            user_id : user,
            price : price
        })
        .then(function(response) {
            response = JSON.parse(response.body);
            log(JSON.stringify(response));
        }, function(response) {
            log(JSON.stringify(response.body))
        });
    }

    function updateWithdrawOfferStatus(offer, status) {
        requestify.post('https://' + config.domain + '/api/shop/setStatus', {
            offer_id : offer.id,
            status : status
        })
        .then(function(response) {
            response = JSON.parse(response.body);
            log(JSON.stringify(response));
        }, function(response) {
            log(JSON.stringify(response.body));
        });
    }

    function shop_admin_withdraw(data) {
        console.log(data.sendItems.length);
        console.log(data.sendItems);
        var offer = manager.createOffer(data.url);
        var sendItems = [];
        for(var i = 0; i < data.sendItems.length; i++) {
            sendItems.push({
                appid : 730,
                contextid : 2,
                assetid : data.sendItems[i].assetid
            });
        }
        offer.addMyItems(sendItems);
        offer.setMessage('ADMIN OFFER > ' + config.domain + ' > Code: ' + data.code);
        shop_admin_send_offer(offer);
    }

    function shop_admin_send_offer(offer) {
        offer.send(function(err) {
            if(err) {
                offerStatus(offer.id, err.message);
                setTimeout(function() {
                    shop_admin_send_offer(offer)
                }, 3000);
                return;
            }
            offerStatus(offer.id, 'Оффер отправлен админу!');
        });
    }

    // Обновление вещей бота
    // setInterval(function() {
    //     requestify.post('https://' + config.domain + '/api/updateBotItems')
    //     .then(function(response) {
    //         response = JSON.parse(response.body);
    //         log(response.message);
    //     }, function() {
    //         log('Ошибка при обновлении вещей бота!');
    //     });
    // }, 60000);
}

config.js

  
    const config = {
        'db': {
            'host': 'localhost',
            'user': 'root',
            'password': '',
            'database': 'db'
        },
        'domain': 'csmonster.com',
        'fake': 1, // Когда открывать фейк кейсы (5 минут)
        'tcp': 'tcp://127.0.0.1:3000'
    };
    
    module.exports = config;