How to use isNumber method in Appium Base Driver

Best JavaScript code snippet using appium-base-driver

Run Appium Base Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

is_number.js

Source: is_number.js Github

copy
1import { module, test } from '../qunit';
2import isNumber from '../../lib/utils/is-number.js';
3
4
5test('isNumber recognizes numbers', function (assert) {
6    assert.ok(isNumber(1), 'simple integer');
7    assert.ok(isNumber(0), 'simple number');
8    assert.ok(isNumber(-0), 'silly number');
9    assert.ok(isNumber(1010010293029), 'large number');
10    assert.ok(isNumber(Infinity), 'largest number');
11    assert.ok(isNumber(-Infinity), 'smallest number');
12    assert.ok(isNumber(NaN), 'not number');
13    assert.ok(isNumber(1.100393830000), 'decimal numbers');
14    assert.ok(isNumber(Math.LN2), 'natural log of two');
15    assert.ok(isNumber(Math.PI), 'delicious number');
16    assert.ok(isNumber(5e10), 'scientifically notated number');
17    assert.ok(isNumber(new Number(1)), 'number primitive wrapped in an object'); // jshint ignore:line
18});
19
20test('isNumber rejects non-numbers', function (assert) {
21    assert.ok(!isNumber(), 'nothing');
22    assert.ok(!isNumber(undefined), 'undefined');
23    assert.ok(!isNumber(null), 'null');
24    assert.ok(!isNumber([1]), 'array');
25    assert.ok(!isNumber('[1,2,3]'), 'string');
26    assert.ok(!isNumber(new Date()), 'date');
27    assert.ok(!isNumber({a:1,b:2}), 'object');
28});
29
Full Screen

handler.js

Source: handler.js Github

