added steambot, trades and trasctions.

This commit is contained in:
2026-01-10 05:31:01 +00:00
parent 232968de1e
commit b90cdd59df
10 changed files with 3113 additions and 138 deletions

View File

@@ -5,6 +5,7 @@ import SteamTotp from "steam-totp";
import { EventEmitter } from "events";
import { SocksProxyAgent } from "socks-proxy-agent";
import HttpsProxyAgent from "https-proxy-agent";
import wsManager from "../utils/websocket.js";
/**
* Steam Bot Service with Multi-Bot Support, Proxies, and Verification Codes
@@ -223,7 +224,9 @@ class SteamBotInstance extends EventEmitter {
}
/**
* Create trade offer with verification code
* Create a trade offer
* @param {Object} options - Trade offer options
* @returns {Promise<Object>} Trade offer result
*/
async createTradeOffer(options) {
if (!this.isReady) {
@@ -235,6 +238,7 @@ class SteamBotInstance extends EventEmitter {
itemsToReceive,
verificationCode,
metadata = {},
userId,
} = options;
if (!tradeUrl) throw new Error("Trade URL is required");
@@ -247,6 +251,19 @@ class SteamBotInstance extends EventEmitter {
`📤 Bot ${this.botId} creating trade offer for ${itemsToReceive.length} items (Code: ${verificationCode})`
);
// Notify user that trade is being created
if (userId) {
wsManager.sendToUser(userId, {
type: "trade_creating",
data: {
verificationCode,
itemCount: itemsToReceive.length,
botId: this.botId,
timestamp: Date.now(),
},
});
}
return new Promise((resolve, reject) => {
const offer = this.manager.createOffer(tradeUrl);
@@ -263,6 +280,20 @@ class SteamBotInstance extends EventEmitter {
err.message
);
this.errorCount++;
// Notify user of error
if (userId) {
wsManager.sendToUser(userId, {
type: "trade_error",
data: {
verificationCode,
error: err.message,
botId: this.botId,
timestamp: Date.now(),
},
});
}
return reject(err);
}
@@ -270,6 +301,9 @@ class SteamBotInstance extends EventEmitter {
`✅ Bot ${this.botId} trade sent: ${offer.id} (Code: ${verificationCode})`
);
// Get trade offer URL
const tradeOfferUrl = `https://steamcommunity.com/tradeoffer/${offer.id}`;
this.activeTrades.set(offer.id, {
id: offer.id,
status: status,
@@ -279,23 +313,71 @@ class SteamBotInstance extends EventEmitter {
metadata: metadata,
createdAt: new Date(),
botId: this.botId,
userId: userId,
tradeOfferUrl: tradeOfferUrl,
});
this.tradeCount++;
this.lastTradeTime = new Date();
// Notify user that trade was sent
if (userId) {
wsManager.sendToUser(userId, {
type: "trade_sent",
data: {
offerId: offer.id,
verificationCode,
status,
botId: this.botId,
itemCount: itemsToReceive.length,
tradeOfferUrl,
timestamp: Date.now(),
},
});
}
if (status === "pending") {
this._confirmTradeOffer(offer)
.then(() => {
// Notify user that trade was confirmed
if (userId) {
wsManager.sendToUser(userId, {
type: "trade_confirmed",
data: {
offerId: offer.id,
verificationCode,
botId: this.botId,
tradeOfferUrl,
timestamp: Date.now(),
},
});
}
resolve({
offerId: offer.id,
botId: this.botId,
status: "sent",
verificationCode: verificationCode,
requiresConfirmation: true,
tradeOfferUrl,
});
})
.catch((confirmErr) => {
// Notify user of confirmation error
if (userId) {
wsManager.sendToUser(userId, {
type: "trade_confirmation_error",
data: {
offerId: offer.id,
verificationCode,
error: confirmErr.message,
botId: this.botId,
tradeOfferUrl,
timestamp: Date.now(),
},
});
}
resolve({
offerId: offer.id,
botId: this.botId,
@@ -303,6 +385,7 @@ class SteamBotInstance extends EventEmitter {
verificationCode: verificationCode,
requiresConfirmation: true,
error: confirmErr.message,
tradeOfferUrl,
});
});
} else {
@@ -312,6 +395,7 @@ class SteamBotInstance extends EventEmitter {
status: "sent",
verificationCode: verificationCode,
requiresConfirmation: false,
tradeOfferUrl,
});
}
});
@@ -365,26 +449,103 @@ class SteamBotInstance extends EventEmitter {
tradeData.state = offer.state;
tradeData.updatedAt = new Date();
const userId = tradeData.userId;
switch (offer.state) {
case TradeOfferManager.ETradeOfferState.Accepted:
console.log(`✅ Bot ${this.botId} trade ${offer.id} ACCEPTED`);
this.emit("tradeAccepted", offer, tradeData);
this.errorCount = Math.max(0, this.errorCount - 1); // Decrease error count on success
// Notify user via WebSocket
if (userId) {
wsManager.sendToUser(userId, {
type: "trade_accepted",
data: {
offerId: offer.id,
verificationCode: tradeData.verificationCode,
botId: this.botId,
itemCount: tradeData.itemsToReceive?.length || 0,
timestamp: Date.now(),
},
});
}
break;
case TradeOfferManager.ETradeOfferState.Declined:
console.log(`❌ Bot ${this.botId} trade ${offer.id} DECLINED`);
this.emit("tradeDeclined", offer, tradeData);
this.activeTrades.delete(offer.id);
// Notify user via WebSocket
if (userId) {
wsManager.sendToUser(userId, {
type: "trade_declined",
data: {
offerId: offer.id,
verificationCode: tradeData.verificationCode,
botId: this.botId,
timestamp: Date.now(),
},
});
}
break;
case TradeOfferManager.ETradeOfferState.Expired:
console.log(`⏰ Bot ${this.botId} trade ${offer.id} EXPIRED`);
this.emit("tradeExpired", offer, tradeData);
this.activeTrades.delete(offer.id);
// Notify user via WebSocket
if (userId) {
wsManager.sendToUser(userId, {
type: "trade_expired",
data: {
offerId: offer.id,
verificationCode: tradeData.verificationCode,
botId: this.botId,
timestamp: Date.now(),
},
});
}
break;
case TradeOfferManager.ETradeOfferState.Canceled:
console.log(`🚫 Bot ${this.botId} trade ${offer.id} CANCELED`);
this.emit("tradeCanceled", offer, tradeData);
this.activeTrades.delete(offer.id);
// Notify user via WebSocket
if (userId) {
wsManager.sendToUser(userId, {
type: "trade_canceled",
data: {
offerId: offer.id,
verificationCode: tradeData.verificationCode,
botId: this.botId,
timestamp: Date.now(),
},
});
}
break;
case TradeOfferManager.ETradeOfferState.Invalid:
console.log(`⚠️ Bot ${this.botId} trade ${offer.id} INVALID`);
this.emit("tradeInvalid", offer, tradeData);
this.activeTrades.delete(offer.id);
// Notify user via WebSocket
if (userId) {
wsManager.sendToUser(userId, {
type: "trade_invalid",
data: {
offerId: offer.id,
verificationCode: tradeData.verificationCode,
botId: this.botId,
timestamp: Date.now(),
},
});
}
break;
}
}
@@ -579,6 +740,7 @@ class SteamBotManager extends EventEmitter {
tradeUrl,
itemsToReceive,
verificationCode,
userId,
metadata: {
...metadata,
userId,
@@ -592,9 +754,11 @@ class SteamBotManager extends EventEmitter {
createdAt: new Date(),
});
// Return result with trade offer URL
return {
...result,
verificationCode,
code: verificationCode,
tradeOfferUrl: result.tradeOfferUrl,
};
}