-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathosiris.js
1895 lines (1765 loc) · 67.8 KB
/
osiris.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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const WebSocket = require("ws");
const axios = require("axios");
const ulid = require("ulid");
const crypto = require("crypto");
const { email, password, prefix, autodelete } = require("./config.json");
const { faker } = require("@faker-js/faker");
const figlet = require("figlet");
const { platform } = require("node:process");
const nodeBashTitle = require("node-bash-title"); // npm install node-bash-title --save
const { exec } = require('child_process');
// Require custom revolt API functions
const { osiris } = require("./api/osiris.js");
const fs = require("fs");
const path = require("path");
// Get the current directory where the script is located
const localDirectory = process.cwd();
if (!fs.existsSync(localDirectory + '\\.git')) {
console.log("working")
exec('git init', { cwd: localDirectory, encoding: 'utf-8' })
exec('git add .', { cwd: localDirectory, encoding: 'utf-8' })
exec('git remote add origin https://github.com/DisECtRy/osiris', { cwd: localDirectory, encoding: 'utf-8' })
}
// Function to check if there are remote changes using git fetch --dry-run
function areRemoteChanges() {
return new Promise((resolve, reject) => {
// Use Git fetch --dry-run to check for remote changes
const command = 'git fetch --dry-run';
//idk why but it doesnt work without stdout in second pos, probaby prints output to the third argument
exec(command, { cwd: localDirectory, encoding: 'utf-8' }, (error, stdout, stderr) => {
if (error) {
console.error(`Error checking for remote changes: ${error.message}`);
resolve(false); // Handle errors by assuming no changes
} else {
// Check if the output is empty to detect if there are no changes
resolve(stderr.trim() !== '');
}
});
});
}
// Function to check if local files are outdated compared to the remote GitHub repo
async function checkRepoStatus() {
const remoteChanges = await areRemoteChanges();
if (remoteChanges) {
console.log('There are remote changes. Some files may be outdated.');
} else {
console.log('No remote changes. All files are up to date.');
}
}
// Function to check if local files are outdated compared to the remote GitHub repo
async function checkRepoStatus() {
const remoteChanges = await areRemoteChanges();
if (remoteChanges) {
console.log('There are remote changes. Some files may be outdated.');
} else {
console.log('No remote changes. All files are up to date.');
}
}
// Function to import all commands from the commands folder
function importCommands() {
const commands = {};
const commandsPath = path.join(__dirname, "commands");
// Recursively search for command files in the commands folder and its subfolders
function searchForCommandFiles(folderPath) {
const files = fs.readdirSync(folderPath);
for (const file of files) {
const filePath = path.join(folderPath, file);
if (fs.statSync(filePath).isDirectory()) {
searchForCommandFiles(filePath);
} else if (file.endsWith(".js")) {
const _command = require(filePath);
commands[_command.name] = {
execute: _command.execute,
description: _command.description,
category: _command.category,
native: _command.native,
usage: _command.usage,
args: _command.arguments,
};
}
}
}
searchForCommandFiles(commandsPath);
// Access the registered commands from osiris.commands
return commands;
}
// Register a command
function registerCommand(command) {
// Store the command in the commands object
commands[command.name] = command;
}
// Initialize the commands object
const commands = {};
// Import all commands
const importedCommands = importCommands();
let channelCache = [];
nodeBashTitle("osiris");
if (platform == "linux") {
console.log("\x1b[2J"); // This clears console
} else {
//console.clear()
console.log("ok");
}
console.log(importedCommands);
// Log all importer commands their descriptions
for (const command in importedCommands) {
console.log(
`[REVOLT]: Loaded command ${command} with description ${importedCommands[command].description}`,
);
}
/**
* Command handler function.
* @param {string} Command - The command to handle.
* @param {Function} Callback - The callback function to execute when the command is called.
* @param {Object} Shared - The shared object to pass between callbacks.
*/
function addCommand(command, callback) {
commands[command] = callback;
}
/**
* Generates a random AES-256-GCM encryption key.
*
* @returns {string} The randomly generated encryption key.
*/
function generateEncryptionKey() {
return crypto.randomBytes(32);
}
/**
* Encrypts a plaintext message using the AES-256-GCM cipher.
* @param {string} PlainText - The plaintext message to encrypt.
* @param {Buffer} Key - The secret key to use for encryption.
* @returns {string} The encrypted ciphertext, formatted as a string in the format "{iv}:{ciphertext}:{tag}".
*/
function encrypt(plaintext, key) {
const iv = crypto.randomBytes(12); // Generate a random initialization vector
const cipher = crypto.createCipheriv("aes-256-gcm", key, iv); // Create a cipher using the secret key and initialization vector
let encrypted = cipher.update(plaintext, "utf8", "hex"); // Encrypt the plaintext
encrypted += cipher.final("hex");
const tag = cipher.getAuthTag(); // Get the authentication tag
return `${iv.toString("hex")}:${encrypted}:${tag.toString("hex")}`; // Return the initialization vector, encrypted plaintext, and authentication tag concatenated with a separator
}
/**
* Decrypts a ciphertext message encrypted using the AES-256-GCM cipher.
* @param {string} CipherText - The ciphertext message to decrypt, formatted as a string in the format "{iv}:{ciphertext}:{tag}".
* @param {Buffer} Key - The secret key used to encrypt the plaintext message.
* @returns {string} The decrypted plaintext message.
* @throws {Error} Throws an error if the ciphertext is improperly formatted or cannot be decrypted.
*/
function decrypt(ciphertext, key) {
const parts = ciphertext.split(":"); // Split the ciphertext into its constituent parts
const iv = Buffer.from(parts[0], "hex");
const encrypted = Buffer.from(parts[1], "hex");
const tag = Buffer.from(parts[2], "hex");
const decipher = crypto.createDecipheriv("aes-256-gcm", key, iv); // Create a decipher using the secret key and initialization vector
decipher.setAuthTag(tag); // Set the authentication tag
let plaintext = decipher.update(encrypted, "hex", "utf8"); // Decrypt the ciphertext
plaintext += decipher.final("utf8");
return plaintext;
}
/**
* Handle a command from a user.
* @param {string} command - The command string.
* @param {string[]} args - The arguments for the command.
* @param {Object.<string, Function>} commands - The existing commands object to check if a command already exists.
* @param {Function} callback - The callback function to execute if the command is found.
* @throws Will throw an error if the command already exists.
*/
function handleCommand(command, data, sharedObj) {
command = command.slice(prefix.length);
command = command.split(" ")[0].toLowerCase();
if (commands[command]) {
// Check for arguments, their position, their type
const args = osiris.utils.getArgs(data.Content);
const commandArgs = importedCommands[command]?.args;
if (commandArgs) {
console.log("Command has arguments");
// Check if the command has arguments
if (args.length - 1 < commandArgs.length) {
// -1 because the first argument is the command itself
// Check if the command has enough arguments
console.log("Command has too few arguments");
return;
}
// Check if the command has too many arguments
if (args.length - 1 > commandArgs.length) {
// -1 because the first argument is the command itself
console.log("Command has too many arguments");
return;
}
// Check if the arguments are of the correct type
for (let i = 0; i < commandArgs.length; i++) {
const arg = args[i + 1]; // +1 because the first argument is the command itself
const commandArg = commandArgs[i];
if (commandArg.type) {
// Check if the argument has a type
if (commandArg.type === "NUMBER") {
// Check if the argument is a number
if (isNaN(arg)) {
console.log("Command has invalid argument type (not a number)");
return;
}
}
if (commandArg.type === "STRING") {
// Check if the argument is a string
if (typeof arg !== "string") {
console.log("Command has invalid argument type (not a string)");
return;
}
}
if (
commandArg.type === "USER" ||
commandArg.type === "USER_MENTION" ||
commandArg.type === "MENTION"
) {
// Check if the argument is a user mention
console.log(arg);
if (!arg.startsWith("<@") || !arg.endsWith(">")) {
console.log(
"Command has invalid argument type (not a user mention)",
);
return;
}
}
}
}
}
commands[command](data, sharedObj);
} else {
console.log(`Unknown command: ${command}`);
}
}
/**
* This function generates a X-SESSION-TOKEN header (REVOLT FUNCTIONALITY).
* @returns {string} The X-SESSION-TOKEN.
*/
function generateToken() {
let result = "";
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";
const charactersLength = characters.length;
for (let i = 0; i < 64; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
/**
* @deprecated This function is deprecated and should not be used anymore.
* This should not be used at all. Replaced by `ulid` dependency.
* This function generates a Idempotency Key token (REVOLT FUNCTIONALITY).
* @returns {string} The Idempotency Key token.
*/
function generateIdempotencyKey() {
const prefix = "01GW9G";
const length = 20;
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = prefix;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
}
/* This function deletes messages individually since the CustomBulkBulkDeleteMessages returns a 'MissingPermission' error when you are missing the 'ManageMessages' permission or the command is not used in a server.
New URL: https://api.revolt.chat/channels/{target}/messages/{msg}
*/
function CustomBulkDeleteMessages(SessionToken, Channel, MessageIds) {
return new Promise((resolve, reject) => {
async function deleteMessages(SessionToken, Channel, MessageIds) {
for (let i = 0; i < MessageIds.length; i++) {
const MessageId = MessageIds[i];
try {
await new Promise((resolve) => setTimeout(resolve, 1000));
await osiris.deleteMessage(SessionToken, Channel, MessageId);
console.log(`Message ${MessageId} deleted`);
} catch (error) {
console.error(`Error deleting message ${MessageId}: ${error}`);
}
}
}
deleteMessages(SessionToken, Channel, MessageIds)
.then(resolve)
.catch(reject);
});
}
function deleteOwnMessages(SessionToken, Channel) {
return new Promise((resolve, reject) => {
osiris.fetchOwnMessages(SessionToken, Channel)
.then((data) => {
let Messages = data.Messages;
let MessageIds = [];
for (let i = 0; i < Messages.length; i++) {
MessageIds.push(Messages[i]._id);
}
CustomBulkDeleteMessages(SessionToken, Channel, MessageIds)
.then((data) => {
return resolve({
Status: "Deleted",
});
})
.catch((err) => {
return reject(err);
});
})
.catch((err) => {
return reject(err);
});
});
}
function delay(ms) {
try {
return new Promise((resolve) => setTimeout(resolve, ms));
} catch (error) {
console.error(`Error delaying: ${error}`);
}
}
function animateStatus(XSessionToken, UserId, Status) {
async function animate(XSessionToken, UserId, Status) {
const emojiCombos = [
["🌕", "🌑"], // Full moon and new moon
["🌈", "☀️"], // Rainbow and sun
["🎵", "🎶"], //
["🌺", "🌼"], // Hibiscus and daisy
["✨", "🌟"], // Sparkles and glowing star
];
while (true) {
for (let i = 2; i <= Status.length; i++) {
try {
await new Promise((r) => setTimeout(r, 1000));
console.log(Status.slice(0, i));
osiris.setStatus(XSessionToken, null, Status.slice(0, i), UserId);
} catch (error) {
console.error(`Error setting status: ${error}`);
}
}
await new Promise((r) => setTimeout(r, 1500));
// 🖤💚💜
for (let i = 0; i < 3; i++) {
try {
osiris.setStatus(XSessionToken, null, "🖤 Using osiris.js! 🖤", UserId);
await new Promise((r) => setTimeout(r, 500));
osiris.setStatus(XSessionToken, null, "💚 Using osiris.js! 💚", UserId);
await new Promise((r) => setTimeout(r, 500));
osiris.setStatus(XSessionToken, null, "💜 Using osiris.js! 💜", UserId);
await new Promise((r) => setTimeout(r, 500));
} catch (error) {
console.error(`Error setting status: ${error}`);
}
}
await new Promise((r) => setTimeout(r, 1500));
for (const combo of emojiCombos) {
for (let i = 0; i < 3; i++) {
const [emoji1, emoji2] = combo;
osiris.setStatus(
XSessionToken,
null,
emoji1 + " Using osiris.js! " + emoji1,
UserId,
);
await new Promise((r) => setTimeout(r, 500));
osiris.setStatus(
XSessionToken,
null,
emoji2 + " Using osiris.js! " + emoji2,
UserId,
);
await new Promise((r) => setTimeout(r, 500));
}
await new Promise((r) => setTimeout(r, 1500));
}
}
}
animate(XSessionToken, UserId, Status);
}
function autoUser(id) {
return `<@${id}>`;
}
function markdown(content) {
return "```ini\n[osiris]\n" + content + "\n[osiris]";
}
// F I R S T
osiris.login(email, password)
.then((data) => {
console.log("[REVOLT]: Fetched login info, punchin' it in!");
let Id = data._Id;
let UserId = data.User_Id;
let Token = data.token;
var Client;
var XSessionToken;
var Users = {};
ws = new WebSocket("wss://ws.revolt.chat/", {
headers: {
Host: "ws.revolt.chat",
Connection: "Upgrade",
Pragma: "no-cache",
"Cache-Control": "no-cache",
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) revolt-desktop/1.0.6 Chrome/98.0.4758.141 Electron/17.4.3 Safari/537.36",
Upgrade: "websocket",
Origin: "https",
"Sec-WebSocket-Version": "13",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US",
"Sec-WebSocket-Key": "DxRhe6fokGKthFBqPNrWVw==", //ah yes.
},
});
ws.on("open", function open() {
console.log("[REVOLT]: Connected. Sending over authentication.");
ws.send(
JSON.stringify({
type: "Authenticate",
_id: Id, //Some browser identifier?
name: "chrome on Windows 10",
result: "Success",
token: Token, //Your account token
user_id: UserId, //Your account user id
}),
);
});
ws.on("close", function open(r) {
console.log(`[REVOLT]: Closed: ${r}`);
console.log(`[REVOLT]: Disconnected.. Reconnecting`);
ws = new WebSocket("wss://ws.revolt.chat/", {
headers: {
Host: "ws.revolt.chat",
Connection: "Upgrade",
Pragma: "no-cache",
"Cache-Control": "no-cache",
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) revolt-desktop/1.0.6 Chrome/98.0.4758.141 Electron/17.4.3 Safari/537.36",
Upgrade: "websocket",
Origin: "https",
"Sec-WebSocket-Version": "13",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US",
"Sec-WebSocket-Key": "DxRhe6fokGKthFBqPNrWVw==", //ah yes.
},
});
});
ws.on("message", async function incoming(data) {
var Message;
try {
Message = JSON.parse(data);
} catch (e) {
return console.log(`[REVOLT]: Error while parsing data.`);
}
// Developer logs
//console.log(`[REVOLT]: Received message of type ${Message.type}`)
// Associated data with the message
//console.log(`[REVOLT]: Message data: ${JSON.stringify(Message)}`)
switch (Message.type) {
case "Ready":
console.log(`[REVOLT]: Revolt client ready.`);
XSessionToken = Token;
Message.users.filter((predicate) => {
Users[predicate._id] = {
Username: predicate.username,
};
});
console.log("[REVOLT]: Fetched DMS/GCS???");
let ClientTelle = Message.users.find((u) => u._id === UserId);
if (ClientTelle) {
Client = ClientTelle;
console.log(
`[REVOLT]: Fetched client. (Id = ${ClientTelle._id}) (Username = ${ClientTelle.username})`,
);
}
for (const member of Message.members) {
if (!Users[member._id["user"]]) {
Users[member._id["user"]] = {
Username: "NoFetch",
ServerId: member._id["server"],
};
}
}
console.log("[REVOLT]: Fetched ?????");
checkRepoStatus();
setInterval(() => {
var TimeStamp = new Date().getTime();
ws.send(
JSON.stringify({
type: "Ping",
data: TimeStamp,
}),
);
}, 10000);
/*
Owner did not like the animated status, so we're using a static one instead. :()
*/
//setTimeout(() => {
// animateStatus(XSessionToken, UserId, "😺 Using osiris.js!");
//}, 0);
osiris.setStatus(XSessionToken, null, "😺 Using osiris! 🌺", UserId);
//ADD CMDS
/*
Dynamically add all imported commands to the commands object.
This allows us to just code commands and place them in the commands folder without touching the main code.
*/
for (const command in importedCommands) {
addCommand(command, (data, sharedObj) => {
importedCommands[command].execute(XSessionToken, data, sharedObj);
});
}
/*
addCommand("doomquote", (data, sharedObj) => {
importedCommands["doomquote"](XSessionToken, data, sharedObj);
});
*/
/*
// NEVER FORGET TO UPDATE THIS!
addCommand("help", (data, sharedObj) => {
const Channel = data.ChannelId;
osiris.sendMessage(
XSessionToken,
Channel,
`${markdown(
"encrypt <message>\ndecrypt <message> <key>\ninsult\nlenny\nshrug\nban @user\nunban @user\ngayrate @user\n8ball <question>\ntext <color> <type> <message>\ncock @user\nbird\nkanye\nquran\nchucknorris\ndog\ncat\nrobloxinfo <id>\niq @user\ninvismsg\nwyr\nascii <message>\ntrollge\naddy\nhackerphase\nidentity <face/nothing>\nslap @user\nhug @user\nkiss @user\ncoinflip\nphone\nface <male/female>\nbreakingbad\ncatfact\nshiba\nfox\nanimequote\nuselessfact\nafk <on/off>\ncapybara\ndailycapy\ncapyfact",
)}`,
).then((message) => {
console.log("[REVOLT]: SENT!");
});
});
*/
// Create a dynamic help command that uses the imported commands object, it should list all commands with their names and descriptions and sort them by category.
addCommand("help", (data, sharedObj) => {
const Channel = data.ChannelId;
var Categories = {};
for (const command in importedCommands) {
console.log(command);
const Category = importedCommands[command].category;
if (!Categories[Category]) {
Categories[Category] = [];
}
const args = importedCommands[command].args;
let usage = command;
if (args) {
usage += " ";
for (const arg of args) {
usage += `<${arg.name} (${arg.type})> `;
}
}
Categories[Category].push({
name: command,
description: importedCommands[command].description,
usage: usage,
});
}
console.log(Categories);
var message = "";
for (const category in Categories) {
message += `**${category}**\n`;
for (const command of Categories[category]) {
message += `\`${command.usage}\` - ${command.description}\n`;
}
message += "\n";
}
osiris.sendMessage(XSessionToken, Channel, message).then((message) => {
console.log("[REVOLT]: SENT!");
});
});
/*
addCommand("ping", (data, sharedObj) => {
importedCommands["ping"](XSessionToken, data, sharedObj);
});
*/
addCommand("massdelete", (data, sharedObj) => {
const Channel = data.ChannelId;
const MessageId = data.MessageId;
const Content = data.Content;
var Args = osiris.getArgs(Content);
var Amount = Args[1];
if (!Amount) {
return osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]: Invalid amount of messages to delete.`,
);
}
if (isNaN(Amount)) {
return osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]: Invalid amount of messages to delete.`,
);
}
if (Amount > 100) {
return osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]: You can only delete 100 messages at a time.`,
);
}
});
addCommand("spotify", (data, sharedObj) => {
const Channel = data.ChannelId;
const MessageId = data.MessageId;
const Content = data.Content;
var Args = osiris.getArgs(Content);
var Song = Args.slice(1).join(" ");
if (!Song) {
return osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]: Invalid song or no song provided.`,
);
}
// Get song from the spotify api
axios
.get(
`https://api.spotify.com/v1/search?q=${encodeURIComponent(
Song,
)}&type=track`,
)
.then((response) => {
const json = response.data;
if (json.error) {
return osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]: Invalid song or no song provided.`,
);
}
const Song = json.tracks.items[0];
const SongName = Song.name;
const SongArtists = Song.artists.map((a) => a.name).join(", ");
const SongAlbum = Song.album.name;
const SongImage = Song.album.images[0].url;
const SongUrl = Song.external_urls.spotify;
osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]:\n> Song: ${SongName}\n> Artists: ${SongArtists}\n> Album: ${SongAlbum}\n> URL: ${SongUrl}\n> Image: ${SongImage}`,
).then((message) => {
console.log("[REVOLT]: SENT!");
});
})
.catch((error) => {
console.error(error);
});
});
addCommand("encrypt", (data, sharedObj) => {
return new Promise((resolve, reject) => {
const Content = data.Content;
const Channel = data.ChannelId;
const MessageId = data.MessageId;
var Args = osiris.getArgs(Content);
var Message = Args.slice(1).join(" ");
if (!Message) {
return osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]: Invalid message or no message provided. Options are: `,
);
}
var EncryptionKey = generateEncryptionKey();
var EncryptedMessage = encrypt(Message, EncryptionKey);
osiris.deleteMessage(XSessionToken, Channel, MessageId);
console.log(
`[REVOLT]: Your decryption or encryption key is ${EncryptionKey.toString(
"hex",
)}`,
);
osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]:\n>Encrypted Message: ${EncryptedMessage}\n>Decryption Key: In your console.`,
).then((message) => {
console.log("[REVOLT]: SENT!");
});
});
});
addCommand("decrypt", (data, sharedObj) => {
return new Promise((resolve, reject) => {
const Content = data.Content;
const Channel = data.ChannelId;
const MessageId = data.MessageId;
var Args = osiris.getArgs(Content);
var Message = Args[1];
var Key = Args.slice(2).join(" ");
if (!Message) {
return osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]: Invalid message or no message provided. Options are: `,
);
}
if (!Key) {
return osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]: Invalid key or no key provided. Options are: buffer of 32 bytes`,
);
}
var decrypted;
try {
decrypted = decrypt(Message, Buffer.from(Key, "hex"));
} catch (e) {
return osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]: An error occured while decrypting: ${e.code}`,
);
}
osiris.deleteMessage(XSessionToken, Channel, MessageId);
osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]:\n>Encrypted Message: ${Message}\n>Decrypted Message: ${decrypted}`,
).then((message) => {
console.log("[REVOLT]: SENT!");
});
});
});
addCommand("shrug", (data, sharedObj) => {
return new Promise((resolve, reject) => {
const Content = data.Content;
const Channel = data.ChannelId;
const message = `¯I_(ツ)_/¯`;
osiris.sendMessage(XSessionToken, Channel, message)
.then((message) => {
console.log("[REVOLT]: SENT!");
})
.catch((error) => {
console.log(error);
});
});
});
addCommand("trollge", (data, sharedObj) => {
return new Promise((resolve, reject) => {
const Content = data.Content;
const Channel = data.ChannelId;
const message = `░░░░░▄▄▄▄▀▀▀▀▀▀▀▀▄▄▄▄▄▄░░░░░░░
░░░░░█░░░░▒▒▒▒▒▒▒▒▒▒▒▒░░▀▀▄░░░░
░░░░█░░░▒▒▒▒▒▒░░░░░░░░▒▒▒░░█░░░
░░░█░░░░░░▄██▀▄▄░░░░░▄▄▄░░░░█░░
░▄▀▒▄▄▄▒░█▀▀▀▀▄▄█░░░██▄▄█░░░░█░
█░▒█▒▄░▀▄▄▄▀░░░░░░░░█░░░▒▒▒▒▒░█
█░▒█░█▀▄▄░░░░░█▀░░░░▀▄░░▄▀▀▀▄▒█
░█░▀▄░█▄░█▀▄▄░▀░▀▀░▄▄▀░░░░█░░█░
░░█░░░▀▄▀█▄▄░█▀▀▀▄▄▄▄▀▀█▀██░█░░
░░░█░░░░██░░▀█▄▄▄█▄▄█▄████░█░░░
░░░░█░░░░▀▀▄░█░░░█░█▀██████░█░░
░░░░░▀▄░░░░░▀▀▄▄▄█▄█▄█▄█▄▀░░█░░
░░░░░░░▀▄▄░▒▒▒▒░░░░░░░░░░▒░░░█░
░░░░░░░░░░▀▀▄▄░▒▒▒▒▒▒▒▒▒▒░░░░█░
░░░░░░░░░░░░░░▀▄▄▄▄▄░░░░░░░░█░░`;
osiris.sendMessage(XSessionToken, Channel, message)
.then((message) => {
console.log("[REVOLT]: SENT!");
})
.catch((error) => {
console.log(error);
});
});
});
addCommand("ban", (data, sharedObj) => {
return new Promise((resolve, reject) => {
const Content = data.Content;
const Channel = data.ChannelId;
const Server = data?.ServerId;
const Args = osiris.getArgs(Content);
const User = osiris.utils.scanForMentionsAndExtract(Content);
if (!User) {
return osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]: Invalid user or no user provided. Options are: `,
);
}
if (!Args[2]) {
return osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]: Invalid reason or no reason provided. Options are: `,
);
}
if (Server) {
osiris.banUser(XSessionToken, Server, User, Args.slice(1).join(" "))
.then((ban) => {
osiris.sendMessage(
XSessionToken,
Channel,
`Successfully Banned ${autoUser(User)}(${User}) For "${
Args[2]
}"`,
)
.then((message) => {
console.log("[REVOLT]: SENT!");
})
.catch((error) => {
console.log(error);
});
})
.catch((ban) => {
console.log("[REVOLT]: Couldnt ban.");
console.log(ban);
});
}
});
});
addCommand("unban", (data, sharedObj) => {
return new Promise((resolve, reject) => {
const Content = data.Content;
const Channel = data.ChannelId;
const Server = data?.ServerId;
const Args = osiris.getArgs(Content);
const User = osiris.utils.scanForMentionsAndExtract(Content);
if (!User) {
return osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]: Invalid user or no user provided. Options are: `,
);
}
if (Server) {
Unosiris.banUser(XSessionToken, Server, User)
.then((ban) => {
osiris.sendMessage(
XSessionToken,
Channel,
`Successfully UnBanned ${autoUser(User)}(${User}) For "${
Args[2]
}"`,
)
.then((message) => {
console.log("[REVOLT]: SENT!");
})
.catch((error) => {
console.log(error);
});
})
.catch((ban) => {
console.log(ban);
console.log("[REVOLT]: Couldnt unban.");
osiris.sendMessage(
XSessionToken,
Channel,
`[REVOLT]: Couldnt ban.\n>${ban}`,
);
});
}
});
});
//assuming to be a server command
addCommand("argstest", (data, sharedObj) => {
return new Promise((resolve, reject) => {
const Content = data.Content;
const Channel = data.ChannelId;
const Args = osiris.getArgs(Content);
osiris.sendMessage(
XSessionToken,
Channel,
`${Args[1]}, ${Args[2]}`,
).then((message) => {
console.log("[REVOLT]: SENT!");
});
});
});
addCommand("gayrate", (data, sharedObj) => {
return new Promise((resolve, reject) => {
const Content = data.Content;
const Channel = data.ChannelId;
const User = osiris.utils.scanForMentionsAndExtract(Content);
const Gayrate = Math.floor(Math.random() * 101); // should work
osiris.sendMessage(
XSessionToken,
Channel,
`${autoUser(User)} is ${Gayrate}% gay!`,
).then((message) => {
console.log("[REVOLT]: SENT!");
});
});
});
addCommand("8ball", (data, sharedObj) => {
return new Promise((resolve, reject) => {
const Content = data.Content;
const Channel = data.ChannelId;
const Args = osiris.getArgs(Content);
const responses = [
"It is certain.",
"It is decidedly so.",
"Without a doubt.",
"Yes - definitely.",
"You may rely on it.",
"As I see it, yes.",
"Most likely.",
"Outlook good.",
"Yes.",
"Signs point to yes.",
"Reply hazy, try again.",
"Ask again later.",
"Better not tell you now.",
"Cannot predict now.",
"Concentrate and ask again.",
"Don't count on it.",
"Outlook not so good.",
"My sources say no.",
"Very doubtful.",
];
osiris.sendMessage(
XSessionToken,
Channel,
" `` " +
Args.slice(1).join(" ") +
"\n" +
responses[Math.floor(Math.random() * responses.length)] +
" `` ",
).then((message) => {
console.log("[REVOLT]: SENT!");
});
});
});
addCommand("text", (data, sharedObj) => {
return new Promise((resolve, reject) => {
const Content = data.Content;
const Channel = data.ChannelId;
const Args = osiris.getArgs(Content);
var types = ["big", "small"];
const colors = [
"red",
"green",
"blue",
"pink",
"purple",
"white",
"magenta",
"yellow",