fca-smart-shankar 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. package/.cache/replit/env/latest +55 -0
  2. package/.cache/replit/env/latest.json +1 -0
  3. package/.cache/replit/modules/nodejs-14.res +1 -0
  4. package/.cache/replit/modules/replit.res +1 -0
  5. package/.cache/replit/modules/web.res +1 -0
  6. package/.cache/replit/modules.stamp +0 -0
  7. package/.cache/typescript/5.5/package.json +1 -0
  8. package/.config/configstore/update-notifier-npm.json +4 -0
  9. package/.gitattributes +2 -0
  10. package/.replit +8 -0
  11. package/.upm/store.json +1 -0
  12. package/Extra/Bypass/956/index.js +234 -0
  13. package/Extra/Bypass/test/aaaa.json +170 -0
  14. package/Extra/Bypass/test/index.js +188 -0
  15. package/Extra/Database/index.js +469 -0
  16. package/Extra/ExtraAddons.js +82 -0
  17. package/Extra/ExtraFindUID.js +62 -0
  18. package/Extra/ExtraGetThread.js +365 -0
  19. package/Extra/ExtraScreenShot.js +430 -0
  20. package/Extra/ExtraUptimeRobot.js +38 -0
  21. package/Extra/Html/Classic/script.js +119 -0
  22. package/Extra/Html/Classic/style.css +8 -0
  23. package/Extra/Security/AES_256_GCM/index.js +0 -0
  24. package/Extra/Security/Base/Step_1.js +6 -0
  25. package/Extra/Security/Base/Step_2.js +22 -0
  26. package/Extra/Security/Base/Step_3.js +22 -0
  27. package/Extra/Security/Base/index.js +191 -0
  28. package/Extra/Security/Index.js +5 -0
  29. package/Extra/Security/Step_1.js +6 -0
  30. package/Extra/Security/Step_2.js +22 -0
  31. package/Extra/Security/Step_3.js +22 -0
  32. package/Extra/Src/Change_Environment.js +24 -0
  33. package/Extra/Src/Check_Update.js +67 -0
  34. package/Extra/Src/History.js +115 -0
  35. package/Extra/Src/Instant_Update.js +65 -0
  36. package/Extra/Src/Last-Run.js +65 -0
  37. package/Extra/Src/Premium.js +81 -0
  38. package/Extra/Src/Release_Memory.js +160 -0
  39. package/Extra/Src/Websocket.js +213 -0
  40. package/Extra/Src/image/checkmate.jpg +0 -0
  41. package/Extra/Src/test.js +28 -0
  42. package/Extra/Src/uuid.js +137 -0
  43. package/Func/AcceptAgreement.js +31 -0
  44. package/Func/ClearCache.js +64 -0
  45. package/Func/ReportV1.js +54 -0
  46. package/LICENSE +21 -0
  47. package/Language/index.json +222 -0
  48. package/Main.js +1266 -0
  49. package/README.md +1 -0
  50. package/SECURITY.md +18 -0
  51. package/broadcast.js +44 -0
  52. package/index.js +448 -0
  53. package/logger.js +66 -0
  54. package/package.json +91 -0
  55. package/src/Dev_Horizon_Data.js +125 -0
  56. package/src/Dev_getThreadInfoOLD.js +422 -0
  57. package/src/Dev_shareTest2.js +68 -0
  58. package/src/Dev_shareTest3.js +71 -0
  59. package/src/Premium.js +25 -0
  60. package/src/Screenshot.js +83 -0
  61. package/src/addExternalModule.js +16 -0
  62. package/src/addUserToGroup.js +79 -0
  63. package/src/changeAdminStatus.js +79 -0
  64. package/src/changeArchivedStatus.js +41 -0
  65. package/src/changeAvt.js +85 -0
  66. package/src/changeBio.js +65 -0
  67. package/src/changeBlockedStatus.js +36 -0
  68. package/src/changeGroupImage.js +106 -0
  69. package/src/changeNickname.js +45 -0
  70. package/src/changeThreadColor.js +62 -0
  71. package/src/changeThreadEmoji.js +42 -0
  72. package/src/createNewGroup.js +70 -0
  73. package/src/createPoll.js +60 -0
  74. package/src/deleteMessage.js +45 -0
  75. package/src/deleteThread.js +43 -0
  76. package/src/editMessage.js +53 -0
  77. package/src/forwardAttachment.js +48 -0
  78. package/src/getAccessToken.js +28 -0
  79. package/src/getCurrentUserID.js +7 -0
  80. package/src/getEmojiUrl.js +27 -0
  81. package/src/getFriendsList.js +73 -0
  82. package/src/getMessage.js +103 -0
  83. package/src/getThreadHistory.js +537 -0
  84. package/src/getThreadInfo.js +424 -0
  85. package/src/getThreadInfoOLD.js +422 -0
  86. package/src/getThreadList.js +213 -0
  87. package/src/getThreadMain.js +220 -0
  88. package/src/getThreadPictures.js +59 -0
  89. package/src/getUID.js +59 -0
  90. package/src/getUserID.js +62 -0
  91. package/src/getUserInfo.js +112 -0
  92. package/src/getUserInfoMain.js +65 -0
  93. package/src/getUserInfoV2.js +32 -0
  94. package/src/getUserInfoV3.js +63 -0
  95. package/src/getUserInfoV4.js +55 -0
  96. package/src/getUserInfoV5.js +61 -0
  97. package/src/handleFriendRequest.js +46 -0
  98. package/src/handleMessageRequest.js +49 -0
  99. package/src/httpGet.js +49 -0
  100. package/src/httpPost.js +48 -0
  101. package/src/httpPostFormData.js +41 -0
  102. package/src/listenMqtt.js +936 -0
  103. package/src/listenMqttV1.js +846 -0
  104. package/src/logout.js +68 -0
  105. package/src/markAsDelivered.js +48 -0
  106. package/src/markAsRead.js +70 -0
  107. package/src/markAsReadAll.js +43 -0
  108. package/src/markAsSeen.js +51 -0
  109. package/src/muteThread.js +47 -0
  110. package/src/removeUserFromGroup.js +49 -0
  111. package/src/resolvePhotoUrl.js +37 -0
  112. package/src/searchForThread.js +43 -0
  113. package/src/sendMessage.js +386 -0
  114. package/src/sendMqttMessage.js +71 -0
  115. package/src/sendTypingIndicator.js +80 -0
  116. package/src/setMessageReaction.js +109 -0
  117. package/src/setPostReaction.js +102 -0
  118. package/src/setTitle.js +74 -0
  119. package/src/shareContact.js +55 -0
  120. package/src/shareLink.js +58 -0
  121. package/src/threadColors.js +39 -0
  122. package/src/unfriend.js +43 -0
  123. package/src/unsendMessage.js +40 -0
  124. package/test/Database_Test.js +4 -0
  125. package/test/Db2.js +530 -0
  126. package/test/Horizon_Database/A_README.md +1 -0
  127. package/test/Horizon_Database/Database.db +0 -0
  128. package/test/data/shareAttach.js +146 -0
  129. package/test/data/something.mov +0 -0
  130. package/test/data/test.png +0 -0
  131. package/test/data/test.txt +7 -0
  132. package/test/env/.env +0 -0
  133. package/test/example-config.json +18 -0
  134. package/test/example-db.db +0 -0
  135. package/test/memoryleak.js +18 -0
  136. package/test/test-page.js +140 -0
  137. package/test/test.js +385 -0
  138. package/test/testname.js +1342 -0
  139. package/test/testv2.js +3 -0
  140. package/utils.js +3038 -0
