-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
109 lines (86 loc) · 2.98 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
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
const Discord = require('discord.js');
const client = new Discord.Client();
const settings = require('./settings.json');
const tokens = require('./tokens.json');
const SysLoad = require("sysload");
const load = new SysLoad();
const { spawn } = require('child_process');
var bot_state = 'none';
load.start();
function treat_output(message) {
message = message.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
message = message.slice(-1980);
message = message.replace(/```/g, "'''");
return message = "```console\n" + message + "```";
}
function execute(message, cmd, args) {
var child = spawn(cmd, args);
let old_last = "Empty"
let last = "";
let finished = 0;
message.react("⛔");
child.stdout.on('data', (data) => {
last += (`${data}`);
});
child.stderr.on('data', (data) => {
last += (`${data}`);
});
child.on('error', (data) => {
last += (`${data}`);
});
child.on('exit', () => {
finished = 1;
})
const filter = (reaction, user) => {
return reaction.emoji.name === '⛔' && user.id === settings.owner_id;
};
const collector = message.createReactionCollector(filter, { time: 600000 });
collector.on('collect', () => {
child.kill();
});
collector.on('end', () => {
if (!finished) {
child.kill();
last += "Timed out."
}
});
let handler = setInterval(() => {
if (old_last != last && last.length > 0) {
old_last = last;
message.edit(treat_output(last));
}
if (finished) {
clearInterval(handler);
message.reactions.removeAll().then(() => {
message.react("👍");
})
if (last.length < 1) {
message.edit(treat_output("Empty callback."));
}
}
}, 2000);
}
client.on("ready", async () => {
console.log('Connected.');
bot_state = 'idle';
setInterval(function () {
client.user.setPresence({ activity: { type: 'WATCHING', name: "droplet - CPU: " + load.average().s1 + "%" }, status: bot_state });
}, 5000)
});
client.on("message", async message => {
if (message.author.id === settings.owner_id && message.guild && message.guild.id === settings.owner_server && !message.content.startsWith("//")) {
if (message.channel.id === settings.exec_channel) {
if (!message.content.startsWith(settings.cmd_prefix)) {
const args = (message.content).trim().split(/ +/g);
const cmd = args.shift();
message.channel.send('Executing command...').then(message => {
execute(message, cmd, args);
});
} else {
return message.channel.send("Commands not supported yet.");
}
} else if (message.channel.id === settings.eval_channel) {
}
}
})
client.login(tokens.discord);