Commit 1cdecdb9 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 901c2de3
const db = require('./db')
const constant = require('./const')
var numeral = require('numeral');
const nodeHtmlToImage = require('node-html-to-image')
function startMessage(bot, msg) {
simpleMessage(bot, msg, 'به ربات حسابداری خودش آمدید.')
}
......@@ -54,7 +54,9 @@ async function deleteMessage(bot, msg) {
}
function userShowMessage(bot, msg, user) {
async function userShowMessage(bot, msg, user) {
let table=tableGenerator('🇮🇷 ','تومان',numberize(Math.abs(user.toman_balance)),user.toman_balance === 0 ? '' : user.toman_balance > 0 ? 'بدهکار' : 'بستانکار')
var opts = {
reply_markup: {
......@@ -116,6 +118,9 @@ function userShowMessage(bot, msg, user) {
text += '\n'
text += '\n'
table+= tableGenerator('🇺🇸 ','دلار',numberize(Math.abs(user.dollar_balance)),user.dollar_balance === 0 ? '' : user.dollar_balance > 0 ? 'بدهکار' : 'بستانکار')
}
......@@ -129,6 +134,9 @@ function userShowMessage(bot, msg, user) {
user.euro_balance > 0 ? 'بدهکار' : 'بستانکار'
text += '\n'
text += '\n'
table+= tableGenerator('🇪🇺 ','یورو',numberize(Math.abs(user.euro_balance)),user.euro_balance === 0 ? '' : user.euro_balance > 0 ? 'بدهکار' : 'بستانکار')
}
if (user.lir_balance !== 0) {
......@@ -139,6 +147,9 @@ function userShowMessage(bot, msg, user) {
text += '\n'
text += '\n'
table+= tableGenerator('🇹🇷 ','لیر',numberize(Math.abs(user.lir_balance)),user.lir_balance === 0 ? '' : user.lir_balance > 0 ? 'بدهکار' : 'بستانکار')
}
if (user.aed_balance !== 0) {
......@@ -148,6 +159,9 @@ function userShowMessage(bot, msg, user) {
user.aed_balance > 0 ? 'بدهکار' : 'بستانکار'
text += '\n'
text += '\n'
table+= tableGenerator('🇦🇪 ','لیر',numberize(Math.abs(user.aed_balance)),user.aed_balance === 0 ? '' : user.aed_balance > 0 ? 'بدهکار' : 'بستانکار')
}
if (user.can_balance !== 0) {
......@@ -158,6 +172,10 @@ function userShowMessage(bot, msg, user) {
text += '\n'
text += '\n'
table+= tableGenerator('🇨🇦 ','دلار کانادا',numberize(Math.abs(user.can_balance)),user.can_balance === 0 ? '' : user.can_balance > 0 ? 'بدهکار' : 'بستانکار')
}
if (user.pon_balance !== 0) {
......@@ -168,6 +186,9 @@ function userShowMessage(bot, msg, user) {
text += '\n'
text += '\n'
table+= tableGenerator('🇬🇧 ','پوند',numberize(Math.abs(user.pon_balance)),user.pon_balance === 0 ? '' : user.pon_balance > 0 ? 'بدهکار' : 'بستانکار')
}
if (user.aud_balance !== 0) {
......@@ -178,6 +199,10 @@ function userShowMessage(bot, msg, user) {
text += '\n'
text += '\n'
table+= tableGenerator('🇦🇺 ','دلار استرالیا',numberize(Math.abs(user.aud_balance)),user.aud_balance === 0 ? '' : user.aud_balance > 0 ? 'بدهکار' : 'بستانکار')
}
if (user.rmb_balance !== 0) {
......@@ -188,12 +213,43 @@ function userShowMessage(bot, msg, user) {
text += '\n'
text += '\n'
table+= tableGenerator('🇨🇳 ','یوان چین',numberize(Math.abs(user.rmb_balance)),user.rmb_balance === 0 ? '' : user.rmb_balance > 0 ? 'بدهکار' : 'بستانکار')
}
nodeHtmlToImage({
output: './image.png',
html: htmlGenerator(table)
})
.then(() => bot.sendPhoto(typeof msg.chat !== 'undefined' ? msg.chat.id : msg.message.chat.id, './image.png'))
bot.editMessageText(text, opts)
}
function tableGenerator(flag,curName,value,type)
{
let q = ` <tr>
<td>${flag}</td>
<td>${curName}</td>
<td>${value}</td>
<td>${type}</td>
</tr>
`
return q
}
function htmlGenerator(table)
{
let html='<!DOCTYPE html>\n<html>\n<head>\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'
html=html.replace('salam',table)
return html
}
async function showCurrencyMessage(bot, msg, user) {
var opts = {
reply_markup: {
......
This diff is collapsed.
var numeral = require('numeral');
const nodeHtmlToImage = require('node-html-to-image')
var string = numeral(15285).format('0,0');
console.log(string)
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