@dongdev/fca-unofficial 0.0.7 → 0.0.8

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.
package/README.md CHANGED
@@ -1,38 +1,74 @@
1
- This repo is a fork from main repo and will usually have new features bundled faster than main repo (and maybe bundle some bugs, too).
1
+ <div align="center">
2
2
 
3
- # Unofficial Facebook Chat API
4
- <img alt="version" src="https://img.shields.io/github/package-json/v/miraiPr0ject/fca-unofficial?label=github&style=flat-square">
3
+ ![20241210_183831](https://files.catbox.moe/4rl0za.webp)
5
4
 
6
- Facebook now has an official API for chat bots [here](https://developers.facebook.com/docs/messenger-platform).
5
+ <h2 align="center"><b>Unoffcial Facebook Chat API</b></h2><br>This package is created by <b>DongDev</b>
7
6
 
8
- This API is the only way to automate chat functionalities on a user account. We do this by emulating the browser. This means doing the exact same GET/POST requests and tricking Facebook into thinking we're accessing the website normally. Because we're doing it this way, this API won't work with an auth token but requires the credentials of a Facebook account.
7
+ ![Image](https://i.imgur.com/nFCeYmQ.jpeg)
9
8
 
10
9
  _Disclaimer_: We are not responsible if your account gets banned for spammy activities such as sending lots of messages to people you don't know, sending messages very quickly, sending spammy looking URLs, logging in and out very quickly... Be responsible Facebook citizens.
11
10
 
12
11
  See [below](#projects-using-this-api) for projects using this API.
13
12
 
14
- See the [full changelog](/CHANGELOG.md) for release details.
13
+ # 🤖 Features:
14
+
15
+ - [X] Once the error is detected it will automatically relogin the appstate.
16
+ - [X] If the appstate itself is logged out it will automatically logged out and you can resubmit it again, But aside of that, if it has an automated behavior, it will relogin then it will dismiss automatically and refreshes the login.
17
+
18
+ ![Image](https://i.imgur.com/Pt6oCS0.jpeg)
19
+
20
+ - [X] Added a feature where if the account is locked/suspended, it will stop the login process and shows the information and why it was locked/suspended.
21
+
22
+ ![Image](https://i.imgur.com/R0lzR6R.jpeg)
23
+ ![Image](https://i.imgur.com/PPE3fB5.jpeg)
24
+
25
+ - [X] Added api.stopListenMqtt()
26
+ - [X] Added api.getRegion()
27
+ - [X] Added api.setProfileGuard()
28
+ - [X] Added api.addFunctions()
29
+ - [X] Added api.getBotInitialData()
30
+ - [X] Added refreshFb_dtsg (*Facebook's dynamic token security generation*): This will automatically refresh every 12:00 AM in GMT+8 PH time.
31
+ - [X] Added a detection if it's locked or suspended (*will show the information about the lock/suspension*)
32
+ - [X] Added randomUserAgent on setOptions (*experimental*)
33
+ - [X] Added bypassRegion on setOptions (*choose between PRN, PNB, HKG, SYD, VLL, LLA, SIN..., experimental*)
34
+ - [X] Added a userAgent that has a possibility for less logout on accounts (*contributor to jonellcc*)
35
+ - [X] Tested on Mirai/Autobot (*try on Xavia or Goat*)
36
+
37
+ > You can use cookies editor available in kiwi browser, edge and chrome extension for PC.
38
+ > We the @dongdev/fca-unofficiala team/contributors are recommending you to use the Firefox app for less logout, or use this website if you have no access on these browsers specially iOS user.
39
+
40
+ If you encounter errors on fca, you can contact me [here](https://www.facebook.com/minhdong.dev)
41
+
42
+ `</div>`
43
+
44
+ Facebook now has an official API for chat bots [here](https://developers.facebook.com/docs/messenger-platform).
45
+
46
+ This API is the only way to automate chat functionalities on a user account. We do this by emulating the browser. This means doing the exact same GET/POST requests and tricking Facebook into thinking we're accessing the website normally. Because we're doing it this way, this API won't work with an auth token but requires the credentials of a Facebook account.
15
47
 
16
48
  ## Install
17
- If you just want to use fca-unofficial, you should use this command:
49
+
50
+ If you just want to use ws3-fca, you should use this command:
51
+
18
52
  ```bash
19
- npm install @miraipr0ject/fca-unofficial
53
+ npm install @dongdev/fca-unofficial@latest
20
54
  ```
21
- It will download `fca-unofficial` from NPM repositories
22
55
 
23
- ## Testing your bots
24
- If you want to test your bots without creating another account on Facebook, you can use [Facebook Whitehat Accounts](https://www.facebook.com/whitehat/accounts/).
56
+ It will download @dongdev/fca-unofficial from NPM repositories
25
57
 
26
58
  ## Example Usage
59
+
27
60
  ```javascript
28
- const login = require("fca-unofficial");
61
+ const login = require("@dongdev/fca-unofficial");
29
62
 
30
63
  // Create simple echo bot
31
- login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
32
- if(err) return console.error(err);
33
-
34
- api.listen((err, message) => {
35
- api.sendMessage(message.body, message.threadID);
64
+ login({
65
+ appState: []
66
+ }, {
67
+ //setOptions will be here
68
+ } (err, api) => {
69
+ if (err) return utils.error(err);
70
+ api.listenMqtt((err, event) => {
71
+ api.sendMessage(event.body, event.threadID);
36
72
  });
37
73
  });
38
74
  ```
@@ -41,17 +77,14 @@ Result:
41
77
 
42
78
  <img width="517" alt="screen shot 2016-11-04 at 14 36 00" src="https://cloud.githubusercontent.com/assets/4534692/20023545/f8c24130-a29d-11e6-9ef7-47568bdbc1f2.png">
43
79
 
44
-
45
- ## Documentation
46
-
47
- You can see it [here](DOCS.md).
48
-
49
80
  ## Main Functionality
50
81
 
51
82
  ### Sending a message
83
+
52
84
  #### api.sendMessage(message, threadID[, callback][, messageID])
53
85
 
54
86
  Various types of message can be sent:
87
+
55
88
  * *Regular:* set field `body` to the desired message as a string.
56
89
  * *Sticker:* set a field `sticker` to the desired sticker ID.
57
90
  * *File or image:* Set field `attachment` to a readable stream or an array of readable streams.
@@ -63,10 +96,13 @@ Note that a message can only be a regular message (which can be empty) and optio
63
96
  __Tip__: to find your own ID, you can look inside the cookies. The `userID` is under the name `c_user`.
64
97
 
65
98
  __Example (Basic Message)__
99
+
66
100
  ```js
67
- const login = require("fca-unofficial");
101
+ const login = require("@dongdev/fca-unofficial");
68
102
 
69
- login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
103
+ login({
104
+ appState: []
105
+ }, (err, api) => {
70
106
  if(err) return console.error(err);
71
107
 
72
108
  var yourID = "000000000000000";
@@ -76,10 +112,13 @@ login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
76
112
  ```
77
113
 
78
114
  __Example (File upload)__
115
+
79
116
  ```js
80
- const login = require("fca-unofficial");
117
+ const login = require("@dongdev/fca-unofficial");
81
118
 
82
- login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
119
+ login({
120
+ appState: []
121
+ }, (err, api) => {
83
122
  if(err) return console.error(err);
84
123
 
85
124
  // Note this example uploads an image called image.jpg
@@ -92,7 +131,8 @@ login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
92
131
  });
93
132
  ```
94
133
 
95
- ------------------------------------
134
+ ---
135
+
96
136
  ### Saving session.
97
137
 
98
138
  To avoid logging in every time you should save AppState (cookies etc.) to a file, then you can use it without having password in your scripts.
@@ -101,9 +141,11 @@ __Example__
101
141
 
102
142
  ```js
103
143
  const fs = require("fs");
104
- const login = require("fca-unofficial");
144
+ const login = require("@dongdev/fca-unofficial");
105
145
 
106
- var credentials = {email: "FB_EMAIL", password: "FB_PASSWORD"};
146
+ var credentials = {
147
+ appState: []
148
+ };
107
149
 
108
150
  login(credentials, (err, api) => {
109
151
  if(err) return console.error(err);
@@ -114,10 +156,11 @@ login(credentials, (err, api) => {
114
156
 
115
157
  Alternative: Use [c3c-fbstate](https://github.com/c3cbot/c3c-fbstate) to get fbstate.json (appstate.json)
116
158
 
117
- ------------------------------------
159
+ ---
118
160
 
119
161
  ### Listening to a chat
120
- #### api.listen(callback)
162
+
163
+ #### api.listenMqtt(callback)
121
164
 
122
165
  Listen watches for messages sent in a chat. By default this won't receive events (joining/leaving a chat, title change etc…) but it can be activated with `api.setOptions({listenEvents: true})`. This will by default ignore messages sent by the current account, you can enable listening to your own messages with `api.setOptions({selfListen: true})`.
123
166
 
@@ -125,7 +168,7 @@ __Example__
125
168
 
126
169
  ```js
127
170
  const fs = require("fs");
128
- const login = require("fca-unofficial");
171
+ const login = require("@dongdev/fca-unofficial");
129
172
 
130
173
  // Simple echo bot. It will repeat everything that you say.
131
174
  // Will stop when you say '/stop'
@@ -135,7 +178,7 @@ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, ap
135
178
  api.setOptions({listenEvents: true});
136
179
 
137
180
  var stopListening = api.listenMqtt((err, event) => {
138
- if(err) return console.error(err);
181
+ if( err) return console.error(err);
139
182
 
140
183
  api.markAsRead(event.threadID, (err) => {
141
184
  if(err) console.error(err);
@@ -157,38 +200,8 @@ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, ap
157
200
  });
158
201
  ```
159
202
 
160
- ## FAQS
161
-
162
- 1. How do I run tests?
163
- > For tests, create a `test-config.json` file that resembles `example-config.json` and put it in the `test` directory. From the root >directory, run `npm test`.
164
-
165
- 2. Why doesn't `sendMessage` always work when I'm logged in as a page?
166
- > Pages can't start conversations with users directly; this is to prevent pages from spamming users.
167
-
168
- 3. What do I do when `login` doesn't work?
169
- > First check that you can login to Facebook using the website. If login approvals are enabled, you might be logging in incorrectly. For how to handle login approvals, read our docs on [`login`](DOCS.md#login).
170
-
171
- 4. How can I avoid logging in every time? Can I log into a previous session?
172
- > We support caching everything relevant for you to bypass login. `api.getAppState()` returns an object that you can save and pass into login as `{appState: mySavedAppState}` instead of the credentials object. If this fails, your session has expired.
173
-
174
- 5. Do you support sending messages as a page?
175
- > Yes, set the pageID option on login (this doesn't work if you set it using api.setOptions, it affects the login process).
176
- > ```js
177
- > login(credentials, {pageID: "000000000000000"}, (err, api) => { … }
178
- > ```
179
-
180
- 6. I'm getting some crazy weird syntax error like `SyntaxError: Unexpected token [`!!!
181
- > Please try to update your version of node.js before submitting an issue of this nature. We like to use new language features.
182
-
183
- 7. I don't want all of these logging messages!
184
- > You can use `api.setOptions` to silence the logging. You get the `api` object from `login` (see example above). Do
185
- > ```js
186
- > api.setOptions({
187
- > logLevel: "silent"
188
- > });
189
- > ```
203
+ `<a name="projects-using-this-api"></a>`
190
204
 
191
- <a name="projects-using-this-api"></a>
192
205
  ## Projects using this API:
193
206
 
194
207
  - [c3c](https://github.com/lequanglam/c3c) - A bot that can be customizable using plugins. Support Facebook & Discord.
package/index.js CHANGED
@@ -1,13 +1,68 @@
1
1
  "use strict";
2
-
3
2
  const utils = require("./utils");
4
3
  const log = require("npmlog");
4
+ const axios = require("axios");
5
+ const { execSync } = require("child_process");
6
+ const fs = require("fs");
7
+ const path = require("path");
8
+ const models = require("./lib/database/models");
9
+ const logger = require("./lib/logger");
5
10
  let checkVerified = null;
6
11
  const defaultLogRecordSize = 100;
7
12
  log.maxRecordSize = defaultLogRecordSize;
13
+ const defaultConfig = {
14
+ autoUpdate: true,
15
+ mqtt: {
16
+ enabled: true,
17
+ reconnectInterval: 3600,
18
+ }
19
+ };
20
+ const configPath = path.join(process.cwd(), "fca-config.json");
21
+ let config;
22
+ if (!fs.existsSync(configPath)) {
23
+ fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
24
+ config = defaultConfig;
25
+ } else {
26
+ try {
27
+ const fileContent = fs.readFileSync(configPath, 'utf8');
28
+ config = JSON.parse(fileContent);
29
+ config = { ...defaultConfig, ...config };
30
+ } catch (err) {
31
+ logger("Error reading config file, using defaults", "error");
32
+ config = defaultConfig;
33
+ }
34
+ }
35
+ global.fca = {
36
+ config: config
37
+ };
38
+ async function checkForUpdates() {
39
+ if (!global.fca.config.autoUpdate) {
40
+ logger("Auto update is disabled", "info");
41
+ }
42
+ try {
43
+ const response = await axios.get("https://raw.githubusercontent.com/DongDev-VN/fca-unofficial/refs/heads/main/package.json");
44
+ const remoteVersion = response.data.version;
45
+ const localPackage = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8"));
46
+ const localVersion = localPackage.version;
47
+ if (remoteVersion !== localVersion) {
48
+ logger(`New version available: ${remoteVersion}`, "FCA-UPDATE");
49
+ logger("Installing latest version...", "FCA-UPDATE");
50
+ execSync(`npm i ${localPackage.name}@latest`);
51
+ logger("Update completed! Please restart your application", "FCA-UPDATE");
52
+ process.exit(1);
53
+ } else {
54
+ logger(`You are using the latest version: ${localVersion}`, 'info');
55
+ }
56
+ } catch (err) {
57
+ logger("Failed to check for updates:", err, "error");
58
+ }
59
+ }
60
+ if (global.fca.config.autoUpdate) {
61
+ checkForUpdates();
62
+ }
8
63
  const Boolean_Option = [
9
64
  "online",
10
- "selfListen",
65
+ "selfListen",
11
66
  "listenEvents",
12
67
  "updatePresence",
13
68
  "forceLogin",
@@ -92,18 +147,17 @@ function buildAPI(globalOptions, html, jar) {
92
147
  "Error retrieving userID. This can be caused by a lot of things, including getting blocked by Facebook for logging in from an unknown location. Try logging in with a browser to verify.",
93
148
  };
94
149
  }
95
- if (html.indexOf("/checkpoint/block/?next") > -1) {
96
- log.warn(
97
- "login",
98
- "Checkpoint detected. Please log in with a browser to verify."
99
- );
150
+ if (html.indexOf("/checkpoint/block/?next") > -1 || html.indexOf("/checkpoint/?next") > -1) {
151
+ throw {
152
+ error: "Checkpoint detected. Please log in with a browser to verify.",
153
+ }
100
154
  }
101
155
  const userID = maybeCookie[0]
102
156
  .cookieString()
103
157
  .split("=")[1]
104
158
  .toString();
105
159
  const i_userID = objCookie.i_user || null;
106
- log.info("login", `Logged in as ${userID}`);
160
+ logger(`Logged in as ${userID}`, 'info');
107
161
  try {
108
162
  clearInterval(checkVerified);
109
163
  } catch (_) {}
@@ -116,7 +170,7 @@ function buildAPI(globalOptions, html, jar) {
116
170
  const url = new URL(mqttEndpoint);
117
171
  region = url.searchParams.get("region")?.toUpperCase() || "PRN";
118
172
  }
119
- log.info("login", `Sever region ${region}`);
173
+ logger(`Sever region ${region}`, 'info');
120
174
  } catch (e) {
121
175
  log.warning("login", "Not MQTT endpoint");
122
176
  }
@@ -124,6 +178,16 @@ function buildAPI(globalOptions, html, jar) {
124
178
  if (tokenMatch) {
125
179
  fb_dtsg = tokenMatch[1];
126
180
  }
181
+ (async () => {
182
+ try {
183
+ await models.sequelize.authenticate();
184
+ await models.syncAll();
185
+ } catch (error) {
186
+ console.error(error);
187
+ console.error('Database connection failed:', error.message);
188
+ }
189
+ })();
190
+ logger(`FCA fix by DongDev`, 'info');
127
191
  const ctx = {
128
192
  userID: userID,
129
193
  i_userID: i_userID,
@@ -161,16 +225,17 @@ function buildAPI(globalOptions, html, jar) {
161
225
  api[v.replace(".js", "")] = require("./src/" + v)(defaultFuncs, api, ctx);
162
226
  });
163
227
  api.listen = api.listenMqtt;
228
+ setInterval(checkForUpdates, 1000 * 60 * 60 * 24);
164
229
  setInterval(async () => {
165
230
  api
166
231
  .refreshFb_dtsg()
167
232
  .then(() => {
168
- console.log("Successfully refreshed fb_dtsg");
233
+ logger("Successfully refreshed fb_dtsg", 'info');
169
234
  })
170
235
  .catch((err) => {
171
236
  console.error("An error occurred while refreshing fb_dtsg", err);
172
237
  });
173
- }, 1000 * 60 * 60 * 48);
238
+ }, 1000 * 60 * 60 * 24);
174
239
  return [ctx, defaultFuncs, api];
175
240
  }
176
241
  function loginHelper(
@@ -248,12 +313,6 @@ function loginHelper(
248
313
  return res;
249
314
  })
250
315
  .then(function(res) {
251
- if (res.body.indexOf("checkpoint") > -1) {
252
- log.warn(
253
- "login",
254
- "Checkpoint detected. Please log in with a browser to verify."
255
- );
256
- }
257
316
  const html = res.body;
258
317
  const stuff = buildAPI(globalOptions, html, jar);
259
318
  ctx = stuff[0];
@@ -293,7 +352,7 @@ function loginHelper(
293
352
  }
294
353
  mainPromise
295
354
  .then(function() {
296
- log.info("login", "Done logging in.");
355
+ logger("Done logging in", 'info');
297
356
  return callback(null, api);
298
357
  })
299
358
  .catch(function(e) {
@@ -355,4 +414,5 @@ function login(loginData, options, callback) {
355
414
  );
356
415
  return returnPromise;
357
416
  }
358
- module.exports = login;
417
+
418
+ module.exports = login;
@@ -0,0 +1,47 @@
1
+ const { Sequelize } = require('sequelize');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const databasePath = path.join(process.cwd(), 'Fca_Database');
5
+ if (!fs.existsSync(databasePath)) {
6
+ fs.mkdirSync(databasePath, { recursive: true });
7
+ }
8
+ const sequelize = new Sequelize({
9
+ dialect: 'sqlite',
10
+ storage: path.join(databasePath, 'database.sqlite'),
11
+ logging: false,
12
+ pool: {
13
+ max: 5,
14
+ min: 0,
15
+ acquire: 30000,
16
+ idle: 10000
17
+ },
18
+ retry: {
19
+ max: 3
20
+ },
21
+ dialectOptions: {
22
+ timeout: 5000
23
+ },
24
+ isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.READ_COMMITTED
25
+ });
26
+ const models = {};
27
+ fs.readdirSync(__dirname).filter(file => file.endsWith('.js') && file !== 'index.js').forEach(file => {
28
+ const model = require(path.join(__dirname, file))(sequelize);
29
+ models[model.name] = model;
30
+ });
31
+ Object.keys(models).forEach(modelName => {
32
+ if (models[modelName].associate) {
33
+ models[modelName].associate(models);
34
+ }
35
+ });
36
+ models.sequelize = sequelize;
37
+ models.Sequelize = Sequelize;
38
+ models.syncAll = async () => {
39
+ try {
40
+ await sequelize.sync({ force: false });
41
+ } catch (error) {
42
+ console.error('Failed to synchronize models:', error);
43
+ throw error;
44
+ }
45
+ };
46
+
47
+ module.exports = models;
@@ -0,0 +1,31 @@
1
+ module.exports = function(sequelize) {
2
+ const { Model, DataTypes } = require("sequelize");
3
+
4
+ class Thread extends Model {}
5
+
6
+ Thread.init(
7
+ {
8
+ num: {
9
+ type: DataTypes.INTEGER,
10
+ allowNull: false,
11
+ autoIncrement: true,
12
+ primaryKey: true,
13
+ },
14
+ threadID: {
15
+ type: DataTypes.STRING,
16
+ allowNull: false,
17
+ unique: true,
18
+ },
19
+ data: {
20
+ type: DataTypes.JSONB,
21
+ allowNull: true,
22
+ }
23
+ },
24
+ {
25
+ sequelize,
26
+ modelName: "Thread",
27
+ timestamps: true,
28
+ }
29
+ );
30
+ return Thread;
31
+ };
@@ -0,0 +1,93 @@
1
+ const { Thread } = require('./models');
2
+
3
+ const validateThreadID = (threadID) => {
4
+ if (typeof threadID !== 'string' && typeof threadID !== 'number') {
5
+ throw new Error('Invalid threadID: must be a string or number.');
6
+ }
7
+ return String(threadID);
8
+ };
9
+ const validateData = (data) => {
10
+ if (!data || typeof data !== 'object' || Array.isArray(data)) {
11
+ throw new Error('Invalid data: must be a non-empty object.');
12
+ }
13
+ };
14
+
15
+ module.exports = function (bot) {
16
+ return {
17
+ async create(threadID, data) {
18
+ try {
19
+ let thread = await Thread.findOne({ where: { threadID } });
20
+ if (thread) {
21
+ return { thread: thread.get(), created: false };
22
+ }
23
+ thread = await Thread.create({ threadID, ...data });
24
+ return { thread: thread.get(), created: true };
25
+ } catch (error) {
26
+ throw new Error(`Failed to create thread: ${error.message}`);
27
+ }
28
+ },
29
+
30
+ async get(threadID) {
31
+ try {
32
+ threadID = validateThreadID(threadID);
33
+ const thread = await Thread.findOne({ where: { threadID } });
34
+ return thread ? thread.get() : null;
35
+ } catch (error) {
36
+ throw new Error(`Failed to get thread: ${error.message}`);
37
+ }
38
+ },
39
+
40
+ async update(threadID, data) {
41
+ try {
42
+ threadID = validateThreadID(threadID);
43
+ validateData(data);
44
+ const thread = await Thread.findOne({ where: { threadID } });
45
+
46
+ if (thread) {
47
+ await thread.update(data);
48
+ return { thread: thread.get(), created: false };
49
+ } else {
50
+ const newThread = await Thread.create({ ...data, threadID });
51
+ return { thread: newThread.get(), created: true };
52
+ }
53
+ } catch (error) {
54
+ throw new Error(`Failed to update thread: ${error.message}`);
55
+ }
56
+ },
57
+
58
+ async del(threadID) {
59
+ try {
60
+ if (!threadID) {
61
+ throw new Error('threadID is required and cannot be undefined');
62
+ }
63
+ threadID = validateThreadID(threadID);
64
+ if (!threadID) {
65
+ throw new Error('Invalid threadID');
66
+ }
67
+ const result = await Thread.destroy({ where: { threadID } });
68
+ if (result === 0) {
69
+ throw new Error('No thread found with the specified threadID');
70
+ }
71
+ return result;
72
+ } catch (error) {
73
+ throw new Error(`Failed to delete thread: ${error.message}`);
74
+ }
75
+ },
76
+ async delAll() {
77
+ try {
78
+ return await Thread.destroy({ where: {} });
79
+ } catch (error) {
80
+ throw new Error(`Failed to delete all threads: ${error.message}`);
81
+ }
82
+ },
83
+ async getAll(keys = null) {
84
+ try {
85
+ const attributes = typeof keys === 'string' ? [keys] : Array.isArray(keys) ? keys : undefined;
86
+ const threads = await Thread.findAll({ attributes });
87
+ return threads.map(thread => thread.get());
88
+ } catch (error) {
89
+ throw new Error(`Failed to get all threads: ${error.message}`);
90
+ }
91
+ },
92
+ };
93
+ };
package/lib/logger.js ADDED
@@ -0,0 +1,96 @@
1
+ const chalk = require('chalk');
2
+ const gradient = require("gradient-string");
3
+ const themes = [
4
+ 'blue',
5
+ 'dream2',
6
+ 'dream',
7
+ 'test',
8
+ 'fiery',
9
+ 'rainbow',
10
+ 'pastel',
11
+ 'cristal',
12
+ 'red',
13
+ 'aqua',
14
+ 'pink',
15
+ 'retro',
16
+ 'sunlight',
17
+ 'teen',
18
+ 'summer',
19
+ 'flower',
20
+ 'ghost',
21
+ 'hacker'
22
+ ];
23
+ const theme = themes[Math.floor(Math.random() * themes.length)];
24
+ let co;
25
+ let error;
26
+ if (theme.toLowerCase() === 'blue') {
27
+ co = gradient([{ color: "#1affa3", pos: 0.2 }, { color: "cyan", pos: 0.4 }, { color: "pink", pos: 0.6 }, { color: "cyan", pos: 0.8 }, { color: '#1affa3', pos: 1 }]);
28
+ error = chalk.red.bold;
29
+ } else if (theme == "dream2") {
30
+ cra = gradient("blue", "pink")
31
+ co = gradient("#a200ff", "#21b5ff", "#a200ff")
32
+ } else if (theme.toLowerCase() === 'dream') {
33
+ co = gradient([{ color: "blue", pos: 0.2 }, { color: "pink", pos: 0.3 }, { color: "gold", pos: 0.6 }, { color: "pink", pos: 0.8 }, { color: "blue", pos: 1 }]);
34
+ error = chalk.red.bold;
35
+ } else if (theme.toLowerCase() === 'fiery') {
36
+ co = gradient("#fc2803", "#fc6f03", "#fcba03");
37
+ error = chalk.red.bold;
38
+ } else if (theme.toLowerCase() === 'rainbow') {
39
+ co = gradient.rainbow
40
+ error = chalk.red.bold;
41
+ } else if (theme.toLowerCase() === 'pastel') {
42
+ co = gradient.pastel
43
+ error = chalk.red.bold;
44
+ } else if (theme.toLowerCase() === 'cristal') {
45
+ co = gradient.cristal
46
+ error = chalk.red.bold;
47
+ } else if (theme.toLowerCase() === 'red') {
48
+ co = gradient("red", "orange");
49
+ error = chalk.red.bold;
50
+ } else if (theme.toLowerCase() === 'aqua') {
51
+ co = gradient("#0030ff", "#4e6cf2");
52
+ error = chalk.blueBright;
53
+ } else if (theme.toLowerCase() === 'pink') {
54
+ cra = gradient('purple', 'pink');
55
+ co = gradient("#d94fff", "purple");
56
+ } else if (theme.toLowerCase() === 'retro') {
57
+ cra = gradient("#d94fff", "purple");
58
+ co = gradient.retro;
59
+ } else if (theme.toLowerCase() === 'sunlight') {
60
+ cra = gradient("#f5bd31", "#f5e131");
61
+ co = gradient("orange", "#ffff00", "#ffe600");
62
+ } else if (theme.toLowerCase() === 'teen') {
63
+ cra = gradient("#00a9c7", "#853858", "#853858", "#00a9c7");
64
+ co = gradient.teen;
65
+ } else if (theme.toLowerCase() === 'summer') {
66
+ cra = gradient("#fcff4d", "#4de1ff");
67
+ co = gradient.summer;
68
+ } else if (theme.toLowerCase() === 'flower') {
69
+ cra = gradient("blue", "purple", "yellow", "#81ff6e");
70
+ co = gradient.pastel;
71
+ } else if (theme.toLowerCase() === 'ghost') {
72
+ cra = gradient("#0a658a", "#0a7f8a", "#0db5aa");
73
+ co = gradient.mind;
74
+ } else if (theme === 'hacker') {
75
+ cra = chalk.hex('#4be813');
76
+ co = gradient('#47a127', '#0eed19', '#27f231');
77
+ } else {
78
+ co = gradient("#243aff", "#4687f0", "#5800d4");
79
+ error = chalk.red.bold;
80
+ }
81
+ module.exports = (text, type) => {
82
+ switch (type) {
83
+ case "warn":
84
+ process.stderr.write(co(`\r[ FCA-WARN ] > ${text}`) + '\n');
85
+ break;
86
+ case "error":
87
+ process.stderr.write(chalk.bold.hex("#ff0000").bold(`\r[ FCA-ERROR ]`) + ` > ${text}` + '\n');
88
+ break;
89
+ case "info":
90
+ process.stderr.write(chalk.bold(co(`\r[ FCA-UNO ] > ${text}`) + '\n'));
91
+ break;
92
+ default:
93
+ process.stderr.write(chalk.bold(co(`\r${String(type).toUpperCase()} ${text}`) + '\n'));
94
+ break;
95
+ }
96
+ };