Skip to content

Commit

Permalink
Console Features
Browse files Browse the repository at this point in the history
  • Loading branch information
Nurutomo committed Jan 30, 2021
1 parent 7117412 commit 26b8a06
Show file tree
Hide file tree
Showing 7 changed files with 1,014 additions and 14 deletions.
14 changes: 11 additions & 3 deletions lib/print.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
let { WA_MESSAGE_STUB_TYPES, URL_REGEX } = require('@adiwajshing/baileys')
let { WA_MESSAGE_STUB_TYPES, URL_REGEX, MessageType } = require('@adiwajshing/baileys')
let terminalImage = require('terminal-image')
let chalk = require('chalk')

module.exports = function (m, conn = {user: {}}) {
module.exports = async function (m, conn = {user: {}}) {
let sender = typeof m.text == 'string' || m.mtype ? [m.sender] : m.messageStubParameters
sender = sender.map(v => v.split`@`[0] + (conn.getName(v) ? ' ~' + conn.getName(v) : '')).join` & `
let chat = conn.getName(m.chat)
let ansi = '\x1b['
let img
try {
img = [MessageType.image, 1+MessageType.sticker].includes(m.mtype) ? await terminalImage.buffer(await conn.downloadM(m)) : false
} catch (e) {
console.error(e)
}
console.log(
`${chalk.red('%s')} ${chalk.black(chalk.bgYellow('%s'))} ${chalk.black(chalk.bgGreen('%s'))}\n${chalk.green('%s')} ${chalk.yellow('%s')} ${chalk.blue('to')} ${chalk.green('%s')} ${chalk.black(chalk.bgYellow('%s'))}`,
(conn.user.jid + ' ~' + conn.user.name).replace('@s.whatsapp.net', ''),
Expand All @@ -16,6 +23,7 @@ module.exports = function (m, conn = {user: {}}) {
m.chat + (chat ? ' ~' + chat : ''),
m.mtype ? m.mtype.replace(/message$/i, '') : ''
)
if (img) console.log(img.trimEnd())
if (typeof m.text == 'string') {
let log = m.text
if (m.mentionedJid) for (let user of m.mentionedJid) log = log.replace('@' + user.split`@`[0], chalk.blue('@' + conn.getName(user)))
Expand All @@ -26,8 +34,8 @@ module.exports = function (m, conn = {user: {}}) {
.replace(/(?<=(?:^|\s|\n|\*|_))~(.+?)~(?=(?:$|\s|\n|\*|_))/g, `${ansi}9m$1${ansi}29m`) // Strikethrough
.replace(/(?<=(?:^|\s|\n|\*|_|~))\x60{3}(.+?)\x60{3}(?=(?:$|\s|\n|\*|_|~))/gm, `$1`) // Monospace (...)
console.log(m.error ? chalk.red(log) : m.isCommand ? chalk.yellow(log) : log)
console.log()
}
console.log()
}

delete require.cache[require.resolve(__filename)]
Loading

0 comments on commit 26b8a06

Please sign in to comment.