-
-
Notifications
You must be signed in to change notification settings - Fork 919
/
multiple_from_file.js
45 lines (40 loc) · 1.46 KB
/
multiple_from_file.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
/*
* This example is for people with multiple (mojang) minecraft accounts,
* in a file in the format "username:password" on each line,
* change the file property of config to set your .txt file location
*/
const fs = require('fs')
const util = require('util')
const mineflayer = require('mineflayer')
const readFile = (fileName) => util.promisify(fs.readFile)(fileName, 'utf8')
const config = {
host: 'localhost',
port: 25565,
file: './accounts.txt',
interval: 500 // cooldown between joining server too prevent joining too quickly
}
function makeBot ([_u, _p], ix) {
return new Promise((resolve, reject) => {
setTimeout(() => {
const bot = mineflayer.createBot({
username: _u,
password: _p,
host: config.host,
port: config.port
})
bot.on('spawn', () => resolve(bot))
bot.on('error', (err) => reject(err))
setTimeout(() => reject(Error('Took too long to spawn.')), 5000) // 5 sec
}, config.interval * ix)
})
}
async function main () {
// convert accounts.txt => array
const file = await readFile(config.file)
const accounts = file.split(/\r?\n/).map(login => login.split(':'))
const botProms = accounts.map(makeBot)
// const bots = await Promise.allSettled(botProms)
const bots = (await Promise.allSettled(botProms)).map(({ value, reason }) => value || reason).filter(value => !(value instanceof Error))
console.log(`Bots (${bots.length} / ${accounts.length}) successfully logged in.`)
}
main()