fca-naughty2 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.gitattributes +2 -0
- package/.github/workflows/publish.yml +20 -0
- package/Extra/Database/index.js +469 -0
- package/Extra/ExtraAddons.js +80 -0
- package/Extra/ExtraFindUID.js +62 -0
- package/Extra/ExtraGetThread.js +118 -0
- package/Extra/ExtraScreenShot.js +430 -0
- package/Extra/ExtraUptimeRobot.js +38 -0
- package/Extra/Html/Classic/script.js +119 -0
- package/Extra/Html/Classic/style.css +8 -0
- package/Extra/Security/Index.js +146 -0
- package/Extra/Security/Step_1.js +6 -0
- package/Extra/Security/Step_2.js +22 -0
- package/Extra/Security/Step_3.js +22 -0
- package/Extra/Src/Change_Environment.js +24 -0
- package/Extra/Src/Check_Update.js +67 -0
- package/Extra/Src/History.js +115 -0
- package/Extra/Src/Instant_Update.js +65 -0
- package/Extra/Src/Last-Run.js +65 -0
- package/Extra/Src/Premium.js +81 -0
- package/Extra/Src/Release_Memory.js +41 -0
- package/Extra/Src/uuid.js +137 -0
- package/Func/AcceptAgreement.js +32 -0
- package/Func/ClearCache.js +64 -0
- package/Func/ReportV1.js +54 -0
- package/LICENSE +24 -0
- package/Language/index.json +206 -0
- package/Main.js +1099 -0
- package/README.md +140 -0
- package/SECURITY.md +17 -0
- package/broadcast.js +40 -0
- package/index.js +350 -0
- package/logger.js +66 -0
- package/package.json +94 -0
- package/src/Dev_Horizon_Data.js +125 -0
- package/src/Premium.js +30 -0
- package/src/Screenshot.js +83 -0
- package/src/addExternalModule.js +16 -0
- package/src/addUserToGroup.js +79 -0
- package/src/changeAdminStatus.js +79 -0
- package/src/changeArchivedStatus.js +41 -0
- package/src/changeAvt.js +85 -0
- package/src/changeBio.js +65 -0
- package/src/changeBlockedStatus.js +36 -0
- package/src/changeGroupImage.js +106 -0
- package/src/changeNickname.js +45 -0
- package/src/changeThreadColor.js +62 -0
- package/src/changeThreadEmoji.js +42 -0
- package/src/createNewGroup.js +70 -0
- package/src/createPoll.js +60 -0
- package/src/deleteMessage.js +45 -0
- package/src/deleteThread.js +43 -0
- package/src/forwardAttachment.js +48 -0
- package/src/getAccessToken.js +28 -0
- package/src/getCurrentUserID.js +7 -0
- package/src/getEmojiUrl.js +27 -0
- package/src/getFriendsList.js +73 -0
- package/src/getMessage.js +80 -0
- package/src/getThreadHistory.js +537 -0
- package/src/getThreadInfo.js +412 -0
- package/src/getThreadList.js +213 -0
- package/src/getThreadMain.js +220 -0
- package/src/getThreadPictures.js +59 -0
- package/src/getUID.js +59 -0
- package/src/getUserID.js +62 -0
- package/src/getUserInfo.js +113 -0
- package/src/getUserInfoMain.js +65 -0
- package/src/getUserInfoV2.js +32 -0
- package/src/getUserInfoV3.js +63 -0
- package/src/getUserInfoV4.js +55 -0
- package/src/getUserInfoV5.js +61 -0
- package/src/handleFriendRequest.js +46 -0
- package/src/handleMessageRequest.js +49 -0
- package/src/httpGet.js +49 -0
- package/src/httpPost.js +48 -0
- package/src/httpPostFormData.js +41 -0
- package/src/listenMqtt.js +697 -0
- package/src/logout.js +68 -0
- package/src/markAsDelivered.js +48 -0
- package/src/markAsRead.js +70 -0
- package/src/markAsReadAll.js +43 -0
- package/src/markAsSeen.js +51 -0
- package/src/muteThread.js +47 -0
- package/src/removeUserFromGroup.js +49 -0
- package/src/resolvePhotoUrl.js +37 -0
- package/src/searchForThread.js +43 -0
- package/src/sendMessage.js +334 -0
- package/src/sendTypingIndicator.js +80 -0
- package/src/setMessageReaction.js +109 -0
- package/src/setPostReaction.js +102 -0
- package/src/setTitle.js +74 -0
- package/src/threadColors.js +39 -0
- package/src/unfriend.js +43 -0
- package/src/unsendMessage.js +40 -0
- package/test/Database_Test.js +4 -0
- package/test/Db2.js +530 -0
- package/test/Horizon_Database/A_README.md +1 -0
- package/test/Horizon_Database/Database.db +0 -0
- package/test/data/shareAttach.js +146 -0
- package/test/data/something.mov +0 -0
- package/test/data/test.png +0 -0
- package/test/data/test.txt +7 -0
- package/test/env/.env +0 -0
- package/test/example-config.json +18 -0
- package/test/example-db.db +0 -0
- package/test/memoryleak.js +18 -0
- package/test/test-page.js +140 -0
- package/test/test.js +385 -0
- package/test/testv2.js +18 -0
- package/utils.js +1628 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
module.exports = function(_defaultFuncs, _api, _ctx) {
|
4
|
+
// Currently the only colors that can be passed to api.changeThreadColor(); may change if Facebook adds more
|
5
|
+
return {
|
6
|
+
////MessengerBlue: null,
|
7
|
+
////Viking: "#44bec7",
|
8
|
+
////GoldenPoppy: "#ffc300",
|
9
|
+
////RadicalRed: "#fa3c4c",
|
10
|
+
////Shocking: "#d696bb",
|
11
|
+
////PictonBlue: "#6699cc",
|
12
|
+
////FreeSpeechGreen: "#13cf13",
|
13
|
+
////Pumpkin: "#ff7e29",
|
14
|
+
////LightCoral: "#e68585",
|
15
|
+
////MediumSlateBlue: "#7646ff",
|
16
|
+
////DeepSkyBlue: "#20cef5",
|
17
|
+
////Fern: "#67b868",
|
18
|
+
////Cameo: "#d4a88c",
|
19
|
+
////BrilliantRose: "#ff5ca1",
|
20
|
+
////BilobaFlower: "#a695c7"
|
21
|
+
DefaultBlue: "196241301102133",
|
22
|
+
HotPink: "169463077092846",
|
23
|
+
AquaBlue: "2442142322678320",
|
24
|
+
BrightPurple: "234137870477637",
|
25
|
+
CoralPink: "980963458735625",
|
26
|
+
Orange: "175615189761153",
|
27
|
+
Green: "2136751179887052",
|
28
|
+
LavenderPurple: "2058653964378557",
|
29
|
+
Red: "2129984390566328",
|
30
|
+
Yellow: "174636906462322",
|
31
|
+
TealBlue: "1928399724138152",
|
32
|
+
Aqua: "417639218648241",
|
33
|
+
Mango: "930060997172551",
|
34
|
+
Berry: "164535220883264",
|
35
|
+
Citrus: "370940413392601",
|
36
|
+
Candy: "205488546921017",
|
37
|
+
StarWars: "809305022860427"
|
38
|
+
};
|
39
|
+
};
|
package/src/unfriend.js
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
+
return function unfriend(userID, callback) {
|
8
|
+
var resolveFunc = function () { };
|
9
|
+
var rejectFunc = function () { };
|
10
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
11
|
+
resolveFunc = resolve;
|
12
|
+
rejectFunc = reject;
|
13
|
+
});
|
14
|
+
|
15
|
+
if (!callback) {
|
16
|
+
callback = function (err, friendList) {
|
17
|
+
if (err) return rejectFunc(err);
|
18
|
+
resolveFunc(friendList);
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
22
|
+
var form = {
|
23
|
+
uid: userID,
|
24
|
+
unref: "bd_friends_tab",
|
25
|
+
floc: "friends_tab",
|
26
|
+
"nctr[_mod]": "pagelet_timeline_app_collection_" + ctx.userID + ":2356318349:2"
|
27
|
+
};
|
28
|
+
|
29
|
+
defaultFuncs
|
30
|
+
.post("https://www.facebook.com/ajax/profile/removefriendconfirm.php", ctx.jar, form)
|
31
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
32
|
+
.then(function (resData) {
|
33
|
+
if (resData.error) throw resData;
|
34
|
+
return callback();
|
35
|
+
})
|
36
|
+
.catch(function (err) {
|
37
|
+
log.error("unfriend", err);
|
38
|
+
return callback(err);
|
39
|
+
});
|
40
|
+
|
41
|
+
return returnPromise;
|
42
|
+
};
|
43
|
+
};
|
@@ -0,0 +1,40 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
7
|
+
return function unsendMessage(messageID, callback) {
|
8
|
+
var resolveFunc = function () { };
|
9
|
+
var rejectFunc = function () { };
|
10
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
11
|
+
resolveFunc = resolve;
|
12
|
+
rejectFunc = reject;
|
13
|
+
});
|
14
|
+
|
15
|
+
if (!callback) {
|
16
|
+
callback = function (err, friendList) {
|
17
|
+
if (err) return rejectFunc(err);
|
18
|
+
resolveFunc(friendList);
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
22
|
+
var form = {
|
23
|
+
message_id: messageID
|
24
|
+
};
|
25
|
+
|
26
|
+
defaultFuncs
|
27
|
+
.post("https://www.facebook.com/messaging/unsend_message/", ctx.jar, form)
|
28
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
29
|
+
.then(function (resData) {
|
30
|
+
if (resData.error) throw resData;
|
31
|
+
return callback();
|
32
|
+
})
|
33
|
+
.catch(function (err) {
|
34
|
+
log.error("unsendMessage", err);
|
35
|
+
return callback(err);
|
36
|
+
});
|
37
|
+
|
38
|
+
return returnPromise;
|
39
|
+
};
|
40
|
+
};
|
package/test/Db2.js
ADDED
@@ -0,0 +1,530 @@
|
|
1
|
+
/* eslint-disable no-self-assign */
|
2
|
+
/* eslint-disable linebreak-style */
|
3
|
+
const get = require('lodash/get');
|
4
|
+
const set = require('lodash/set');
|
5
|
+
const sqlite3 = require('sqlite3');
|
6
|
+
const fs = require('fs-extra');
|
7
|
+
const request = require('request');
|
8
|
+
const deasync = require('deasync');
|
9
|
+
|
10
|
+
if (!fs.existsSync(process.cwd() + '/Horizon_Database')) {
|
11
|
+
fs.mkdirSync(process.cwd() + '/Horizon_Database');
|
12
|
+
fs.writeFileSync(process.cwd() + '/Horizon_Database/A_README.md', 'This folder is used by ChernobyL(NANI =)) ) to store data. Do not delete this folder or any of the files in it.', 'utf8');
|
13
|
+
}
|
14
|
+
var Database = new sqlite3.Database(process.cwd() + "/Horizon_Database/SyntheticDatabase.sqlite");
|
15
|
+
|
16
|
+
Database.serialize(function() {
|
17
|
+
Database.run("CREATE TABLE IF NOT EXISTS json (ID TEXT, json TEXT)");
|
18
|
+
});
|
19
|
+
|
20
|
+
function Lset(key, value) {
|
21
|
+
try {
|
22
|
+
//check if key is exists if yes then update it
|
23
|
+
if (Lhas(key)) {
|
24
|
+
var done = false;
|
25
|
+
Database.run(`UPDATE json SET json = (?) WHERE ID = (?)`, [JSON.stringify(value), key], function(err) {
|
26
|
+
done = true;
|
27
|
+
});
|
28
|
+
deasync.loopWhile(function(){
|
29
|
+
return !done;
|
30
|
+
});
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
var done = false;
|
35
|
+
Database.run(`INSERT INTO json(ID, json) VALUES(?, ?)`, [key, JSON.stringify(value)], function(err) {
|
36
|
+
done = true;
|
37
|
+
});
|
38
|
+
deasync.loopWhile(function(){
|
39
|
+
return !done;
|
40
|
+
});
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
catch (e) {
|
45
|
+
console.log(e);
|
46
|
+
return false;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
function Lget(key) {
|
51
|
+
try {
|
52
|
+
var done = false;
|
53
|
+
var Data = undefined;
|
54
|
+
Database.get(`SELECT * FROM json WHERE ID = (?)`, [key], function(err, row) {
|
55
|
+
Data = row;
|
56
|
+
done = true;
|
57
|
+
});
|
58
|
+
deasync.loopWhile(function(){
|
59
|
+
return !done;
|
60
|
+
});
|
61
|
+
if (Data === undefined) return undefined;
|
62
|
+
return JSON.parse(Data.json);
|
63
|
+
}
|
64
|
+
catch (e) {
|
65
|
+
console.log(e);
|
66
|
+
return false;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
function Lhas(key) {
|
71
|
+
try {
|
72
|
+
var done = false;
|
73
|
+
var Data = undefined;
|
74
|
+
Database.get(`SELECT * FROM json WHERE ID = (?)`, [key], function(err, row) {
|
75
|
+
Data = row;
|
76
|
+
done = true;
|
77
|
+
});
|
78
|
+
deasync.loopWhile(function(){
|
79
|
+
return !done;
|
80
|
+
});
|
81
|
+
if (Data === undefined) return false;
|
82
|
+
return true;
|
83
|
+
}
|
84
|
+
catch (e) {
|
85
|
+
console.log(e);
|
86
|
+
return false;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
function Lremove(key) {
|
91
|
+
try {
|
92
|
+
var done = false;
|
93
|
+
Database.run(`DELETE FROM json WHERE ID = (?)`, [key], function(err) {
|
94
|
+
done = true;
|
95
|
+
});
|
96
|
+
deasync.loopWhile(function(){
|
97
|
+
return !done;
|
98
|
+
});
|
99
|
+
return;
|
100
|
+
}
|
101
|
+
catch (e) {
|
102
|
+
console.log(e);
|
103
|
+
return false;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
function LremoveMultiple(keys) {
|
108
|
+
try {
|
109
|
+
for (const key of keys) {
|
110
|
+
Database.run(`DELETE FROM json WHERE ID = (?)`, [key], function(err) {});
|
111
|
+
}
|
112
|
+
return true;
|
113
|
+
}
|
114
|
+
catch (e) {
|
115
|
+
console.log(e);
|
116
|
+
return false;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
function Llist() {
|
121
|
+
var done = false;
|
122
|
+
var Data = undefined;
|
123
|
+
Database.all(`SELECT * FROM json`,[], function(err, rows) {
|
124
|
+
Data = rows;
|
125
|
+
done = true;
|
126
|
+
});
|
127
|
+
deasync.loopWhile(function(){
|
128
|
+
return !done;
|
129
|
+
});
|
130
|
+
return Data;
|
131
|
+
}
|
132
|
+
|
133
|
+
function Replit_Set(key, value) {
|
134
|
+
try {
|
135
|
+
var done = false;
|
136
|
+
|
137
|
+
request({
|
138
|
+
url: process.env.REPLIT_DB_URL,
|
139
|
+
method: "POST",
|
140
|
+
headers: {
|
141
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
142
|
+
},
|
143
|
+
body: `${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(value))}`
|
144
|
+
|
145
|
+
}, function (error, response, body) {
|
146
|
+
done = true;
|
147
|
+
});
|
148
|
+
|
149
|
+
deasync.loopWhile(function(){
|
150
|
+
return !done;
|
151
|
+
});
|
152
|
+
|
153
|
+
return;
|
154
|
+
|
155
|
+
}
|
156
|
+
catch (e) {
|
157
|
+
console.log(e);
|
158
|
+
return false;
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
function Replit_Get(key) {
|
163
|
+
try {
|
164
|
+
var done = false;
|
165
|
+
var response = null;
|
166
|
+
|
167
|
+
request(process.env.REPLIT_DB_URL + "/" + key, function (error, res, body) {
|
168
|
+
if (!error && res.statusCode == 200) {
|
169
|
+
response = body;
|
170
|
+
}
|
171
|
+
done = true;
|
172
|
+
});
|
173
|
+
|
174
|
+
deasync.loopWhile(function(){
|
175
|
+
return !done;
|
176
|
+
});
|
177
|
+
|
178
|
+
return JSON.parse(response);
|
179
|
+
}
|
180
|
+
catch (e) {
|
181
|
+
console.log(e);
|
182
|
+
return false;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
function Replit_Has(key) {
|
187
|
+
try {
|
188
|
+
var done = false;
|
189
|
+
var response = null;
|
190
|
+
|
191
|
+
request(process.env.REPLIT_DB_URL + "/" + key, function (error, res, body) {
|
192
|
+
if (!error && res.statusCode == 200) {
|
193
|
+
response = body;
|
194
|
+
}
|
195
|
+
done = true;
|
196
|
+
});
|
197
|
+
|
198
|
+
deasync.loopWhile(function(){
|
199
|
+
return !done;
|
200
|
+
});
|
201
|
+
|
202
|
+
return response != null;
|
203
|
+
}
|
204
|
+
catch (e) {
|
205
|
+
console.log(e);
|
206
|
+
return false;
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
function Replit_Remove(key) {
|
211
|
+
try {
|
212
|
+
var done = false;
|
213
|
+
request.delete(process.env.REPLIT_DB_URL + "/" + key , function (error, response, body) {
|
214
|
+
done = true;
|
215
|
+
});
|
216
|
+
|
217
|
+
deasync.loopWhile(function(){
|
218
|
+
return !done;
|
219
|
+
});
|
220
|
+
|
221
|
+
return;
|
222
|
+
}
|
223
|
+
catch (e) {
|
224
|
+
console.log(e);
|
225
|
+
return false;
|
226
|
+
}
|
227
|
+
}
|
228
|
+
function Replit_RemoveMultiple(keys) {
|
229
|
+
try {
|
230
|
+
for (const key of keys) {
|
231
|
+
request.delete(process.env.REPLIT_DB_URL + "/" + key , function (error, response, body) {});
|
232
|
+
}
|
233
|
+
return true;
|
234
|
+
}
|
235
|
+
catch (e) {
|
236
|
+
console.log(e);
|
237
|
+
return false;
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
function Replit_List() {
|
242
|
+
var done = false;
|
243
|
+
var response = null;
|
244
|
+
|
245
|
+
request(process.env.REPLIT_DB_URL + "?encode=true" + `&prefix=${encodeURIComponent("")}`, function (error, res, body) {
|
246
|
+
if (!error && res.statusCode == 200) {
|
247
|
+
response = body;
|
248
|
+
}
|
249
|
+
done = true;
|
250
|
+
|
251
|
+
});
|
252
|
+
|
253
|
+
deasync.loopWhile(function(){
|
254
|
+
return !done;
|
255
|
+
});
|
256
|
+
|
257
|
+
if (response.length === 0) {
|
258
|
+
return [];
|
259
|
+
}
|
260
|
+
return response.split("\n").map(decodeURIComponent);
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
var methods = {
|
265
|
+
fetch: function(db, params, options) {
|
266
|
+
let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
|
267
|
+
if (!fetched) return null;
|
268
|
+
try {
|
269
|
+
fetched = JSON.parse(fetched.json);
|
270
|
+
} catch (e) {
|
271
|
+
fetched = fetched.json;
|
272
|
+
}
|
273
|
+
if (params.ops.target) fetched = get(fetched, params.ops.target);
|
274
|
+
return fetched;
|
275
|
+
},
|
276
|
+
set: function(db, params, options) {
|
277
|
+
let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
|
278
|
+
if (!fetched) {
|
279
|
+
db.prepare(`INSERT INTO ${options.table} (ID,json) VALUES (?,?)`).run(params.id, '{}');
|
280
|
+
fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
|
281
|
+
}
|
282
|
+
try {
|
283
|
+
fetched = JSON.parse(fetched);
|
284
|
+
} catch (e) {
|
285
|
+
fetched = fetched;
|
286
|
+
}
|
287
|
+
if (typeof fetched === 'object' && params.ops.target) {
|
288
|
+
params.data = JSON.parse(params.data);
|
289
|
+
params.data = set(fetched, params.ops.target, params.data);
|
290
|
+
}
|
291
|
+
else if (params.ops.target) throw new TypeError('Cannot target a non-object.');
|
292
|
+
db.prepare(`UPDATE ${options.table} SET json = (?) WHERE ID = (?)`).run(JSON.stringify(params.data), params.id);
|
293
|
+
let newData = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id).json;
|
294
|
+
if (newData === '{}') return null;
|
295
|
+
else {
|
296
|
+
try { newData = JSON.parse(newData);
|
297
|
+
}
|
298
|
+
catch (e) {
|
299
|
+
newData = newData;
|
300
|
+
}
|
301
|
+
return newData;
|
302
|
+
}
|
303
|
+
},
|
304
|
+
add: function addDB(db, params, options) {
|
305
|
+
let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
|
306
|
+
if (!fetched) {
|
307
|
+
db.prepare(`INSERT INTO ${options.table} (ID,json) VALUES (?,?)`).run(params.id, '{}');
|
308
|
+
fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
|
309
|
+
}
|
310
|
+
if (params.ops.target) {
|
311
|
+
try {
|
312
|
+
fetched = JSON.parse(fetched);
|
313
|
+
}
|
314
|
+
catch (e) {
|
315
|
+
fetched = fetched;
|
316
|
+
}
|
317
|
+
let oldValue = get(fetched, params.ops.target);
|
318
|
+
if (oldValue === undefined) oldValue = 0;
|
319
|
+
else if (isNaN(oldValue)) throw new Error(`Data @ ID: "${params.id}" IS NOT A number.\nFOUND: ${fetched}\nEXPECTED: number`);
|
320
|
+
params.data = set(fetched, params.ops.target, oldValue + JSON.parse(params.data));
|
321
|
+
}
|
322
|
+
else {
|
323
|
+
if (fetched.json === '{}') fetched.json = 0;
|
324
|
+
try {
|
325
|
+
fetched.json = JSON.parse(fetched);
|
326
|
+
} catch (e) {
|
327
|
+
fetched.json = fetched.json;
|
328
|
+
}
|
329
|
+
if (isNaN(fetched.json)) throw new Error(`Data @ ID: "${params.id}" IS NOT A number.\nFOUND: ${fetched.json}\nEXPECTED: number`);
|
330
|
+
params.data = parseInt(fetched.json, 10) + parseInt(params.data, 10);
|
331
|
+
}
|
332
|
+
db.prepare(`UPDATE ${options.table} SET json = (?) WHERE ID = (?)`).run(JSON.stringify(params.data), params.id);
|
333
|
+
let newData = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id).json;
|
334
|
+
if (newData === '{}') return null;
|
335
|
+
else {
|
336
|
+
try {
|
337
|
+
newData = JSON.parse(newData);
|
338
|
+
}
|
339
|
+
catch (e) {
|
340
|
+
newData = newData;
|
341
|
+
}
|
342
|
+
return newData;
|
343
|
+
}
|
344
|
+
},
|
345
|
+
subtract: function subtractDB(db, params, options) {
|
346
|
+
let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
|
347
|
+
if (!fetched) {
|
348
|
+
db.prepare(`INSERT INTO ${options.table} (ID,json) VALUES (?,?)`).run(params.id, '{}');
|
349
|
+
fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
|
350
|
+
}
|
351
|
+
if (params.ops.target) {
|
352
|
+
try { fetched = JSON.parse(fetched); } catch (e) {}
|
353
|
+
params.data = JSON.parse(params.data);
|
354
|
+
let oldValue = get(fetched, params.ops.target);
|
355
|
+
if (oldValue === undefined) oldValue = 0;
|
356
|
+
else if (isNaN(oldValue)) throw new Error('Target is not a number.');
|
357
|
+
params.data = set(fetched, params.ops.target, oldValue - params.data);
|
358
|
+
} else {
|
359
|
+
if (fetched.json === '{}') fetched.json = 0;
|
360
|
+
else fetched.json = JSON.parse(fetched.json);
|
361
|
+
try { fetched.json = JSON.parse(fetched); } catch (e) {}
|
362
|
+
if (isNaN(fetched.json)) throw new Error('Target is not a number.');
|
363
|
+
params.data = parseInt(fetched.json, 10) - parseInt(params.data, 10);
|
364
|
+
}
|
365
|
+
params.data = JSON.stringify(params.data);
|
366
|
+
db.prepare(`UPDATE ${options.table} SET json = (?) WHERE ID = (?)`).run(params.data, params.id);
|
367
|
+
let newData = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id).json;
|
368
|
+
if (newData === '{}') return null;
|
369
|
+
else {
|
370
|
+
try { newData = JSON.parse(newData); } catch (e) {}
|
371
|
+
return newData;
|
372
|
+
}
|
373
|
+
},
|
374
|
+
push: function pushDB(db, params, options) {
|
375
|
+
let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
|
376
|
+
if (!fetched) {
|
377
|
+
db.prepare(`INSERT INTO ${options.table} (ID,json) VALUES (?,?)`).run(params.id, '{}');
|
378
|
+
fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
|
379
|
+
}
|
380
|
+
if (params.ops.target) {
|
381
|
+
fetched = JSON.parse(fetched.json);
|
382
|
+
try { fetched = JSON.parse(fetched); } catch (e) {}
|
383
|
+
params.data = JSON.parse(params.data);
|
384
|
+
if (typeof fetched !== 'object') throw new TypeError('Cannot push into a non-object.');
|
385
|
+
let oldArray = get(fetched, params.ops.target);
|
386
|
+
if (oldArray === undefined) oldArray = [];
|
387
|
+
else if (!Array.isArray(oldArray)) throw new TypeError('Target is not an array.');
|
388
|
+
oldArray.push(params.data);
|
389
|
+
params.data = set(fetched, params.ops.target, oldArray);
|
390
|
+
} else {
|
391
|
+
if (fetched.json === '{}') fetched.json = [];
|
392
|
+
else fetched.json = JSON.parse(fetched.json);
|
393
|
+
try { fetched.json = JSON.parse(fetched.json); } catch (e) {}
|
394
|
+
params.data = JSON.parse(params.data);
|
395
|
+
if (!Array.isArray(fetched.json)) throw new TypeError('Target is not an array.');
|
396
|
+
fetched.json.push(params.data);
|
397
|
+
params.data = fetched.json;
|
398
|
+
}
|
399
|
+
params.data = JSON.stringify(params.data);
|
400
|
+
db.prepare(`UPDATE ${options.table} SET json = (?) WHERE ID = (?)`).run(params.data, params.id);
|
401
|
+
let newData = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id).json;
|
402
|
+
if (newData === '{}') return null;
|
403
|
+
else {
|
404
|
+
newData = JSON.parse(newData);
|
405
|
+
try { newData = JSON.parse(newData); } catch (e) {}
|
406
|
+
return newData;
|
407
|
+
}
|
408
|
+
},
|
409
|
+
delete: function deleteDB(db, params, options) {
|
410
|
+
const unset = require('lodash/unset');
|
411
|
+
let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
|
412
|
+
if (!fetched) return false;
|
413
|
+
else fetched = JSON.parse(fetched.json);
|
414
|
+
try { fetched = JSON.parse(fetched); } catch (e) {}
|
415
|
+
if (typeof fetched === 'object' && params.ops.target) {
|
416
|
+
unset(fetched, params.ops.target);
|
417
|
+
fetched = JSON.stringify(fetched);
|
418
|
+
db.prepare(`UPDATE ${options.table} SET json = (?) WHERE ID = (?)`).run(fetched, params.id);
|
419
|
+
return true;
|
420
|
+
}
|
421
|
+
else if (params.ops.target) throw new TypeError('Target is not an object.');
|
422
|
+
else db.prepare(`DELETE FROM ${options.table} WHERE ID = (?)`).run(params.id);
|
423
|
+
return true;
|
424
|
+
},
|
425
|
+
has: function hasDB(db, params, options) {
|
426
|
+
let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
|
427
|
+
if (!fetched) return false;
|
428
|
+
else fetched = JSON.parse(fetched.json);
|
429
|
+
try { fetched = JSON.parse(fetched); } catch (e) {}
|
430
|
+
if (params.ops.target) fetched = get(fetched, params.ops.target);
|
431
|
+
return (typeof fetched != 'undefined');
|
432
|
+
},
|
433
|
+
all: function allDB(db, params, options) {
|
434
|
+
var stmt = db.prepare(`SELECT * FROM ${options.table} WHERE ID IS NOT NULL`);
|
435
|
+
let resp = [];
|
436
|
+
for (var row of stmt.iterate()) {
|
437
|
+
try {
|
438
|
+
resp.push({
|
439
|
+
ID: row.ID,
|
440
|
+
data: JSON.parse(row.json)
|
441
|
+
});
|
442
|
+
}
|
443
|
+
catch (e) {
|
444
|
+
return [];
|
445
|
+
}
|
446
|
+
}
|
447
|
+
return resp;
|
448
|
+
},
|
449
|
+
type: function typeDB(db, params, options) {
|
450
|
+
let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
|
451
|
+
if (!fetched) return null; // If empty, return null
|
452
|
+
fetched = JSON.parse(fetched.json);
|
453
|
+
try { fetched = JSON.parse(fetched); } catch (e) {}
|
454
|
+
if (params.ops.target) fetched = get(fetched, params.ops.target); // Get prop using dot notation
|
455
|
+
return typeof fetched;
|
456
|
+
},
|
457
|
+
clear: function clearDB(db, params, options) {
|
458
|
+
let fetched = db.prepare(`DELETE FROM ${options.table}`).run();
|
459
|
+
if(!fetched) return null;
|
460
|
+
return fetched.changes;
|
461
|
+
|
462
|
+
}
|
463
|
+
};
|
464
|
+
|
465
|
+
|
466
|
+
function arbitrate(method, params) {
|
467
|
+
let options = {table: "json"};
|
468
|
+
db.prepare(`CREATE TABLE IF NOT EXISTS ${options.table} (ID TEXT, json TEXT)`).run();
|
469
|
+
if (params.ops.target && params.ops.target[0] === ".") params.ops.target = params.ops.target.slice(1); // Remove prefix if necessary
|
470
|
+
if (params.data && params.data === Infinity) throw new TypeError(`You cannot set Infinity into the database @ ID: ${params.id}`);
|
471
|
+
if (params.id && typeof params.id == "string" && params.id.includes(".")) {
|
472
|
+
let unparsed = params.id.split(".");
|
473
|
+
params.id = unparsed.shift();
|
474
|
+
params.ops.target = unparsed.join(".");
|
475
|
+
}
|
476
|
+
return methods[method](db, params, options);
|
477
|
+
}
|
478
|
+
|
479
|
+
|
480
|
+
module.exports = function ChernobyL(Local) {
|
481
|
+
if (Local && process.env["REPL_ID"]) {
|
482
|
+
return {
|
483
|
+
set: Lset,
|
484
|
+
get: Lget,
|
485
|
+
has: Lhas,
|
486
|
+
delete: Lremove,
|
487
|
+
deleteMultiple: LremoveMultiple,
|
488
|
+
list: Llist
|
489
|
+
};
|
490
|
+
} else if (!Local && process.env["REPL_ID"]) {
|
491
|
+
return {
|
492
|
+
set: Replit_Set,
|
493
|
+
get: Replit_Get,
|
494
|
+
has: Replit_Has,
|
495
|
+
delete: Replit_Remove,
|
496
|
+
deleteMultiple: Replit_RemoveMultiple,
|
497
|
+
list: Replit_List
|
498
|
+
};
|
499
|
+
}
|
500
|
+
else if (Local && !process.env["REPL_ID"]) {
|
501
|
+
return {
|
502
|
+
set: Lset,
|
503
|
+
get: Lget,
|
504
|
+
has: Lhas,
|
505
|
+
delete: Lremove,
|
506
|
+
deleteMultiple: LremoveMultiple,
|
507
|
+
list: Llist
|
508
|
+
};
|
509
|
+
}
|
510
|
+
else if (!Local && !process.env["REPL_ID"]) {
|
511
|
+
return {
|
512
|
+
set: Lset,
|
513
|
+
get: Lget,
|
514
|
+
has: Lhas,
|
515
|
+
delete: Lremove,
|
516
|
+
deleteMultiple: LremoveMultiple,
|
517
|
+
list: Llist
|
518
|
+
};
|
519
|
+
}
|
520
|
+
else {
|
521
|
+
return {
|
522
|
+
set: Lset,
|
523
|
+
get: Lget,
|
524
|
+
has: Lhas,
|
525
|
+
delete: Lremove,
|
526
|
+
deleteMultiple: LremoveMultiple,
|
527
|
+
list: Llist
|
528
|
+
};
|
529
|
+
}
|
530
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
This folder is used by ChernobyL(NANI =)) ) to store data. Do not delete this folder or any of the files in it.
|
Binary file
|