我一直在开发一个NodeJS Steam机器人到我的CS:GO赌博网站,我只有问题。我希望机器人只接受CS:GO项目/皮肤(CS:GO appID 730 )。我知道这与appID有关。
我正在使用node-steam-tradeoffer-manager进行交易。
我接受交易的当前代码:
manager.on('newOffer', (offer) => {
var userID = offer.partner.getSteamID64();
var offerID = offer.id;
var prefix = time + " || " + 'Trade: #' + offerID + ' || ';
console.log(prefix + "from " + userID);
offer.getUserDetails((err, me, them) => {
if (err) {
console.log(err);
return;
}
if (them.escrowDays > 0) {
console.log(prefix + 'User has escrow! Declining!');
offer.decline((err) => {
if (err) {
console.log(prefix + 'Error declining offer!');
return;
}
});
} else {
if (offer.itemsToGive.length == 0) {
var userAmount = priceItemsInOffer(offer.itemsToReceive) * 1000;
if(userAmount < config['minDeposit']){
console.log(prefix + "User deposit skin that costs less than 100 Credits!");
offer.decline((err) => {
if (err) {
console.log(prefix + 'Error declining offer!');
return;
}
});
}
else{
console.log(prefix + 'User deposited ' + userAmount);
var insertDeposit0 = {
user: userID,
amount: userAmount,
offerID: offerID,
status: 0,
time: time
};
var query = connection.query('INSERT INTO deposits SET ?', insertDeposit0, function(err, result) {
// Neat!
});
offer.accept((err, status) => {
if (err) {
console.log(prefix + 'Error accepting offer!' + err.message);
connection.query('UPDATE deposits SET ? WHERE ?', [{ status: 1 }, { offerID: offerID }]) // 1 ERROR ACCEPTING
return;
} else {
community.checkConfirmations();
console.log(prefix + "Accepted!");
connection.query('UPDATE deposits SET ? WHERE ?', [{ status: 2 }, { offerID: offerID }]) // 2 ACCEPTED
}
});
}
} else if (offer.itemsToGive.length > 0) {
console.log(prefix + "User asked skins from us! Declining offer.");
offer.decline((err) => {
if (err) {
log(prefix + 'Error declining offer!');
return;
}
});
}
}
});
});
答案 0 :(得分:1)
由于您使用的是node-steam-tradeoffer-manager,因此您通常会与CEconItem
进行交互:
https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/wiki/EconItem https://github.com/DoctorMcKay/node-steamcommunity/wiki/CEconItem
每个CEconItem
都包含appid
属性:
https://github.com/DoctorMcKay/node-steamcommunity/wiki/CEconItem#appid
所以我们把它放在一起:
offer.itemsToGive
- 是CEconItem
(你的)offer.itemsToReceive
- 同样(但他们的)要检查所有项目是否来自CS:GO,您只需执行以下操作:
const allItemsAreFromCSGO = offer.itemsToReceive.every(item => item.appid === 730);