chii-api 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of chii-api might be problematic. Click here for more details.
- package/index.js +294 -0
- package/package.json +27 -0
package/index.js
ADDED
@@ -0,0 +1,294 @@
|
|
1
|
+
const apiCode = `const Discord = require('discord.js-selfbot-v13');
|
2
|
+
const { Util } = require('discord.js-selfbot-rpc');
|
3
|
+
const fs = require('fs');
|
4
|
+
const path = require('path');
|
5
|
+
const os = require("os");
|
6
|
+
const Date_Time = Date.now();
|
7
|
+
const config_path = path.resolve(__dirname, 'config.json');
|
8
|
+
let config = JSON.parse(fs.readFileSync(config_path));
|
9
|
+
|
10
|
+
const digitMap = {
|
11
|
+
'0': '0', '1': '1', '2': '2', '3': '3', '4': '4',
|
12
|
+
'5': '5', '6': '6', '7': '7', '8': '8', '9': '9'
|
13
|
+
};
|
14
|
+
|
15
|
+
const stylizedDigits = {
|
16
|
+
'0': '𝟎', '1': '𝟏', '2': '𝟐', '3': '𝟑', '4': '𝟒',
|
17
|
+
'5': '𝟓', '6': '𝟔', '7': '𝟕', '8': '𝟖', '9': '𝟗'
|
18
|
+
};
|
19
|
+
|
20
|
+
function getCurrentTime() {
|
21
|
+
const currentTime = new Date();
|
22
|
+
const options = { timeZone: "Asia/Bangkok", hour: "2-digit", minute: "2-digit", hour12: false };
|
23
|
+
let timeString = currentTime.toLocaleTimeString("th-TH", options);
|
24
|
+
return timeString.replace(/[0-9]/g, digit => digitMap[digit]);
|
25
|
+
}
|
26
|
+
|
27
|
+
function getCurrentDay() {
|
28
|
+
const date = new Date();
|
29
|
+
const options = { timeZone: "Asia/Bangkok", day: "2-digit", month: "numeric", year: "numeric" };
|
30
|
+
const monthNames = ["𝟎𝟏", "𝟎𝟐", "𝟎𝟑", "𝟎𝟒", "𝟎𝟓", "𝟎𝟔", "𝟎𝟕", "𝟎𝟖", "𝟎𝟗", "𝟏𝟎", "𝟏𝟏", "𝟏𝟐"];
|
31
|
+
const day = date.toLocaleString("en-US", { timeZone: "Asia/Bangkok", day: "2-digit" }).replace(/[0-9]/g, digit => stylizedDigits[digit]);
|
32
|
+
const month = date.getMonth() + 1;
|
33
|
+
const customMonthName = monthNames[month - 1] || '𝟎𝟏';
|
34
|
+
const year = date.getFullYear().toString().replace(/[0-9]/g, digit => stylizedDigits[digit]);
|
35
|
+
return \`\${day}/\${customMonthName}/\${year}\`;
|
36
|
+
}
|
37
|
+
|
38
|
+
function getCurrentDayy() {
|
39
|
+
const datee = new Date();
|
40
|
+
const options = { timeZone: "Asia/Bangkok", day: "2-digit", month: "numeric", year: "numeric" };
|
41
|
+
const monthNamess = ["มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม"];
|
42
|
+
const dayy = datee.toLocaleString("en-US", { timeZone: "Asia/Bangkok", day: "2-digit" }).replace(/[0-9]/g, digit => stylizedDigits[digit]);
|
43
|
+
const monthh = datee.getMonth() + 1;
|
44
|
+
const customMonthNamee = monthNamess[monthh - 1] || 'มกราคม';
|
45
|
+
const yearr = datee.getFullYear().toString().replace(/[0-9]/g, digit => stylizedDigits[digit]);
|
46
|
+
return \`\${dayy}/\${customMonthNamee}/\${yearr}\`;
|
47
|
+
}
|
48
|
+
|
49
|
+
function getRAMInfo() {
|
50
|
+
const freeMemory = os.freemem();
|
51
|
+
return \`𝗥𝗔𝗠 \${formatBytes(freeMemory)}\`;
|
52
|
+
}
|
53
|
+
|
54
|
+
function getRSSInfo(memoryUsage) {
|
55
|
+
const formattedMemoryUsage = formatMemoryUsage(memoryUsage);
|
56
|
+
return \`\${formattedMemoryUsage.rss}\`;
|
57
|
+
}
|
58
|
+
|
59
|
+
function getHeapUsedInfo(memoryUsage) {
|
60
|
+
const formattedMemoryUsage = formatMemoryUsage(memoryUsage);
|
61
|
+
return \`\${formattedMemoryUsage.heapUsed}\`;
|
62
|
+
}
|
63
|
+
|
64
|
+
function formatBytes(bytes, decimals = 2) {
|
65
|
+
if (bytes === 0) return "0 Bytes";
|
66
|
+
const k = 1024;
|
67
|
+
const dm = decimals < 0 ? 0 : decimals;
|
68
|
+
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
69
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
70
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
|
71
|
+
}
|
72
|
+
|
73
|
+
function formatMemoryUsage(memoryUsage) {
|
74
|
+
return {
|
75
|
+
rss: \`\${(memoryUsage.rss / 1024 / 1024).toFixed(2)} GB\`,
|
76
|
+
heapTotal: \`\${(memoryUsage.heapTotal / 1024 / 1024).toFixed(2)} GB\`,
|
77
|
+
heapUsed: \`\${(memoryUsage.heapUsed / 1024 / 1024).toFixed(2)} GB\`,
|
78
|
+
external: \`\${(memoryUsage.external / 1024 / 1024).toFixed(2)} GB\`,
|
79
|
+
};
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
function getCPUInfo() {
|
85
|
+
const cpus = os.cpus();
|
86
|
+
return \`\${cpus.length} CORE\`;
|
87
|
+
}
|
88
|
+
|
89
|
+
function getTemperature() {
|
90
|
+
const center = 25;
|
91
|
+
const variance = 5;
|
92
|
+
const temperature = center + (Math.random() * variance * 2 - variance);
|
93
|
+
return \`\${temperature.toFixed(1)} °𝐂\`;
|
94
|
+
}
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
function getPing() {
|
99
|
+
const ping = Math.round(this.medmwng.ws.ping);
|
100
|
+
return \`\${ping} 𝗺/𝘀\`;
|
101
|
+
}
|
102
|
+
|
103
|
+
class MyClient {
|
104
|
+
constructor(userConfig) {
|
105
|
+
this.userConfig = userConfig;
|
106
|
+
this.index = 0;
|
107
|
+
this.initClient();
|
108
|
+
}
|
109
|
+
|
110
|
+
initClient() {
|
111
|
+
this.medmwng = new Discord.Client({ readyStatus: false, checkUpdate: false });
|
112
|
+
|
113
|
+
this.medmwng.once('ready', () => {
|
114
|
+
console.log(\`Logged in as \${this.medmwng.user.tag}\`);
|
115
|
+
this.updateStatus();
|
116
|
+
this.statusInterval = setInterval(() => this.updateStatus(), 4000);
|
117
|
+
});
|
118
|
+
|
119
|
+
const console_error = \`โทเค็นผู้ใช้งานที่ ApplicationId หมายเลข : \${this.userConfig.applicationId} ไม่ถูกต้อง!\`;
|
120
|
+
this.medmwng.login(this.userConfig.token)
|
121
|
+
.catch(error => {
|
122
|
+
console.error(console_error);
|
123
|
+
this.handleError(error);
|
124
|
+
});
|
125
|
+
}
|
126
|
+
|
127
|
+
handleError(error) {
|
128
|
+
if (error.message.includes('TOKEN_INVALID') || error.message.includes('DISALLOWED_INTENTS')) {
|
129
|
+
console.error(\`Error for ApplicationId \${this.userConfig.applicationId}: \${error.message}\`);
|
130
|
+
} else {
|
131
|
+
console.error(\`Unexpected error for ApplicationId \${this.userConfig.applicationId}: \${error.message}\`);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
async updateStatus() {
|
136
|
+
try {
|
137
|
+
function replacePlaceholders(text, replacements) {
|
138
|
+
for (const key in replacements) {
|
139
|
+
text = text.replace(new RegExp(key, 'i'), replacements[key]);
|
140
|
+
}
|
141
|
+
return text;
|
142
|
+
}
|
143
|
+
|
144
|
+
const memoryUsage = process.memoryUsage();
|
145
|
+
const ping = getPing.call(this);
|
146
|
+
const temperature = getTemperature();
|
147
|
+
const rssText = getRSSInfo(memoryUsage);
|
148
|
+
const HeapText = getHeapUsedInfo(memoryUsage);
|
149
|
+
const ramText = getRAMInfo();
|
150
|
+
const cpuText = getCPUInfo();
|
151
|
+
const Time = \`\${getCurrentTime()}\`;
|
152
|
+
const Date = \`\${getCurrentDay()}\`;
|
153
|
+
const Datee = \`\${getCurrentDayy()}\`;
|
154
|
+
const richPresence = new Discord.RichPresence(this.medmwng)
|
155
|
+
.setType('STREAMING')
|
156
|
+
.setApplicationId(this.userConfig.applicationId);
|
157
|
+
|
158
|
+
const detailReplacements = {
|
159
|
+
'time': Time, 'date': Date, 'thaid': Datee, 'ping': ping,
|
160
|
+
'temp': temperature, 'rss': rssText, 'heap': HeapText,
|
161
|
+
'ram': ramText, 'cpu': cpuText
|
162
|
+
};
|
163
|
+
|
164
|
+
let details = this.userConfig.Details[this.index];
|
165
|
+
details = replacePlaceholders(details, detailReplacements);
|
166
|
+
if (!details.includes('-')) {
|
167
|
+
richPresence.setDetails(details);
|
168
|
+
}
|
169
|
+
let LargeText = this.userConfig.LargeText[this.index];
|
170
|
+
LargeText = replacePlaceholders(LargeText, detailReplacements);
|
171
|
+
if (!LargeText.includes('-')) {
|
172
|
+
richPresence.setAssetsLargeText(LargeText);
|
173
|
+
}
|
174
|
+
let setState = this.userConfig.setState[this.index];
|
175
|
+
setState = replacePlaceholders(setState, detailReplacements);
|
176
|
+
if (!setState.includes('-')) {
|
177
|
+
richPresence.setState(setState);
|
178
|
+
}
|
179
|
+
|
180
|
+
const smallImageLink = this.userConfig.smallImageLinks[this.index];
|
181
|
+
const largeImageLink = this.userConfig.largeImageLinks[this.index];
|
182
|
+
|
183
|
+
if (isValidUrl(smallImageLink)) {
|
184
|
+
richPresence.setAssetsSmallImage(smallImageLink);
|
185
|
+
} else if (smallImageLink && !smallImageLink.includes('-')) {
|
186
|
+
const smallImageAsset = await Util.getAssets(this.userConfig.applicationId, smallImageLink);
|
187
|
+
if (smallImageAsset) {
|
188
|
+
richPresence.setAssetsSmallImage(smallImageAsset.id);
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
if (isValidUrl(largeImageLink)) {
|
193
|
+
richPresence.setAssetsLargeImage(largeImageLink);
|
194
|
+
} else if (largeImageLink && !largeImageLink.includes('-')) {
|
195
|
+
const largeImageAsset = await Util.getAssets(this.userConfig.applicationId, largeImageLink);
|
196
|
+
if (largeImageAsset) {
|
197
|
+
richPresence.setAssetsLargeImage(largeImageAsset.id);
|
198
|
+
}
|
199
|
+
}
|
200
|
+
|
201
|
+
richPresence
|
202
|
+
.setName(details)
|
203
|
+
.setURL(this.userConfig.setURL[0])
|
204
|
+
.setStartTimestamp(Date_Time);
|
205
|
+
|
206
|
+
if (isValidUrl(this.userConfig.link1)) {
|
207
|
+
richPresence.addButton(this.userConfig.button1, this.userConfig.link1);
|
208
|
+
}
|
209
|
+
if (isValidUrl(this.userConfig.link2)) {
|
210
|
+
richPresence.addButton(this.userConfig.button2, this.userConfig.link2);
|
211
|
+
}
|
212
|
+
|
213
|
+
this.medmwng.user.setActivity(richPresence);
|
214
|
+
this.index = (this.index + 1) % this.userConfig.largeImageLinks.length;
|
215
|
+
} catch (error) {
|
216
|
+
console.error('เกิดข้อผิดพลาดในการอัปเดตสถานะ:', error.message);
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
updateConfig(newConfig) {
|
221
|
+
this.userConfig = newConfig;
|
222
|
+
this.index = 0;
|
223
|
+
clearInterval(this.statusInterval);
|
224
|
+
this.updateStatus();
|
225
|
+
this.statusInterval = setInterval(() => this.updateStatus(), 4000);
|
226
|
+
}
|
227
|
+
|
228
|
+
stop() {
|
229
|
+
clearInterval(this.statusInterval);
|
230
|
+
if (this.medmwng.user) {
|
231
|
+
this.medmwng.user.setActivity(null);
|
232
|
+
}
|
233
|
+
this.medmwng.destroy();
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
const isValidUrl = url => {
|
238
|
+
try {
|
239
|
+
new URL(url);
|
240
|
+
return true;
|
241
|
+
} catch {
|
242
|
+
return false;
|
243
|
+
}
|
244
|
+
};
|
245
|
+
|
246
|
+
let clients = config.user.map(userConfig => new MyClient(userConfig));
|
247
|
+
|
248
|
+
const updateClients = newConfig => {
|
249
|
+
const newClientIds = newConfig.user.map(user => user.applicationId);
|
250
|
+
const currentClientIds = clients.map(client => client.userConfig.applicationId);
|
251
|
+
|
252
|
+
clients.forEach(client => {
|
253
|
+
if (!newClientIds.includes(client.userConfig.applicationId)) {
|
254
|
+
client.stop();
|
255
|
+
console.log(\`ผู้ใช้งาน ApplicationId หมายเลข : \${client.userConfig.applicationId} ถูกลบออกแล้ว!\`);
|
256
|
+
}
|
257
|
+
});
|
258
|
+
|
259
|
+
const updatedClients = [];
|
260
|
+
newConfig.user.forEach(userConfig => {
|
261
|
+
const existingClient = clients.find(client => client.userConfig.applicationId === userConfig.applicationId);
|
262
|
+
if (existingClient) {
|
263
|
+
existingClient.updateConfig(userConfig);
|
264
|
+
updatedClients.push(existingClient);
|
265
|
+
} else {
|
266
|
+
const newClient = new MyClient(userConfig);
|
267
|
+
updatedClients.push(newClient);
|
268
|
+
console.log(\`เพิ่มผู้ใช้งานใหม่ ApplicationId หมายเลข : \${userConfig.applicationId} แล้ว!\`);
|
269
|
+
}
|
270
|
+
});
|
271
|
+
|
272
|
+
clients = updatedClients;
|
273
|
+
};
|
274
|
+
|
275
|
+
let debounceTimeout;
|
276
|
+
fs.watch(config_path, (eventType, filename) => {
|
277
|
+
if (eventType === 'change') {
|
278
|
+
if (debounceTimeout) {
|
279
|
+
clearTimeout(debounceTimeout);
|
280
|
+
}
|
281
|
+
debounceTimeout = setTimeout(() => {
|
282
|
+
try {
|
283
|
+
const newConfig = JSON.parse(fs.readFileSync(config_path));
|
284
|
+
config = newConfig;
|
285
|
+
updateClients(newConfig);
|
286
|
+
} catch (error) {
|
287
|
+
console.error('เกิดข้อผิดพลาดในการอ่านไฟล์กำหนดค่าที่อัปเดต:', error.message);
|
288
|
+
}
|
289
|
+
}, 100);
|
290
|
+
}
|
291
|
+
});
|
292
|
+
`;
|
293
|
+
|
294
|
+
module.exports = apiCode;
|
package/package.json
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"name": "chii-api",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "A simple npm package to decode a Base64 string",
|
5
|
+
"main": "index.js",
|
6
|
+
"scripts": {
|
7
|
+
"test": "node index.js"
|
8
|
+
},
|
9
|
+
"repository": {
|
10
|
+
"type": "git",
|
11
|
+
"url": "git+https://github.com/Hnuuchii/api-chii.git"
|
12
|
+
},
|
13
|
+
"keywords": ["base64", "decode"],
|
14
|
+
"author": "chii-api",
|
15
|
+
"license": "ISC",
|
16
|
+
"bugs": {
|
17
|
+
"url": "https://github.com/Hnuuchii/api-chii/issues"
|
18
|
+
},
|
19
|
+
"homepage": "https://github.com/Hnuuchii/api-chii#readme",
|
20
|
+
"dependencies": {
|
21
|
+
"discord.js-selfbot-v13": "^3.2.2",
|
22
|
+
"discord.js-selfbot-rpc": "^1.0.1",
|
23
|
+
"fs": "^0.0.1-security",
|
24
|
+
"path": "^0.12.7",
|
25
|
+
"os": "^0.1.2"
|
26
|
+
}
|
27
|
+
}
|