-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
233 lines (200 loc) · 7.54 KB
/
index.js
File metadata and controls
233 lines (200 loc) · 7.54 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
var TelegramBot = require('node-telegram-bot-api');
const pogobuf = require('pogobuf-vnext');
const POGOProtos = require('node-pogo-protos-vnext');
const RequestType = POGOProtos.Networking.Requests.RequestType;
const _ = require('lodash');
var utils = require('./utils');
var Settings = require('./settings');
var Raid = require('./raid');
var Map = require("collections/map");
var raidArr = [];
const settings = new Settings();
const telegramUserID = settings.telegramUserID;
const telegramBotID = settings.telegramBotID;
const ptcUsername = settings.ptcUsername;
const ptcPassword = settings.ptcPassword;
const hashingKey = settings.hashingKey;
telegram = new TelegramBot(telegramBotID, { polling: true });
var latestResult = "";
var coords = {
latitude: 51.2603015,
longitude: 4.2176376,
altitude: _.random(0, 20, true),
};
coords.latitude = settings.lat;
coords.longitude = settings.long;
const client = new pogobuf.Client({
authType: 'ptc',
username: ptcUsername,
password: ptcPassword,
useHashingServer: true,
hashingKey: hashingKey,
version: 7301,
includeRequestTypeInResponse: true,
});
telegram.on("text", (message) => {
//Check if user has sent coordinates
var coordsRegexp = /^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$/;
if (message.text.match(coordsRegexp)) {
var match = coordsRegexp.exec(message.text);
updateLocation(match[1],match[3],message);
raidArr = [];
return;
}
if (message.text === "Alive?"){
telegram.sendMessage(message.chat.id, latestResult);
return;
}
telegram.sendMessage(message.chat.id, "Hello world");
});
telegram.on("location", (message) => {
updateLocation(message.location.latitude, message.location.longitude,message);
raidArr = [];
});
async function updateLocation (latitude,longitude,message){
coords.latitude = latitude;
coords.longitude = longitude;
telegram.sendMessage(message.chat.id, "Location changed to: " + coords.latitude + "," + coords.longitude);
console.log("Location changed to: " + coords.latitude + "," + coords.longitude);
await initializeClient();
await generalScan();
await doRaidScans();
}
async function initializeClient(){
// set player position
client.setPosition(coords);
// init the app
await client.init();
// first empty request like the app
await client.batchStart().batchCall();
// get player info
await client.getPlayer('US', 'en', 'Europe/Paris');
// get settings, inventory, etc...
let response = await client.batchStart()
.downloadRemoteConfigVersion(POGOProtos.Enums.Platform.IOS, '', '', '', 7301)
.checkChallenge()
.getHatchedEggs()
.getInventory()
.checkAwardedBadges()
.downloadSettings()
.batchCall();
// get data returned by the server that it expect in following calls
const inventoryResponse = _.find(response, resp => resp._requestType === RequestType.GET_INVENTORY);
// call getPlayerProfile with data got before
response = await client.batchStart()
.getPlayerProfile()
.checkChallenge()
.getHatchedEggs()
.checkAwardedBadges()
.getBuddyWalked()
.batchCall();
// same for levelUpRewards
response = await client.batchStart()
.checkChallenge()
.getHatchedEggs()
.checkAwardedBadges()
.getBuddyWalked()
.getInbox(true, false, 0)
.batchCall();
}
async function generalScan() {
// then call a getMapObjects
const cellIDs = pogobuf.Utils.getCellIDs(coords.latitude, coords.longitude);
response = await client.batchStart()
.getMapObjects(cellIDs, Array(cellIDs.length).fill(0))
.checkChallenge()
.getHatchedEggs()
.checkAwardedBadges()
.getBuddyWalked()
.getInbox(true, false, 0)
.batchCall();
const forts = response[0].map_cells.reduce((all, c) => all.concat(c.forts), []);
const pokestops = forts.filter(f => f.type === 1);
let gyms = forts.filter(f => f.type === 0);
console.log(`Found ${pokestops.length} pokestops.`);
console.log(`Found ${gyms.length} gyms`);
var raids;
if (gyms.length > 0) {
raids = gyms.filter(g => g.raid_info != null);
console.log(` with ${raids.length} raids.`);
}
latestResult = ` Found ${raids.length} raids.`
latestResult += "\n" + new Date();
for (var i=0; i<raids.length; i++) {
if (raids.length < 1) {
continue
}
if (raids[i].raid_info.raid_pokemon === null) {
continue
}
var raid_info = raids[i].raid_info;
var raid_seed = raid_info.raid_seed;
var gym_id = raids[i].id;
var raid_latitude = raids[i].latitude;
var raid_longitude = raids[i].longitude;
var raid_level = raid_info.raid_level;
var pokemon_id = raid_info.raid_pokemon.pokemon_id;
var raid = new Raid(pokemon_id, gym_id, raid_seed, raid_latitude, raid_longitude, raid_info.raid_end_ms, raid_level);
raidArr.push(raid);
console.log("\n");
console.log("Gym ID:" + gym_id);
console.log("Raid Level:" + raid_level);
console.log("Lat:" + raid_latitude);
console.log("Long:" + raid_longitude);
console.log("Pokemon id:" + utils.idToName(pokemon_id));
console.log(utils.getTimeString(raid_info.raid_end_ms));
}
}
async function moveAndScanRaid(latitude, longitude, seed, gymId, pokemonId){
var raidCoords = {
latitude: latitude,
longitude: longitude,
altitude: _.random(0, 20, true),
};
client.setPosition(raidCoords);
// Do normal scan of the area first
const cellIDs = pogobuf.Utils.getCellIDs(coords.latitude, coords.longitude);
response = await client.batchStart()
.getMapObjects(cellIDs, Array(cellIDs.length).fill(0))
.checkChallenge()
.getHatchedEggs()
.checkAwardedBadges()
.getBuddyWalked()
.getInbox(true, false, 0)
.batchCall();
//Get info about Raid
const response2 = await client.getRaidDetails(seed,gymId,[]);
var numbers_of_players = response2.num_players_in_lobby;
console.log("Pokemon: " + utils.idToName(pokemonId) + " Numbers of Players: " + numbers_of_players);
console.log("\n");
if (numbers_of_players > 0){
telegram.sendMessage(telegramUserID, "Active raid: \n" + utils.idToName(pokemonId) + "\n People in loby:" + numbers_of_players +"\nDeeplink: pokego2://" + utils.addRandomDistanceToCoords(latitude) + "," + utils.addRandomDistanceToCoords(longitude) );
telegram.sendMessage(telegramUserID, "" + utils.addRandomDistanceToCoords(latitude) + "," + utils.addRandomDistanceToCoords(longitude));
}
}
async function doRaidScans() {
//Check if raidtimer is not existing anymore
raidArr = raidArr.filter(item => item.deSpawn > Date.now())
for (var i = 0, len = raidArr.length; i < len; i++) {
var lat = raidArr[i].lat;
var long = raidArr[i].long;
var seed = raidArr[i].seed;
var gymId = raidArr[i].gymId;
var pokemonId =raidArr[i].pokemonId;
await moveAndScanRaid(lat,long,seed,gymId,pokemonId);
}
}
async function Main() {
await initializeClient();
await generalScan();
await doRaidScans();
// Run the general Area Scan every 5 minutes
setInterval(generalScan, 300000);
// Do the Active Raids scan every 20 seconds
setInterval(doRaidScans, 20000);
// But mom, I don't want to clean up!
//client.cleanUp();
}
Main()
.then(() => console.log('---- Done With first round.'))
.catch(e => console.error(e));