handler.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. import { smsg } from './lib/simple.js'
  2. import { format } from 'util'
  3. import { fileURLToPath } from 'url'
  4. import path, { join } from 'path'
  5. import { unwatchFile, watchFile } from 'fs'
  6. import chalk from 'chalk'
  7. import fetch from 'node-fetch'
  8. import ws from 'ws';
  9. import { tr, translateText } from './lib/_checkLang.js';
  10. /**
  11. * @type {import('@whiskeysockets/baileys')}
  12. */
  13. const { proto } = (await import('@whiskeysockets/baileys')).default
  14. const isNumber = x => typeof x === 'number' && !isNaN(x)
  15. const delay = ms => isNumber(ms) && new Promise(resolve => setTimeout(function () {
  16. clearTimeout(this)
  17. resolve()
  18. }, ms))
  19. /**
  20. * Handle messages upsert
  21. * @param {import('@whiskeysockets/baileys').BaileysEventMap<unknown>['messages.upsert']} groupsUpdate
  22. */
  23. export async function handler(chatUpdate) {
  24. this.msgqueque = this.msgqueque || [];
  25. this.uptime = this.uptime || Date.now();
  26. if (!chatUpdate) return
  27. this.pushMessage(chatUpdate.messages).catch(console.error)
  28. let m = chatUpdate.messages[chatUpdate.messages.length - 1]
  29. if (!m) return
  30. if (global.db.data == null)
  31. await global.loadDatabase()
  32. try {
  33. m = smsg(this, m) || m
  34. global.currentMessageContext = m;
  35. if (!m) return
  36. m.exp = 0
  37. m.limit = false
  38. m.money = false
  39. try {
  40. let user = global.db.data.users[m.sender]
  41. if (typeof user !== 'object')
  42. global.db.data.users[m.sender] = {}
  43. if (user) {
  44. if (!isNumber(user.exp)) user.exp = 0;
  45. if (user.exp < 0) user.exp = 0;
  46. if (!isNumber(user.money)) user.money = 10;
  47. if (user.money < 0) user.money = 0;
  48. if (!isNumber(user.limit)) user.limit = 8;
  49. if (user.limit < 0) user.limit = 0;
  50. if (!('premium' in user)) user.premium = false;
  51. if (!('registered' in user)) user.registered = false;
  52. if (!user.registered) {
  53. if (!('name' in user)) user.name = m.name;
  54. if (!isNumber(user.age)) user.age = -1;
  55. if (!isNumber(user.premiumDate)) user.premiumDate = -1;
  56. if (!isNumber(user.regTime)) user.regTime = -1;
  57. }
  58. if (!isNumber(user.afk)) user.afk = -1;
  59. if (!('autolevelup' in user)) user.autolevelup = true;
  60. if (!('role' in user)) user.role = 'Novato';
  61. if (!isNumber(user.level)) user.level = 0;
  62. if (!('language' in user)) user.language = 'es'
  63. if (!user.gender) user.gender = null
  64. if (!user.birthday) user.birthday = null
  65. if (!isNumber(user.antispam)) user.antispam = 0;
  66. if (!isNumber(user.banco)) user.banco = 0
  67. if (!user.premium) user.premium = false;
  68. if (!user.warnPv) user.warnPv = false
  69. if (!user.premium) user.premiumTime = 0;
  70. if (!user.marry) user.marry = 0;
  71. if (!user.wait) user.wait = 0;
  72. if (!user.lastmiming) user.lastmiming = 0;
  73. if (!user.lastwork) user.lastwork = 0;
  74. if (!user.lastcofre) user.lastcofre = 0;
  75. if (!user.lastclaim) user.lastclaim = 0;
  76. if (!user.messageSpam) user.messageSpam = 0;
  77. if (!user.crime) user.crime = 0;
  78. if (!user.lastrob) user.lastrob = 0;
  79. if (!user.packname) user.packname = null
  80. if (!user.author) user.author = null
  81. if (!user.timeRy) user.timeRy = 0;
  82. if (!user.timevot) user.timevot = 0;
  83. if (!user.mensaje) user.mensaje = 0;
  84. if (!user.rtrofi) user.rtrofi = 'Bronce';
  85. } else
  86. global.db.data.users[m.sender] = {
  87. exp: 0,
  88. money: 10,
  89. limit: 8,
  90. registered: false,
  91. premium: false,
  92. regTime: -1,
  93. premiumTime: 0,
  94. role: 'Novato',
  95. autolevelup: true,
  96. banned: false,
  97. language: 'es',
  98. gender: null,
  99. birthday: null,
  100. afk: -1,
  101. afkReason: '',
  102. lastwork: 0,
  103. messageSpam: 0,
  104. lastclaim: 0,
  105. level: 0,
  106. wait: 0,
  107. age: -1,
  108. marry: 0,
  109. bank: 0,
  110. BannedReason: '',
  111. Banneduser: false,
  112. warnPv: false,
  113. packname: null,
  114. author: null,
  115. banco: 0,
  116. timeRy: 0,
  117. lastmiming: 0,
  118. lastcofre: 0,
  119. crime: 0,
  120. lastrob: 0,
  121. timevot: 0,
  122. rtrofi: 'bronce',
  123. mensaje: 0,
  124. }
  125. let chat = global.db.data.chats[m.chat]
  126. if (typeof chat !== 'object')
  127. global.db.data.chats[m.chat] = {}
  128. if (chat) {
  129. if (!('sAutorespond' in chat)) chat.sAutorespond = ''
  130. if (!('isBanned' in chat)) chat.isBanned = false
  131. if (!('welcome' in chat)) chat.welcome = true
  132. if (!('detect' in chat)) chat.detect = true
  133. if (!('sWelcome' in chat)) chat.sWelcome = ''
  134. if (!('sBye' in chat)) chat.sBye = ''
  135. if (!('sPromote' in chat)) chat.sPromote = ''
  136. if (!('sDemote' in chat)) chat.sDemote = ''
  137. if (!('delete' in chat)) chat.delete = false
  138. if (!('modohorny' in chat)) chat.modohorny = true
  139. if (!('stickers' in chat)) chat.stickers = false
  140. if (!('autosticker' in chat)) chat.autosticker = false
  141. if (!('audios' in chat)) chat.audios = false
  142. if (!('antiLink' in chat)) chat.antiLink = false
  143. if (!('antiLink2' in chat)) chat.antiLink2 = false
  144. if (!('antiTiktok' in chat)) chat.antiTiktok = false
  145. if (!('antiYoutube' in chat)) chat.antiYoutube = false
  146. if (!('antiTelegram' in chat)) chat.antiTelegram = false
  147. if (!('antiFacebook' in chat)) chat.antiFacebook = false
  148. if (!('antiInstagram' in chat)) chat.antiInstagram = false
  149. if (!('antiTwitter' in chat)) chat.antiTwitter = false
  150. if (!('antiDiscord' in chat)) chat.antiDiscord = false
  151. if (!('antiThreads' in chat)) chat.antiThreads = false
  152. if (!('antiTwitch' in chat)) chat.antiTwitch = false
  153. if (!('antifake' in chat)) chat.antifake = false
  154. if (!('reaction' in chat)) chat.reaction = true
  155. if (!('modoadmin' in chat)) chat.modoadmin = false
  156. if (!('game' in chat)) chat.game = true
  157. if (!('game2' in chat)) chat.game2 = false
  158. if (!('simi' in chat)) chat.simi = false
  159. if (!('antiTraba' in chat)) chat.antiTraba = true
  160. if (!('primaryBot' in chat)) chat.primaryBot = null
  161. if (!('autorespond' in chat)) chat.autorespond = true
  162. if (!('autolevelup' in chat)) chat.autolevelup = true
  163. if (!isNumber(chat.expired)) chat.expired = 0
  164. if (!('horarioNsfw' in chat)) {
  165. chat.horarioNsfw = {
  166. inicio: "00:00",
  167. fin: "23:59"
  168. };
  169. }
  170. } else
  171. global.db.data.chats[m.chat] = {
  172. isBanned: false,
  173. welcome: true,
  174. detect: true,
  175. sWelcome: '',
  176. sBye: '',
  177. sPromote: '',
  178. sDemote: '',
  179. sAutorespond: '',
  180. delete: false,
  181. modohorny: true,
  182. stickers: false,
  183. autosticker: false,
  184. audios: false,
  185. antiLink: false,
  186. antiLink2: false,
  187. antiTiktok: false,
  188. antiYoutube: false,
  189. antiTelegram: false,
  190. antiFacebook: false,
  191. antiInstagram: false,
  192. antiTwitter: false,
  193. antiDiscord: false,
  194. antiThreads: false,
  195. antiTwitch: false,
  196. antifake: false,
  197. reaction: true,
  198. modoadmin: false,
  199. antitoxic: false,
  200. game: true,
  201. game2: false,
  202. simi: false,
  203. primaryBot: null,
  204. antiTraba: true,
  205. autorespond: true,
  206. autolevelup: true,
  207. expired: 0,
  208. horarioNsfw: {
  209. inicio: "00:00",
  210. fin: "23:59"
  211. }
  212. }
  213. var settings = global.db.data.settings[this.user.jid]
  214. if (typeof settings !== 'object') global.db.data.settings[this.user.jid] = {}
  215. if (settings) {
  216. if (!('self' in settings)) settings.self = false
  217. if (!('autoread' in settings)) settings.autoread = false
  218. if (!('autoread2' in settings)) settings.autoread2 = false
  219. if (!('restrict' in settings)) settings.restrict = true
  220. if (!('temporal' in settings)) settings.temporal = false
  221. if (!('antiPrivate' in settings)) settings.antiPrivate = false
  222. if (!('antiCall' in settings)) settings.antiCall = true
  223. if (!('antiSpam' in settings)) settings.antiSpam = true
  224. if (!('modoia' in settings)) settings.modoia = false
  225. if (!('anticommand' in settings)) settings.anticommand = false
  226. if (!('jadibotmd' in settings)) settings.jadibotmd = true
  227. if (!('prefix' in settings)) settings.prefix = opts['prefix'] || '*/i!#$%+£¢€¥^°=¶∆×÷π√✓©®&.\\-.@';
  228. if (!('status' in settings)) settings.status = 0
  229. } else global.db.data.settings[this.user.jid] = {
  230. self: false,
  231. autoread: false,
  232. autoread2: false,
  233. restrict: true,
  234. temporal: false,
  235. antiPrivate: false,
  236. antiCall: true,
  237. antiSpam: true,
  238. modoia: false,
  239. anticommand: false,
  240. jadibotmd: true,
  241. prefix: opts['prefix'] || '*/i!#$%+£¢€¥^°=¶∆×÷π√✓©®&.\\-.@',
  242. status: 0
  243. }} catch (e) {
  244. console.error(e)
  245. }
  246. var settings = global.db.data.settings[this.user.jid];
  247. let prefix;
  248. const defaultPrefix = '*/i!#$%+£¢€¥^°=¶∆×÷π√✓©®&.\\-.@';
  249. if (settings.prefix) {
  250. if (settings.prefix.includes(',')) {
  251. const prefixes = settings.prefix.split(',').map(p => p.trim());
  252. prefix = new RegExp('^(' + prefixes.map(p => p.replace(/[|\\{}()[\]^$+*.\-\^]/g, '\\$&')).join('|') + ')');
  253. } else if (settings.prefix === defaultPrefix) {
  254. prefix = new RegExp('^[' + settings.prefix.replace(/[|\\{}()[\]^$+*.\-\^]/g, '\\$&') + ']');
  255. } else {
  256. prefix = new RegExp('^' + settings.prefix.replace(/[|\\{}()[\]^$+*.\-\^]/g, '\\$&'));
  257. }} else {
  258. prefix = new RegExp('');
  259. }
  260. const isROwner = [conn.decodeJid(global.conn.user.id), ...global.owner.map(([number]) => number)].map(v => v.replace(/[^0-9]/g, '') + '@s.whatsapp.net').includes(m.sender)
  261. const isOwner = isROwner || m.fromMe
  262. const isMods = isOwner || global.mods.map(v => v.replace(/[^0-9]/g, '') + '@s.whatsapp.net').includes(m.sender)
  263. //const isPrems = isROwner || global.prems.map(v => v.replace(/[^0-9]/g, '') + '@s.whatsapp.net').includes(m.sender)
  264. const isPrems = isROwner || global.db.data.users[m.sender].premiumTime > 0
  265. if (opts['queque'] && m.text && !(isMods || isPrems)) {
  266. let queque = this.msgqueque, time = 1000 * 5
  267. const previousID = queque[queque.length - 1]
  268. queque.push(m.id || m.key.id)
  269. setInterval(async function () {
  270. if (queque.indexOf(previousID) === -1) clearInterval(this)
  271. await delay(time)
  272. }, time)
  273. }
  274. //if(m.id.startsWith('NJX-') || m.id.startsWith('BAE5') && m.id.length === 16 || m.id.startsWith('3EB0') && m.id.length === 12 || m.id.startsWith('3EB0') && (m.id.length === 20 || m.id.length === 22) || m.id.startsWith('B24E') && m.id.length === 20 || m.id.startsWith('FizzxyTheGreat-')) return
  275. if(m.id.startsWith('NJX-') || m.id.startsWith('Lyru-') || m.id.startsWith('EvoGlobalBot-') || m.id.startsWith('BAE5') && m.id.length === 16 || m.id.startsWith('3EB0') && m.id.length === 12 || m.id.startsWith('3EB0') && (m.id.length === 20 || m.id.length === 22) || m.id.startsWith('B24E') || m.id.startsWith('8SCO') && m.id.length === 20 || m.id.startsWith('FizzxyTheGreat-')) return
  276. if (opts['nyimak']) return
  277. if (!isROwner && opts['self']) return
  278. if (opts['pconly'] && m.chat.endsWith('g.us')) return
  279. if (opts['gconly'] && !m.chat.endsWith('g.us')) return
  280. if (opts['swonly'] && m.chat !== 'status@broadcast') return
  281. if (typeof m.text !== 'string')
  282. m.text = ''
  283. //if (m.isBaileys) return
  284. let _user = global.db.data && global.db.data.users && global.db.data.users[m.sender]
  285. //m.exp += Math.ceil(Math.random() * 10)
  286. let usedPrefix
  287. const groupMetadata = (m.isGroup ? ((conn.chats[m.chat] || {}).metadata || await this.groupMetadata(m.chat).catch(_ => null)) : {}) || {}
  288. const participants = (m.isGroup ? groupMetadata.participants : []) || []
  289. const user = (m.isGroup ? participants.find(u => conn.decodeJid(u.id) === m.sender) : {}) || {} // User Data
  290. const bot = (m.isGroup ? participants.find(u => conn.decodeJid(u.id) == this.user.jid) : {}) || {} // Your Data
  291. const isRAdmin = user?.admin == 'superadmin' || false
  292. const isAdmin = isRAdmin || user?.admin == 'admin' || false // Is User Admin?
  293. const isBotAdmin = bot?.admin || false // Are you Admin?
  294. m.isWABusiness = global.conn.authState?.creds?.platform === 'smba' || global.conn.authState?.creds?.platform === 'smbi'
  295. //m.isChannel = m.chat.includes('@newsletter') || m.sender.includes('@newsletter')
  296. const ___dirname = path.join(path.dirname(fileURLToPath(import.meta.url)), './plugins')
  297. for (let name in global.plugins) {
  298. let plugin = global.plugins[name]
  299. if (!plugin) continue
  300. if (plugin.disabled) continue
  301. const __filename = join(___dirname, name)
  302. if (typeof plugin.all === 'function') {
  303. try {
  304. await plugin.all.call(this, m, { chatUpdate, __dirname: ___dirname, __filename })
  305. } catch (e) {
  306. // if (typeof e === 'string') continue
  307. console.error(e)
  308. /*for (let [jid] of global.owner.filter(([number, _, isDeveloper]) => isDeveloper && number)) {
  309. let data = (await conn.onWhatsApp(jid))[0] || {}
  310. if (data.exists)
  311. m.reply(`*Plugin:* ${name}\n*Sender:* ${m.sender}\n*Chat:* ${m.chat}\n*Command:* ${m.text}\n\n${format(e)}.trim(), data.jid)
  312. }*/
  313. }}
  314. if (!opts['restrict'])
  315. if (plugin.tags && plugin.tags.includes('admin')) {
  316. //global.dfail('restrict', m, this)
  317. continue
  318. }
  319. const str2Regex = str => str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
  320. let _prefix = plugin.customPrefix ? plugin.customPrefix : this.prefix ? this.prefix : prefix; // Usamos prefix local
  321. let match = (_prefix instanceof RegExp ?
  322. [[_prefix.exec(m.text), _prefix]] :
  323. Array.isArray(_prefix) ?
  324. _prefix.map(p => {
  325. let re = p instanceof RegExp ? p : new RegExp(str2Regex(p));
  326. return [re.exec(m.text), re];
  327. }) :
  328. typeof _prefix === 'string' ?
  329. [[new RegExp(str2Regex(_prefix)).exec(m.text), new RegExp(str2Regex(_prefix))]] :
  330. [[[], new RegExp]]
  331. ).find(p => p[1]);
  332. if (typeof plugin.before === 'function') {
  333. if (await plugin.before.call(this, m, {
  334. match,
  335. conn: this,
  336. participants,
  337. groupMetadata,
  338. user,
  339. bot,
  340. isROwner,
  341. isOwner,
  342. isRAdmin,
  343. isAdmin,
  344. isBotAdmin,
  345. isPrems,
  346. chatUpdate,
  347. __dirname: ___dirname,
  348. __filename
  349. })) continue;
  350. }
  351. if (typeof plugin !== 'function') continue;
  352. if ((usedPrefix = (match[0] || '')[0])) {
  353. let noPrefix = m.text.replace(usedPrefix, '');
  354. let [command, ...args] = noPrefix.trim().split` `.filter(v => v);
  355. args = args || [];
  356. let _args = noPrefix.trim().split` `.slice(1);
  357. let text = _args.join` `;
  358. command = (command || '').toLowerCase();
  359. let fail = plugin.fail || global.dfail;
  360. let isAccept = plugin.command instanceof RegExp ?
  361. plugin.command.test(command) :
  362. Array.isArray(plugin.command) ?
  363. plugin.command.some(cmd => cmd instanceof RegExp ? cmd.test(command) : cmd === command) :
  364. typeof plugin.command === 'string' ?
  365. plugin.command === command :
  366. false;
  367. if (!isAccept) continue;
  368. m.plugin = name;
  369. if (m.chat in global.db.data.chats || m.sender in global.db.data.users) {
  370. let chat = global.db.data.chats[m.chat]
  371. let user = global.db.data.users[m.sender]
  372. if (!['owner-unbanchat.js'].includes(name) && chat && chat.isBanned && !isROwner) return // Except this
  373. if (name != 'owner-unbanchat.js' && name != 'owner-exec.js' && name != 'owner-exec2.js' && name != 'tool-delete.js' && chat?.isBanned && !isROwner) return
  374. if (m.text && user.banned && !isROwner) {
  375. if (user.antispam > 2) return
  376. m.reply(`⚠️ ${await tr("ESTAS BANEADO")} ⚠️\n*• ${await tr("Motivo")}:* ${user.messageSpam === 0 ? 'Spam' : user.messageSpam}\n*👉🏻 ${await tr("Puedes contactar al propietario del Bot si crees que se trata de un error o para charlar sobre tu desbaneo")}*\n\n👉 ${fb}`)
  377. user.antispam++
  378. return
  379. }
  380. /*if (settings.antiPrivate && !m.isGroup && !m.fromMe) {
  381. let user = global.db.data.users[m.sender] || {};
  382. if (user.warnPv && !m.text.includes('code')) {
  383. console.log(`[AntiPrivate]`);
  384. return;
  385. }
  386. if (!user.warnPv) {
  387. m.reply(`Hola esta prohibido usar los comando al privado del bot...\n\n> _*Para usar mi funciones unirte al grupo oficial 👇*_\n${[nnn, nnnttt, nnnt].getRandom()}`);
  388. user.warnPv = true;
  389. global.db.data.users[m.sender] = user;
  390. return;
  391. }}
  392. */
  393. //Antispam2
  394. if (user.antispam2 && isROwner) return
  395. let time = global.db.data.users[m.sender].spam + 3000
  396. if (new Date - global.db.data.users[m.sender].spam < 3000) return console.log(`[ SPAM ]`)
  397. global.db.data.users[m.sender].spam = new Date * 1
  398. }
  399. const hl = _prefix;
  400. const adminMode = global.db.data.chats[m.chat].modoadmin;
  401. const lolibott = `${plugin.botAdmin || plugin.admin || plugin.group || plugin || noPrefix || hl || m.text.slice(0, 1) == hl || plugin.command}`;
  402. if (adminMode && !isOwner && !isROwner && m.isGroup && !isAdmin && lolibott) return;
  403. if (plugin.rowner && plugin.owner && !(isROwner || isOwner)) { // Both Owner
  404. fail('owner', m, this)
  405. continue
  406. }
  407. if (plugin.rowner && !isROwner) { // Real Owner
  408. fail('rowner', m, this)
  409. continue
  410. }
  411. if (plugin.owner && !isOwner) { // Number Owner
  412. fail('owner', m, this)
  413. continue
  414. }
  415. if (plugin.mods && !isMods) { // Moderator
  416. fail('mods', m, this)
  417. continue
  418. }
  419. if (plugin.premium && !isPrems) { // Usuarios Premium
  420. fail('premium', m, this)
  421. continue
  422. }
  423. if (plugin.group && !m.isGroup) { // Group Only
  424. fail('group', m, this)
  425. continue
  426. } else if (plugin.botAdmin && !isBotAdmin) { // You Admin
  427. fail('botAdmin', m, this)
  428. continue
  429. } else if (plugin.admin && !isAdmin) { // User Admin
  430. fail('admin', m, this)
  431. continue
  432. }
  433. if (plugin.private && m.isGroup) { // Private Chat Only
  434. fail('private', m, this)
  435. continue
  436. }
  437. if (plugin.register == true && _user.registered == false) { // Butuh daftar?
  438. fail('unreg', m, this)
  439. continue
  440. }
  441. m.isCommand = true
  442. /*let xp = 'exp' in plugin ? parseInt(plugin.exp) : 1 // Ganancia de XP por comando
  443. if (xp > 9000) m.reply('chirrido -_-') //
  444. else
  445. m.exp += xp*/
  446. if (!isPrems && plugin.limit && global.db.data.users[m.sender].limit < plugin.limit * 1) {
  447. m.reply(`*⚠ ${await tr("Sus diamante")} 💎 ${await tr("Se han agotado puede comprar mas usando el comando:")}:* #buy`)
  448. //conn.sendMessage(m.chat, {text: `*⚠ 𝐒𝐮𝐬 𝐝𝐢𝐚𝐦𝐚𝐧𝐭𝐞 💎 𝐬𝐞 𝐡𝐚𝐧 𝐚𝐠𝐨𝐭𝐚𝐝𝐨 𝐩𝐮𝐞𝐝𝐞 𝐜𝐨𝐦𝐩𝐫𝐚𝐫 𝐦𝐚𝐬 𝐮𝐬𝐚𝐧𝐝𝐨 𝐞𝐥 𝐜𝐨𝐦𝐚𝐧𝐝𝐨:* #buy`, contextInfo: {externalAdReply : {mediaUrl: null, mediaType: 1, description: null, "title": wm, body: '', previewType: 0, "thumbnail": img.getRandom(), sourceUrl: [nna, nna2, md, yt, nnn, nnnt, nnnttt, tiktok].getRandom()}}}, { quoted: m })
  449. continue
  450. }
  451. if (plugin.level > _user.level) {
  452. m.reply(`*⚠️ ${await tr("Necesita el nivel")} ${plugin.level} ${await tr("para poder usar este comando, Tu nivel actual es:")}* ${_user.level}`)
  453. //conn.sendMessage(m.chat, {text: `*⚠️𝐍𝐞𝐜𝐞𝐬𝐢𝐭𝐚 𝐞𝐥 𝐧𝐢𝐯𝐞𝐥 ${plugin.level} 𝐩𝐚𝐫𝐚 𝐩𝐨𝐝𝐞𝐫 𝐮𝐬𝐚𝐫 𝐞𝐬𝐭𝐞 𝐜𝐨𝐦𝐚𝐧𝐝𝐨, 𝐓𝐮 𝐧𝐢𝐯𝐞𝐥 𝐚𝐜𝐭𝐮𝐚𝐥 𝐞𝐬:* ${_user.level}`, contextInfo: {externalAdReply : {mediaUrl: null, mediaType: 1, description: null, "title": wm, body: '', previewType: 0, "thumbnail": img.getRandom(), sourceUrl: [nna, nna2, md, yt, nnn, nnnt, nnnttt, tiktok].getRandom()}}}, { quoted: m })
  454. continue // Si no se ha alcanzado el nivel
  455. }
  456. let extra = {match, usedPrefix, noPrefix, _args, args, command, text, conn: this, participants, groupMetadata, user, bot, isROwner, isOwner, isRAdmin, isAdmin, isBotAdmin, isPrems, chatUpdate, __dirname: ___dirname, __filename }
  457. try {
  458. await plugin.call(this, m, extra)
  459. if (!isPrems)
  460. m.limit = m.limit || plugin.limit || false
  461. } catch (e) {
  462. // Error occured
  463. m.error = e
  464. console.error(e)
  465. if (e) {
  466. let text = format(e) || 'Error desconocido';
  467. for (let api in global.APIs) {
  468. let key = global.APIs[api].key;
  469. if (key) text = text.replace(new RegExp(key, 'g'), '#HIDDEN#');
  470. }
  471. m.reply(text);
  472. }
  473. /*if (e) {
  474. let text = format(e)
  475. for (let key of Object.values(global.APIs))
  476. text = text.replace(new RegExp(key, 'g'), '#HIDDEN#')
  477. m.reply(text)
  478. }*/
  479. } finally {
  480. // m.reply(util.format(_user))
  481. if (typeof plugin.after === 'function') {
  482. try {
  483. await plugin.after.call(this, m, extra)
  484. } catch (e) {
  485. console.error(e)
  486. }}
  487. if (m.limit) m.reply(`*${+m.limit}* ${await tr("diamante")} 💎 ${await tr("usados")}`)
  488. if (m.money) m.reply(+m.money + ` KantuCoins ${await tr("usados")} 🪙`)
  489. }
  490. break
  491. }}} catch (e) {
  492. console.error(e)
  493. } finally {
  494. if (opts['queque'] && m.text) {
  495. const quequeIndex = this.msgqueque.indexOf(m.id || m.key.id)
  496. if (quequeIndex !== -1)
  497. this.msgqueque.splice(quequeIndex, 1)
  498. }
  499. //console.log(global.db.data.users[m.sender])
  500. let user, stats = global.db.data.stats
  501. if (m) {
  502. if (m.sender && (user = global.db.data.users[m.sender])) {
  503. user.exp += m.exp
  504. user.limit -= m.limit * 1
  505. }
  506. let stat
  507. if (m.plugin) {
  508. let now = +new Date
  509. if (m.plugin in stats) {
  510. stat = stats[m.plugin]
  511. if (!isNumber(stat.total))
  512. stat.total = 1
  513. if (!isNumber(stat.success))
  514. stat.success = m.error != null ? 0 : 1
  515. if (!isNumber(stat.last))
  516. stat.last = now
  517. if (!isNumber(stat.lastSuccess))
  518. stat.lastSuccess = m.error != null ? 0 : now
  519. } else
  520. stat = stats[m.plugin] = {
  521. total: 1,
  522. success: m.error != null ? 0 : 1,
  523. last: now,
  524. lastSuccess: m.error != null ? 0 : now
  525. }
  526. stat.total += 1
  527. stat.last = now
  528. if (m.error == null) {
  529. stat.success += 1
  530. stat.lastSuccess = now
  531. }}}
  532. try {
  533. if (!opts['noprint']) await (await import(`./lib/print.js`)).default(m, this)
  534. } catch (e) {
  535. console.log(m, m.quoted, e)}
  536. let settingsREAD = global.db.data.settings[this.user.jid] || {}
  537. if (opts['autoread']) await this.readMessages([m.key])
  538. if (settingsREAD.autoread2) await this.readMessages([m.key])
  539. //if (settingsREAD.autoread2 == 'true') await this.readMessages([m.key])
  540. if (!m.fromMem && m.text.match(/(@5217121649714|KantuBot|Botsito|Bot|:v)/gi)) {
  541. let emot = pickRandom(["🐣", "💥", "😹", "🧐", "✨", "🤠", "🙀", "👻", "👽", "🤩", "👾", "😳", "🥵", "🤯", "😱", "😨", "👇", "🥴", "🤧", "🤑", "🤠", "🤖", "🤝", "💪", "👑", "🔎", "🐱", "🚨", "⚓", "🎁", "⚡️", "💯", "☃️", "⛄️", "🌝", "🌛", "🌜", "🍓", "🍎", "🎈", "🪄", "❤️", "🧡", "💛", "💚", "💙", "💜", "🖤", "🤍", "💘", "💝", "💟", "🌝", "😎", "🔥", "🖕", "🐦"])
  542. this.sendMessage(m.chat, { react: { text: emot, key: m.key }})}
  543. function pickRandom(list) { return list[Math.floor(Math.random() * list.length)]}}}
  544. /**
  545. * Handle groups participants update
  546. * @param {import('@adiwajshing/baileys').BaileysEventMap<unknown>['group-participants.update']} groupsUpdate
  547. */
  548. export async function participantsUpdate({ id, participants, action }) {
  549. if (opts['self']) return;
  550. if (this.isInit) return;
  551. if (global.db.data == null) await loadDatabase();
  552. let chat = global.db.data.chats[id] || {};
  553. let text = '';
  554. switch (action) {
  555. case 'add':
  556. if (chat.welcome) {
  557. let groupMetadata = await this.groupMetadata(id) || (conn.chats[id] || {}).metadata;
  558. for (let user of participants) {
  559. let userJoinTime = Date.now();
  560. if (userJoinTime < global.botStartTime) {
  561. console.log(`Bienvenida ignorada para ${user}: unión anterior al inicio del bot (${new Date(userJoinTime)} < ${new Date(global.botStartTime)})`);
  562. continue;
  563. }
  564. let pp = './src/sinfoto.jpg';
  565. try {
  566. pp = await this.profilePictureUrl(user, 'image');
  567. } catch (e) {
  568. } finally {
  569. let apii = await this.getFile(pp);
  570. const botTt2 = groupMetadata.participants.find(u => this.decodeJid(u.id) == this.user.jid) || {};
  571. const isBotAdminNn = botTt2?.admin === "admin" || false;
  572. text = (action === 'add' ? (chat.sWelcome || this.welcome || conn.welcome || 'Welcome, @user!').replace('@subject', await this.getName(id)).replace('@desc', groupMetadata.desc?.toString() || '*ᴜɴ ɢʀᴜᴘᴏ ɢᴇɴɪᴀ😸*\n *sɪɴ ʀᴇɢʟᴀ 😉*') :
  573. (chat.sBye || this.bye || conn.bye || 'Bye, @user!')).replace('@user', '@' + user.split('@')[0]);
  574. if (chat.antifake && isBotAdminNn && action === 'add') {
  575. const numerosPermitidos = ["212", "265", "92", "91", "90", "210", "60", "61", "62", "40", "48", "49", "93", "94", "98", "258"];
  576. if (numerosPermitidos.some(num => user.startsWith(num))) {
  577. this.sendMessage(id, { text: `@${user.split("@")[0]} ${await tr("Nos numero fake no esta permitido el este grupo hasta la próxima...")}`, mentions: [user] }, { quoted: null });
  578. let responseb = await this.groupParticipantsUpdate(id, [user], 'remove');
  579. if (responseb[0].status === "404") return;
  580. return;
  581. }}
  582. let username = this.getName(id);
  583. let fkontak2 = { "key": { "participants": "0@s.whatsapp.net", "remoteJid": "status@broadcast", "fromMe": false, "id": "Halo" }, "message": { "contactMessage": { "vcard": `BEGIN:VCARD\nVERSION:3.0\nN:Sy;Bot;;;\nFN:y\nitem1.TEL;waid=${user.split('@')[0]}:${user.split('@')[0]}\nitem1.X-ABLabel:Ponsel\nEND:VCARD` } }, "participant": "0@s.whatsapp.net" };
  584. let vn = 'https://qu.ax/cUYg.mp3';
  585. let or = ['texto', 'audio'];
  586. let media = or[Math.floor(Math.random() * 2)];
  587. if (media === 'texto') {
  588. this.sendMessage(id, { text: text, contextInfo: { forwardedNewsletterMessageInfo: { newsletterJid: '120363371008200788@newsletter', serverMessageId: '', newsletterName: 'Kantu Bot 🐣' }, forwardingScore: 9999999, isForwarded: true, mentionedJid: [user], externalAdReply: { showAdAttribution: true, renderLargerThumbnail: true, thumbnail: apii.data, title: [wm, ' ' + wm + '😊', '🌟'].getRandom(), containsAutoReply: true, mediaType: 1, sourceUrl: [nna, nna2, nnntt, yt].getRandom() } } }, { quoted: fkontak2 });
  589. }
  590. if (media === 'audio') {
  591. this.sendMessage(id, { audio: { url: vn }, contextInfo: { forwardedNewsletterMessageInfo: { newsletterJid: '120363371008200788@newsletter', serverMessageId: '', newsletterName: 'Kantu Bot 🐣' }, forwardingScore: 9999999, isForwarded: true, mentionedJid: [user], externalAdReply: { mediaType: 1, previewType: "PHOTO", thumbnail: apii.data, title: `乂 WELCOME 乂`, body: [wm, ' ' + wm + '😊', '🌟'].getRandom(), showAdAttribution: true, renderLargerThumbnail: true, sourceUrl: [nna, nna2, nnntt, yt].getRandom() } }, ptt: true, mimetype: 'audio/mpeg', fileName: `error.mp3` }, { quoted: fkontak2 });
  592. }}}}
  593. break
  594. case 'promote':
  595. case 'daradmin':
  596. case 'darpoder':
  597. text = (chat.sPromote || this.spromote || conn.spromote || '@user ```is now Admin```')
  598. case 'demote':
  599. case 'quitarpoder':
  600. case 'quitaradmin':
  601. if (!text)
  602. text = (chat.sDemote || this.sdemote || conn.sdemote || '@user ```is no longer Admin```')
  603. text = text.replace('@user', '@' + participants[0].split('@')[0])
  604. if (chat.detect)
  605. //this.sendMessage(id, { text, mentions: this.parseMention(text) })
  606. break
  607. }}
  608. /**
  609. * Actualización de grupos de control
  610. * Handle groups update
  611. * @param {import('@adiwajshing/baileys').BaileysEventMap<unknown>['groups.update']} groupsUpdate
  612. */
  613. export async function groupsUpdate(groupsUpdate) {
  614. if (opts['self'])
  615. return
  616. for (const groupUpdate of groupsUpdate) {
  617. const id = groupUpdate.id
  618. if (!id) continue
  619. let chats = global.db.data.chats[id], text = ''
  620. if (!chats?.detect) continue
  621. // if (groupUpdate.desc) text = (chats.sDesc || this.sDesc || conn.sDesc || '```Description has been changed to```\n@desc').replace('@desc', groupUpdate.desc)
  622. //if (groupUpdate.subject) text = (chats.sSubject || this.sSubject || conn.sSubject || '```Subject has been changed to```\n@subject').replace('@subject', groupUpdate.subject)
  623. //if (groupUpdate.icon) text = (chats.sIcon || this.sIcon || conn.sIcon || '```Icon has been changed to```').replace('@icon', groupUpdate.icon)
  624. //if (groupUpdate.revoke) text = (chats.sRevoke || this.sRevoke || conn.sRevoke || '```Group link has been changed to```\n@revoke').replace('@revoke', groupUpdate.revoke)
  625. if (!text) continue
  626. await this.sendMessage(id, { text, mentions: this.parseMention(text) })
  627. }}
  628. export async function callUpdate(callUpdate) {
  629. let isAnticall = global.db.data.settings[this.user.jid].antiCall
  630. if (!isAnticall) return
  631. for (let nk of callUpdate) {
  632. if (nk.isGroup == false) {
  633. if (nk.status == "offer") {
  634. let callmsg = await this.reply(nk.from, `ʜᴏʟᴀ *@${nk.from.split('@')[0]}*, ʟᴀs ${nk.isVideo ? 'videollamadas' : 'llamadas'} ɴᴏ ᴇsᴛᴀɴ ᴘᴇʀᴍɪᴛɪᴅᴀs, sᴇʀᴀs ʙʟᴏǫᴜᴇᴀᴅᴏ.\n\nsɪ ᴀᴄᴄɪᴅᴇɴᴛᴀʟᴍᴇɴᴛᴇ ʟʟᴀᴍᴀsᴛᴇ ᴘᴏɴɢᴀsᴇ ᴇɴ ᴄᴏɴᴛᴀᴄᴛᴏ ᴄᴏɴ ᴍɪ ᴄʀᴇᴀᴅᴏʀ ᴘᴀʀᴀ ǫᴜᴇ ᴛᴇ ᴅᴇsʙʟᴏǫᴜᴇᴇ!\n\nɢʀᴜᴘᴏ ᴀsɪsᴛᴇɴᴄɪᴀ ғᴀᴄᴇʙᴏᴏᴋ: ${fb}`, false, { mentions: [nk.from] })
  635. let vcard = `BEGIN:VCARD\nVERSION:3.0\nN:;𝐊𝐚𝐧𝐭𝐮 - 𝐁𝐨𝐭 👑;;;\nFN:𝐊𝐚𝐧𝐭𝐮 - 𝐁𝐨𝐭\nORG:𝐊𝐚𝐧𝐭𝐮 - 𝐁𝐨𝐭 👑\nTITLE:\nitem1.TEL;waid=5217121649714:+52 712 164 9714\nitem1.X-ABLabel:𝐊𝐚𝐧𝐭𝐮 - 𝐁𝐨𝐭 👑\nX-WA-BIZ-DESCRIPTION:[❗] ᴇsᴄʀɪʙɪ sᴏʟᴏ ᴘᴏʀ ᴄᴏsᴀs ᴅᴇʟ ʙᴏᴛ.\nX-WA-BIZ-NAME:𝐊𝐚𝐧𝐭𝐮 - 𝐁𝐨𝐭 👑\nEND:VCARD`
  636. await this.sendMessage(nk.from, { contacts: { displayName: '𝐊𝐚𝐧𝐭𝐮 - 𝐁𝐨𝐭 👑', contacts: [{ vcard }] }}, {quoted: callmsg})
  637. await this.updateBlockStatus(nk.from, 'block')
  638. }}}}
  639. export async function deleteUpdate(message) {
  640. try {
  641. const { fromMe, id, participant } = message
  642. if (fromMe) return
  643. let msg = this.serializeM(this.loadMessage(id))
  644. let chat = global.db.data.chats[msg?.chat] || {}
  645. if (!chat?.delete) return
  646. if (!msg) return
  647. if (!msg?.isGroup) return
  648. const antideleteMessage = `*[ ${await tr("ANTI ELIMINAR")} ]*\n\n@${participant.split`@`[0]} ${await tr("Elimino un mensaje\nEnviando el mensaje...\n\n*Para desactivar esta función escriba:*")}\n#disable delete`.trim();
  649. await this.sendMessage(msg.chat, {text: antideleteMessage, mentions: [participant]}, {quoted: msg})
  650. this.copyNForward(msg.chat, msg).catch(e => console.log(e, msg))
  651. } catch (e) {
  652. console.error(e)
  653. }}
  654. global.dfail = async (type, m, conn, usedPrefix) => {
  655. let msg = {
  656. rowner: await tr('「 ꛕ 」 Este comando es solo para mi propietario. ¡Lo siento, este es exclusivo! 🔒'),
  657. owner: await tr('「 ꛕ 」 Este comando es solo para mi propietario. ¡Lo siento, este es exclusivo! 🔒.'),
  658. mods: await tr('「 ꛕ 」 Este comando solo lo puedo usar yo.'),
  659. premium: await tr('「 ꛕ 」 Este comando es solo para usuarios Premium (VIP). ¡Ser VIP tiene sus beneficios! 🌟'),
  660. group: await tr('「 ꛕ 」 Este comando es solo para grupos'),
  661. private: await tr('「 ꛕ 」 Este comando solo funciona en el privado del bot. ¡Escribeme en privado! ⚡'),
  662. admin: await tr('「 ꛕ 」No eres admin. Solo los admins pueden usar este comando. 😇'),
  663. botAdmin: await tr('「 ꛕ 」 Necesito ser admin para poder usar este comando.'),
  664. unreg: await tr('「🚨」 *¡Hey! no estas registrado, registrese para usar esta función*\n\n*/reg nombre.edad*\n*_❕ Ejemplo_* : */reg Crxs.18*'),
  665. restrict: await tr('[ 🔐 ] Este comando esta desactivado por Crxs')
  666. }[type];
  667. if (msg) return conn.sendMessage(m.chat, {text: msg, contextInfo: { mentionedJid: null, forwardingScore: 1, isForwarded: true, forwardedNewsletterMessageInfo: { newsletterJid: '120363371008200788@newsletter', serverMessageId: '', newsletterName: 'Kantu Bot 🐣' }, externalAdReply : {mediaUrl: null, mediaType: 1, description: null, "title": `ℹ️𝐈𝐍𝐅𝐎 ℹ️`, body: wm, previewType: 0, "thumbnail": img.getRandom(), sourceUrl: [nna, nna2, md, yt, nn, tiktok].getRandom()}}}, { quoted: m })
  668. }
  669. const file = global.__filename(import.meta.url, true);
  670. watchFile(file, async () => {
  671. unwatchFile(file)
  672. console.log(chalk.redBright('Update \'handler.js\''));
  673. //if (global.reloadHandler) console.log(await global.reloadHandler());
  674. /*if (global.conns && global.conns.length > 0 ) {
  675. const users = [...new Set([...global.conns.filter((conn) => conn.user && conn.ws.socket && conn.ws.socket.readyState !== ws.CLOSED).map((conn) => conn)])];
  676. for (const userr of users) {
  677. userr.subreloadHandler(false)
  678. }}
  679. */
  680. });