copy
1const simple = require('./lib/simple')
2const util = require('util')
3
4const isNumber = x => typeof x === 'number' && !isNaN(x)
5const delay = ms => isNumber(ms) && new Promise(resolve => setTimeout(resolve, ms))
6
7module.exports = {
8    async handler(chatUpdate) {
9        if (global.db.data == null) await loadDatabase()
10        this.msgqueque = this.msgqueque || []
11        // console.log(chatUpdate)
12        if (!chatUpdate) return
13        // if (chatUpdate.messages.length > 2 || !chatUpdate.messages.length) return
14        if (chatUpdate.messages.length > 1) console.log(chatUpdate.messages)
15        let m = chatUpdate.messages[chatUpdate.messages.length - 1]
16        if (!m) return
17        console.log(JSON.stringify(m, null, 4))
18        try {
19            m = simple.smsg(this, m) || m
20            if (!m) return
21            // console.log(m)
22            m.exp = 0
23            m.limit = false
24            try {
25                let user = global.db.data.users[m.sender]
26                if (typeof user !== 'object') global.db.data.users[m.sender] = {}
27                if (user) {
28                    if (!isNumber(user.healt)) user.healt = 100
29                    if (!isNumber(user.title)) user.title = 0
30                    if (!isNumber(user.stamina)) user.stamina = 100
31                    if (!isNumber(user.haus)) user.haus = 100
32                    if (!isNumber(user.laper)) user.laper = 100
33                    if (!isNumber(user.level)) user.level = 0
34                    if (!('pasangan' in user)) user.pasangan = ''
35                    if (!isNumber(user.exp)) user.exp = 0
36                    if (!isNumber(user.pc)) user.pc = 0
37                    if (!isNumber(user.korbanngocok)) user.korbanngocok = 0
38                    if (!isNumber(user.ojekk)) user.ojekk = 0
39                    if (!isNumber(user.trofi)) user.trofi= 0
40                    if (!user.rtrofi) user.rtrofi = 'Perunggu'
41                    if (!isNumber(user.troopcamp)) user.troopcamp = 0
42                    if (!isNumber(user.coin)) user.coin = 0
43                    if (!isNumber(user.atm)) user.atm = 0
44                    if (!isNumber(user.limit)) user.limit = 20
45                    if (!isNumber(user.glimit)) user.glimit = 20
46                    if (!isNumber(user.tprem)) user.tprem = 0
47                    if (!isNumber(user.tigame)) user.tigame = 50
48                    if (!isNumber(user.lastclaim)) user.lastclaim = 0
49                    if (!isNumber(user.money)) user.money = 0
50                    if (!isNumber(user.rumahsakit)) user.rumahsakit= 0
51                    if (!isNumber(user.fortress)) user.fortress = 0
52                    if (!isNumber(user.shield)) user.shield = false
53                    if (!isNumber(user.pertanian)) user.pertanian = 0
54                    if (!isNumber(user.pertambangan)) user.pertambangan = 0
55                    
56                    
57                    if (!isNumber(user.botol)) user.botol = 0
58                    if (!isNumber(user.kardus)) user.kardus = 0
59                    if (!isNumber(user.kaleng)) user.kaleng = 0
60                    if (!isNumber(user.aqua)) user.aqua = 0
61                    if (!isNumber(user.diamond)) user.diamond = 0
62                    if (!isNumber(user.iron)) user.iron = 0
63                    if (!isNumber(user.emas)) user.emas = 0
64                    if (!isNumber(user.arlok)) user.arlok = 0
65        
66                    if (!isNumber(user.common)) user.common = 0
67                    if (!isNumber(user.as)) user.as = 0
68                    if (!isNumber(user.uncommon)) user.uncommon = 0
69                    if (!isNumber(user.mythic)) user.mythic = 0
70                    if (!isNumber(user.legendary)) user.legendary = 0
71                    if (!isNumber(user.glory)) user.glory = 0
72                    if (!isNumber(user.enchant)) user.enchant = 0
73                    if (!isNumber(user.pet)) user.pet = 0
74                    if (!isNumber(user.psepick)) user.psepick = 0
75                    if (!isNumber(user.psenjata)) user.psenjata = 0
76                
77                    if (!isNumber(user.potion)) user.potion = 0
78                    if (!isNumber(user.sampah)) user.sampah = 0
79                    if (!isNumber(user.armor)) user.armor = 0
80                    if (!isNumber(user.pancing)) user.pancing = 0
81                    //penambah stamina
82                    if (!isNumber(user.apel)) user.apel = 0
83                    if (!isNumber(user.ayamb)) user.ayamb = 0
84                    if (!isNumber(user.ayamg)) user.ayamg = 0
85                    if (!isNumber(user.sapir)) user.sapir = 0
86                    if (!isNumber(user.ssapi)) user.ssapi = 0
87                    if (!isNumber(user.esteh)) user.esteh = 0
88                    if (!isNumber(user.leleg)) user.leleg = 0
89                    if (!isNumber(user.leleb)) user.leleb = 0
90                    //tools
91                    if (!isNumber(user.sword)) user.sword = 0
92                    if (!isNumber(user.sworddurability)) user.sworddurability = 0
93                    if (!isNumber(user.pickaxe)) user.pickaxe = 0
94                    if (!isNumber(user.pickaxedurability)) user.pickaxedurability = 0
95                    if (!isNumber(user.fishingrod)) user.fishingrod = 0
96                    if (!isNumber(user.fishingroddurability)) user.fishingroddurability = 0
97                    if (!isNumber(user.umpan)) user.umpan = 0
98                    
99                    if (!isNumber(user.kucing)) user.kucing = 0
100                    if (!isNumber(user.kucinglastclaim)) user.kucinglastclaim = 0
101                    if (!isNumber(user.kuda)) user.kuda = 0
102                    if (!isNumber(user.kudalastclaim)) user.kudalastclaim = 0
103                    if (!isNumber(user.rubah)) user.rubah = 0
104                    if (!isNumber(user.rubahlastclaim)) user.rubahlastclaim = 0
105                    if (!isNumber(user.anjing)) user.anjing = 0
106                    if (!isNumber(user.anjinglastclaim)) user.anjinglastclaim = 0
107                    if (!isNumber(user.serigalalastclaim)) user.serigalalastclaim = 0
108                    if (!isNumber(user.nagalastclaim)) user.nagalastclaim = 0
109                    if (!isNumber(user.phonixlastclaim)) user.phonixlastclaim = 0
110                    if (!isNumber(user.griffinlastclaim)) user.griffinlastclaim = 0
111                    if (!isNumber(user.centaurlastclaim)) user.centaurlastclaim = 0
112                    
113                    if (!isNumber(user.makananpet)) user.makananpet
114                    if (!isNumber(user.makanannaga)) user.makanannaga = 0
115                    if (!isNumber(user.makananphonix)) user.makananphonix = 0
116                    if (!isNumber(user.makanangriffin)) user.makanangriffin = 0
117                    if (!isNumber(user.makananserigala)) user.makananserigala = 0
118                    if (!isNumber(user.makanancentaur)) user.makanancentaur = 0
119        
120                    if (!'Banneduser' in user) user.Banneduser = false
121                    if (!'BannedReason' in user) user.BannedReason = ''
122                    if (!isNumber(user.warn)) user.warn = 0
123        
124                    if (!isNumber(user.afk)) user.afk = -1
125                    if (!'afkReason' in user) user.afkReason = ''
126                
127                //PET
128                    if (!isNumber(user.healthmonster)) user.healthmonster = 0
129                    if (!isNumber(user.anakkucing)) user.anakkucing = 0
130                    if (!isNumber(user.anakkuda)) user.anakkuda = 0
131                    if (!isNumber(user.anakrubah)) user.anakrubah = 0
132                    if (!isNumber(user.anakanjing)) user.anakanjing = 0
133                    if (!isNumber(user.serigala)) user.serigala = 0
134                    if (!isNumber(user.anakserigala)) user.anakserigala = 0
135                    if (!isNumber(user.naga)) user.naga = 0
136                    if (!isNumber(user.anaknaga)) user.anaknaga = 0
137                    if (!isNumber(user.phonix)) user.phonix = 0
138                    if (!isNumber(user.anakphonix)) user.anakphonix = 0
139                    if (!isNumber(user.griffin)) user.griffin = 0
140                    if (!isNumber(user.anakgriffin)) user.anakgriffin = 0
141                    if (!isNumber(user.kyubi)) user.kyubi = 0
142                    if (!isNumber(user.anakkyubi)) user.anakkyubi = 0
143                    if (!isNumber(user.centaur)) user.centaur = 0
144                    if (!isNumber(user.anakcentaur)) user.anakcentaur = 0
145                    if (!isNumber(user.makananpet)) user.makananpet = 0
146        
147                    if (!isNumber(user.antispam)) user.antispam = 0
148                    if (!isNumber(user.antispamlastclaim)) user.antispamlastclaim = 0
149        
150                    if (!isNumber(user.kayu)) user.kayu = 0
151                    if (!('kingdom' in user)) user.kingdom = false
152                    if (!isNumber(user.batu)) user.batu = 0
153                    if (!isNumber(user.ramuan)) user.ramuan = 0
154                    if (!isNumber(user.string)) user.string = 0
155                    if (!isNumber(user.sword)) user.sword = 0
156                    if (!isNumber(user.sworddurability)) user.sworddurability = 0
157                    if (!isNumber(user.pickaxe)) user.pickaxe = 0
158                    if (!isNumber(user.pickaxedurability)) user.pickaxedurability = 0
159                    if (!isNumber(user.fishingrod)) user.fishingrod = 0
160                    if (!isNumber(user.fishingroddurability)) user.fishingroddurability = 0
161        
162                    //mancing
163                    if (!isNumber(user.paus)) user.paus = 0
164             if (!isNumber(user.kepiting)) user.kepiting = 0
165             if (!isNumber(user.gurita)) user.gurita = 0
166             if (!isNumber(user.cumi)) user.cumi= 0
167             if (!isNumber(user.buntal)) user.buntal = 0
168             if (!isNumber(user.dory)) user.dory = 0
169             if (!isNumber(user.lumba)) user.lumba = 0
170             if (!isNumber(user.lobster)) user.lobster = 0
171             if (!isNumber(user.hiu)) user.hiu = 0
172             if (!isNumber(user.udang)) user.udang = 0
173             if (!isNumber(user.ikan)) user.ikan = 0
174             if (!isNumber(user.nila)) user.nila = 0
175             if (!isNumber(user.bawal)) user.bawal = 0
176             if (!isNumber(user.lele)) user.lele = 0
177             if (!isNumber(user.orca)) user.orca = 0
178                
179             if (!isNumber(user.banteng)) user.banteng = 0
180             if (!isNumber(user.harimau)) user.harimau = 0
181             if (!isNumber(user.gajah)) user.gajah = 0
182             if (!isNumber(user.kambing)) user.kambing = 0
183             if (!isNumber(user.panda)) user.panda = 0
184             if (!isNumber(user.buaya)) user.buaya = 0
185             if (!isNumber(user.kerbau)) user.kerbau = 0
186             if (!isNumber(user.sapi)) user.sapi = 0
187             if (!isNumber(user.monyet)) user.monyet = 0
188             if (!isNumber(user.babihutan)) user.babihutan = 0
189             if (!isNumber(user.babi)) user.babi = 0
190             if (!isNumber(user.ayam)) user.ayam = 0
191         
192                    if (!isNumber(user.lastadventure)) user.lastadventure = 0
193                    if (!isNumber(user.lastkill)) user.lastkill = 0
194                    if (!isNumber(user.lastfishing)) user.lastfishing = 0
195                    if (!isNumber(user.lastdungeon)) user.lastdungeon = 0
196                    if (!isNumber(user.lastwar)) user.lastwar = 0
197                    if (!isNumber(user.lastsda)) user.lastsda = 0
198                    if (!isNumber(user.lastberbru)) user.lastberbru = 0
199                    if (!isNumber(user.lastduel)) user.lastduel = 0
200                    if (!isNumber(user.lastjb)) user.lastjb = 0
201                    if (!isNumber(user.lastSetStatus)) user.lastSetStatus = 0
202                    if (!isNumber(user.lastmining)) user.lastmining = 0
203                    if (!isNumber(user.lasthunt)) user.lasthunt = 0
204                    if (!isNumber(user.lastngocok)) user.lastngocok = 0
205                    if (!isNumber(user.lastgift)) user.lastgift = 0
206                    if (!isNumber(user.lastrob)) user.lastrob = 0
207                    if (!isNumber(user.lastngojek)) user.lastngojek = 0
208                    if (!isNumber(user.lastgrab)) user.lastgrab = 0
209                    if (!isNumber(user.lastberkebon)) user.lastberkebon = 0
210                    if (!isNumber(user.lastcodereg)) user.lastcodereg = 0
211                    if (!isNumber(user.lastdagang)) user.lastdagang = 0
212                    if (!isNumber(user.lasthourly)) user.lasthourly = 0
213                    if (!isNumber(user.lastweekly)) user.lastweekly = 0
214                    if (!isNumber(user.lastmonthly)) user.lastmonthly = 0
215                    if (!isNumber(user.lastIstigfar)) user.lastIstigfar = 0
216                    if (!isNumber(user.lastturu)) user.lastturu = 0
217                    if (!isNumber(user.lastseen)) user.lastseen = 0
218                    if (!isNumber(user.lastbansos)) user.lastbansos = 0
219                    if (!isNumber(user.lastrampok)) user.lastrampok = 0
220                    if (!('registered' in user)) user.registered = false
221                    if (!user.registered) {
222                    if (!('name' in user)) user.name = this.getName(m.sender)
223        
224                    if (!isNumber(user.apel)) user.apel = 0
225                    if (!isNumber(user.anggur)) user.anggur = 0
226                    if (!isNumber(user.jeruk)) user.jeruk = 0
227                    if (!isNumber(user.semangka)) user.semangka = 0
228                    if (!isNumber(user.mangga)) user.mangga = 0
229                    if (!isNumber(user.stroberi)) user.stroberi = 0
230                    if (!isNumber(user.pisang)) user.pisang = 0
231                    if (!isNumber(user.kayu)) user.kayu = 0
232                    if (!isNumber(user.emas)) user.emas = 0
233                    if (!isNumber(user.makanan)) user.makanan = 0
234                    if (!isNumber(user.bibitanggur)) user.bibitanggur = 0
235                    if (!isNumber(user.bibitpisang)) user.bibitpisang = 0
236                    if (!isNumber(user.bibitapel)) user.bibitapel = 0
237                    if (!isNumber(user.bibitmangga)) user.bibitmangga = 0
238                    if (!isNumber(user.bibitjeruk)) user.bibitjeruk = 0
239        
240                      
241                        if (!isNumber(user.age)) user.age = -1
242                        if (!isNumber(user.premiumDate)) user.premiumDate = -1
243                        if (!isNumber(user.regTime)) user.regTime = -1
244                        
245        }
246                    if (!isNumber(user.level)) user.level = 0
247                    if (!user.job) user.job = 'Pengangguran'
248                    if (!user.lbars) user.lbars = '[▒▒▒▒▒▒▒▒▒]'
249                    if (!user.premium) user.premium = false
250                    if (!user.premium) user.premiumTime= 0
251                    if (!user.role) user.role = 'Newbie ㋡'
252                    if (!('autolevelup' in user)) user.autolevelup = true
253                    if (!('lastIstigfar' in user)) user.lastIstigfar = true
254                } else global.db.data.users[m.sender] = {
255                    healt: 100,
256                    title: '',
257                    haus: 100,
258                    laper: 100,
259                    tprem: 0,
260                    stamina : 100,
261                    level: 0,
262                    pasangan: '',
263                    pc : 0,
264                    exp: 0,
265                    coin: 0,
266                    atm: 0,
267                    limit: 20,
268                    tigame: 50,
269                    lastclaim: 0,
270                    money: 0,
271                    diamond: 0,
272                    iron: 0,
273                    emas: 0,
274                    common: 0,
275                    uncommon: 0,
276                    mythic: 0,
277                    legendary: 0,
278                    rumahsakit: 0,
279                    fortress: 0,
280                    trofi: 0,
281                    rtrofi: 'perunggu',
282                    makanan: 0,
283                    troopcamp: 0,
284                    shield: 0,
285                    arlok: 0,
286                    ojekk: 0,
287                    korbanngocok: 0,
288                    //mancing
289             as: 0,
290            paus: 0,
291            kepiting: 0,
292            gurita: 0,
293            cumi: 0,
294            buntal: 0,
295            dory: 0,
296            lumba: 0,
297            lobster: 0,
298            hiu: 0,
299            lele: 0,
300            nila: 0,
301            bawal: 0,
302            udang: 0,
303            ikan: 0,
304            orca: 0,
305            banteng: 0,
306            harimau: 0,
307            gajah: 0,
308            kambing: 0,
309            panda: 0,
310            buaya: 0,
311            kerbau : 0,
312            sapi: 0,
313            monyet : 0,
314            babihutan: 0,
315            babi: 0,
316            ayam: 0,
317            apel: 20,
318            ayamb: 0,
319            ayamg: 0,
320            ssapi: 0,
321            sapir: 0,
322            leleb: 0,
323            leleg: 0,
324            esteh: 0,
325                    pet: 0,
326                    potion: 0,
327                    sampah: 0,
328                    armor: 0,
329                    kucing: 0,
330                    kucinglastclaim: 0,
331                    kuda: 0,
332                    kudalastclaim: 0,
333                    rubah: 0,
334                    rubahlastclaim: 0,
335                    anjing: 0,
336                    anjinglastclaim: 0,
337                    naga: 0,
338                    nagalastclaim: 0,
339                    griffin: 0,
340                    griffinlastclaim: 0,
341                    centaur: 0,
342                    centaurlastclaim: 0,
343                    serigala: 0,
344                    serigalalastclaim: 0,
345                    phonix: 0,
346                    phonixlastclaim: 0,
347                    makanannaga: 0,
348                    makananphonix: 0,
349                    makanancentaur: 0,
350                    makananserigala: 0,
351                    
352                    Banneduser: false,
353                    BannedReason: '',
354                    warn: 0,
355                    afk: -1,
356                    afkReason: '',
357                    anakkucing: 0,
358                    anakkuda: 0,
359                    anakrubah: 0,
360                    anakanjing: 0,
361                    makananpet: 0,
362                    antispam: 0,
363                    antispamlastclaim: 0,
364                    kayu: 0,
365                    batu: 0,
366                    string: 0,
367                    umpan: 0,
368                    sword: 0,
369                    sworddurability: 0,
370                    pickaxe: 0,
371                    pickaxedurability: 0,
372                    fishingrod: 0,
373                    fishingroddurability: 0,
374                    lastadventure: 0,
375                    lastkill: 0,
376                    lastfishing: 0,
377                    lastdungeon: 0,
378                    lastduel: 0,
379                    lastmining: 0,
380                    lasthourly: 0,
381                    lasthunt: 0,
382                    lastweekly: 0,
383                    lastmonthly: 0,
384                    lastjb: 0,
385                    lastrob: 0,
386                    lastdaang: 0,
387                    lastngojek: 0,
388                    lastgrab: 0,
389                    lastngocok: 0,
390                    lastturu: 0,
391                    lastseen: 0,
392                    lastSetStatus: 0,
393                    registered: false,
394                    apel: 20,
395                    mangga: 0,
396                    stroberi: 0,
397                    semangka: 0,
398                    jeruk: 0,
399                    semangka: 0,
400                    name: this.getName(m.sender),
401                    age: -1,
402                    regTime: -1,
403                    premium: false, 
404                    premiumTime: 0,
405                    job: 'Pengangguran', 
406                    lbars: '[▒▒▒▒▒▒▒▒▒]', 
407                    role: 'Newbie ㋡', 
408                    registered: false,
409                    name: this.getName(m.sender),
410                    age: -1,
411                    regTime: -1,
412                    autolevelup: true,
413                    lastIstigfar: 0,
414                }
415                let chat = global.db.data.chats[m.chat]
416                if (typeof chat !== 'object') global.db.data.chats[m.chat] = {}
417                if (chat) {
418                    if (!('isBanned' in chat)) chat.isBanned = false
419                    if (!('welcome' in chat)) chat.welcome = true
420                    if (!('detect' in chat)) chat.detect = false
421                    if (!('sWelcome' in chat)) chat.sWelcome = ''
422                    if (!('sBye' in chat)) chat.sBye = ''
423                    if (!('sPromote' in chat)) chat.sPromote = ''
424                    if (!('sDemote' in chat)) chat.sDemote = ''
425                    if (!('delete' in chat)) chat.delete = true
426                    if (!('antiLink' in chat)) chat.antiLink = true
427                    if (!('viewonce' in chat)) chat.viewonce = false
428                    if (!('antiToxic' in chat)) chat.antiToxic = false
429                } else global.db.data.chats[m.chat] = {
430                    isBanned: false,
431                    welcome: true,
432                    detect: false,
433                    sWelcome: '',
434                    sBye: '',
435                    sPromote: '',
436                    sDemote: '',
437                    delete: true,
438                    antiLink: true,
439                    viewonce: false,
440                    antiToxic: true,
441                }
442            } catch (e) {
443                console.error(e)
444            }
445            if (opts['nyimak']) return
446            if (!m.fromMe && opts['self']) return
447            if (opts['pconly'] && m.chat.endsWith('g.us')) return
448            if (opts['gconly'] && !m.chat.endsWith('g.us')) return
449            if (opts['swonly'] && m.chat !== '[email protected]') return
450            if (typeof m.text !== 'string') m.text = ''
451            if (opts['queque'] && m.text) {
452                this.msgqueque.push(m.id || m.key.id)
453                await delay(this.msgqueque.length * 1000)
454            }
455            for (let name in global.plugins) {
456                let plugin = global.plugins[name]
457                if (!plugin) continue
458                if (plugin.disabled) continue
459                if (!plugin.all) continue
460                if (typeof plugin.all !== 'function') continue
461                try {
462                    await plugin.all.call(this, m, chatUpdate)
463                } catch (e) {
464                    if (typeof e === 'string') continue
465                    console.error(e)
466                }
467            }
468            if (m.isBaileys) return
469            m.exp += Math.ceil(Math.random() * 10)
470
471            let usedPrefix
472            let _user = global.db.data && global.db.data.users && global.db.data.users[m.sender]
473
474            let isROwner = [global.conn.user.jid, ...global.owner].map(v => v.replace(/[^0-9]/g, '') + '@s.whatsapp.net').includes(m.sender)
475            let isOwner = isROwner || m.fromMe
476            let isMods = isOwner || global.mods.map(v => v.replace(/[^0-9]/g, '') + '@s.whatsapp.net').includes(m.sender)
477            let isPrems = isROwner || global.prems.map(v => v.replace(/[^0-9]/g, '') + '@s.whatsapp.net').includes(m.sender)
478            let groupMetadata = (m.isGroup ? (conn.chats[m.chat] || {}).metadata : {}) || {}
479            let participants = (m.isGroup ? groupMetadata.participants : []) || []
480            let user = (m.isGroup ? participants.find(u => conn.decodeJid(u.id) === m.sender) : {}) || {} // User Data
481            let bot = (m.isGroup ? participants.find(u => conn.decodeJid(u.id) == this.user.jid) : {}) || {} // Your Data
482            let isAdmin = user && user.admin || false // Is User Admin?
483            let isBotAdmin = bot && bot.admin || false // Are you Admin?
484            for (let name in global.plugins) {
485                let plugin = global.plugins[name]
486                if (!plugin) continue
487                if (plugin.disabled) continue
488                if (!opts['restrict']) if (plugin.tags && plugin.tags.includes('admin')) {
489                    // global.dfail('restrict', m, this)
490                    continue
491                }
492                const str2Regex = str => str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
493                let _prefix = plugin.customPrefix ? plugin.customPrefix : conn.prefix ? conn.prefix : global.prefix
494                let match = (_prefix instanceof RegExp ? // RegExp Mode?
495                    [[_prefix.exec(m.text), _prefix]] :
496                    Array.isArray(_prefix) ? // Array?
497                        _prefix.map(p => {
498                            let re = p instanceof RegExp ? // RegExp in Array?
499                                p :
500                                new RegExp(str2Regex(p))
501                            return [re.exec(m.text), re]
502                        }) :
503                        typeof _prefix === 'string' ? // String?
504                            [[new RegExp(str2Regex(_prefix)).exec(m.text), new RegExp(str2Regex(_prefix))]] :
505                            [[[], new RegExp]]
506                ).find(p => p[1])
507                if (typeof plugin.before === 'function') if (await plugin.before.call(this, m, {
508                    match,
509                    conn: this,
510                    participants,
511                    groupMetadata,
512                    user,
513                    bot,
514                    isROwner,
515                    isOwner,
516                    isAdmin,
517                    isBotAdmin,
518                    isPrems,
519                    chatUpdate,
520                })) continue
521                if (typeof plugin !== 'function') continue
522                if ((usedPrefix = (match[0] || '')[0])) {
523                    let noPrefix = m.text.replace(usedPrefix, '')
524                    let [command, ...args] = noPrefix.trim().split` `.filter(v => v)
525                    args = args || []
526                    let _args = noPrefix.trim().split` `.slice(1)
527                    let text = _args.join` `
528                    command = (command || '').toLowerCase()
529                    let fail = plugin.fail || global.dfail // When failed
530                    let isAccept = plugin.command instanceof RegExp ? // RegExp Mode?
531                        plugin.command.test(command) :
532                        Array.isArray(plugin.command) ? // Array?
533                            plugin.command.some(cmd => cmd instanceof RegExp ? // RegExp in Array?
534                                cmd.test(command) :
535                                cmd === command
536                            ) :
537                            typeof plugin.command === 'string' ? // String?
538                                plugin.command === command :
539                                false
540
541                    if (!isAccept) continue
542                    m.plugin = name
543                    if (m.chat in global.db.data.chats || m.sender in global.db.data.users) {
544                        let chat = global.db.data.chats[m.chat]
545                        let user = global.db.data.users[m.sender]
546                        if (name != 'unbanchat.js' && chat && chat.isBanned) return // Except this
547                        if (name != 'unbanuser.js' && user && user.banned) return
548                    }
549                    if (plugin.rowner && plugin.owner && !(isROwner || isOwner)) { // Both Owner
550                        fail('owner', m, this)
551                        continue
552                    }
553                    if (plugin.rowner && !isROwner) { // Real Owner
554                        fail('rowner', m, this)
555                        continue
556                    }
557                    if (plugin.owner && !isOwner) { // Number Owner
558                        fail('owner', m, this)
559                        continue
560                    }
561                    if (plugin.mods && !isMods) { // Moderator
562                        fail('mods', m, this)
563                        continue
564                    }
565                    if (plugin.premium && !isPrems) { // Premium
566                        fail('premium', m, this)
567                        continue
568                    }
569                    if (plugin.group && !m.isGroup) { // Group Only
570                        fail('group', m, this)
571                        continue
572                    } else if (plugin.botAdmin && !isBotAdmin) { // You Admin
573                        fail('botAdmin', m, this)
574                        continue
575                    } else if (plugin.admin && !isAdmin) { // User Admin
576                        fail('admin', m, this)
577                        continue
578                    }
579                    if (plugin.private && m.isGroup) { // Private Chat Only
580                        fail('private', m, this)
581                        continue
582                    }
583                    if (plugin.register == true && _user.registered == false) { // Butuh daftar?
584                        fail('unreg', m, this)
585                        continue
586                    }
587                    m.isCommand = true
588                    let xp = 'exp' in plugin ? parseInt(plugin.exp) : 17 // XP Earning per command
589                    if (xp > 200) m.reply('Ngecit -_-') // Hehehe
590                    else m.exp += xp
591                    if (!isPrems && plugin.limit && global.db.data.users[m.sender].limit < plugin.limit * 1) {
592                        this.reply(m.chat, `Limit anda habis, silahkan beli melalui *${usedPrefix}buy*`, m)
593                        continue // Limit habis
594                    }
595                    if (plugin.level > _user.level) {
596                        this.reply(m.chat, `diperlukan level ${plugin.level} untuk menggunakan perintah ini. Level kamu ${_user.level}`, m)
597                        continue // If the level has not been reached
598                    }
599                    let extra = {
600                        match,
601                        usedPrefix,
602                        noPrefix,
603                        _args,
604                        args,
605                        command,
606                        text,
607                        conn: this,
608                        participants,
609                        groupMetadata,
610                        user,
611                        bot,
612                        isROwner,
613                        isOwner,
614                        isAdmin,
615                        isBotAdmin,
616                        isPrems,
617                        chatUpdate,
618                    }
619                    try {
620                        await plugin.call(this, m, extra)
621                        if (!isPrems) m.limit = m.limit || plugin.limit || false
622                    } catch (e) {
623                        // Error occured
624                        m.error = e
625                        console.error(e)
626                        if (e) {
627                            let text = util.format(e)
628                            for (let key of Object.values(global.APIKeys))
629                                text = text.replace(new RegExp(key, 'g'), '#HIDDEN#')
630                            m.reply(text)
631                        }
632                    } finally {
633                        // m.reply(util.format(_user))
634                        if (typeof plugin.after === 'function') {
635                            try {
636                                await plugin.after.call(this, m, extra)
637                            } catch (e) {
638                                console.error(e)
639                            }
640                        }
641                        if (m.limit) m.reply(+ m.limit + ' Limit terpakai')
642                    }
643                    break
644                }
645            }
646        } catch (e) {
647            console.error(e)
648        } finally {
649            //console.log(global.db.data.users[m.sender])
650            let user, stats = global.db.data.stats
651            if (m) {
652                if (m.sender && (user = global.db.data.users[m.sender])) {
653                    user.exp += m.exp
654                    user.limit -= m.limit * 1
655                }
656
657                let stat
658                if (m.plugin) {
659                    let now = + new Date
660                    if (m.plugin in stats) {
661                        stat = stats[m.plugin]
662                        if (!isNumber(stat.total)) stat.total = 1
663                        if (!isNumber(stat.success)) stat.success = m.error != null ? 0 : 1
664                        if (!isNumber(stat.last)) stat.last = now
665                        if (!isNumber(stat.lastSuccess)) stat.lastSuccess = m.error != null ? 0 : now
666                    } else stat = stats[m.plugin] = {
667                        total: 1,
668                        success: m.error != null ? 0 : 1,
669                        last: now,
670                        lastSuccess: m.error != null ? 0 : now
671                    }
672                    stat.total += 1
673                    stat.last = now
674                    if (m.error == null) {
675                        stat.success += 1
676                        stat.lastSuccess = now
677                    }
678                }
679            }
680
681            // try {
682            //     require('./lib/print')(m, this)
683            // } catch (e) {
684            //     console.log(m, m.quoted, e)
685            // }
686            if (opts['autoread']) await this.chatRead(m.chat, m.isGroup ? m.sender : undefined, m.id || m.key.id).catch(() => { })
687            let quequeIndex = this.msgqueque.indexOf(m.id || m.key.id)
688            if (opts['queque'] && m.text && quequeIndex !== -1) this.msgqueque.splice(quequeIndex, 1)
689        }
690    },
691    async participantsUpdate({ id, participants, action }) {
692        if (opts['self']) return
693        // if (id in conn.chats) return // First login will spam
694        if (global.isInit) return
695        let chat = global.db.data.chats[id] || {}
696        let fetch = require('node-fetch')
697        let text = ''
698        switch (action) {
699            case 'add':
700            case 'remove':
701                if (chat.welcome) {
702                    let groupMetadata = await this.groupMetadata(id) || (conn.chats[id] || {}).metadata
703                    for (let user of participants) {
704                       let pp = './src/welcome.jpg'
705                        try {
706                            pp = await this.profilePictureUrl(user, 'image')
707                        } catch (e) {
708                        } finally {
709                            text = (action === 'add' ? (chat.sWelcome || this.welcome || conn.welcome || 'Yah,si Beban Masuk Grup').replace('@subject', groupMetadata.subject).replace('@desc', groupMetadata.desc.toString()) :
710                                (chat.sBye || this.bye || conn.bye || 'Sip, Beban Berkurang 1'))
711                                this.sendButtonLoc(id, await(await fetch(pp)).buffer(), text, '', "ok", "huuu", null)
712                                }
713                    }
714                }
715                break
716            case 'promote':
717                text = (chat.sPromote || this.spromote || conn.spromote || '@user ```is now Admin```')
718            case 'demote':
719                if (!text) text = (chat.sDemote || this.sdemote || conn.sdemote || '@user ```is no longer Admin```')
720                text = text.replace('@user', '@' + participants[0].split('@')[0])
721                if (chat.detect) this.sendMessage(id, text, MessageType.extendedText, {
722                    contextInfo: {
723                        mentionedJid: this.parseMention(text)
724                    }
725                })
726                break
727        }
728    },
729    async delete({ remoteJid, fromMe, id, participant }) {
730        if (fromMe) return
731        let chats = Object.entries(conn.chats).find(([user, data]) => data.messages && data.messages[id])
732        if (!chats) return
733        let msg = JSON.parse(chats[1].messages[id])
734        let chat = global.db.data.chats[msg.key.remoteJid] || {}
735        if (chat.delete) return
736        await this.reply(msg.key.remoteJid, `
737Terdeteksi @${participant.split`@`[0]} telah menghapus pesan
738Untuk mematikan fitur ini, ketik
739*.enable delete*
740`.trim(), msg, {
741            mentions: [participant]
742        })
743        this.copyNForward(msg.key.remoteJid, msg).catch(e => console.log(e, msg))
744    }
745}
746
747global.dfail = (type, m, conn) => {
748    let msg = {
749        rowner: 'Perintah ini hanya dapat digunakan oleh _*OWWNER!1!1!*_',
750        owner: 'Perintah ini hanya dapat digunakan oleh _*Owner Bot*_!',
751        mods: 'Perintah ini hanya dapat digunakan oleh _*Moderator*_ !',
752        premium: 'Perintah ini hanya untuk member _*Premium*_ !',
753        group: 'Perintah ini hanya dapat digunakan di grup!',
754        private: 'Perintah ini hanya dapat digunakan di Chat Pribadi!',
755        admin: 'Perintah ini hanya untuk *Admin* grup!',
756        botAdmin: 'Jadikan bot sebagai *Admin* untuk menggunakan perintah ini!',
757        unreg: 'Silahkan daftar untuk menggunakan fitur ini dengan cara mengetik:\n\n*#daftar nama.umur*\n\nContoh: *#daftar Manusia.16*',
758        restrict: 'Fitur ini di *disable*!'
759    }[type]
760    if (msg) return m.reply(msg)
761}
762
763let fs = require('fs')
764let chalk = require('chalk')
765let file = require.resolve(__filename)
766fs.watchFile(file, () => {
767    fs.unwatchFile(file)
768    console.log(chalk.redBright("Update 'handler.js'"))
769    delete require.cache[file]
770    if (global.reloadHandler) console.log(global.reloadHandler())
771})
772
Full Screen

