-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
69 lines (61 loc) · 1.89 KB
/
main.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
import Promise from 'bluebird'
import request from 'request'
import minimist from 'minimist'
import Farmer from './Farmer'
import credentials from './credentials.json'
import filter from './filter.json'
const { username, password, provider } = credentials
const argv = minimist(process.argv.slice(2))
if (typeof(argv.l) !== "string") {
console.log("Location must be provided after -l flag")
process.exit(1)
}
const ballNames = ["Poke Ball", "Great Ball", "Ultra ball"]
const pokeballFlag = argv.b || 1
console.log("Using %s", ballNames[pokeballFlag - 1])
const locationString = argv.l
let targetIds = {}
const farmer = new Farmer(1000, 7500, pokeballFlag)
farmer.login(username, password, locationString, provider)
setInterval(() => {
request('http://pokesnipers.com/api/v1/pokemon.json', (err, res, body) => {
if (!err && res.statusCode === 200) {
const json = JSON.parse(body)
let newTargets = json.results.map((pokemon) => {
const regex = /\/(\d+).\w+$/
const found = pokemon.icon.match(regex)
const coords = packCoordsString(pokemon.coords)
return {
id: pokemon.id,
name: pokemon.name,
indexID: parseInt(found[1]),
coords: coords,
until: new Date(pokemon.until).getTime()
}
})
newTargets = newTargets.filter(target => {
const isFresh = targetIds[target.id] === undefined
if (isFresh) {
targetIds[target.id] = true
if (filter[target.indexID]) {
return true
}
}
return false
})
farmer.addNewTargets(newTargets)
} else {
console.log('Pokesnipers ERR')
}
})
}, 10000)
function packCoordsString (coordsString) {
const coords = coordsString.split(',')
return {
type: 'coords',
coords: {
latitude: parseFloat(coords[0]),
longitude: parseFloat(coords[1])
}
}
}