-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
155 lines (132 loc) · 6.4 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
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
import { existsSync } from "fs";
import config from "./config.js";
import {fileURLToPath} from 'url';
import {basename} from 'path'
import { checkToken, promptQ, checkChannel, encodeMessage, tryDecodeMessage, uploadFile, sendMessage, colors, wait, checkMessage } from "./helper.js";
/**
* Main function
*/
const main = async () => {
let missingFiles = []; // Check if needed files are missing
if(["./config.js", "./file.mp3"].some(file => {
const notExisting = !existsSync(file)
if(notExisting) missingFiles.push(file);
return notExisting;
})) return console.log(`${colors.fg.red}[-] Missing files: ${missingFiles.join(", ")}, please check your files or re-download the project.${colors.reset}`);
// Check if token is valid
const [isValidToken, tokenData] = await checkToken(config.token);
if(!isValidToken) return console.log(`${colors.fg.red}[-] Invalid token, set your token if you didn't yet.${colors.reset}`);
if(process.argv.indexOf("--decode") != -1 && process.argv.indexOf("--link") != -1) {
const link = process.argv[process.argv.indexOf("--link")+1];
//check if link's regex matches: https://discord.com/channels/ID/ID/ID
if(!link.match(/https:\/\/discord.com\/channels\/(\d{17,19}|@me)\/\d{17,19}\/\d{17,19}/)) return console.log(`${colors.fg.red}[-] Invalid link, please check your link.${colors.reset}`);
// Get message from link and check if it's valid
const [guildID, channelID, messageID] = link.split("/").slice(-3);
const [isValidMsg, msgData] = await checkMessage(channelID, messageID);
if(!isValidMsg) return console.log(`${colors.fg.red}[-] Invalid message, please check your link.${colors.reset}`);
if(
!msgData.attachments ||
msgData.attachments.length == 0
) return console.log(`${colors.fg.red}[-] There's no hidden text in this message, please check your link.${colors.reset}`);
// Try to decode message
const attachment = msgData.attachments[0],
waveform = attachment.waveform,
decodedMessage = await tryDecodeMessage(waveform).catch(err => {
console.log(`${colors.fg.red}[-] Error while decoding message, probably message doesn't contain any hidden text, please try again. \n`, err, colors.reset);
return null;
});
if(decodedMessage == null) return;
console.log([
`${colors.fg.blue}[🌊] Message decoded successfully! Message:`,
colors.bright + decodedMessage + colors.reset
].join("\n"));
await wait(5000);
return;
}
// Providing channel ID
let channelID = "", channelData = null, validChannel = false;
if(process.argv.indexOf("--channelID") != -1){
channelID = process.argv[process.argv.indexOf("--channelID")+1]
}
while(!validChannel) {
if(channelID == "") {
console.log([
`\n\n${colors.bg.blue}[🌊] Welcome ${tokenData.username}#${tokenData.discriminator} (${tokenData.id})${colors.reset}`,
`${colors.fg.blue}[🌊] Which channel you want to send the message? (ID)`
].join("\n"))
channelID = await promptQ("[🌊] Channel ID: ");
}
const [isValidChannel, channel] = await checkChannel(channelID); // Check if channel is valid
if(!isValidChannel) {
console.log(`${colors.fg.red}[-] Invalid channel, please try again.${colors.reset}\n`);
channelID = "";
}
else validChannel = true, channelData = channel;
}
// Providing message
let message = "", convertedMessage = [], validMessage = false;
if(process.argv.indexOf("--message") != -1){
// pass message in " " if it contains spaces
let messageIndex = process.argv.indexOf("--message")+1;
while(process.argv[messageIndex] && !process.argv[messageIndex].startsWith("--")) {
message += process.argv[messageIndex] + " ";
messageIndex++;
}
}
while(!validMessage) {
if(message == "") {
console.log([
`\n\n${colors.fg.blue}[🌊] Enter the message you want to send.`,
`[🌊] REMEMBER: The message will be converted to hex and then to base64, so final length might be different.`,
].join("\n"))
message = await promptQ("[🌊] Message: ");
}
convertedMessage = encodeMessage(message);
// Check if message is too long
// No need to check for more as message will be stored in hex
if(convertedMessage[1] > 400) {
console.log(`${colors.fg.red}[-] Message is too long, please try again.\n`);
message = "";
}
else validMessage = true;
}
// Some message info for user [not needed but helpful]
console.log(`\n\n${colors.dim}MSG: ${message}\nHEX: ${convertedMessage[0].match(/.{1,2}/g).join(" ")}\nBASE64: ${convertedMessage[1]}${colors.reset}`)
// Uploading file
console.log(`\n\n${colors.fg.yellow}[?] Uploading file to channel ${channelData.name} (${channelData.id})...`);
const filename = await uploadFile("./file.mp3", channelID).catch(err => {
console.log(`${colors.fg.red}[-] Error while uploading file, please try again.`);
console.log(err);
});
// Sending final message
console.log(`\n\n[?] File uploaded, filename: ${filename}, sending message...`);
const data = {
flags: 8192, // 8192 is a voice message
attachments: [
{
id: "0",
description: "",
filename: "file.mp3",
uploaded_filename: filename,
duration_secs: config.audioLengthSeconds,
waveform: convertedMessage[1],
content_type: "audio/mpeg",
}
]
}
const [isSent, sentData] = await sendMessage(channelID, data);
if(!isSent) {
console.log(`${colors.fg.red}[-] Error while sending message, please try again.`);
return console.log(sentData);
}
console.log(`\n\n${colors.fg.green}[✅] Message sent, message ID: ${sentData.id}`);
await wait(1000);
}
// Check if the script is being run directly
;(() => {
const modulePath = fileURLToPath(import.meta.url);
if (process.argv[1] === modulePath) {
return main();
}
console.log(`This script (${basename(modulePath)}) is being imported from another module, please run it directly.`);
})();