Skip to content

Commit

Permalink
small change
Browse files Browse the repository at this point in the history
  • Loading branch information
Nurutomo committed Jan 13, 2021
1 parent ae5858b commit 7fc9d06
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
36 changes: 24 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ conn.handler = async function (m) {
if (!isAccept) continue
let isMods = isOwner || global.mods.includes(m.sender)
let isPrems = isMods || global.prems.includes(m.sender)
let participants = m.isGroup ? (await this.groupMetadata(m.chat)).participants : []
let groupMetadata = m.isGroup ? await this.groupMetadata(m.chat) : {}
let participants = m.isGroup ? groupMetadata.participants : []
let user = m.isGroup ? participants.filter(u => u.jid == m.sender)[0] : {}
let bot = m.isGroup ? participants.filter(u => u.jid == this.user.jid)[0] : {}
let isAdmin = user.isAdmin || user.isSuperAdmin || false
let isBotAdmin = bot.isAdmin || bot.isSuperAdmin || false
if (plugin.before) plugin.before({
usedPrefix
})
let fail = plugin.fail || global.dfail
if (plugin.owner && !isOwner) {
fail('owner', m, this)
Expand Down Expand Up @@ -132,16 +136,23 @@ conn.handler = async function (m) {
m.isCommand = true
m.exp += 'exp' in plugin ? parseInt(plugin.exp) : 10
if (!isPrems && global.DATABASE._data.users[m.sender].limit < 1 && plugin.limit) continue
await plugin(m, {
usedPrefix,
noPrefix,
_args,
args,
command,
text,
conn: this
}).catch(e => this.reply(m.chat, util.format(e), m))
if (!isPrems) m.limit = m.limit || plugin.limit || false
try {
await plugin(m, {
usedPrefix,
noPrefix,
_args,
args,
command,
text,
conn: this,
participants,
groupMetdadata
})
if (!isPrems) m.limit = m.limit || plugin.limit || false
} catch (e) {
console.log(e)
conn.reply(m.chat, util.format(e), m)
}
break
}
}
Expand Down Expand Up @@ -203,7 +214,8 @@ console.log(global.plugins)
fs.watch(path.join(__dirname, 'plugins'), (event, filename) => {
if (pluginFilter(filename)) {
let dir = './plugins/' + filename
if (delete require.cache[require.resolve(dir)]) {
if (require.resolve(dir) in require.cache) {
delete require.cache[require.resolve(dir)]
if (fs.existsSync(require.resolve(dir))) conn.logger.info(`re - require plugin '${dir}'`)
else {
conn.logger.warn(`deleted plugin '${dir}'`)
Expand Down
5 changes: 3 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let fs = require('fs')
let path = require('path')
let assert = require('assert')
let { spawn } = require('child_process')
let folders = ['.', ...Object.keys(require('./package.json').directories)]
let files = []
Expand All @@ -10,6 +11,6 @@ for (let file of files) {
if (file == path.join(__dirname, __filename)) continue
console.error('Checking', file)
spawn('node', ['-c', file])
.on('exit', () => console.error('Done', file))
.stderr.on('data', chunk => console.log(chunk.toString()))
.on('exit', () => assert.ok(file) & console.log('Done', file))
.stderr.on('data', chunk => assert.fail(chunk.toString()))
}

0 comments on commit 7fc9d06

Please sign in to comment.