-
Notifications
You must be signed in to change notification settings - Fork 13
/
bot.js
61 lines (46 loc) · 1.5 KB
/
bot.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
if (process.argv.length < 3 || process.argv.length > 6) {
console.log('Usage: node bot.js [-microsoft] <ip> <port> <username/email> <password>')
process.exit(1)
}
const bindManager = require('./bindManager')
const config = require('./config.json')
const mineflayer = require('mineflayer')
const DBInterface = require('./DBInterface')
console.log("Starting up!")
let flags = []
for (let i in process.argv) {
if (i[0] === '-' && i.length >= 1) {
flags.push(i)
} else {
process.argv.slice(flags.length)
break;
}
}
let options = {
username: process.argv[4] ? process.argv[4] : 'testbot',
verbose: true,
port: parseInt(process.argv[3]),
host: process.argv[2],
password: process.argv[5] ? process.argv[5] : undefined,
auth: flags.includes('-microsoft') ? 'microsoft' : 'mojang'
}
let bot = null;
exports.login = () => {
console.log("Trying to log in...")
bot = mineflayer.createBot(options);
// wait for 2 seconds to allow for a successful login before we do anything else
setTimeout(()=>{
// Discord.bindDiscord(this.bot)
bindManager.bind(bot)
bot.chat(config.welcoming_message)
}, 2000)
}
exports.getBot = function () {
return bot
}
// process.on('uncaughtException', function (err) {
// console.log(err)
// Discord.sendMessage(`Bot has encountered an error: ` + String(err))
// })
exports.dbi = new DBInterface.DBInterface();
this.login()