-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbot.js
156 lines (137 loc) · 3.86 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
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
#! /usr/bin/env node
const mf = require('mineflayer');
const readline = require('readline');
const config = require('./config.json');
let num = 0;
let interval = null;
let eating = false;
let eatingslot;
let options = {
host: config.server.address,
port: config.server.port,
username: config.user.username,
password: (process.argv[2] ? process.argv[2] : config.user.pass)
}
if(!process.argv[2] && !config.user.pass){
console.log("bot.js - AFK bot");
console.log("Usage : ./start.sh OU node bot.js");
return;
}
const bot = mf.createBot(options);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
bot.on('chat', (username, message) => {
if (username === bot.username) return;
console.log(username + ": " + message);
});
/*bot.on('playerJoined', (player) => { Tu peux l'activer si tu veux en supprimant le /* et * /
bot.chat("Hey " + player.username + "! Je suis un bot pas ouf, me dérangez pas");
})*/
bot.on('error', function(err) {
console.log('Erreur : ' + err.errno);
if (err.code === undefined) {
console.log('Mauvais identifiant, serveur inaccesible ou autre erreur non définie');
}
console.log('Reconnexion dans 60 secondes, Ctrl+C pour annuler');
process.exit(60)
});
bot.on('end', () => {
process.exit(60);
})
bot.on('login', () => {
console.log("| Connexion");
});
bot.on('spawn', () => {
console.log("| Connecté")
if(config.toggle.sneakbydefault) bot.setControlState("sneak", true);
});
bot.on('health', () => {
if(bot.health < config.toggle.autodisconnect.health && config.toggle.autodisconnect.toggledisconnect){
console.log("Deconnexion car plus de vie")
if(config.toggle.autodisconnect.togglemsg){
bot.chat(config.toggle.autodisconnect.msg);
console.log(bot.username+": "+config.toggle.autodisconnect.msg);
}
bot.quit();
process.exit(1);
}
if(bot.food < 3 && !eating && config.toggle.autofeed.autofeed){
eating = true;
eatingslot = bot.quickBarSlot;
bot.setQuickBarSlot(config.toggle.autofeed.autofeedslot);
bot.consume(function () {
bot.setQuickBarSlot(eatingslot);
eating = false;
});
}
})
rl.on("line", input =>{
let array = input.split(' ')
switch(array[0]){
case "/quit":
bot.quit();
process.exit(1);
break;
case "/reconnect":
bot.quit();
process.exit();
break;
case "/autoclick":
if(!array[1] || Number.isInteger(array[1])) array[1] = 700;
if(!interval){
interval = setInterval(autofunc, array[1]);
console.log("| Autoclick démarré")
return;
}
if(interval){
console.log("| Autoclick déjà actif, pour l'arrêter utilisez /stopautoclick")
return;
}
break;
case "/stopautoclick":
if(!interval){
console.log("| Il n'y a actuellement aucun autoclick d'actif");
return;
}
clearInterval(interval);
interval = null;
console.log("| Autoclick stoppé");
console.log("| Autoclicker a tapé "+num+" fois.");
num = 0;
break;
case "/tps":
console.log("| Les tps sont à "+bot.getTps());
break;
case "/sneak":
if(bot.getControlState("sneak")){
console.log("| Le bot ne sneak plus");
bot.setControlState("sneak", false);
} else {
console.log("| Le bot sneak maintenant");
bot.setControlState("sneak", true);
}
break;
case "/help":
console.log("/quit - Quitter");
console.log("/reconnect - Déco reconnect (fonctionne uniquement quand lancé via ./start.sh)");
console.log("/autoclick [ms] - Activer Autoclick sur entité la plus proche (par défault 700 ms | check entité plus proche + tape uniquement si c'est un mob)");
console.log("/stopautoclick - Stopper l'autoclick");
console.log("/sneak - Toggle sneak");
console.log("Contact : dadodasyra#0001 OU [email protected]")
break;
default:
bot.chat(input)
}
});
function autofunc()
{
let entity = bot.nearestEntity()
if(entity){
if (entity.type === 'mob') {
bot.attack(entity)
num++;
}
}
}