-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
143 lines (130 loc) · 4.56 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const TradeOfferManager = require('steam-tradeoffer-manager');
const SteamCommunity = require('steamcommunity');
const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp');
const TeamFortress2 = require('tf2');
const fs = require('fs');
const path = require('path');
const commandsFolder = path.join(__dirname, './commands');
const modulesFolder = path.join(__dirname, './modules');
const functions = require('./functions/functions.js');
const craftReclaimed = require('./functions/craftReclaimed.js')
const craftRefined = require('./functions/craftRefined.js')
const defIndexJSON = require('./items/defIndex.json');
const config = require('./config.json');
const client = new SteamUser();
const tf2 = new TeamFortress2(client);
const community = new SteamCommunity();
const manager = new TradeOfferManager({
steam: client,
community: community,
language: 'en'
});
const logOnOptions = {
accountName: config.username,
password: config.password,
twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret),
identitySecret: config.identitySecret,
};
client.logOn(logOnOptions);
client.on('loggedOn', () => {
console.clear();
console.log('Logged On.');
client.setPersona(SteamUser.EPersonaState.Online);
client.gamesPlayed(440);
});
client.on('webSession', (sessionid, cookies) => {
manager.setCookies(cookies);
community.setCookies(cookies);
community.startConfirmationChecker(5000, config.identitySecret);
});
function acceptOffer(offer) {
offer.accept((err) => {
community.checkConfirmations();
console.log("I accepted an offer.")
client.chatMessage(config.ownerID, "✅ I accepted an offer.")
if (err) console.log("There was an error accepting the offer.\n"+err)
})
}
function declineOffer(offer) {
offer.decline((err) => {
console.log("I declined an offer.")
client.chatMessage(config.ownerID, "❌ I declined an offer.")
if (err) console.log("There was an error declining the offer.")
})
}
function processOffer(offer) {
if (offer.isGlitched() || offer.state === 11){
console.log('Offer was glitched, declining.');
} else if (offer.partner.getSteamID64() == config.ownerID){
acceptOffer(offer);
} else {
var ourItems = offer.itemsToGive;
var theirItems = offer.itemsToReceive;
if (ourItems.length <= 0 && theirItems.length >= 0) {
console.log('Offer was a donation, accepting.');
acceptOffer(offer);
} else {
console.log('Offer was not a donation, declining.');
declineOffer(offer);
}
}
}
function autoMelt(){
if(tf2.haveGCSession){
if(functions.countItemsByDefIndex(tf2.backpack, defIndexJSON.ScrapMetal) >= 3){
craftReclaimed.craftReclaimed(tf2, 1);
client.chatMessage(config.ownerID, "⏱ Auto melting scrap.")
}
if(functions.countItemsByDefIndex(tf2.backpack, defIndexJSON.ReclaimedMetal) >= 3){
craftRefined.craftRefined(tf2, 1);
client.chatMessage(config.ownerID, "⏱ Auto melting reclaimed.")
}
}
}
manager.on('newOffer', (offer) => {
processOffer(offer);
console.log("New trade offer.")
});
tf2.on('connectedToGC', function() {
console.log("Connected to tf2 game server.");
});
tf2.on('backpackLoaded', function() {
console.log("Backpack loaded.");
setInterval(autoMelt, 5000);
});
tf2.on('craftingComplete', function(){
console.log("Craft completed.")
client.chatMessage(config.ownerID, "⚠️ Craft completed.")
});
tf2.on('itemAcquired', function(){
console.log("Item acquired.")
client.chatMessage(config.ownerID, "📦 Item acquired.")
})
tf2.on('itemRemoved', function(){
console.log("Item removed.")
client.chatMessage(config.ownerID, "🗑️ Item removed.")
})
client.setOption("promptSteamGuardCode", false);
fs.readdirSync(commandsFolder).forEach(file => {
if(file.endsWith('.js')){
const commandName = file.split('.')[0];
const command = require(path.join(commandsFolder, file));
client.on('friendMessage', (steamID, message) => {
if (message.startsWith(commandName)) {
command(client, tf2, steamID, message);
}
});
}
});
fs.readdirSync(modulesFolder).forEach(file => {
if(file.endsWith('.js')){
const moduleName = file.split('.')[0];
const module = require(path.join(modulesFolder, file));
module(client, tf2);
}
});
module.exports = {
client,
tf2
};