forked from ShirokamiRyzen/Nao-MD
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ShirokamiRyzen:main' into main
- Loading branch information
Showing
4 changed files
with
129 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,98 @@ | ||
import { WAMessageStubType } from '@adiwajshing/baileys'; | ||
import PhoneNumber from 'awesome-phonenumber'; | ||
import chalk from 'chalk'; | ||
import { watchFile } from 'fs'; | ||
import { WAMessageStubType } from '@adiwajshing/baileys' | ||
import PhoneNumber from 'awesome-phonenumber' | ||
import chalk from 'chalk' | ||
import { watchFile } from 'fs' | ||
|
||
const terminalImage = global.opts['img'] ? require('terminal-image') : ''; | ||
const urlRegex = (await import('url-regex-safe')).default({ strict: false }); | ||
const terminalImage = global.opts['img'] ? (await import('terminal-image')).default : '' | ||
const urlRegex = (await import('url-regex-safe')).default({ strict: false }) | ||
|
||
export default async function (m, conn = { user: {} }) { | ||
let _name = await conn.getName(m.sender) | ||
let sender = PhoneNumber('+' + m.sender.replace('@s.whatsapp.net', '')).getNumber('international') + (_name ? ' ~' + _name : '') | ||
let chat = await conn.getName(m.chat) | ||
// let ansi = '\x1b[' | ||
let img | ||
try { | ||
const _name = await conn.getName(m.sender); | ||
const sender = PhoneNumber('+' + m.sender.replace('@s.whatsapp.net', '')).getNumber('international') + (_name ? ' ~' + _name : ''); | ||
const chat = await conn.getName(m.chat); | ||
|
||
let img; | ||
if (global.opts['img']) { | ||
img = /sticker|image/gi.test(m.mtype) ? await terminalImage.buffer(await m.download()) : false; | ||
} | ||
|
||
const filesize = calculateFileSize(m); | ||
const user = global.db.data.users[m.sender]; | ||
const me = PhoneNumber('+' + (conn.user?.jid).replace('@s.whatsapp.net', '')).getNumber('international'); | ||
logMessage(me, conn.user.name, m, chat, filesize, sender, user); | ||
|
||
if (img) console.log(img.trimEnd()); | ||
await handleTextFormatting(m, conn); | ||
} catch (error) { | ||
console.error('Error processing message:', error); | ||
if (global.opts['img']) | ||
img = /sticker|image/gi.test(m.mtype) ? await terminalImage.buffer(await m.download()) : false | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
} | ||
|
||
function calculateFileSize(m) { | ||
return (m.msg?.vcard?.length || m.msg?.fileLength?.low || m.msg?.text?.length || 0) || 0; | ||
} | ||
|
||
function logMessage(me, name, m, chat, filesize, sender, user) { | ||
console.log(` | ||
▣ ${chalk.redBright('%s')} | ||
│⏰ ${chalk.black(chalk.bgYellow('%s'))} | ||
│📑 ${chalk.black(chalk.bgGreen('%s'))} | ||
│📊 ${chalk.magenta('%s [%s %sB]')} | ||
│📤 ${chalk.green('%s')} | ||
│📪 ${chalk.yellow('%s%s')} | ||
│📥 ${chalk.green('%s')} | ||
│💬 ${chalk.black(chalk.bgYellow('%s'))} | ||
│📜 ${chalk.cyan('%s')} | ||
▣──────··· | ||
`.trim(), | ||
`${me} ~ ${name}`, | ||
(m.messageTimestamp ? new Date(1000 * (m.messageTimestamp.low || m.messageTimestamp)) : new Date()).toTimeString(), | ||
let filesize = (m.msg ? | ||
m.msg.vcard ? | ||
m.msg.vcard.length : | ||
m.msg.fileLength ? | ||
m.msg.fileLength.low || m.msg.fileLength : | ||
m.msg.axolotlSenderKeyDistributionMessage ? | ||
m.msg.axolotlSenderKeyDistributionMessage.length : | ||
m.text ? | ||
m.text.length : | ||
0 | ||
: m.text ? m.text.length : 0) || 0 | ||
let user = global.db.data.users[m.sender] | ||
let me = PhoneNumber('+' + ((conn.user?.jid || conn.user?.id)?.replace('@s.whatsapp.net', '') || '')).getNumber('international') | ||
console.log(`${chalk.red('——————————————— NAO-MD ESM ———————————————')} | ||
${chalk.white('» Bot Name:')} ${chalk.black(chalk.bgYellow('%s'))} | ||
${chalk.white('» Date:')} ${chalk.yellow('%s')} ${chalk.blueBright('%s')} ${chalk.magenta('%s [%s %sB]')} | ||
${chalk.white('» User Name:')} ${chalk.black(chalk.bgYellow('%s'))} | ||
${chalk.white('» User info:')} ${chalk.yellow('%s%s')} | ||
${chalk.white('» Send to:')} ${chalk.green('%s')} | ||
${chalk.white(chalk.bgBlue('%s'))} | ||
`.trim(), | ||
me + ' ~' + conn.user.name, | ||
(m.messageTimestamp ? new Date(1000 * (m.messageTimestamp.low || m.messageTimestamp)) : new Date).toLocaleString('id', { timeZone: 'Asia/Jakarta' }), | ||
m.messageStubType ? WAMessageStubType[m.messageStubType] : '', | ||
filesize, | ||
filesize === 0 ? 0 : (filesize / 1009 ** Math.floor(Math.log(filesize) / Math.log(1000))).toFixed(1), | ||
['', ...'KMGTP'][Math.floor(Math.log(filesize) / Math.log(1000))] || '', | ||
sender, | ||
m?.exp || '?', | ||
user ? `|${user.exp}| |${user.limit}` : `|${user.level}`, | ||
m ? m.exp : '?', | ||
user ? '|' + user.exp + '|' + user.limit : '' + ('|' + user.level), | ||
m.chat + (chat ? ' ~' + chat : ''), | ||
m.mtype ? m.mtype.replace(/message$/i, '').replace('audio', m.msg.ptt ? 'PTT' : 'audio').replace(/^./, v => v.toUpperCase()) : '', | ||
m.text || '' | ||
); | ||
} | ||
|
||
async function handleTextFormatting(m, conn) { | ||
m.mtype ? m.mtype.replace(/message$/i, '').replace('audio', m.msg.ptt ? 'PTT' : 'audio').replace(/^./, v => v.toUpperCase()) : '' | ||
) | ||
if (img) console.log(img.trimEnd()) | ||
if (typeof m.text === 'string' && m.text) { | ||
let log = m.text.replace(/\u200e+/g, ''); | ||
let log = m.text.replace(/\u200e+/g, '') | ||
let mdRegex = /(?<=(?:^|[\s\n])\S?)(?:([*_~])(.+?)\1|```((?:.||[\n\r])+?)```)(?=\S?(?:[\s\n]|$))/g | ||
let mdFormat = (depth = 4) => (_, type, text, monospace) => { | ||
let types = { | ||
_: 'italic', | ||
'*': 'bold', | ||
'~': 'strikethrough' | ||
} | ||
text = text || monospace | ||
let formatted = !types[type] || depth < 1 ? text : chalk[types[type]](text.replace(mdRegex, mdFormat(depth - 1))) | ||
// console.log({ depth, type, formatted, text, monospace }, formatted) | ||
return formatted | ||
} | ||
if (log.length < 4096) | ||
log = log.replace(urlRegex, (url, i, text) => { | ||
let end = url.length + i | ||
return i === 0 || end === text.length || (/^\s$/.test(text[end]) && /^\s$/.test(text[i - 1])) ? chalk.blueBright(url) : url | ||
}) | ||
log = log.replace(mdRegex, mdFormat(4)) | ||
if (m.mentionedJid) for (let user of m.mentionedJid) log = log.replace('@' + user.split`@`[0], chalk.blueBright('@' + await conn.getName(user))) | ||
console.log(m.error != null ? chalk.red(log) : m.isCommand ? chalk.yellow(log) : log) | ||
} | ||
if (m.messageStubParameters) console.log(m.messageStubParameters.map(jid => { | ||
jid = conn.decodeJid(jid) | ||
let name = conn.getName(jid) | ||
return chalk.gray(PhoneNumber('+' + jid.replace('@s.whatsapp.net', '')).getNumber('international') + (name ? ' ~' + name : '')) | ||
}).join(', ')) | ||
if (/document/i.test(m.mtype)) console.log(`📄 ${m.msg.fileName || m.msg.displayName || 'Document'}`) | ||
else if (/ContactsArray/i.test(m.mtype)) console.log(`👨👩👧👦 ${' ' || ''}`) | ||
else if (/contact/i.test(m.mtype)) console.log(`👨 ${m.msg.displayName || ''}`) | ||
else if (/audio/i.test(m.mtype)) { | ||
const duration = m.msg.seconds | ||
console.log(`${m.msg.ptt ? '🎤 (PTT ' : '🎵 ('}AUDIO) ${Math.floor(duration / 60).toString().padStart(2, 0)}:${(duration % 60).toString().padStart(2, 0)}`) | ||
} | ||
|
||
console.log() | ||
// if (m.quoted) console.log(m.msg.contextInfo) | ||
} | ||
|
||
let file = global.__filename(import.meta.url) | ||
watchFile(file, () => { | ||
console.log(chalk.redBright("Update 'lib/print.js'")) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,48 @@ | ||
import fetch from 'node-fetch'; | ||
import axios from 'axios' | ||
|
||
var handler = async (m, { conn, text }) => { | ||
if (!text) throw `*_Masukan Nama Mahasiswa/Siswa Yang Ingin Kamu Cari !_*`; | ||
conn.reply(m.chat, 'Sedang mencari Orangnya... Silahkan tunggu', m); | ||
let res = await fetch('https://api-frontend.kemdikbud.go.id/hit_mhs/' + text); | ||
if (!res.ok) throw 'Tidak Ditemukan'; | ||
let json = await res.json(); | ||
let message = ''; | ||
let Xnuvers007 = 'Scrape By Xnuvers007'; | ||
|
||
json.mahasiswa.forEach(data => { | ||
let nama = data.text; | ||
let websiteLink = data['website-link']; | ||
let website = `https://pddikti.kemdikbud.go.id${websiteLink}`; | ||
message += `\nNama = ${nama}\n\nData Ditemukan pada website = ${website}\n\n\n`; | ||
}); | ||
|
||
conn.reply(m.chat, message, m); | ||
//conn.reply(m.chat, `JANGAN LUPA SUPPORT DEVELOPERNYA\nXnuvers007\nhttps://saweria.co/xnuvers007\n\nfollow Me On github\nhttps://github.com/Xnuvers007\nDana = DANA-KAMU`, m); | ||
} | ||
|
||
handler.help = ['mahasiswa <nama>'] | ||
handler.tags = ['internet'] | ||
handler.command = /^(mahasiswa)$/i | ||
if (!text) throw `*_Masukkan Nama Mahasiswa/Siswa Yang Ingin Kamu Cari !_*`; | ||
|
||
conn.reply(m.chat, 'Sedang mencari orangnya... Silahkan tunggu.', m); | ||
|
||
const apiKey = '3ed297db-db1c-4266-8bf4-a89f21c01317'; | ||
const url = `https://pddikti.kemdikbud.go.id/api/pencarian/mhs/${text.replaceAll(' ', '%20')}`; | ||
|
||
try { | ||
let res = await axios.get(url, { | ||
headers: { | ||
'x-api-key': apiKey, | ||
}, | ||
}); | ||
|
||
const data = res.data; | ||
|
||
if (!Array.isArray(data) || data.length === 0) { | ||
throw 'Tidak ditemukan data untuk nama tersebut.'; | ||
} | ||
|
||
let message = `Hasil pencarian untuk nama "${text}":\n\n`; | ||
|
||
data.forEach((mahasiswa, index) => { | ||
const nama = mahasiswa.nama || 'Tidak Diketahui'; | ||
const nim = mahasiswa.nim || 'Tidak Diketahui'; | ||
const namaPt = mahasiswa.nama_pt || 'Tidak Diketahui'; | ||
const namaProdi = mahasiswa.nama_prodi || 'Tidak Diketahui'; | ||
|
||
message += `${index + 1}. Nama: ${nama}\n NIM: ${nim}\n Perguruan Tinggi: ${namaPt}\n Program Studi: ${namaProdi}\n\n`; | ||
}); | ||
|
||
conn.reply(m.chat, message, m); | ||
} catch (error) { | ||
console.error(error); | ||
conn.reply(m.chat, `Terjadi kesalahan: ${error.message || error}`, m); | ||
} | ||
}; | ||
|
||
handler.help = ['mahasiswa <nama>']; | ||
handler.tags = ['internet']; | ||
handler.command = /^(mahasiswa)$/i; | ||
|
||
handler.register = true | ||
|
||
export default handler | ||
export default handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters