@dongdev/fca-unofficial 0.0.6 → 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 +77 -64
- package/index.js +403 -293
- package/lib/database/models/index.js +47 -0
- package/lib/database/models/thread.js +31 -0
- package/lib/database/threadData.js +93 -0
- package/lib/logger.js +96 -0
- package/package.json +8 -3
- package/src/getThreadInfo.js +293 -223
- package/src/getUserInfo.js +1 -7
- package/src/listenMqtt.js +716 -647
- package/src/refreshFb_dtsg.js +60 -75
- package/src/shareContact.js +49 -0
- package/utils.js +1236 -1350
- package/.travis.yml +0 -6
@@ -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
|
+
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dongdev/fca-unofficial",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.8",
|
4
4
|
"description": "A Facebook chat API without XMPP, will not be deprecated after April 30th, 2015.",
|
5
5
|
"main": "index.js",
|
6
6
|
"repository": {
|
@@ -10,13 +10,18 @@
|
|
10
10
|
"author": "Avery, David, Maude, Benjamin, UIRI, DongDev",
|
11
11
|
"license": "MIT",
|
12
12
|
"dependencies": {
|
13
|
-
"
|
13
|
+
"axios": "^1.8.4",
|
14
|
+
"bluebird": "^3.7.2",
|
15
|
+
"chalk": "^4.1.2",
|
14
16
|
"cheerio": "^1.0.0-rc.10",
|
15
17
|
"duplexify": "^4.1.3",
|
18
|
+
"gradient-string": "^2.0.2",
|
16
19
|
"https-proxy-agent": "^4.0.0",
|
17
|
-
"mqtt": "^4.3.
|
20
|
+
"mqtt": "^4.3.8",
|
18
21
|
"npmlog": "^1.2.0",
|
19
22
|
"request": "^2.53.0",
|
23
|
+
"sequelize": "^6.37.6",
|
24
|
+
"sqlite3": "^5.1.7",
|
20
25
|
"ws": "^8.18.1"
|
21
26
|
},
|
22
27
|
"devDependencies": {
|