-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewdoria1.3.js
201 lines (173 loc) · 5.85 KB
/
newdoria1.3.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp');
const SteamCommunity = require('steamcommunity');
const TradeOfferManager = require('steam-tradeoffer-manager');
const TeamFortress2 = require('tf2');
const Prices = require('./prices.json');
const config = require('./config-new1.3.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
};
client.logOn(logOnOptions);
console.log('succesfully logged on.');
client.on('loggedOn', () => {
client.setPersona(SteamUser.EPersonaState.Online);
client.gamesPlayed([440]);
});
client.on("friendMessage", function(steamID, message) {
if (message == "hi") {
client.chatMessage(steamID, "Hello, this works.");
}
else {
client.chatMessage(steamID, "Hello, my name is Newdoria and I am an automated bot made by my owner. Feel free to send me a trade offer. I trade items in team fortress 2 and more. I will accept any offer if it profits me.");
}
});
client.on('webSession', (sessionid, cookies) => {
manager.setCookies(cookies);
community.setCookies(cookies);
community.startConfirmationChecker(20000, config.identitySecret);
});
manager.on('newOffer', function (offer) {
console.log("New offer #" + offer.id + " from " + offer.partner.getSteam3RenderedID());
offer.accept(function (err) {
if (err) {
console.log("Unable to accept offer: " + err.message);
console.log("Cause: " + err.eresult);
if (err.eresult == 28) {
retryOffer(offer.id);
}
}
else {
SteamUser.checkConfirmations();
console.log("Offer accepted");
}
});
});
var steam;
function retryOffer(id) {
manager.getOffer(id, function (err,offer) {
if (err) {
console.log("Unable to get offer: " + err.message);
console.log("Retrying to get.");
setTimeout(function(){
retryOffer(id);
}, retryTime);
}
else {
offer.accept(function (err) {
if (err) {
console.log("Unable to accept offer: " + err.message);
if (err.eresult == 28) {
console.log("Retrying to accept.");
retryOffer(offer.id);
}
}
else {
SteamUser.checkConfirmations();
console.log("Offer accepted");
}
});
}
});
}
var scrapAmt = 25;
var pollCraft = 30;
tf2.on('connectedToGC', function() {
console.log("Connected to tf2 game server.");
});
tf2.on('backpackLoaded', function () {
console.log("Loaded our backpack.");
});
function craftS(amtNeedScrap) {
if (tf2.backpack == undefined) {
console.log("unable to load backpack, can't craft.");
return;
} else {
console.log("attempting to craft...");
var amtOfScrap = 0;
for (var i = 0; i <tf2.backpack.length; i++) {
if (tf2.backpack[i].defIndex === 5000) {
amtOfScrap++;
}
}
for (i = 0; i <tf2.backpack.length; i++) {
if (tf2.backpack[i].defIndex === 5002) {
amtOfScrap +=9;
let beep = new [Array]();
beep.push(parseInt(tf2.backpack[i].id));
tf2.craft(beep);
} else if (tf2.backpack[i].defIndex === 5001) {
amtOfScrap +=3;
beep = new [Array]();
beep.push(parseInt(tf2.backpack[i].id));
tf2.craft(beep);
}
if (amtOfScrap >= amtNeedScrap) {
break;
}
}
}
}
tf2.on('craftingComplete', function(e) {
console.log("Finished crafting.");
});
client.on('friendMessage#'+config.ownerID, function(steamID, message) {
if (message == "craft") {
craftS(scrapAmt);
console.log("Recieved order to craft from admin.");
} else {
console.log("craft error.");
}
});
setInterval(function() {
craftS(scrapAmt);
}, 1000 * 60 * pollCraft);
client.on('friendRelationship', function(sid, relationship) {
if (relationship == SteamUser.EFriendRelationship.RequestRecipient) {
console.log("We recieved a friend request from "+sid);
client.addFriend(sid, function (err, name) {
if (err) {
console.log(err);
return;
}
console.log("Accepted user with the name of "+name);
});
};
});
client.on('groupRelationship', function(sid, relationship) {
if (relationship == SteamUser.EClanRelationship.Invited) {
console.log("We were asked to join steam group #"+sid);
client.respondToGroupInvite(sid, true);
}
});
client.on('friendsList', function() {
for (var sid in client.myFriends);
var relationship = client.myFriends[sid];
if (relationship == SteamUser.EFriendRelationship.RequestRecipient) {
console.log("(offline) We recieved a friend request from "+sid);
client.addFriend(sid, function (err, name) {
if (err) {
console.log(err);
return;
}
console.log("(offline) Accepted user with the name of "+name);
});
}
});
client.on('groupList', function() {
for (var sid in client.myGroups);
var relationship = client.myGroups[sid];
if (relationship == SteamUser.EClanRelationship.Invited) {
console.log("(offline) We were asked to join steam group #"+sid);
client.respondToGroupInvite(sid, true);
}
});