Skip to content

Commit

Permalink
feat: fix broadcast on schema & add auto clear session
Browse files Browse the repository at this point in the history
  • Loading branch information
neoxr committed Apr 10, 2024
1 parent 5d8eaf8 commit d6842b7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
26 changes: 25 additions & 1 deletion client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const spinnies = new(require('spinnies'))(),
path = require('path'),
colors = require('@colors/colors'),
stable = require('json-stable-stringify'),
env = require('./config.json')
env = require('./config.json'),
{ platform } = require('os')
const cache = new(require('node-cache'))({
stdTTL: env.cooldown
})
Expand Down Expand Up @@ -63,6 +64,29 @@ client.on('ready', async () => {
if (tmpFiles.length > 0) {
tmpFiles.filter(v => !v.endsWith('.file')).map(v => fs.unlinkSync('./temp/' + v))
}

/* this source from @jarspay */
const TIME = 1000 * 60 * 60
const filename = []
const files = await fs.readdirSync('./session')
for (const file of files) {
if (file != 'creds.json') filename.push(path.join('./session', file))
}

await Promise.allSettled(filename.map(async (file) => {
const stat = await fs.statSync(file)
if (stat.isFile() && (Date.now() - stat.mtimeMs >= TIME)) {
if (platform() === 'win32') {
let fileHandle
try {
fileHandle = await fs.openSync(file, 'r+')
} catch (e) {} finally {
await fileHandle.close()
}
}
await fs.unlinkSync(file)
}
}))
} catch {}
}, 60 * 1000 * 10)

Expand Down
2 changes: 2 additions & 0 deletions lib/system/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ module.exports = (m, env) => {
if (!('error' in setting)) setting.error = []
if (!('hidden' in setting)) setting.hidden = []
if (!('pluginDisable' in setting)) setting.pluginDisable = []
if (!('receiver' in setting)) setting.receiver = []
if (!('groupmode' in setting)) setting.groupmode = false
if (!('sk_pack' in setting)) setting.sk_pack = 'Sticker by'
if (!('sk_author' in setting)) setting.sk_author = '© neoxr.js'
Expand All @@ -120,6 +121,7 @@ module.exports = (m, env) => {
error: [],
hidden: [],
pluginDisable: [],
receiver: [],
groupmode: false,
sk_pack: 'Sticker by',
sk_author: '© neoxr.js',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"homepage":"https://github.com/neoxr/wbot#readme",
"dependencies":{
"@colors/colors": "^1.6.0",
"@neoxr/wb": "^1.37.51",
"@neoxr/wb": "^1.38.52",
"bytes": "^3.1.2",
"cfonts": "3.1.1",
"express": "~4.16.4",
Expand All @@ -37,6 +37,6 @@
"devDependencies": {
"@adiwajshing/baileys": "npm:@neoxr/baileys",
"@adiwajshing/keyed-db": "^0.2.4",
"jimp": "^0.16.13"
"jimp": "~0.16.13"
}
}

0 comments on commit d6842b7

Please sign in to comment.