@@ -0,0 +1,188 @@
1
+ /** By @KanzuWakazaki 03/05/2024 - DD/MM/YYYY */
2
+ var Form_P1;
3
+ var CanResolve_P1;
4
+ var NextToken_P1;
5
+ var lsd;
6
+ utils.get('https://www.facebook.com/checkpoint/828281030927956/?next=https%3A%2F%2Faccountscenter.facebook.com%2Fpassword_and_security', ctx.jar, null, ctx.globalOptions)
7
+ .then(function(data) {
8
+ lsd = utils.getFrom(data.body, "[\"LSD\",[],{\"token\":\"", "\"}")
9
+ Form_P1 = {
10
+ lsd: lsd,
11
+ fb_api_caller_class: 'RelayModern',
12
+ fb_api_req_friendly_name: 'useEpsilonNavigateMutation',
13
+ variables: JSON.stringify({
14
+ input:{
15
+ client_mutation_id:"1",
16
+ actor_id: ctx.userId,
17
+ step:"STEPPER_CONFIRMATION",
18
+ token : JSON.stringify({
19
+ sensitive_string_value: Find_And_Parse(data.body)
20
+ })
21
+ },
22
+ scale:1
23
+ }),
24
+ server_timestamps: true,
25
+ doc_id: 7414856831926043
26
+ };
27
+ })
28
+ .then(function() {
29
+ defaultFuncs.postFormData('https://www.facebook.com/api/graphql/', ctx.jar, Form_P1, {})
30
+ .then(function(resp) {
31
+ let checkpoint = resp.data.epsilon_navigate.epsilon_checkpoint;
32
+ if (checkpoint.id == '__EPSILON_CLIENT__' && checkpoint.__typename == "EpsilonStepperScreen" && checkpoint.screen.next_screen == 'CONTACT_POINT_REVIEW' && checkpoint.screen.steps.length === 3 && checkpoint.screen.steps[1].active == true) {
33
+ NextToken_P1 = checkpoint.screen.token;
34
+ return CanResolve_P1 = true;
35
+ }
36
+ else return CanResolve_P1 = false;
37
+ });
38
+ })
39
+
40
+ var CanResolve_P2;
41
+ var NextToken_P2;
42
+
43
+ let Form_P2 = {
44
+ doc_id: 7414856831926043,
45
+ lsd: lsd,
46
+ fb_api_caller_class: "RelayModern",
47
+ fb_api_req_friendly_name: "useEpsilonNavigateMutation",
48
+ server_timestamps: true,
49
+ variables: JSON.stringify({
50
+ input: {
51
+ client_mutation_id: 2,
52
+ actor_id: ctx.userId,
53
+ step:"CONTACT_POINT_REVIEW",
54
+ token: JSON.stringify({
55
+ sensitive_string_value: NextToken_P1
56
+ })
57
+ },
58
+ scale: 1
59
+ })
60
+ }
61
+
62
+ defaultFuncs.postFormData('https://www.facebook.com/api/graphql/', ctx.jar, Form_P2, {}).then(function(resp) {
63
+ let checkpoint = resp.data.epsilon_navigate.epsilon_checkpoint;
64
+ if (checkpoint.id == '__EPSILON_CLIENT__' && checkpoint.__typename == "EpsilonContactPointReview" && checkpoint.screen.contact_points.length >= 1 && checkpoint.screen.contact_points[0].suspicious == "UNSUSPICIOUS") {
65
+ NextToken_P2 = checkpoint.screen.token;
66
+ return CanResolve_P2 = true;
67
+ }
68
+ else return CanResolve_P2 = false;
69
+ });
70
+
71
+
72
+ var CanResolve_P3;
73
+ var NextToken_P3;
74
+ let Form_P3 ={
75
+ doc_id: 7414856831926043,
76
+ lsd: lsd,
77
+ fb_api_caller_class: "RelayModern",
78
+ fb_api_req_friendly_name: "useEpsilonNavigateMutation",
79
+ server_timestamps: true,
80
+ variables: JSON.stringify({
81
+ input: {
82
+ client_mutation_id: 3,
83
+ actor_id: ctx.userId,
84
+ step: "CHANGE_PASSWORD",
85
+ token: JSON.stringify({
86
+ sensitive_string_value: NextToken_P2
87
+ })
88
+ },
89
+ scale:1
90
+ })
91
+ }
92
+
93
+ defaultFuncs.postFormData('https://www.facebook.com/api/graphql/', ctx.jar, Form_P3, {}).then(function(resp) {
94
+ let checkpoint = resp.data.epsilon_navigate.epsilon_checkpoint;
95
+ if (checkpoint.id == '__EPSILON_CLIENT__' && checkpoint.__typename == "EpsilonLoginDetailsConfirmationScreen" && checkpoint.screen.contact_points.length >= 1) {
96
+ NextToken_P3 = checkpoint.screen.token;
97
+ return CanResolve_P3 = true;
98
+ }
99
+ else return CanResolve_P3 = false;
100
+ });
101
+
102
+ var CanResolve_P4;
103
+ var NextToken_P4;
104
+ let Form_P4 ={
105
+ doc_id: 7414856831926043,
106
+ lsd: lsd,
107
+ fb_api_caller_class: "RelayModern",
108
+ fb_api_req_friendly_name: "useEpsilonNavigateMutation",
109
+ server_timestamps: true,
110
+ variables: JSON.stringify({
111
+ input: {
112
+ client_mutation_id: 4,
113
+ actor_id: ctx.userId,
114
+ step: "OUTRO",
115
+ token: JSON.stringify({
116
+ sensitive_string_value: NextToken_P3
117
+ })
118
+ },
119
+ scale:1
120
+ })
121
+ }
122
+
123
+ defaultFuncs.postFormData('https://www.facebook.com/api/graphql/', ctx.jar, Form_P4, {}).then(function(resp) {
124
+ let checkpoint = resp.data.epsilon_navigate.epsilon_checkpoint;
125
+ if (checkpoint.id == '__EPSILON_CLIENT__' && checkpoint.__typename == "EpsilonOutroScreen" && checkpoint.screen.fallback.uri == 'https://www.facebook.com/') {
126
+ NextToken_P4 = checkpoint.screen.token;
127
+ return CanResolve_P4 = true;
128
+ }
129
+ else return CanResolve_P4 = false;
130
+ });
131
+
132
+
133
+ function Find_And_Parse(Data) {
134
+ const regex = /<script\s+type="application\/json"\s+data-content-len="([0-9]+)"\s+data-sjs\s*(.*?)\s*<\/script>/gs;
135
+ const matches = Data.matchAll(regex);
136
+ let Data_resp;
137
+ for (const match of matches) {
138
+ if (JSON.parse(JSON.stringify((match[2]))).includes('any_eligible_challenges')) {
139
+ const Data_ = JSON.parse(match[2].replace('>', ''))
140
+ Data_resp = findAnyEligibleChallengesAndSiblings(Data_)
141
+ }
142
+
143
+ }
144
+
145
+
146
+ function findAnyEligibleChallengesAndSiblings(data) {
147
+ const screenData = findScreenData(data);
148
+ if (!screenData) {
149
+ return null;
150
+ }
151
+
152
+ const siblings = {};
153
+ for (const [key, value] of Object.entries(screenData)) {
154
+ if (key === 'any_eligible_challenges') {
155
+ siblings[key] = value;
156
+ }
157
+ else {
158
+ siblings[key] = value;
159
+ }
160
+ }
161
+
162
+ return siblings;
163
+ }
164
+
165
+ function findScreenData(data) {
166
+ if (Array.isArray(data)) {
167
+ for (const item of data) {
168
+ const result = findScreenData(item);
169
+ if (result) {
170
+ return result;
171
+ }
172
+ }
173
+ }
174
+ else if (typeof data === 'object' && data !== null) {
175
+ if (data.screen) {
176
+ return data.screen;
177
+ }
178
+ for (const value of Object.values(data)) {
179
+ const result = findScreenData(value);
180
+ if (result) {
181
+ return result;
182
+ }
183
+ }
184
+ }
185
+ return null;
186
+ }
187
+ return Data_resp.token || null
188
+ }
@@ -0,0 +1,469 @@
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 BetterDB = require("better-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 db = new BetterDB(process.cwd() + "/Horizon_Database/SyntheticDatabase.sqlite");
15
+
16
+ function Lset(key, value) {
17
+ if (!key)
18
+ throw new TypeError(
19
+ "No key specified."
20
+ );
21
+ return arbitrate("set",{
22
+ stringify: false,
23
+ id: key,
24
+ data: value,
25
+ ops: {},
26
+ });
27
+ }
28
+
29
+ function Lget(key) {
30
+ if (!key)
31
+ throw new TypeError(
32
+ "No key specified."
33
+ );
34
+ return arbitrate("fetch", { id: key, ops: {} || {} });
35
+ }
36
+
37
+ function Lhas(key) {
38
+ if (!key)
39
+ throw new TypeError(
40
+ "No key specified."
41
+ );
42
+ return arbitrate("has", { id: key, ops: {} });
43
+ }
44
+
45
+ function Lremove(key) {
46
+ if (!key)
47
+ throw new TypeError(
48
+ "No key specified."
49
+ );
50
+ return arbitrate("delete", { id: key, ops: {} });
51
+ }
52
+
53
+ function LremoveMultiple(key) {
54
+ if (!key)
55
+ throw new TypeError(
56
+ "No key specified."
57
+ );
58
+ try {
59
+ for (let i of key) {
60
+ arbitrate("delete", { id: i, ops: {} });
61
+ }
62
+ return true;
63
+ }
64
+ catch (err) {
65
+ return false;
66
+ }
67
+ }
68
+
69
+ function Llist() {
70
+ return arbitrate("all",{ ops: {} });
71
+ }
72
+
73
+ function Replit_Set(key, value) {
74
+ try {
75
+ var done = false;
76
+
77
+ request({
78
+ url: process.env.REPLIT_DB_URL,
79
+ method: "POST",
80
+ headers: {
81
+ 'Content-Type': 'application/x-www-form-urlencoded',
82
+ },
83
+ body: `${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(value))}`
84
+
85
+ }, function (error, response, body) {
86
+ done = true;
87
+ });
88
+
89
+ deasync.loopWhile(function(){
90
+ return !done;
91
+ });
92
+
93
+ return;
94
+
95
+ }
96
+ catch (e) {
97
+ console.log(e);
98
+ return false;
99
+ }
100
+ }
101
+
102
+ function Replit_Get(key) {
103
+ try {
104
+ var done = false;
105
+ var response = null;
106
+
107
+ request(process.env.REPLIT_DB_URL + "/" + key, function (error, res, body) {
108
+ if (!error && res.statusCode == 200) {
109
+ response = body;
110
+ }
111
+ done = true;
112
+ });
113
+
114
+ deasync.loopWhile(function(){
115
+ return !done;
116
+ });
117
+
118
+ return JSON.parse(response);
119
+ }
120
+ catch (e) {
121
+ console.log(e);
122
+ return false;
123
+ }
124
+ }
125
+
126
+ function Replit_Has(key) {
127
+ try {
128
+ var done = false;
129
+ var response = null;
130
+
131
+ request(process.env.REPLIT_DB_URL + "/" + key, function (error, res, body) {
132
+ if (!error && res.statusCode == 200) {
133
+ response = body;
134
+ }
135
+ done = true;
136
+ });
137
+
138
+ deasync.loopWhile(function(){
139
+ return !done;
140
+ });
141
+
142
+ return response != null;
143
+ }
144
+ catch (e) {
145
+ console.log(e);
146
+ return false;
147
+ }
148
+ }
149
+
150
+ function Replit_Remove(key) {
151
+ try {
152
+ var done = false;
153
+ request.delete(process.env.REPLIT_DB_URL + "/" + key , function (error, response, body) {
154
+ done = true;
155
+ });
156
+
157
+ deasync.loopWhile(function(){
158
+ return !done;
159
+ });
160
+
161
+ return;
162
+ }
163
+ catch (e) {
164
+ console.log(e);
165
+ return false;
166
+ }
167
+ }
168
+ function Replit_RemoveMultiple(keys) {
169
+ try {
170
+ for (const key of keys) {
171
+ request.delete(process.env.REPLIT_DB_URL + "/" + key , function (error, response, body) {});
172
+ }
173
+ return true;
174
+ }
175
+ catch (e) {
176
+ console.log(e);
177
+ return false;
178
+ }
179
+ }
180
+
181
+ function Replit_List() {
182
+ var done = false;
183
+ var response = null;
184
+
185
+ request(process.env.REPLIT_DB_URL + "?encode=true" + `&prefix=${encodeURIComponent("")}`, function (error, res, body) {
186
+ if (!error && res.statusCode == 200) {
187
+ response = body;
188
+ }
189
+ done = true;
190
+
191
+ });
192
+
193
+ deasync.loopWhile(function(){
194
+ return !done;
195
+ });
196
+
197
+ if (response.length === 0) {
198
+ return [];
199
+ }
200
+ return response.split("\n").map(decodeURIComponent);
201
+ }
202
+
203
+
204
+ var methods = {
205
+ fetch: function(db, params, options) {
206
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
207
+ if (!fetched) return null;
208
+ try {
209
+ fetched = JSON.parse(fetched.json);
210
+ } catch (e) {
211
+ fetched = fetched.json;
212
+ }
213
+ return fetched;
214
+ },
215
+ set: function(db, params, options) {
216
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
217
+ if (!fetched) {
218
+ db.prepare(`INSERT INTO ${options.table} (ID,json) VALUES (?,?)`).run(params.id, '{}');
219
+ fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
220
+ }
221
+ try {
222
+ fetched = JSON.parse(fetched);
223
+ } catch (e) {
224
+ fetched = fetched;
225
+ }
226
+ if (typeof fetched === 'object' && params.ops.target) {
227
+ params.data = JSON.parse(params.data);
228
+ params.data = set(fetched, params.ops.target, params.data);
229
+ }
230
+ else if (params.ops.target) throw new TypeError('Cannot target a non-object.');
231
+ db.prepare(`UPDATE ${options.table} SET json = (?) WHERE ID = (?)`).run(JSON.stringify(params.data), params.id);
232
+ let newData = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id).json;
233
+ if (newData === '{}') return null;
234
+ else {
235
+ try { newData = JSON.parse(newData);
236
+ }
237
+ catch (e) {
238
+ newData = newData;
239
+ }
240
+ return newData;
241
+ }
242
+ },
243
+ add: function addDB(db, params, options) {
244
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
245
+ if (!fetched) {
246
+ db.prepare(`INSERT INTO ${options.table} (ID,json) VALUES (?,?)`).run(params.id, '{}');
247
+ fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
248
+ }
249
+ if (params.ops.target) {
250
+ try {
251
+ fetched = JSON.parse(fetched);
252
+ }
253
+ catch (e) {
254
+ fetched = fetched;
255
+ }
256
+ let oldValue = get(fetched, params.ops.target);
257
+ if (oldValue === undefined) oldValue = 0;
258
+ else if (isNaN(oldValue)) throw new Error(`Data @ ID: "${params.id}" IS NOT A number.\nFOUND: ${fetched}\nEXPECTED: number`);
259
+ params.data = set(fetched, params.ops.target, oldValue + JSON.parse(params.data));
260
+ }
261
+ else {
262
+ if (fetched.json === '{}') fetched.json = 0;
263
+ try {
264
+ fetched.json = JSON.parse(fetched);
265
+ } catch (e) {
266
+ fetched.json = fetched.json;
267
+ }
268
+ if (isNaN(fetched.json)) throw new Error(`Data @ ID: "${params.id}" IS NOT A number.\nFOUND: ${fetched.json}\nEXPECTED: number`);
269
+ params.data = parseInt(fetched.json, 10) + parseInt(params.data, 10);
270
+ }
271
+ db.prepare(`UPDATE ${options.table} SET json = (?) WHERE ID = (?)`).run(JSON.stringify(params.data), params.id);
272
+ let newData = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id).json;
273
+ if (newData === '{}') return null;
274
+ else {
275
+ try {
276
+ newData = JSON.parse(newData);
277
+ }
278
+ catch (e) {
279
+ newData = newData;
280
+ }
281
+ return newData;
282
+ }
283
+ },
284
+ subtract: function subtractDB(db, params, options) {
285
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
286
+ if (!fetched) {
287
+ db.prepare(`INSERT INTO ${options.table} (ID,json) VALUES (?,?)`).run(params.id, '{}');
288
+ fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
289
+ }
290
+ if (params.ops.target) {
291
+ try { fetched = JSON.parse(fetched); } catch (e) {}
292
+ params.data = JSON.parse(params.data);
293
+ let oldValue = get(fetched, params.ops.target);
294
+ if (oldValue === undefined) oldValue = 0;
295
+ else if (isNaN(oldValue)) throw new Error('Target is not a number.');
296
+ params.data = set(fetched, params.ops.target, oldValue - params.data);
297
+ } else {
298
+ if (fetched.json === '{}') fetched.json = 0;
299
+ else fetched.json = JSON.parse(fetched.json);
300
+ try { fetched.json = JSON.parse(fetched); } catch (e) {}
301
+ if (isNaN(fetched.json)) throw new Error('Target is not a number.');
302
+ params.data = parseInt(fetched.json, 10) - parseInt(params.data, 10);
303
+ }
304
+ params.data = JSON.stringify(params.data);
305
+ db.prepare(`UPDATE ${options.table} SET json = (?) WHERE ID = (?)`).run(params.data, params.id);
306
+ let newData = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id).json;
307
+ if (newData === '{}') return null;
308
+ else {
309
+ try { newData = JSON.parse(newData); } catch (e) {}
310
+ return newData;
311
+ }
312
+ },
313
+ push: function pushDB(db, params, options) {
314
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
315
+ if (!fetched) {
316
+ db.prepare(`INSERT INTO ${options.table} (ID,json) VALUES (?,?)`).run(params.id, '{}');
317
+ fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
318
+ }
319
+ if (params.ops.target) {
320
+ fetched = JSON.parse(fetched.json);
321
+ try { fetched = JSON.parse(fetched); } catch (e) {}
322
+ params.data = JSON.parse(params.data);
323
+ if (typeof fetched !== 'object') throw new TypeError('Cannot push into a non-object.');
324
+ let oldArray = get(fetched, params.ops.target);
325
+ if (oldArray === undefined) oldArray = [];
326
+ else if (!Array.isArray(oldArray)) throw new TypeError('Target is not an array.');
327
+ oldArray.push(params.data);
328
+ params.data = set(fetched, params.ops.target, oldArray);
329
+ } else {
330
+ if (fetched.json === '{}') fetched.json = [];
331
+ else fetched.json = JSON.parse(fetched.json);
332
+ try { fetched.json = JSON.parse(fetched.json); } catch (e) {}
333
+ params.data = JSON.parse(params.data);
334
+ if (!Array.isArray(fetched.json)) throw new TypeError('Target is not an array.');
335
+ fetched.json.push(params.data);
336
+ params.data = fetched.json;
337
+ }
338
+ params.data = JSON.stringify(params.data);
339
+ db.prepare(`UPDATE ${options.table} SET json = (?) WHERE ID = (?)`).run(params.data, params.id);
340
+ let newData = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id).json;
341
+ if (newData === '{}') return null;
342
+ else {
343
+ newData = JSON.parse(newData);
344
+ try { newData = JSON.parse(newData); } catch (e) {}
345
+ return newData;
346
+ }
347
+ },
348
+ delete: function deleteDB(db, params, options) {
349
+ const unset = require('lodash/unset');
350
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
351
+ if (!fetched) return false;
352
+ else fetched = JSON.parse(fetched.json);
353
+ try { fetched = JSON.parse(fetched); } catch (e) {}
354
+ if (typeof fetched === 'object' && params.ops.target) {
355
+ unset(fetched, params.ops.target);
356
+ fetched = JSON.stringify(fetched);
357
+ db.prepare(`UPDATE ${options.table} SET json = (?) WHERE ID = (?)`).run(fetched, params.id);
358
+ return true;
359
+ }
360
+ else if (params.ops.target) throw new TypeError('Target is not an object.');
361
+ else db.prepare(`DELETE FROM ${options.table} WHERE ID = (?)`).run(params.id);
362
+ return true;
363
+ },
364
+ has: function hasDB(db, params, options) {
365
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
366
+ if (!fetched) return false;
367
+ else fetched = JSON.parse(fetched.json);
368
+ try { fetched = JSON.parse(fetched); } catch (e) {}
369
+ if (params.ops.target) fetched = get(fetched, params.ops.target);
370
+ return (typeof fetched != 'undefined');
371
+ },
372
+ all: function allDB(db, params, options) {
373
+ var stmt = db.prepare(`SELECT * FROM ${options.table} WHERE ID IS NOT NULL`);
374
+ let resp = [];
375
+ for (var row of stmt.iterate()) {
376
+ try {
377
+ resp.push({
378
+ ID: row.ID,
379
+ data: JSON.parse(row.json)
380
+ });
381
+ }
382
+ catch (e) {
383
+ return [];
384
+ }
385
+ }
386
+ return resp;
387
+ },
388
+ type: function typeDB(db, params, options) {
389
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
390
+ if (!fetched) return null; // If empty, return null
391
+ fetched = JSON.parse(fetched.json);
392
+ try { fetched = JSON.parse(fetched); } catch (e) {}
393
+ if (params.ops.target) fetched = get(fetched, params.ops.target); // Get prop using dot notation
394
+ return typeof fetched;
395
+ },
396
+ clear: function clearDB(db, params, options) {
397
+ let fetched = db.prepare(`DELETE FROM ${options.table}`).run();
398
+ if(!fetched) return null;
399
+ return fetched.changes;
400
+
401
+ }
402
+ };
403
+
404
+
405
+ function arbitrate(method, params) {
406
+ let options = {table: "json"};
407
+ db.prepare(`CREATE TABLE IF NOT EXISTS ${options.table} (ID TEXT, json TEXT)`).run();
408
+ if (params.ops.target && params.ops.target[0] === ".") params.ops.target = params.ops.target.slice(1); // Remove prefix if necessary
409
+ if (params.data && params.data === Infinity) throw new TypeError(`You cannot set Infinity into the database @ ID: ${params.id}`);
410
+ if (params.id && typeof params.id == "string" && params.id.includes(".")) {
411
+ let unparsed = params.id.split(".");
412
+ params.id = unparsed.shift();
413
+ params.ops.target = unparsed.join(".");
414
+ }
415
+ return methods[method](db, params, options);
416
+ }
417
+
418
+
419
+ module.exports = function ChernobyL(Local) {
420
+ if (Local && process.env["REPL_ID"]) {
421
+ return {
422
+ set: Lset,
423
+ get: Lget,
424
+ has: Lhas,
425
+ delete: Lremove,
426
+ deleteMultiple: LremoveMultiple,
427
+ list: Llist
428
+ };
429
+ } else if (!Local && process.env["REPL_ID"]) {
430
+ return {
431
+ set: Replit_Set,
432
+ get: Replit_Get,
433
+ has: Replit_Has,
434
+ delete: Replit_Remove,
435
+ deleteMultiple: Replit_RemoveMultiple,
436
+ list: Replit_List
437
+ };
438
+ }
439
+ else if (Local && !process.env["REPL_ID"]) {
440
+ return {
441
+ set: Lset,
442
+ get: Lget,
443
+ has: Lhas,
444
+ delete: Lremove,
445
+ deleteMultiple: LremoveMultiple,
446
+ list: Llist
447
+ };
448
+ }
449
+ else if (!Local && !process.env["REPL_ID"]) {
450
+ return {
451
+ set: Lset,
452
+ get: Lget,
453
+ has: Lhas,
454
+ delete: Lremove,
455
+ deleteMultiple: LremoveMultiple,
456
+ list: Llist
457
+ };
458
+ }
459
+ else {
460
+ return {
461
+ set: Lset,
462
+ get: Lget,
463
+ has: Lhas,
464
+ delete: Lremove,
465
+ deleteMultiple: LremoveMultiple,
466
+ list: Llist
467
+ };
468
+ }
469
+ };