isNumber.test.js

Source: isNumber.test.js Github

copy
1import assert from 'assert';
2import lodashStable from 'lodash';
3import { falsey, args, slice, symbol, realm } from './utils.js';
4import isNumber from '../isNumber.js';
5
6describe('isNumber', function() {
7  it('should return `true` for numbers', function() {
8    assert.strictEqual(isNumber(0), true);
9    assert.strictEqual(isNumber(Object(0)), true);
10    assert.strictEqual(isNumber(NaN), true);
11  });
12
13  it('should return `false` for non-numbers', function() {
14    var expected = lodashStable.map(falsey, function(value) {
15      return typeof value == 'number';
16    });
17
18    var actual = lodashStable.map(falsey, function(value, index) {
19      return index ? isNumber(value) : isNumber();
20    });
21
22    assert.deepStrictEqual(actual, expected);
23
24    assert.strictEqual(isNumber(args), false);
25    assert.strictEqual(isNumber([1, 2, 3]), false);
26    assert.strictEqual(isNumber(true), false);
27    assert.strictEqual(isNumber(new Date), false);
28    assert.strictEqual(isNumber(new Error), false);
29    assert.strictEqual(isNumber(_), false);
30    assert.strictEqual(isNumber(slice), false);
31    assert.strictEqual(isNumber({ 'a': 1 }), false);
32    assert.strictEqual(isNumber(/x/), false);
33    assert.strictEqual(isNumber('a'), false);
34    assert.strictEqual(isNumber(symbol), false);
35  });
36
37  it('should work with numbers from another realm', function() {
38    if (realm.number) {
39      assert.strictEqual(isNumber(realm.number), true);
40    }
41  });
42});
43
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium Base Driver on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)