Best JavaScript code snippet using jest-extended
handler.js
Source:handler.js
1const simple = require('./lib/simple')2const util = require('util')3const isNumber = x => typeof x === 'number' && !isNaN(x)4const delay = ms => isNumber(ms) && new Promise(resolve => setTimeout(resolve, ms))5module.exports = {6 async handler(chatUpdate) {7 if (global.db.data == null) await loadDatabase()8 this.msgqueque = this.msgqueque || []9 // console.log(chatUpdate)10 if (!chatUpdate) return11 // if (chatUpdate.messages.length > 2 || !chatUpdate.messages.length) return12 if (chatUpdate.messages.length > 1) console.log(chatUpdate.messages)13 let m = chatUpdate.messages[chatUpdate.messages.length - 1]14 if (!m) return15 console.log(JSON.stringify(m, null, 4))16 try {17 m = simple.smsg(this, m) || m18 if (!m) return19 // console.log(m)20 m.exp = 021 m.limit = false22 try {23 let user = global.db.data.users[m.sender]24 if (typeof user !== 'object') global.db.data.users[m.sender] = {}25 if (user) {26 if (!isNumber(user.healt)) user.healt = 10027 if (!isNumber(user.title)) user.title = 028 if (!isNumber(user.stamina)) user.stamina = 10029 if (!isNumber(user.haus)) user.haus = 10030 if (!isNumber(user.laper)) user.laper = 10031 if (!isNumber(user.level)) user.level = 032 if (!('pasangan' in user)) user.pasangan = ''33 if (!isNumber(user.exp)) user.exp = 034 if (!isNumber(user.pc)) user.pc = 035 if (!isNumber(user.korbanngocok)) user.korbanngocok = 036 if (!isNumber(user.ojekk)) user.ojekk = 037 if (!isNumber(user.trofi)) user.trofi= 038 if (!user.rtrofi) user.rtrofi = 'Perunggu'39 if (!isNumber(user.troopcamp)) user.troopcamp = 040 if (!isNumber(user.coin)) user.coin = 041 if (!isNumber(user.atm)) user.atm = 042 if (!isNumber(user.limit)) user.limit = 2043 if (!isNumber(user.glimit)) user.glimit = 2044 if (!isNumber(user.tprem)) user.tprem = 045 if (!isNumber(user.tigame)) user.tigame = 5046 if (!isNumber(user.lastclaim)) user.lastclaim = 047 if (!isNumber(user.money)) user.money = 048 if (!isNumber(user.rumahsakit)) user.rumahsakit= 049 if (!isNumber(user.fortress)) user.fortress = 050 if (!isNumber(user.shield)) user.shield = false51 if (!isNumber(user.pertanian)) user.pertanian = 052 if (!isNumber(user.pertambangan)) user.pertambangan = 053 54 55 if (!isNumber(user.botol)) user.botol = 056 if (!isNumber(user.kardus)) user.kardus = 057 if (!isNumber(user.kaleng)) user.kaleng = 058 if (!isNumber(user.aqua)) user.aqua = 059 if (!isNumber(user.diamond)) user.diamond = 060 if (!isNumber(user.iron)) user.iron = 061 if (!isNumber(user.emas)) user.emas = 062 if (!isNumber(user.arlok)) user.arlok = 063 64 if (!isNumber(user.common)) user.common = 065 if (!isNumber(user.as)) user.as = 066 if (!isNumber(user.uncommon)) user.uncommon = 067 if (!isNumber(user.mythic)) user.mythic = 068 if (!isNumber(user.legendary)) user.legendary = 069 if (!isNumber(user.glory)) user.glory = 070 if (!isNumber(user.enchant)) user.enchant = 071 if (!isNumber(user.pet)) user.pet = 072 if (!isNumber(user.psepick)) user.psepick = 073 if (!isNumber(user.psenjata)) user.psenjata = 074 75 if (!isNumber(user.potion)) user.potion = 076 if (!isNumber(user.sampah)) user.sampah = 077 if (!isNumber(user.armor)) user.armor = 078 if (!isNumber(user.pancing)) user.pancing = 079 //penambah stamina80 if (!isNumber(user.apel)) user.apel = 081 if (!isNumber(user.ayamb)) user.ayamb = 082 if (!isNumber(user.ayamg)) user.ayamg = 083 if (!isNumber(user.sapir)) user.sapir = 084 if (!isNumber(user.ssapi)) user.ssapi = 085 if (!isNumber(user.esteh)) user.esteh = 086 if (!isNumber(user.leleg)) user.leleg = 087 if (!isNumber(user.leleb)) user.leleb = 088 //tools89 if (!isNumber(user.sword)) user.sword = 090 if (!isNumber(user.sworddurability)) user.sworddurability = 091 if (!isNumber(user.pickaxe)) user.pickaxe = 092 if (!isNumber(user.pickaxedurability)) user.pickaxedurability = 093 if (!isNumber(user.fishingrod)) user.fishingrod = 094 if (!isNumber(user.fishingroddurability)) user.fishingroddurability = 095 if (!isNumber(user.umpan)) user.umpan = 096 97 if (!isNumber(user.kucing)) user.kucing = 098 if (!isNumber(user.kucinglastclaim)) user.kucinglastclaim = 099 if (!isNumber(user.kuda)) user.kuda = 0100 if (!isNumber(user.kudalastclaim)) user.kudalastclaim = 0101 if (!isNumber(user.rubah)) user.rubah = 0102 if (!isNumber(user.rubahlastclaim)) user.rubahlastclaim = 0103 if (!isNumber(user.anjing)) user.anjing = 0104 if (!isNumber(user.anjinglastclaim)) user.anjinglastclaim = 0105 if (!isNumber(user.serigalalastclaim)) user.serigalalastclaim = 0106 if (!isNumber(user.nagalastclaim)) user.nagalastclaim = 0107 if (!isNumber(user.phonixlastclaim)) user.phonixlastclaim = 0108 if (!isNumber(user.griffinlastclaim)) user.griffinlastclaim = 0109 if (!isNumber(user.centaurlastclaim)) user.centaurlastclaim = 0110 111 if (!isNumber(user.makananpet)) user.makananpet112 if (!isNumber(user.makanannaga)) user.makanannaga = 0113 if (!isNumber(user.makananphonix)) user.makananphonix = 0114 if (!isNumber(user.makanangriffin)) user.makanangriffin = 0115 if (!isNumber(user.makananserigala)) user.makananserigala = 0116 if (!isNumber(user.makanancentaur)) user.makanancentaur = 0117 118 if (!'Banneduser' in user) user.Banneduser = false119 if (!'BannedReason' in user) user.BannedReason = ''120 if (!isNumber(user.warn)) user.warn = 0121 122 if (!isNumber(user.afk)) user.afk = -1123 if (!'afkReason' in user) user.afkReason = ''124 125 //PET126 if (!isNumber(user.healthmonster)) user.healthmonster = 0127 if (!isNumber(user.anakkucing)) user.anakkucing = 0128 if (!isNumber(user.anakkuda)) user.anakkuda = 0129 if (!isNumber(user.anakrubah)) user.anakrubah = 0130 if (!isNumber(user.anakanjing)) user.anakanjing = 0131 if (!isNumber(user.serigala)) user.serigala = 0132 if (!isNumber(user.anakserigala)) user.anakserigala = 0133 if (!isNumber(user.naga)) user.naga = 0134 if (!isNumber(user.anaknaga)) user.anaknaga = 0135 if (!isNumber(user.phonix)) user.phonix = 0136 if (!isNumber(user.anakphonix)) user.anakphonix = 0137 if (!isNumber(user.griffin)) user.griffin = 0138 if (!isNumber(user.anakgriffin)) user.anakgriffin = 0139 if (!isNumber(user.kyubi)) user.kyubi = 0140 if (!isNumber(user.anakkyubi)) user.anakkyubi = 0141 if (!isNumber(user.centaur)) user.centaur = 0142 if (!isNumber(user.anakcentaur)) user.anakcentaur = 0143 if (!isNumber(user.makananpet)) user.makananpet = 0144 145 if (!isNumber(user.antispam)) user.antispam = 0146 if (!isNumber(user.antispamlastclaim)) user.antispamlastclaim = 0147 148 if (!isNumber(user.kayu)) user.kayu = 0149 if (!('kingdom' in user)) user.kingdom = false150 if (!isNumber(user.batu)) user.batu = 0151 if (!isNumber(user.ramuan)) user.ramuan = 0152 if (!isNumber(user.string)) user.string = 0153 if (!isNumber(user.sword)) user.sword = 0154 if (!isNumber(user.sworddurability)) user.sworddurability = 0155 if (!isNumber(user.pickaxe)) user.pickaxe = 0156 if (!isNumber(user.pickaxedurability)) user.pickaxedurability = 0157 if (!isNumber(user.fishingrod)) user.fishingrod = 0158 if (!isNumber(user.fishingroddurability)) user.fishingroddurability = 0159 160 //mancing161 if (!isNumber(user.paus)) user.paus = 0162 if (!isNumber(user.kepiting)) user.kepiting = 0163 if (!isNumber(user.gurita)) user.gurita = 0164 if (!isNumber(user.cumi)) user.cumi= 0165 if (!isNumber(user.buntal)) user.buntal = 0166 if (!isNumber(user.dory)) user.dory = 0167 if (!isNumber(user.lumba)) user.lumba = 0168 if (!isNumber(user.lobster)) user.lobster = 0169 if (!isNumber(user.hiu)) user.hiu = 0170 if (!isNumber(user.udang)) user.udang = 0171 if (!isNumber(user.ikan)) user.ikan = 0172 if (!isNumber(user.nila)) user.nila = 0173 if (!isNumber(user.bawal)) user.bawal = 0174 if (!isNumber(user.lele)) user.lele = 0175 if (!isNumber(user.orca)) user.orca = 0176 177 if (!isNumber(user.banteng)) user.banteng = 0178 if (!isNumber(user.harimau)) user.harimau = 0179 if (!isNumber(user.gajah)) user.gajah = 0180 if (!isNumber(user.kambing)) user.kambing = 0181 if (!isNumber(user.panda)) user.panda = 0182 if (!isNumber(user.buaya)) user.buaya = 0183 if (!isNumber(user.kerbau)) user.kerbau = 0184 if (!isNumber(user.sapi)) user.sapi = 0185 if (!isNumber(user.monyet)) user.monyet = 0186 if (!isNumber(user.babihutan)) user.babihutan = 0187 if (!isNumber(user.babi)) user.babi = 0188 if (!isNumber(user.ayam)) user.ayam = 0189 190 if (!isNumber(user.lastadventure)) user.lastadventure = 0191 if (!isNumber(user.lastkill)) user.lastkill = 0192 if (!isNumber(user.lastfishing)) user.lastfishing = 0193 if (!isNumber(user.lastdungeon)) user.lastdungeon = 0194 if (!isNumber(user.lastwar)) user.lastwar = 0195 if (!isNumber(user.lastsda)) user.lastsda = 0196 if (!isNumber(user.lastberbru)) user.lastberbru = 0197 if (!isNumber(user.lastduel)) user.lastduel = 0198 if (!isNumber(user.lastjb)) user.lastjb = 0199 if (!isNumber(user.lastSetStatus)) user.lastSetStatus = 0200 if (!isNumber(user.lastmining)) user.lastmining = 0201 if (!isNumber(user.lasthunt)) user.lasthunt = 0202 if (!isNumber(user.lastngocok)) user.lastngocok = 0203 if (!isNumber(user.lastgift)) user.lastgift = 0204 if (!isNumber(user.lastrob)) user.lastrob = 0205 if (!isNumber(user.lastngojek)) user.lastngojek = 0206 if (!isNumber(user.lastgrab)) user.lastgrab = 0207 if (!isNumber(user.lastberkebon)) user.lastberkebon = 0208 if (!isNumber(user.lastcodereg)) user.lastcodereg = 0209 if (!isNumber(user.lastdagang)) user.lastdagang = 0210 if (!isNumber(user.lasthourly)) user.lasthourly = 0211 if (!isNumber(user.lastweekly)) user.lastweekly = 0212 if (!isNumber(user.lastmonthly)) user.lastmonthly = 0213 if (!isNumber(user.lastIstigfar)) user.lastIstigfar = 0214 if (!isNumber(user.lastturu)) user.lastturu = 0215 if (!isNumber(user.lastseen)) user.lastseen = 0216 if (!isNumber(user.lastbansos)) user.lastbansos = 0217 if (!isNumber(user.lastrampok)) user.lastrampok = 0218 if (!('registered' in user)) user.registered = false219 if (!user.registered) {220 if (!('name' in user)) user.name = this.getName(m.sender)221 222 if (!isNumber(user.apel)) user.apel = 0223 if (!isNumber(user.anggur)) user.anggur = 0224 if (!isNumber(user.jeruk)) user.jeruk = 0225 if (!isNumber(user.semangka)) user.semangka = 0226 if (!isNumber(user.mangga)) user.mangga = 0227 if (!isNumber(user.stroberi)) user.stroberi = 0228 if (!isNumber(user.pisang)) user.pisang = 0229 if (!isNumber(user.kayu)) user.kayu = 0230 if (!isNumber(user.emas)) user.emas = 0231 if (!isNumber(user.makanan)) user.makanan = 0232 if (!isNumber(user.bibitanggur)) user.bibitanggur = 0233 if (!isNumber(user.bibitpisang)) user.bibitpisang = 0234 if (!isNumber(user.bibitapel)) user.bibitapel = 0235 if (!isNumber(user.bibitmangga)) user.bibitmangga = 0236 if (!isNumber(user.bibitjeruk)) user.bibitjeruk = 0237 238 239 if (!isNumber(user.age)) user.age = -1240 if (!isNumber(user.premiumDate)) user.premiumDate = -1241 if (!isNumber(user.regTime)) user.regTime = -1242 243 }244 if (!isNumber(user.level)) user.level = 0245 if (!user.job) user.job = 'Pengangguran'246 if (!user.lbars) user.lbars = '[âââââââââ]'247 if (!user.premium) user.premium = false248 if (!user.premium) user.premiumTime= 0249 if (!user.role) user.role = 'Newbie ã¡'250 if (!('autolevelup' in user)) user.autolevelup = true251 if (!('lastIstigfar' in user)) user.lastIstigfar = true252 } else global.db.data.users[m.sender] = {253 healt: 100,254 title: '',255 haus: 100,256 laper: 100,257 tprem: 0,258 stamina : 100,259 level: 0,260 pasangan: '',261 pc : 0,262 exp: 0,263 coin: 0,264 atm: 0,265 limit: 20,266 tigame: 50,267 lastclaim: 0,268 money: 0,269 diamond: 0,270 iron: 0,271 emas: 0,272 common: 0,273 uncommon: 0,274 mythic: 0,275 legendary: 0,276 rumahsakit: 0,277 fortress: 0,278 trofi: 0,279 rtrofi: 'perunggu',280 makanan: 0,281 troopcamp: 0,282 shield: 0,283 arlok: 0,284 ojekk: 0,285 korbanngocok: 0,286 //mancing287 as: 0,288 paus: 0,289 kepiting: 0,290 gurita: 0,291 cumi: 0,292 buntal: 0,293 dory: 0,294 lumba: 0,295 lobster: 0,296 hiu: 0,297 lele: 0,298 nila: 0,299 bawal: 0,300 udang: 0,301 ikan: 0,302 orca: 0,303 banteng: 0,304 harimau: 0,305 gajah: 0,306 kambing: 0,307 panda: 0,308 buaya: 0,309 kerbau : 0,310 sapi: 0,311 monyet : 0,312 babihutan: 0,313 babi: 0,314 ayam: 0,315 apel: 20,316 ayamb: 0,317 ayamg: 0,318 ssapi: 0,319 sapir: 0,320 leleb: 0,321 leleg: 0,322 esteh: 0,323 pet: 0,324 potion: 0,325 sampah: 0,326 armor: 0,327 kucing: 0,328 kucinglastclaim: 0,329 kuda: 0,330 kudalastclaim: 0,331 rubah: 0,332 rubahlastclaim: 0,333 anjing: 0,334 anjinglastclaim: 0,335 naga: 0,336 nagalastclaim: 0,337 griffin: 0,338 griffinlastclaim: 0,339 centaur: 0,340 centaurlastclaim: 0,341 serigala: 0,342 serigalalastclaim: 0,343 phonix: 0,344 phonixlastclaim: 0,345 makanannaga: 0,346 makananphonix: 0,347 makanancentaur: 0,348 makananserigala: 0,349 350 Banneduser: false,351 BannedReason: '',352 warn: 0,353 afk: -1,354 afkReason: '',355 anakkucing: 0,356 anakkuda: 0,357 anakrubah: 0,358 anakanjing: 0,359 makananpet: 0,360 antispam: 0,361 antispamlastclaim: 0,362 kayu: 0,363 batu: 0,364 string: 0,365 umpan: 0,366 sword: 0,367 sworddurability: 0,368 pickaxe: 0,369 pickaxedurability: 0,370 fishingrod: 0,371 fishingroddurability: 0,372 lastadventure: 0,373 lastkill: 0,374 lastfishing: 0,375 lastdungeon: 0,376 lastduel: 0,377 lastmining: 0,378 lasthourly: 0,379 lasthunt: 0,380 lastweekly: 0,381 lastmonthly: 0,382 lastjb: 0,383 lastrob: 0,384 lastdaang: 0,385 lastngojek: 0,386 lastgrab: 0,387 lastngocok: 0,388 lastturu: 0,389 lastseen: 0,390 lastSetStatus: 0,391 registered: false,392 apel: 20,393 mangga: 0,394 stroberi: 0,395 semangka: 0,396 jeruk: 0,397 semangka: 0,398 name: this.getName(m.sender),399 age: -1,400 regTime: -1,401 premium: false, 402 premiumTime: 0,403 job: 'Pengangguran', 404 lbars: '[âââââââââ]', 405 role: 'Newbie ã¡', 406 registered: false,407 name: this.getName(m.sender),408 age: -1,409 regTime: -1,410 autolevelup: true,411 lastIstigfar: 0,412 }413 let chat = global.db.data.chats[m.chat]414 if (typeof chat !== 'object') global.db.data.chats[m.chat] = {}415 if (chat) {416 if (!('isBanned' in chat)) chat.isBanned = false417 if (!('welcome' in chat)) chat.welcome = true418 if (!('detect' in chat)) chat.detect = false419 if (!('sWelcome' in chat)) chat.sWelcome = ''420 if (!('sBye' in chat)) chat.sBye = ''421 if (!('sPromote' in chat)) chat.sPromote = ''422 if (!('sDemote' in chat)) chat.sDemote = ''423 if (!('delete' in chat)) chat.delete = true424 if (!('antiLink' in chat)) chat.antiLink = true425 if (!('viewonce' in chat)) chat.viewonce = false426 if (!('antiToxic' in chat)) chat.antiToxic = false427 } else global.db.data.chats[m.chat] = {428 isBanned: false,429 welcome: true,430 detect: false,431 sWelcome: '',432 sBye: '',433 sPromote: '',434 sDemote: '',435 delete: true,436 antiLink: true,437 viewonce: false,438 antiToxic: true,439 }440 } catch (e) {441 console.error(e)442 }443 if (opts['nyimak']) return444 if (!m.fromMe && opts['self']) return445 if (opts['pconly'] && m.chat.endsWith('g.us')) return446 if (opts['gconly'] && !m.chat.endsWith('g.us')) return447 if (opts['swonly'] && m.chat !== 'status@broadcast') return448 if (typeof m.text !== 'string') m.text = ''449 if (opts['queque'] && m.text) {450 this.msgqueque.push(m.id || m.key.id)451 await delay(this.msgqueque.length * 1000)452 }453 for (let name in global.plugins) {454 let plugin = global.plugins[name]455 if (!plugin) continue456 if (plugin.disabled) continue457 if (!plugin.all) continue458 if (typeof plugin.all !== 'function') continue459 try {460 await plugin.all.call(this, m, chatUpdate)461 } catch (e) {462 if (typeof e === 'string') continue463 console.error(e)464 }465 }466 if (m.isBaileys) return467 m.exp += Math.ceil(Math.random() * 10)468 let usedPrefix469 let _user = global.db.data && global.db.data.users && global.db.data.users[m.sender]470 let isROwner = [global.conn.user.jid, ...global.owner].map(v => v.replace(/[^0-9]/g, '') + '@s.whatsapp.net').includes(m.sender)471 let isOwner = isROwner || m.fromMe472 let isMods = isOwner || global.mods.map(v => v.replace(/[^0-9]/g, '') + '@s.whatsapp.net').includes(m.sender)473 let isPrems = isROwner || global.prems.map(v => v.replace(/[^0-9]/g, '') + '@s.whatsapp.net').includes(m.sender)474 let groupMetadata = (m.isGroup ? (conn.chats[m.chat] || {}).metadata : {}) || {}475 let participants = (m.isGroup ? groupMetadata.participants : []) || []476 let user = (m.isGroup ? participants.find(u => conn.decodeJid(u.id) === m.sender) : {}) || {} // User Data477 let bot = (m.isGroup ? participants.find(u => conn.decodeJid(u.id) == this.user.jid) : {}) || {} // Your Data478 let isAdmin = user && user.admin || false // Is User Admin?479 let isBotAdmin = bot && bot.admin || false // Are you Admin?480 for (let name in global.plugins) {481 let plugin = global.plugins[name]482 if (!plugin) continue483 if (plugin.disabled) continue484 if (!opts['restrict']) if (plugin.tags && plugin.tags.includes('admin')) {485 // global.dfail('restrict', m, this)486 continue487 }488 const str2Regex = str => str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')489 let _prefix = plugin.customPrefix ? plugin.customPrefix : conn.prefix ? conn.prefix : global.prefix490 let match = (_prefix instanceof RegExp ? // RegExp Mode?491 [[_prefix.exec(m.text), _prefix]] :492 Array.isArray(_prefix) ? // Array?493 _prefix.map(p => {494 let re = p instanceof RegExp ? // RegExp in Array?495 p :496 new RegExp(str2Regex(p))497 return [re.exec(m.text), re]498 }) :499 typeof _prefix === 'string' ? // String?500 [[new RegExp(str2Regex(_prefix)).exec(m.text), new RegExp(str2Regex(_prefix))]] :501 [[[], new RegExp]]502 ).find(p => p[1])503 if (typeof plugin.before === 'function') if (await plugin.before.call(this, m, {504 match,505 conn: this,506 participants,507 groupMetadata,508 user,509 bot,510 isROwner,511 isOwner,512 isAdmin,513 isBotAdmin,514 isPrems,515 chatUpdate,516 })) continue517 if (typeof plugin !== 'function') continue518 if ((usedPrefix = (match[0] || '')[0])) {519 let noPrefix = m.text.replace(usedPrefix, '')520 let [command, ...args] = noPrefix.trim().split` `.filter(v => v)521 args = args || []522 let _args = noPrefix.trim().split` `.slice(1)523 let text = _args.join` `524 command = (command || '').toLowerCase()525 let fail = plugin.fail || global.dfail // When failed526 let isAccept = plugin.command instanceof RegExp ? // RegExp Mode?527 plugin.command.test(command) :528 Array.isArray(plugin.command) ? // Array?529 plugin.command.some(cmd => cmd instanceof RegExp ? // RegExp in Array?530 cmd.test(command) :531 cmd === command532 ) :533 typeof plugin.command === 'string' ? // String?534 plugin.command === command :535 false536 if (!isAccept) continue537 m.plugin = name538 if (m.chat in global.db.data.chats || m.sender in global.db.data.users) {539 let chat = global.db.data.chats[m.chat]540 let user = global.db.data.users[m.sender]541 if (name != 'unbanchat.js' && chat && chat.isBanned) return // Except this542 if (name != 'unbanuser.js' && user && user.banned) return543 }544 if (plugin.rowner && plugin.owner && !(isROwner || isOwner)) { // Both Owner545 fail('owner', m, this)546 continue547 }548 if (plugin.rowner && !isROwner) { // Real Owner549 fail('rowner', m, this)550 continue551 }552 if (plugin.owner && !isOwner) { // Number Owner553 fail('owner', m, this)554 continue555 }556 if (plugin.mods && !isMods) { // Moderator557 fail('mods', m, this)558 continue559 }560 if (plugin.premium && !isPrems) { // Premium561 fail('premium', m, this)562 continue563 }564 if (plugin.group && !m.isGroup) { // Group Only565 fail('group', m, this)566 continue567 } else if (plugin.botAdmin && !isBotAdmin) { // You Admin568 fail('botAdmin', m, this)569 continue570 } else if (plugin.admin && !isAdmin) { // User Admin571 fail('admin', m, this)572 continue573 }574 if (plugin.private && m.isGroup) { // Private Chat Only575 fail('private', m, this)576 continue577 }578 if (plugin.register == true && _user.registered == false) { // Butuh daftar?579 fail('unreg', m, this)580 continue581 }582 m.isCommand = true583 let xp = 'exp' in plugin ? parseInt(plugin.exp) : 17 // XP Earning per command584 if (xp > 200) m.reply('Ngecit -_-') // Hehehe585 else m.exp += xp586 if (!isPrems && plugin.limit && global.db.data.users[m.sender].limit < plugin.limit * 1) {587 this.reply(m.chat, `Limit anda habis, silahkan beli melalui *${usedPrefix}buy*`, m)588 continue // Limit habis589 }590 if (plugin.level > _user.level) {591 this.reply(m.chat, `diperlukan level ${plugin.level} untuk menggunakan perintah ini. Level kamu ${_user.level}`, m)592 continue // If the level has not been reached593 }594 let extra = {595 match,596 usedPrefix,597 noPrefix,598 _args,599 args,600 command,601 text,602 conn: this,603 participants,604 groupMetadata,605 user,606 bot,607 isROwner,608 isOwner,609 isAdmin,610 isBotAdmin,611 isPrems,612 chatUpdate,613 }614 try {615 await plugin.call(this, m, extra)616 if (!isPrems) m.limit = m.limit || plugin.limit || false617 } catch (e) {618 // Error occured619 m.error = e620 console.error(e)621 if (e) {622 let text = util.format(e)623 for (let key of Object.values(global.APIKeys))624 text = text.replace(new RegExp(key, 'g'), '#HIDDEN#')625 m.reply(text)626 }627 } finally {628 // m.reply(util.format(_user))629 if (typeof plugin.after === 'function') {630 try {631 await plugin.after.call(this, m, extra)632 } catch (e) {633 console.error(e)634 }635 }636 if (m.limit) m.reply(+ m.limit + ' Limit terpakai')637 }638 break639 }640 }641 } catch (e) {642 console.error(e)643 } finally {644 //console.log(global.db.data.users[m.sender])645 let user, stats = global.db.data.stats646 if (m) {647 if (m.sender && (user = global.db.data.users[m.sender])) {648 user.exp += m.exp649 user.limit -= m.limit * 1650 }651 let stat652 if (m.plugin) {653 let now = + new Date654 if (m.plugin in stats) {655 stat = stats[m.plugin]656 if (!isNumber(stat.total)) stat.total = 1657 if (!isNumber(stat.success)) stat.success = m.error != null ? 0 : 1658 if (!isNumber(stat.last)) stat.last = now659 if (!isNumber(stat.lastSuccess)) stat.lastSuccess = m.error != null ? 0 : now660 } else stat = stats[m.plugin] = {661 total: 1,662 success: m.error != null ? 0 : 1,663 last: now,664 lastSuccess: m.error != null ? 0 : now665 }666 stat.total += 1667 stat.last = now668 if (m.error == null) {669 stat.success += 1670 stat.lastSuccess = now671 }672 }673 }...
tool.js
Source:tool.js
...21 * @return {Boolean} [description]22 * @example23 * {24 * const isNumber = require('is-number');25 * isNumber(5e3); // true26 * isNumber(0xff); // true27 * isNumber(-1.1); // true28 * isNumber(0); // true29 * isNumber(1); // true30 * isNumber(1.1); // true31 * isNumber(10); // true32 * isNumber(10.10); // true33 * isNumber(100); // true34 * isNumber('-1.1'); // true35 * isNumber('0'); // true36 * isNumber('012'); // true37 * isNumber('0xff'); // true38 * isNumber('1'); // true39 * isNumber('1.1'); // true40 * isNumber('10'); // true41 * isNumber('10.10'); // true42 * isNumber('100'); // true43 * isNumber('5e3'); // true44 * isNumber(parseInt('012')); // true45 * isNumber(parseFloat('012')); // true46 * isNumber(Infinity); // false47 * isNumber(NaN); // false48 * isNumber(null); // false49 * isNumber(undefined); // false50 * isNumber(''); // false51 * isNumber(' '); // false52 * isNumber('foo'); // false53 * isNumber([1]); // false54 * isNumber([]); // false55 * isNumber(function () {}); // false56 * isNumber({}); // false57 * }58 */59function isNumber(num){60 if (typeof num === 'number') {61 return num - num === 0;62 }63 if (typeof num === 'string' && num.trim() !== '') {64 return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);65 }66 return false;67}6869/**70 * [isOdd å¤ææ¯å¦æ¯åºæ°]71 * @param {[type]} value [description]72 * @return {Boolean} [description]73 * @example74 * {75 * const isOdd = require('is-odd');76 * console.log(isOdd('1')); //=> true77 * console.log(isOdd('3')); //=> true78 * console.log(isOdd(0)); //=> false79 * console.log(isOdd(2)); //=> false80 * }81 */82function isOdd(value) {83 const n = Math.abs(value);84 if (!isNumber(n)) {85 throw new TypeError('expected a number');86 }87 if (!Number.isInteger(n)) {88 throw new Error('expected an integer');89 }90 if (!Number.isSafeInteger(n)) {91 throw new Error('value exceeds maximum safe integer');92 }93 return (n % 2) === 1;94}959697/**98 * [isObj æ£æ¥å¼æ¯å¦ä¸ºå¯¹è±¡]
...
065.valid-number.js
Source:065.valid-number.js
...76 }77 return true78}79write('algorithms: 65. æææ°å', 'title')80write(isNumber('+.8')) // true81write(isNumber('4e+')) // false82write(isNumber(' ')) // false83write(isNumber('.1')) // true84write(isNumber('3.')) // true85write(isNumber('.')) // false86write(isNumber('.e1')) // false87write(isNumber('0')) // true88write(isNumber('0.1')) // true89write(isNumber('abc')) // false90write(isNumber('1 a')) // false91write(isNumber('1 2')) // false92write(isNumber('2e10')) // true93write(isNumber(' -90e3Â Â ')) // true94write(isNumber(' 1e')) // false95write(isNumber('e3')) // false96write(isNumber(' 6e-1')) // true97write(isNumber(' 99e2.5Â ')) // false98write(isNumber('53.5e93')) // true99write(isNumber(' --6 ')) // false100write(isNumber('-+3')) // false101write(isNumber('95a54e53')) // false...
isNumber.test.js
Source:isNumber.test.js
...3import { falsey, args, slice, symbol, realm } from './utils.js';4import isNumber from '../isNumber.js';5describe('isNumber', function() {6 it('should return `true` for numbers', function() {7 assert.strictEqual(isNumber(0), true);8 assert.strictEqual(isNumber(Object(0)), true);9 assert.strictEqual(isNumber(NaN), true);10 });11 it('should return `false` for non-numbers', function() {12 var expected = lodashStable.map(falsey, function(value) {13 return typeof value == 'number';14 });15 var actual = lodashStable.map(falsey, function(value, index) {16 return index ? isNumber(value) : isNumber();17 });18 assert.deepStrictEqual(actual, expected);19 assert.strictEqual(isNumber(args), false);20 assert.strictEqual(isNumber([1, 2, 3]), false);21 assert.strictEqual(isNumber(true), false);22 assert.strictEqual(isNumber(new Date), false);23 assert.strictEqual(isNumber(new Error), false);24 assert.strictEqual(isNumber(_), false);25 assert.strictEqual(isNumber(slice), false);26 assert.strictEqual(isNumber({ 'a': 1 }), false);27 assert.strictEqual(isNumber(/x/), false);28 assert.strictEqual(isNumber('a'), false);29 assert.strictEqual(isNumber(symbol), false);30 });31 it('should work with numbers from another realm', function() {32 if (realm.number) {33 assert.strictEqual(isNumber(realm.number), true);34 }35 });...
index.js
Source:index.js
2var test = require('tape');3var isNumber = require('../');4var hasSymbols = require('has-symbols')();5test('not Numbers', function (t) {6 t.notOk(isNumber(), 'undefined is not Number');7 t.notOk(isNumber(null), 'null is not Number');8 t.notOk(isNumber(false), 'false is not Number');9 t.notOk(isNumber(true), 'true is not Number');10 t.notOk(isNumber('foo'), 'string is not Number');11 t.notOk(isNumber([]), 'array is not Number');12 t.notOk(isNumber({}), 'object is not Number');13 t.notOk(isNumber(function () {}), 'function is not Number');14 t.notOk(isNumber(/a/g), 'regex literal is not Number');15 t.notOk(isNumber(new RegExp('a', 'g')), 'regex object is not Number');16 t.notOk(isNumber(new Date()), 'new Date() is not Number');17 t.end();18});19test('@@toStringTag', { skip: !hasSymbols || !Symbol.toStringTag }, function (t) {20 var fakeNumber = {21 toString: function () { return '7'; },22 valueOf: function () { return 42; }23 };24 fakeNumber[Symbol.toStringTag] = 'Number';25 t.notOk(isNumber(fakeNumber), 'fake Number with @@toStringTag "Number" is not Number');26 t.end();27});28test('Numbers', function (t) {29 t.ok(isNumber(42), 'number is Number');30 t.ok(isNumber(Object(42)), 'number object is Number');31 t.ok(isNumber(NaN), 'NaN is Number');32 t.ok(isNumber(Infinity), 'Infinity is Number');33 t.end();...
is_number.js
Source:is_number.js
1import { module, test } from '../qunit';2import isNumber from '../../lib/utils/is-number.js';3test('isNumber recognizes numbers', function (assert) {4 assert.ok(isNumber(1), 'simple integer');5 assert.ok(isNumber(0), 'simple number');6 assert.ok(isNumber(-0), 'silly number');7 assert.ok(isNumber(1010010293029), 'large number');8 assert.ok(isNumber(Infinity), 'largest number');9 assert.ok(isNumber(-Infinity), 'smallest number');10 assert.ok(isNumber(NaN), 'not number');11 assert.ok(isNumber(1.100393830000), 'decimal numbers');12 assert.ok(isNumber(Math.LN2), 'natural log of two');13 assert.ok(isNumber(Math.PI), 'delicious number');14 assert.ok(isNumber(5e10), 'scientifically notated number');15 assert.ok(isNumber(new Number(1)), 'number primitive wrapped in an object'); // jshint ignore:line16});17test('isNumber rejects non-numbers', function (assert) {18 assert.ok(!isNumber(), 'nothing');19 assert.ok(!isNumber(undefined), 'undefined');20 assert.ok(!isNumber(null), 'null');21 assert.ok(!isNumber([1]), 'array');22 assert.ok(!isNumber('[1,2,3]'), 'string');23 assert.ok(!isNumber(new Date()), 'date');24 assert.ok(!isNumber({a:1,b:2}), 'object');...
crop.js
Source:crop.js
1$(function () {2 'use strict';3 var $image = $(window.createCropperImage());4 function isNumber(n) {5 return typeof n === 'number' && !isNaN(n);6 }7 $image.on('crop.cropper', function (e) {8 QUnit.test('events#crop', function (assert) {9 assert.equal(e.type, 'crop');10 assert.ok(isNumber(e.x));11 assert.ok(isNumber(e.y));12 assert.ok(isNumber(e.width));13 assert.ok(isNumber(e.height));14 assert.ok(isNumber(e.rotate));15 assert.ok(isNumber(e.scaleX));16 assert.ok(isNumber(e.scaleY));17 });18 }).cropper({19 ready: function () {20 var $dragBox = $image.data('cropper').$dragBox;21 // Triggers events manually when ready22 $dragBox.trigger('mousedown').trigger('mousemove').trigger('mouseup');23 },24 crop: function (e) {25 QUnit.test('options#crop', function (assert) {26 assert.equal(e.type, 'crop');27 assert.ok(isNumber(e.x));28 assert.ok(isNumber(e.y));29 assert.ok(isNumber(e.width));30 assert.ok(isNumber(e.height));31 assert.ok(isNumber(e.rotate));32 assert.ok(isNumber(e.scaleX));33 assert.ok(isNumber(e.scaleY));34 });35 }36 });...
Using AI Code Generation
1const { isNumber } = require('jest-extended');2test('isNumber', () => {3 expect(isNumber(3)).toBe(true);4 expect(isNumber(NaN)).toBe(true);5 expect(isNumber(Infinity)).toBe(true);6 expect(isNumber(-Infinity)).toBe(true);7 expect(isNumber(Number.MAX_VALUE)).toBe(true);8 expect(isNumber(Number.MIN_VALUE)).toBe(true);9 expect(isNumber(0)).toBe(true);10 expect(isNumber(3.3)).toBe(true);11 expect(isNumber(new Number(3))).toBe(true);12 expect(isNumber('3')).toBe(false);13 expect(isNumber(true)).toBe(false);14 expect(isNumber(false)).toBe(false);15 expect(isNumber(null)).toBe(false);16 expect(isNumber(undefined)).toBe(false);17 expect(isNumber([])).toBe(false);18 expect(isNumber({})).toBe(false);19 expect(isNumber(() => {})).toBe(false);20});21{22 "scripts": {23 },24 "devDependencies": {25 }26}27Your name to display (optional):
Using AI Code Generation
1const isNumber = require('jest-extended').isNumber;2test('isNumber', () => {3 expect(isNumber(0)).toBe(true);4 expect(isNumber(1)).toBe(true);5 expect(isNumber(Infinity)).toBe(true);6 expect(isNumber(NaN)).toBe(true);7 expect(isNumber(-Infinity)).toBe(true);8 expect(isNumber(1.1)).toBe(true);9 expect(isNumber(1e3)).toBe(true);10 expect(isNumber(1e-3)).toBe(true);11 expect(isNumber(-1.1)).toBe(true);12 expect(isNumber(-1e3)).toBe(true);13 expect(isNumber(-1e-3)).toBe(true);14 expect(isNumber(0xff)).toBe(true);15 expect(isNumber(0o77)).toBe(true);16 expect(isNumber(0b1111)).toBe(true);17 expect(isNumber('0')).toBe(true);18 expect(isNumber('1')).toBe(true);19 expect(isNumber('Infinity')).toBe(true);20 expect(isNumber('NaN')).toBe(true);21 expect(isNumber('-Infinity')).toBe(true);22 expect(isNumber('1.1')).toBe(true);23 expect(isNumber('1e3')).toBe(true);24 expect(isNumber('1e-3')).toBe(true);25 expect(isNumber('-1.1')).toBe(true);26 expect(isNumber('-1e3')).toBe(true);27 expect(isNumber('-1e-3')).toBe(true);28 expect(isNumber('0xff')).toBe(true);29 expect(isNumber('0o77')).toBe(true);30 expect(isNumber('0b1111')).toBe(true);31 expect(isNumber('')).toBe(false);32 expect(isNumber(' ')).toBe(false);33 expect(isNumber('foo')).toBe(false);34 expect(isNumber('true')).toBe(false);35 expect(isNumber('false')).toBe(false);36 expect(isNumber([])).toBe(false);37 expect(isNumber({})).toBe(false);38 expect(isNumber(null)).toBe(false);39 expect(isNumber(undefined)).toBe(false);40 expect(isNumber(false)).toBe(false);41 expect(isNumber(true)).toBe(false);42});43const isString = require('jest-extended').isString;44test('isString', () => {45 expect(isString('')).toBe(true);46 expect(isString('
Using AI Code Generation
1const isNumber = require('jest-extended').isNumber;2test('isNumber', () => {3 expect(isNumber(3)).toBe(true);4 expect(isNumber(NaN)).toBe(false);5 expect(isNumber('3')).toBe(false);6});
Using AI Code Generation
1const { isNumber } = require('jest-extended');2describe('isNumber', () => {3 test('should pass', () => {4 expect(isNumber(1)).toBeTrue();5 });6 test('should fail', () => {7 expect(isNumber('1')).toBeFalse();8 });9});10const { isNumber } = require('jest-extended');11describe('isNumber', () => {12 test('should pass', () => {13 expect(isNumber(1)).toBeTrue();14 });15 test('should fail', () => {16 expect(isNumber('1')).toBeFalse();17 });18});19const { isNumber } = require('jest-extended');20describe('isNumber', () => {21 test('should pass', () => {22 expect(isNumber(1)).toBeTrue();23 });24 test('should fail', () => {25 expect(isNumber('1')).toBeFalse();26 });27});28const { isNumber } = require('jest-extended');29describe('isNumber', () => {30 test('should pass', () => {31 expect(isNumber(1)).toBeTrue();32 });33 test('should fail', () => {34 expect(isNumber('1')).toBeFalse();35 });36});37const { isNumber } = require('jest-extended');38describe('isNumber', () => {39 test('should pass', () => {40 expect(isNumber(1)).toBeTrue();41 });42 test('should fail', () => {43 expect(isNumber('1')).toBeFalse();44 });45});46const { isNumber } = require('jest-extended');47describe('isNumber', () => {48 test('should pass', () => {49 expect(isNumber(1)).toBeTrue();50 });51 test('should fail', () => {52 expect(isNumber('1')).toBeFalse();53 });54});
Using AI Code Generation
1const isNumber = require('jest-extended').isNumber;2describe('isNumber', () => {3 it('should pass', () => {4 expect(isNumber(0)).toBe(true);5 expect(isNumber(1)).toBe(true);6 expect(isNumber(Infinity)).toBe(true);7 expect(isNumber(-Infinity)).toBe(true);8 });9});10{11 "scripts": {12 },13 "dependencies": {14 }15}16This is a guide to isNumber() Method of Jest-Extended. Here we discuss how to use the isNumber() method of jest-extended along with practical examples and downloadable code. You may also have a look at the following articles to learn more –
Using AI Code Generation
1const isNumber = require('jest-extended').isNumber;2test('isNumber', () => {3 expect(isNumber(3)).toBe(true);4});5const { isNumber } = require('jest-extended');6test('isNumber', () => {7 expect(isNumber(3)).toBe(true);8});9const isNumber = require('jest-extended/lib/isNumber');10test('isNumber', () => {11 expect(isNumber(3)).toBe(true);12});13const isNumber = require('jest-extended/dist/isNumber');14test('isNumber', () => {15 expect(isNumber(3)).toBe(true);16});17const isNumber = require('jest-extended/cjs/isNumber');18test('isNumber', () => {19 expect(isNumber(3)).toBe(true);20});21const isNumber = require('jest-extended/umd/isNumber');22test('isNumber', () => {23 expect(isNumber(3)).toBe(true);24});25const isNumber = require('jest-extended/esm/isNumber');26test('isNumber', () => {27 expect(isNumber(3)).toBe(true);28});29const isNumber = require('jest-extended/esm/lib/isNumber');30test('isNumber', () => {31 expect(isNumber(3)).toBe(true);32});33const isNumber = require('jest-extended/esm/dist/isNumber');34test('isNumber', () => {35 expect(isNumber(3)).toBe(true);36});37const isNumber = require('jest-extended/esm/cjs/isNumber');38test('isNumber', () => {39 expect(isNumber(3)).toBe(true);40});
Using AI Code Generation
1const { isNumber } = require('jest-extended');2test('isNumber', () => {3 expect(isNumber(1)).toBe(true);4 expect(isNumber('1')).toBe(false);5});6const { isNumber } = require('jest-extended');7test('isNumber', () => {8 expect(isNumber(1)).toBe(true);9 expect(isNumber('1')).toBe(false);10});11const { isNumber } = require('jest-extended');12test('isNumber', () => {13 expect(isNumber(1)).toBe(true);14 expect(isNumber('1')).toBe(false);15});16const { isNumber } = require('jest-extended');17test('isNumber', () => {18 expect(isNumber(1)).toBe(true);19 expect(isNumber('1')).toBe(false);20});21const { isNumber } = require('jest-extended');22test('isNumber', () => {23 expect(isNumber(1)).toBe(true);24 expect(isNumber('1')).toBe(false);25});26const { isNumber } = require('jest-extended');27test('isNumber', () => {28 expect(isNumber(1)).toBe(true);29 expect(isNumber('1')).toBe(false);30});31const { isNumber } = require('jest-extended');32test('isNumber', () => {33 expect(isNumber(1)).toBe(true);34 expect(isNumber('1')).toBe(false);35});36const { isNumber } = require('jest-extended');37test('isNumber', () => {38 expect(isNumber(1)).toBe(true);39 expect(isNumber('1')).toBe(false);40});41const { isNumber } = require('jest-extended');42test('isNumber', () => {43 expect(isNumber(1)).toBe(true);44 expect(isNumber('1')).toBe(false);45});
Using AI Code Generation
1const {isNumber} = require('jest-extended');2test('Is 10 a number', () => {3 expect(isNumber(10)).toBeTruthy();4});5test('Is 10 a number', () => {6 expect(isNumber('10')).toBeFalsy();7});8test('Is 10 a number', () => {9 expect(isNumber('10')).toBe(false);10});11test('Is 10 a number', () => {12 expect(isNumber('10')).not.toBe(true);13});14test('Is 10 a number', () => {15 expect(isNumber('10')).not.toBeTruthy();16});17test('Is 10 a number', () => {18 expect(isNumber('10')).not.toBeFalsy();19});20test('Is 10 a number', () => {21 expect(isNumber('10')).toBe(false);22});23test('Is 10 a number', () => {24 expect(isNumber('10')).not.toBe(true);25});26test('Is 10 a number', () => {27 expect(isNumber('10')).not.toBeTruthy();28});29test('Is 10 a number', () => {30 expect(isNumber('10')).not.toBeFalsy();31});32test('Is 10 a number', () => {33 expect(isNumber('10')).toBe(false);34});35test('Is 10 a number', () => {36 expect(isNumber('10')).not.toBe(true);37});38test('Is 10 a number', () => {39 expect(isNumber('10')).not.toBeTruthy();40});41test('Is 10 a number', () => {42 expect(isNumber('10')).not.toBeFalsy();43});44test('Is 10 a number', () => {45 expect(isNumber('10')).toBe(false);46});47test('Is 10 a number', () => {48 expect(isNumber('10')).not.toBe(true);49});50test('Is 10 a number', () => {51 expect(isNumber('10')).not.toBeTruthy();52});53test('Is 10 a number', () => {54 expect(isNumber('10')).not.toBeFalsy();55});56test('Is 10 a number', () => {57 expect(isNumber('10')).toBe(false);58});59test('Is 10 a number', () => {60 expect(isNumber('10')).not.toBe(true);61});62test('Is 10 a number', () => {63 expect(isNumber('10')).not.toBeTruthy();64});65test('Is 10 a number', () => {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!