Commit aeead253 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 3862fb9c
...@@ -371,7 +371,7 @@ async function generateText(current, num, msg) { ...@@ -371,7 +371,7 @@ async function generateText(current, num, msg) {
} }
runCron()
async function runCron() { async function runCron() {
let admins=await db.getAllAdmins() let admins=await db.getAllAdmins()
let name = './back/'+'backup-' + moment().format('YYYY-MM-DD---HH-mm')+'.sql' let name = './back/'+'backup-' + moment().format('YYYY-MM-DD---HH-mm')+'.sql'
...@@ -385,6 +385,7 @@ async function runCron() { ...@@ -385,6 +385,7 @@ async function runCron() {
}); });
for (let i=0;i<admins.length;i++) for (let i=0;i<admins.length;i++)
{ {
bot.sendDocument(admins[i].teleid, name) bot.sendDocument(admins[i].teleid, name)
} }
} }
......
const db = require('./db') const db = require('./db')
const constant = require('./const') const constant = require('./const')
var numeral = require('numeral');
function startMessage(bot, msg) { function startMessage(bot, msg) {
simpleMessage(bot, msg, 'به ربات حسابداری خودش آمدید.') simpleMessage(bot, msg, 'به ربات حسابداری خودش آمدید.')
...@@ -100,7 +101,7 @@ function userShowMessage(bot, msg, user) { ...@@ -100,7 +101,7 @@ function userShowMessage(bot, msg, user) {
message_id: msg.message.message_id message_id: msg.message.message_id
}; };
let text = '💷 ' let text = '💷 '
text += Math.abs(user.toman_balance) + ' ' + 'تومان' + ' ' text += numberize(Math.abs(user.toman_balance)) + ' ' + 'تومان' + ' '
text += user.toman_balance === 0 ? '' : text += user.toman_balance === 0 ? '' :
user.toman_balance > 0 ? 'بدهکار' : 'طلبکار' user.toman_balance > 0 ? 'بدهکار' : 'طلبکار'
...@@ -109,7 +110,7 @@ function userShowMessage(bot, msg, user) { ...@@ -109,7 +110,7 @@ function userShowMessage(bot, msg, user) {
if (user.dollar_balance !== 0) { if (user.dollar_balance !== 0) {
text += '💵 ' text += '💵 '
text += Math.abs(user.dollar_balance) + ' ' + 'دلار' + ' ' text += numberize(Math.abs(user.dollar_balance)) + ' ' + 'دلار' + ' '
text += user.dollar_balance === 0 ? '' : text += user.dollar_balance === 0 ? '' :
user.dollar_balance > 0 ? 'بدهکار' : 'طلبکار' user.dollar_balance > 0 ? 'بدهکار' : 'طلبکار'
...@@ -123,7 +124,7 @@ function userShowMessage(bot, msg, user) { ...@@ -123,7 +124,7 @@ function userShowMessage(bot, msg, user) {
if (user.euro_balance !== 0) { if (user.euro_balance !== 0) {
text += '💶 ' text += '💶 '
text += Math.abs(user.euro_balance) + ' ' + 'یورو' + ' ' text += numberize(Math.abs(user.euro_balance)) + ' ' + 'یورو' + ' '
text += user.euro_balance === 0 ? '' : text += user.euro_balance === 0 ? '' :
user.euro_balance > 0 ? 'بدهکار' : 'طلبکار' user.euro_balance > 0 ? 'بدهکار' : 'طلبکار'
text += '\n' text += '\n'
...@@ -132,7 +133,7 @@ function userShowMessage(bot, msg, user) { ...@@ -132,7 +133,7 @@ function userShowMessage(bot, msg, user) {
if (user.lir_balance !== 0) { if (user.lir_balance !== 0) {
text += '💴 ' text += '💴 '
text += Math.abs(user.lir_balance) + ' ' + 'لیر' + ' ' text += numberize(Math.abs(user.lir_balance)) + ' ' + 'لیر' + ' '
text += user.lir_balance === 0 ? '' : text += user.lir_balance === 0 ? '' :
user.lir_balance > 0 ? 'بدهکار' : 'طلبکار' user.lir_balance > 0 ? 'بدهکار' : 'طلبکار'
...@@ -142,14 +143,14 @@ function userShowMessage(bot, msg, user) { ...@@ -142,14 +143,14 @@ function userShowMessage(bot, msg, user) {
if (user.aed_balance !== 0) { if (user.aed_balance !== 0) {
text += '💰 ' + Math.abs(user.aed_balance) + ' ' + 'درهم' + " " text += '💰 ' + numberize(Math.abs(user.aed_balance)) + ' ' + 'درهم' + " "
text += user.aed_balance === 0 ? '' : text += user.aed_balance === 0 ? '' :
user.aed_balance > 0 ? 'بدهکار' : 'طلبکار' user.aed_balance > 0 ? 'بدهکار' : 'طلبکار'
} }
if (user.can_balance !== 0) { if (user.can_balance !== 0) {
text += '💵 ' text += '💵 '
text += Math.abs(user.can_balance) + ' ' + 'دلار کانادا' + ' ' text += numberize(Math.abs(user.can_balance)) + ' ' + 'دلار کانادا' + ' '
text += user.can_balance === 0 ? '' : text += user.can_balance === 0 ? '' :
user.can_balance > 0 ? 'بدهکار' : 'طلبکار' user.can_balance > 0 ? 'بدهکار' : 'طلبکار'
...@@ -415,12 +416,12 @@ async function listRequest(bot, msg, reqs) { ...@@ -415,12 +416,12 @@ async function listRequest(bot, msg, reqs) {
let text = '' let text = ''
text += reqs[i].type.replace("variz", "واریز").replace("daryaft", "دریافت").replace("buy", "خرید").replace("sell", "فروش") + " " text += reqs[i].type.replace("variz", "واریز").replace("daryaft", "دریافت").replace("buy", "خرید").replace("sell", "فروش") + " "
text += reqs[i].count + " " text += numberize(reqs[i].count) + " "
text += reqs[i].unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا') + " " text += reqs[i].unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا') + " "
if (reqs[i].type !== 'variz' && reqs[i].type !== 'daryaft' ) { if (reqs[i].type !== 'variz' && reqs[i].type !== 'daryaft' ) {
text += 'با مبلغ ' text += 'با مبلغ '
text += ' ' text += ' '
text += reqs[i].fee text += numberize(reqs[i].fee)
text += ' ' text += ' '
text += reqs[i].toUnit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا') text += reqs[i].toUnit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا')
text += ' ' text += ' '
...@@ -491,6 +492,11 @@ async function showRequest(bot, msg, req) { ...@@ -491,6 +492,11 @@ async function showRequest(bot, msg, req) {
await showDocument(bot, msg, req) await showDocument(bot, msg, req)
} }
function numberize(num)
{
return numeral(num).format('0,0');
}
module.exports = { module.exports = {
......
...@@ -546,6 +546,11 @@ ...@@ -546,6 +546,11 @@
} }
} }
}, },
"numeral": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/numeral/-/numeral-2.0.6.tgz",
"integrity": "sha1-StCAk21EPCVhrtnyGX7//iX05QY="
},
"oauth-sign": { "oauth-sign": {
"version": "0.9.0", "version": "0.9.0",
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
......
let mysqldump = require('mysqldump') var numeral = require('numeral');
const TelegramBot = require('node-telegram-bot-api');
const bot = new TelegramBot('783628734:AAGHs5YcIGy4dhD3ZsKIQOKxcJVDD0ju4jY', {polling: false});
let moment = require('moment-timezone')
var string = numeral(15285).format('0,0');
test() console.log(string)
async function test() {
let name = './back/'+'backup-' + moment().format('YYYY-MM-DD---HH-mm')+'.sql'
const result = await mysqldump({
connection: {
host: '195.201.22.255',
user: 'root',
password: 'mahan7797',
database: 'accounting',
}, dumpToFile: name,
});
bot.sendDocument(84169752, name)
// console.log(result)
}
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