Repository navigation
Expand file tree
/
Copy pathAFK.js
More file actions
229 lines (199 loc) · 7.74 KB
/
Copy pathAFK.js
File metadata and controls
229 lines (199 loc) · 7.74 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//Importing dependencies
const Discord = require("discord.js");
const fs = require("fs")
const cp = require("child_process")
//Creating Discord bot client
var DB = new Discord.Client();
//Setting up command handler
DB.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./Commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./Commands/${file}`);
DB.commands.set(command.name, command);
}
//Importing Settings file, Creating a new one if it doesnt exsist.
var Settings;
try {
if(fs.existsSync("./settings.json")){
console.log("Settings file exists");
const settingsdata = fs.readFileSync("./settings.json");
Settings = JSON.parse(settingsdata);
console.log("Settings File Loaded");
}
else{
console.log("SettingsFile doesn't exsist creating one...")
const createsettings = require("./CreateSettings.js");
createsettings();
console.log("New Settings file was created open it and change the defaults and re run the discord bot")
process.exit();
}
} catch(err) {
console.error(err);
process.exit();
}
var LoginQueue = []
var ALTProccessOBJ = {}
setInterval(() => {
if(LoginQueue.length != 0){
console.log("Spawning new alt");
let SpawnArgs = LoginQueue.shift()
if(Object.keys(SpawnArgs).indexOf("LoginCommand") == -1){
ALTProccessOBJ[SpawnArgs.discordID] = cp.fork("MinecraftClient.js", [SpawnArgs.email, SpawnArgs.password, SpawnArgs.AuthTypem],
{ stdio: ['inherit', 'inherit', 'inherit', 'ipc']})
BindEvents(ALTProccessOBJ[SpawnArgs.discordID], SpawnArgs.discordID, DB);
}
else{
ALTProccessOBJ[SpawnArgs.discordID] = cp.fork("MinecraftClient.js", [SpawnArgs.email, SpawnArgs.password, SpawnArgs.AuthTypem, SpawnArgs.LoginCommand],
{ stdio: ['inherit', 'inherit', 'inherit', 'ipc']})
BindEvents(ALTProccessOBJ[SpawnArgs.discordID], SpawnArgs.discordID, DB);
}
if(LoginQueue.length != 0){
console.log(`Next alt is being Spawned in ${Settings.LoginDelay} seconds`)
}
}
}, Settings.LoginDelay * 1000);
var dontrelog = []
function BindEvents(ALTProccess, discordID, DB){
let ALTchannel = DB.channels.cache.get(discordID)
ALTProccess.on("exit", (code) =>{
console.log(`exit code: ${code}`)
if(dontrelog.indexOf(discordID) == -1){
console.log(`Bot proccess has exited with code ${code} restarting bot...`)
try{
if(Object.keys(AFKAlts).indexOf(discordID) == -1){
console.log("Something went very wrong the alt isnt in the AFKAlts list")
}
else{
LoginQueue.push(AFKAlts[discordID])
}
}catch(err){console.error(err)};
}
else{
dontrelog.splice(dontrelog.indexOf(discordID), 1);
delete ALTProccessOBJ[discordID]
console.log("Client is not being relogged")
}
})
ALTProccess.on("message", (data) =>{
try{
let keys = Object.keys(data)
if(keys.indexOf("embed") != -1){
let embed = new Discord.MessageEmbed();
embed.setColor('#0099ff')
embed.setTitle(data.embed);
ALTchannel.send(embed);
}
else if(keys.indexOf("text") != -1){
ALTchannel.send(data.text)
}
if(keys.indexOf("relog") != -1){
if(data.relog){
ALTProccess.kill();
}
else{
dontrelog.push(discordID);
ALTProccess.kill()
}
}
}catch(err) {console.error(err)}
})
}
var AFKAlts = {};
try{
if(fs.existsSync("./AFKAlts.json")){
AFKAlts = JSON.parse(fs.readFileSync("./AFKAlts.json"));
console.log("Alt Settings Loaded from file");
let AFKkeys = Object.keys(AFKAlts);
AFKkeys.forEach((element) =>{
LoginQueue.push(AFKAlts[element])
})
}
else{
console.log("AFKAlts.json was not found! no alts will be loaded at start");
}
}catch(err){
console.error(err);
}
//Called when the discord bot is ready
DB.on("ready",() => {
console.log("Discord Bot is ready");
});
function NoAdminRole(message){
let Embed = new Discord.MessageEmbed();
Embed.setColor('#0099ff')
Embed.setTitle("⚠️You don't have permission to execute this command!⚠️")
message.channel.send(Embed);
message.delete()
}
DB.on("message", async function(message){
if(!message.content.startsWith(Settings.prefix) || message.author.bot) {return};
const args = message.content.slice(Settings.prefix.length).split(" ");
const command = args.shift().toLocaleLowerCase();
try{
if(command === "add"){
DB.commands.get("add").execute(message, args, Settings, LoginQueue, AFKAlts, DB);
}
else if(command === "remove"){
DB.commands.get("remove").execute(message, ALTProccessOBJ, AFKAlts, dontrelog);
}
else if(command === "drain"){
if(Settings.EnableAdminRole){
if(message.member.roles.cache.has(Settings.AdminRoleID)){
DB.commands.get("drain").execute(message, ALTProccessOBJ, args);
}
else{
NoAdminRole(message)
}
}
else{
DB.commands.get("drain").execute(message, ALTProccessOBJ, args);
}
}
else if(command === "restart"){
DB.commands.get("restart").execute(message, ALTProccessOBJ)
}
else if(command === "kill"){
DB.commands.get("kill").execute(message, ALTProccessOBJ, Settings, dontrelog);
}
else if(command === "sethome"){
DB.commands.get("sethome").execute(message, ALTProccessOBJ)
}
else if(command === "tpyes"){
DB.commands.get("tpyes").execute(message, ALTProccessOBJ)
}
else if(command === "relog"){
DB.commands.get("relog").execute(message, ALTProccessOBJ, AFKAlts, LoginQueue);
}
else if(command === "chat"){
DB.commands.get("chat").execute(message, args, ALTProccessOBJ, Settings)
}
else if(command === "help"){
DB.commands.get("help").execute(message, Settings);
}
else if(command === "resethomes"){
DB.commands.get("resethomes").execute(message, ALTProccessOBJ);
}
else if(command === "force"){
if(Settings.EnableAdminRole){
if(args.indexOf("/pay") != -1 || args.indexOf("/withdraw") != -1){
if(message.member.roles.cache.has(Settings.AdminRoleID)){
DB.commands.get("force").execute(message, ALTProccessOBJ, args, Settings);
}
else{
NoAdminRole(message)
}
}
else{
DB.commands.get("force").execute(message, ALTProccessOBJ, args, Settings);
}
}
else{
DB.commands.get("force").execute(message, ALTProccessOBJ, args, Settings);
}
}
else if(command === "addlogin"){
DB.commands.get("addlogin").execute(message, args, ALTProccessOBJ, AFKAlts)
}
}catch(err){console.error(err);};
});
DB.login(Settings.token)