Commit 457fd41a authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent be7eeadd
const db = require('./db') const db = require('./db')
const constant = require('./const') const constant = require('./const')
var numeral = require('numeral'); var numeral = require('numeral');
const nodeHtmlToImage = require('node-html-to-image') const puppeteer = require('puppeteer');
function startMessage(bot, msg) { function startMessage(bot, msg) {
simpleMessage(bot, msg, 'به ربات حسابداری خودش آمدید.') simpleMessage(bot, msg, 'به ربات حسابداری خودش آمدید.')
} }
...@@ -219,22 +219,23 @@ async function userShowMessage(bot, msg, user) { ...@@ -219,22 +219,23 @@ async function userShowMessage(bot, msg, user) {
} }
nodeHtmlToImage({
output: './image.png',
html: htmlGenerator(table)
})
.then(() => bot.sendPhoto(typeof msg.chat !== 'undefined' ? msg.chat.id : msg.message.chat.id, './image.png'))
.catch(function (e) {
bot.sendPhoto(typeof msg.chat !== 'undefined' ? msg.chat.id : msg.message.chat.id, './image.png')
})
bot.editMessageText(text, opts) bot.editMessageText(text, opts)
let html=htmlGenerator(table)
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setContent( html );
await page.screenshot({path: 'image.png'});
await browser.close();
bot.sendPhoto(typeof msg.chat !== 'undefined' ? msg.chat.id : msg.message.chat.id, './image.png')
} }
function tableGenerator(flag,curName,value,type) function tableGenerator(flag,curName,value,type)
{ {
let q = ` <tr> let q = ` <tr>
<td>${flag}</td>
<td>${curName}</td> <td>${curName}</td>
<td>${value}</td> <td>${value}</td>
<td>${type}</td> <td>${type}</td>
...@@ -248,7 +249,7 @@ let q = ` <tr> ...@@ -248,7 +249,7 @@ let q = ` <tr>
function htmlGenerator(table) function htmlGenerator(table)
{ {
let html='<!DOCTYPE html>\n<html>\n<head>\n<meta charset="UTF-8">\n<meta name="viewport" content="width=device-width, initial-scale=5">\n<style>\ntable {\n border-collapse: collapse;\n border-spacing: 0;\n width: 100%;\n border: 1px solid #ddd;\n}\n\nth, td {\n text-align: right;\n padding: 8px;\n}\n\ntr:nth-child(even){background-color: #f2f2f2}\n</style>\n</head>\n<body>\n\n\n<div style="overflow-x:auto;">\n <table dir="rtl">\n <tr >\n <th>*</th>\n <th>نام ارز</th>\n <th>مانده حساب</th>\n <th>وضعیت</th>\n \n </tr>\n salam\n \n </table>\n</div>\n\n</body>\n</html>\n\n\n' let html='<!DOCTYPE html>\n<html>\n<head>\n<meta charset="UTF-8">\n<meta name="viewport" content="width=device-width, initial-scale=5">\n<style>\ntable {\n border-collapse: collapse;\n border-spacing: 0;\n width: 100%;\n border: 1px solid #ddd;\n}\n\nth, td {\n text-align: right;\n padding: 8px;\n}\n\ntr:nth-child(even){background-color: #f2f2f2}\n</style>\n</head>\n<body>\n\n\n<div style="overflow-x:auto;">\n <table dir="rtl">\n <tr >\n <th>نام ارز</th>\n <th>مانده حساب</th>\n <th>وضعیت</th>\n \n </tr>\n salam\n \n </table>\n</div>\n\n</body>\n</html>\n\n\n'
html=html.replace('salam',table) html=html.replace('salam',table)
return html return html
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment