-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
66 lines (53 loc) · 1.59 KB
/
index.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
const authCommand = require('./lib/generate-auth')
module.exports = function(bot, botConfig) {
// Detect possible login/register failure
var isCommandSended = false;
var config = botConfig.AutoAuth;
if(!bot) {
throw new Error('Bot object is missing, please provide valid mineflayer bot as first argument');
}
if(!config) {
throw new Error('Password is missing, expecting string or object as second argument');
}
if(typeof config === 'string') {
config = {
password: config
};
} else if (!config.password) {
throw new Error('Password property missing in second argument');
}
bot.addChatPattern('registerRequest', /\/register/);
bot.addChatPattern('loginRequest', /\/login/);
bot.on('chat:registerRequest', function() {
bot.chat(authCommand('register', config.password));
if(config.logging) {
console.log('Got register request');
}
bot.emit('serverAuth');
if(isCommandSended) {
console.log('Register request repeated, probably failed to register');
if(config.repeatCb) {
config.repeatCb.call();
}
}
if(!config.ignoreRepeat) {
isCommandSended = true;
}
});
bot.on('chat:loginRequest', function() {
bot.chat(authCommand('login', config.password));
if(config.logging) {
console.log('Got login request');
}
bot.emit('serverAuth');
if(isCommandSended) {
console.log('Login request repeated, probably failed to login');
if(config.repeatCb) {
config.repeatCb.call();
}
}
if(!config.ignoreRepeat) {
isCommandSended = true;
}
});
};