Skip to content

Commit

Permalink
Updet
Browse files Browse the repository at this point in the history
  • Loading branch information
GynnnDev committed Aug 15, 2021
1 parent 02ec335 commit fe97391
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions lib/command.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
class Command {
constructor(client, botinfo, functions) {
this._events = {}
this.default_prefix = /^z/
this.prefix = new RegExp(`^${botinfo.prefix.join('|')}`)
this.client = client
this.functions = functions
this.botinfo = botinfo
this._events = {};
this.default_prefix = /^z/;
this.prefix = new RegExp(`^(${botinfo.prefix.join('|')})`);
this.client = client;
this.functions = functions;
this.botinfo = botinfo;
}

on(eventName, command = [], tags = [], callback = () => {}, opt = {}) {
let eventObj = Object.keys(this._events)
let nitip = !this._events[eventName] ? `Register Event|Command ${eventName}` : `Checking Event|Command ${eventName}`
this._events[eventName] = { eventName,command: new RegExp(`^${command.join('|')}`,'i'),_command: command,callback,usedPrefix:true,enable:true,tags,...opt}
this.functions.logLoading(`${nitip}`)
let eventObj = Object.keys(this._events);
let nitip = !this._events[eventName] ? `Register Event|Command ${eventName}` : `Checking Event|Command ${eventName}`;
this._events[eventName] = { eventName,command: new RegExp(`^(${command.join('|')})`,'i'),_command: command,callback,usedPrefix:true,enable:true,tags,...opt};
this.functions.logLoading(`${nitip}`);
}

modify(name = '', objectName = '', toValue = '') {
if (!this._events[name]) return this._events[name]
this._events[name][objectName] = toValue
return this._events[name]
if (!this._events[name]) return this._events[name];
this._events[name][objectName] = toValue;
return this._events[name];
}
execute(msg){
return new Promise(async(resolve,reject) => {
for (let eventCmd in this._events){
try {
let event = this._events[eventCmd]
if (!event.enable) return
let prefix = !event.usedPrefix ? event.command.exec(msg.string) : this.prefix.exec(msg.string) || this.default_prefix.exec(msg.string)
if (!prefix) return
let usedPref = prefix[0]
let cmd = event.command.exec(msg.string.replace(usedPref,''))
if (!cmd) return
let command = cmd[0]
let commandNpref = usedPref+command
let event = this._events[eventCmd];
if (!event.enable) continue;
let prefix = !event.usedPrefix ? event.command.exec(msg.string) : this.prefix.exec(msg.string) || this.default_prefix.exec(msg.string);
if (!prefix) continue;
let usedPref = prefix[0];
let cmd = event.command.exec(event.usedPrefix ? msg.string.replace(usedPref,'') : msg.string);
if (!cmd) continue;
let command = cmd[0];
let commandNpref = event.usedPrefix ? usedPref+command : command
let args = msg.string.split(' ')
let text = msg.string
let query = msg.string.replace(commandNpref)
let query = msg.string.replace(commandNpref,"")
let isOwner = msg.isOwner
let group = msg.isGroup? await msg.groupMetadata() : false
let isAdmin = msg.isGroup ? group.isSenderAdmin : false
Expand All @@ -46,7 +46,7 @@ if (event.group && !msg.isGroup) return this.client.reply(msg,this.botinfo.respo
if (event.private && msg.isGroup) return this.client.reply(msg,this.botinfo.response.private)
if (event.admin && !isAdmin) return this.client.reply(msg,this.botinfo.response.admin)
if (event.clientAdmin && !isClientAdmin) return this.client.reply(msg,this.botinfo.response.botAdmin)
if (event.owner && !isOwner) return this.client.reply(msg,this.botinfo.response.owner)
if (event.owner && !isOwner) return //this.client.reply(msg,this.botinfo.response.owner) You Can Toogle On By Delete //
if (event.fromMe && quotedMsg && !quotedMsg.fromMe) return this.client.reply(msg,this.botinfo.response.fromMe)
if (event.query && query.length < 1) return this.client.reply(msg,event.query)
if (event.url && !query.startsWith('http')) query = 'http://' + query
Expand All @@ -57,7 +57,7 @@ if (event.mention && !msg.mentionedJid) return this.client.reply(msg,this.botinf
if (event.quoted && !msg.quotedMsg) return this.client.reply(msg,this.botinfo.response.quoted)
if (event._media && !msg.isMedia && !quotedMsg || (quotedMsg && !quotedMsg.isMedia)) return this.client.reply(msg,this.botinfo.response._media)
await event.callback(msg,{client:this.client,text,group,isUrl,isAdmin,isClientAdmin,query,command,commandNpref,prefix,usedPref,args,cmd,prefix,usedPref,quotedMsg,...msg})
resolve({status:200,response:'ok',event:event.eventName})
resolve({status:200,response:'ok',event:event.eventName});
} catch(e) {
let data = {response:'bad',status:0,event:eventName,error: functions.util.format(e)}
console.log(data)
Expand Down

0 comments on commit fe97391

Please sign in to comment.