perf:删除 makeInMemoryStore,解决发群消息

main
LiaoYijun 7 months ago
parent 704110ac70
commit 65d5758148

@ -3,7 +3,6 @@ const {
Browsers,
DisconnectReason,
makeCacheableSignalKeyStore,
makeInMemoryStore,
getMessageFromStore,
useMultiFileAuthState,
downloadMediaMessage,
@ -19,7 +18,9 @@ const generateId = require('../../utils/generateId.util');
const NodeCache = require('node-cache');
const P = require('pino');
// Ref: https://github.com/WhiskeySockets/Baileys/blob/v6.7.19/README.md
// Ref:
// https://github.com/WhiskeySockets/Baileys/blob/v6.7.19/README.md
// https://github.com/WhiskeySockets/Baileys/blob/v6.7.19/Example/example.ts
const createWhatsApp = async phone => {
let qrCode = null;
const channelId = generateId();
@ -31,21 +32,12 @@ const createWhatsApp = async phone => {
const logger = P({ timestamp: () => `,"time":"${new Date().toJSON()}"` }, P.destination('./logs/wa-logs-' + phone + '.txt'));
logger.level = 'warn';
const msgRetryCounterCache = new NodeCache();
const storeFilename = './baileys_auth_info/baileys_store_' + phone + '.json'
const store = makeInMemoryStore({ logger });
store?.readFromFile(storeFilename);
// save every 10s
setInterval(() => {
store?.writeToFile(storeFilename);
}, 10_000);
const authStateFolder = './baileys_auth_info/' + phone;
const { state, saveCreds } = await useMultiFileAuthState(authStateFolder);
// https://git.../WhiskeySockets/.../src/Defaults/baileys-version.json
// https://git.../WhiskeySockets/.../src/Utils/generics.ts
// const fetchLatestWaWebVersion
// https://web.whatsapp.com/sw.js, client_revision: 1027426813
const { version, isLatest, } = { version: [2, 3000, 1027426813], isLatest: true };
const waVersion = version.join('.') + ', ' + (isLatest ? 'latest' : 'maybe');
const whatsAppVersion = [2, 3000, 1027426813];
const stop = () => {
@ -57,21 +49,13 @@ const createWhatsApp = async phone => {
}
});
fs.unlink(storeFilename, (err) => {
if (err && err.code !== 'ENOENT') {
console.error(`Error deleting storeFilename file: ${err.message}`);
} else if (!err) {
console.log('Successfully deleted storeFilename file: ', storeFilename);
}
});
waEmitter.emit('request.' + whatsAppNo + '.stop', {});
};
const start = () => {
const waSocket = makeWASocket({
version,
version: whatsAppVersion,
logger,
auth: {
creds: state.creds,
@ -89,8 +73,6 @@ const createWhatsApp = async phone => {
markOnlineOnConnect: false // Receive Notifications in Whatsapp App
});
store?.bind(waSocket.ev);
const getGroupSubject = async jid => {
const cachedMatadata = groupCache.get(jid);
@ -449,7 +431,7 @@ const createWhatsApp = async phone => {
return {
createTimestamp: Date.now(),
status: 'offline',
version: waVersion,
version: whatsAppVersion.join('.') + ', maybe',
channelId: channelId,
phone: phone,
start,

@ -4,7 +4,7 @@ const waEmitter = require('./core/emitter');
const go = async () => {
waEmitter.on('connection:open', event => {
console.log('connection-open: ', event);
waEmitter.emit('request.8618777396951.send.message', { to: '120363389309889162@g.us', externalId: new Date().getTime(), text: 'connection-open: ' + new Date().toUTCString() });
// waEmitter.emit('request.8618777396951.send.message', { to: '120363389309889162@g.us', externalId: new Date().getTime(), text: '可以发群消息了: ' + new Date().toUTCString() });
});
waEmitter.on('creds:update', event => {
console.log('creds-update: ', event);

Loading…
Cancel
Save