-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnodejs.js
76 lines (74 loc) · 2.3 KB
/
nodejs.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
//help iexist has me hostage
var WebSocketClient = require('websocket').client;
var ws = new WebSocketClient();
var vm = 'darkok.xyz:3037/cvmws'; //ziad87 vm
function connect(){
ws.on('connect', function(f){
function send(string){
f.sendUTF(encodeCommand(['chat', string]));
}
function changeUsername(string){
f.sendUTF('6.rename,' + string.length + '.' + string + ';');
}
f.on('message',function(message){
var cmd = decodeCommand(message.utf8Data);
changeUsername("NodeJS Bot c!help");
var username = cmd[1];
var command = cmd[2];
var prefix = "c!";
//now here is the fun part
if (command == prefix + "test"){
send("hello world");
}
if (command == prefix + "help"){
send("https://raw.githubusercontent.com/imightexist/collabvm-bot/main/commands-nodejs.txt");
}
if (command == prefix + "github"){
send("https://github.com/imightexist/collabvm-bot");
}
if (command == prefix + "about"){
send("hello i am CollabVM bot");
}
if (command.includes(prefix + "say "){
send(command.replace(prefix + "say ",""));
}
if (command == prefix + "flipcoin"){
random = Math.floor(Math.random() * 2);
if (random == 1){
send("heads");
}else{
send("tails");
}
}
setInterval(function(){
if (f.connected){
f.sendUTF('3.nop;');
}
},2500);
})
})
ws.connect('ws://' + vm, 'guacamole');
}
function decodeCommand(cypher) {
var sections = [];
var bump = 0;
while (sections.length <= 50 && cypher.length >= bump) {
var current = cypher.substring(bump);
var length = parseInt(current.substring(current.search(/\./) - 2));
var paramater = current.substring(length.toString().length + 1, Math.floor(length / 10) + 2 + length);
sections[sections.length] = paramater;
bump += Math.floor(length / 10) + 3 + length;
}
sections[sections.length - 1] = sections[sections.length - 1].substring(0, sections[sections.length - 1].length - 1);
return sections;
}
function encodeCommand(cypher) {
var command = "";
for (var i = 0; i < cypher.length; i++) {
var current = cypher[i];
command += current.length + "." + current;
command += (i < cypher.length - 1 ? "," : ";");
}
return command;
}
connect();