Commit 7c72e009 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 3d9ecbe8
...@@ -66,6 +66,7 @@ async function processCallback(msg) { ...@@ -66,6 +66,7 @@ async function processCallback(msg) {
else if (msg.data.startsWith("aed_")) showCount(msg, 'aed') else if (msg.data.startsWith("aed_")) showCount(msg, 'aed')
else if (msg.data.startsWith("can_")) showCount(msg, 'can') else if (msg.data.startsWith("can_")) showCount(msg, 'can')
else if (msg.data.startsWith("pon_")) showCount(msg, 'pon') else if (msg.data.startsWith("pon_")) showCount(msg, 'pon')
else if (msg.data.startsWith("aud_")) showCount(msg, 'aud')
else if (msg.data.startsWith("Rtoman_")) commitRequest(msg, 'toman') else if (msg.data.startsWith("Rtoman_")) commitRequest(msg, 'toman')
else if (msg.data.startsWith("Rdollar_")) commitRequest(msg, 'dollar') else if (msg.data.startsWith("Rdollar_")) commitRequest(msg, 'dollar')
else if (msg.data.startsWith("Reuro_")) commitRequest(msg, 'euro') else if (msg.data.startsWith("Reuro_")) commitRequest(msg, 'euro')
...@@ -73,6 +74,7 @@ async function processCallback(msg) { ...@@ -73,6 +74,7 @@ async function processCallback(msg) {
else if (msg.data.startsWith("Raed_")) commitRequest(msg, 'aed') else if (msg.data.startsWith("Raed_")) commitRequest(msg, 'aed')
else if (msg.data.startsWith("Rcan_")) commitRequest(msg, 'can') else if (msg.data.startsWith("Rcan_")) commitRequest(msg, 'can')
else if (msg.data.startsWith("Rpon_")) commitRequest(msg, 'pon') else if (msg.data.startsWith("Rpon_")) commitRequest(msg, 'pon')
else if (msg.data.startsWith("Raud_")) commitRequest(msg, 'aud')
else if (msg.data.startsWith("yes_")) yesNoDoc(msg, 'yes') else if (msg.data.startsWith("yes_")) yesNoDoc(msg, 'yes')
else if (msg.data.startsWith("no_")) yesNoDoc(msg, 'no') else if (msg.data.startsWith("no_")) yesNoDoc(msg, 'no')
...@@ -156,6 +158,9 @@ async function showCount(msg, unit) { ...@@ -156,6 +158,9 @@ async function showCount(msg, unit) {
case 'pon': case 'pon':
msg.data = msg.data.replace("pon_", "") msg.data = msg.data.replace("pon_", "")
break break
case 'aud':
msg.data = msg.data.replace("aud_", "")
break
} }
...@@ -334,6 +339,11 @@ async function canOrder(data, msg) { ...@@ -334,6 +339,11 @@ async function canOrder(data, msg) {
generateText(user.pon_balance, num, msg) generateText(user.pon_balance, num, msg)
} }
if (data.to === 'aud')
if (user.aud_balance <= 0 || num > user.aud_balance) {
generateText(user.aud_balance, num, msg)
}
} }
......
...@@ -33,6 +33,7 @@ const User = sequelize.define('user', { ...@@ -33,6 +33,7 @@ const User = sequelize.define('user', {
aed_balance: {type: Sequelize.DOUBLE, allowNull: false, defaultValue: 0}, aed_balance: {type: Sequelize.DOUBLE, allowNull: false, defaultValue: 0},
can_balance: {type: Sequelize.DOUBLE, allowNull: false, defaultValue: 0}, can_balance: {type: Sequelize.DOUBLE, allowNull: false, defaultValue: 0},
pon_balance: {type: Sequelize.DOUBLE, allowNull: false, defaultValue: 0}, pon_balance: {type: Sequelize.DOUBLE, allowNull: false, defaultValue: 0},
aud_balance: {type: Sequelize.DOUBLE, allowNull: false, defaultValue: 0},
}); });
...@@ -112,6 +113,9 @@ function runCurrency(data, user) { ...@@ -112,6 +113,9 @@ function runCurrency(data, user) {
case 'pon': case 'pon':
user.pon_balance = user.pon_balance + (-1 * parseFloat(data.count)) user.pon_balance = user.pon_balance + (-1 * parseFloat(data.count))
break break
case 'aud':
user.aud_balance = user.aud_balance + (-1 * parseFloat(data.count))
break
} }
...@@ -145,6 +149,9 @@ function runCurrency(data, user) { ...@@ -145,6 +149,9 @@ function runCurrency(data, user) {
case 'pon': case 'pon':
user.pon_balance = user.pon_balance + (parseFloat(data.count)) user.pon_balance = user.pon_balance + (parseFloat(data.count))
break break
case 'aud':
user.aud_balance = user.aud_balance + (parseFloat(data.count))
break
} }
...@@ -209,6 +216,14 @@ function runCurrency(data, user) { ...@@ -209,6 +216,14 @@ function runCurrency(data, user) {
} }
else if (data.vahed === 'aud') {
if (data.action === 'buy')
user.aud_balance = user.aud_balance + parseFloat(data.count)
else
user.aud_balance = user.aud_balance + (-1 * parseFloat(data.count))
}
if (data.to === 'toman') { if (data.to === 'toman') {
if (data.action === 'buy') if (data.action === 'buy')
...@@ -272,6 +287,15 @@ function runCurrency(data, user) { ...@@ -272,6 +287,15 @@ function runCurrency(data, user) {
user.pon_balance = user.pon_balance + (parseFloat(data.count) * parseFloat(data.fee)) user.pon_balance = user.pon_balance + (parseFloat(data.count) * parseFloat(data.fee))
}
else if (data.vahed === 'aud') {
if (data.action === 'buy')
user.aud_balance = user.aud_balance + (-1 * parseFloat(data.count) * parseFloat(data.fee))
else
user.aud_balance = user.aud_balance + (parseFloat(data.count) * parseFloat(data.fee))
} }
return user return user
...@@ -333,7 +357,8 @@ async function updateBalance(user) { ...@@ -333,7 +357,8 @@ async function updateBalance(user) {
lir_balance: user.lir_balance, lir_balance: user.lir_balance,
aed_balance: user.aed_balance, aed_balance: user.aed_balance,
can_balance: user.can_balance, can_balance: user.can_balance,
pon_balance: user.pon_balance pon_balance: user.pon_balance,
aud_balance: user.aud_balance
}, },
......
...@@ -170,6 +170,16 @@ function userShowMessage(bot, msg, user) { ...@@ -170,6 +170,16 @@ function userShowMessage(bot, msg, user) {
text += '\n' text += '\n'
} }
if (user.aud_balance !== 0) {
text += '🇺🇸 '
text += numberize(Math.abs(user.aud_balance)) + ' ' + 'دلار استرالیا' + ' '
text += user.aud_balance === 0 ? '' :
user.aud_balance > 0 ? 'بدهکار' : 'بستانکار'
text += '\n'
text += '\n'
}
bot.editMessageText(text, opts) bot.editMessageText(text, opts)
} }
...@@ -234,6 +244,14 @@ async function showCurrencyMessage(bot, msg, user) { ...@@ -234,6 +244,14 @@ async function showCurrencyMessage(bot, msg, user) {
callback_data: 'pon_' + user.id callback_data: 'pon_' + user.id
} }
],
[
{
text: 'دلار استرالیا',
callback_data: 'aud_' + user.id
}
] ]
...@@ -358,6 +376,11 @@ async function forwardCurrencyMessage(bot, msg, data) { ...@@ -358,6 +376,11 @@ async function forwardCurrencyMessage(bot, msg, data) {
vahed: 'pon', vahed: 'pon',
text: 'پوند', text: 'پوند',
callback_data: 'Rpon_' + data.user callback_data: 'Rpon_' + data.user
},
{
vahed: 'aud',
text: 'دلار استرالیا',
callback_data: 'Raud_' + data.user
} }
...@@ -442,13 +465,13 @@ async function listRequest(bot, msg, reqs) { ...@@ -442,13 +465,13 @@ 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 += numberize(reqs[i].count) + " " text += numberize(reqs[i].count) + " "
text += reqs[i].unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا').replace('pon', 'پوند') + " " text += reqs[i].unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا').replace('pon', 'پوند').replace('aud', 'دلار استرالیا') + " "
if (reqs[i].type !== 'variz' && reqs[i].type !== 'daryaft' ) { if (reqs[i].type !== 'variz' && reqs[i].type !== 'daryaft' ) {
text += 'با مبلغ ' text += 'با مبلغ '
text += ' ' text += ' '
text += numberize(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', 'دلار کانادا').replace('pon', 'پوند') text += reqs[i].toUnit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا').replace('pon', 'پوند').replace('aud', 'دلار استرالیا')
text += ' ' text += ' '
} }
...@@ -485,13 +508,13 @@ async function showRequest(bot, msg, req) { ...@@ -485,13 +508,13 @@ async function showRequest(bot, msg, req) {
text += ' ' text += ' '
text += req.count text += req.count
text += ' ' text += ' '
text += req.unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا').replace('pon', 'پوند') text += req.unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا').replace('pon', 'پوند').replace('aud', 'دلار استرالیا')
text += ' ' text += ' '
text += 'با مبلغ ' text += 'با مبلغ '
text += ' ' text += ' '
text += req.fee text += req.fee
text += ' ' text += ' '
text += req.toUnit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا').replace('pon', 'پوند') text += req.toUnit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا').replace('pon', 'پوند').replace('aud', 'دلار استرالیا')
text += ' ' text += ' '
} }
else { else {
...@@ -501,7 +524,7 @@ async function showRequest(bot, msg, req) { ...@@ -501,7 +524,7 @@ async function showRequest(bot, msg, req) {
text += ' ' text += ' '
text += req.count text += req.count
text += ' ' text += ' '
text += req.unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا').replace('pon', 'پوند') text += req.unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم').replace('can', 'دلار کانادا').replace('pon', 'پوند').replace('aud', 'دلار استرالیا')
text += ' ' text += ' '
} }
......
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