Commit 9f947926 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 650dcdc5
...@@ -12,11 +12,12 @@ const bot = new TelegramBot(token, {polling: true}); ...@@ -12,11 +12,12 @@ const bot = new TelegramBot(token, {polling: true});
bot.on('message', (msg) => { bot.on('message', (msg) => {
console.log(msg) console.log(msg)
processMessage(msg) processMessage(msg)
}); });
async function processMessage(msg) { async function processMessage(msg) {
await isAdmin(msg) await isAdmin(msg)
...@@ -47,6 +48,7 @@ async function processCallback(msg) { ...@@ -47,6 +48,7 @@ async function processCallback(msg) {
else if (msg.data.startsWith("buy_")) showCurrency(msg, 'buy') else if (msg.data.startsWith("buy_")) showCurrency(msg, 'buy')
else if (msg.data.startsWith("sell_")) showCurrency(msg, 'sell') else if (msg.data.startsWith("sell_")) showCurrency(msg, 'sell')
else if (msg.data.startsWith("variz_")) showCurrency(msg, 'variz') else if (msg.data.startsWith("variz_")) showCurrency(msg, 'variz')
else if (msg.data.startsWith("daryaft_")) showCurrency(msg, 'daryaft')
else if (msg.data.startsWith("toman_")) showCount(msg, 'toman') else if (msg.data.startsWith("toman_")) showCount(msg, 'toman')
else if (msg.data.startsWith("dollar_")) showCount(msg, 'dollar') else if (msg.data.startsWith("dollar_")) showCount(msg, 'dollar')
else if (msg.data.startsWith("euro_")) showCount(msg, 'euro') else if (msg.data.startsWith("euro_")) showCount(msg, 'euro')
...@@ -104,6 +106,9 @@ async function showCurrency(msg, type) { ...@@ -104,6 +106,9 @@ async function showCurrency(msg, type) {
case 'variz': case 'variz':
msg.data = msg.data.replace("variz_", "") msg.data = msg.data.replace("variz_", "")
break break
case 'daryaft':
msg.data = msg.data.replace("daryaft_", "")
break
} }
...@@ -142,7 +147,7 @@ async function showCount(msg, unit) { ...@@ -142,7 +147,7 @@ async function showCount(msg, unit) {
admin.data.vahed = unit admin.data.vahed = unit
await db.updateData(msg, JSON.stringify(admin.data)) await db.updateData(msg, JSON.stringify(admin.data))
message.showCountMessage(bot, msg, type === 'variz') message.showCountMessage(bot, msg, type === 'variz' || type === 'daryaft')
} }
async function elseMessage(msg) { async function elseMessage(msg) {
...@@ -171,7 +176,7 @@ async function input1(msg) { ...@@ -171,7 +176,7 @@ async function input1(msg) {
admin.data = JSON.stringify(admin.data) admin.data = JSON.stringify(admin.data)
await db.updateData(msg, admin.data) await db.updateData(msg, admin.data)
if (type === 'variz') if (type === 'variz' || type === 'daryaft')
message.sendDocMessage(bot, msg) message.sendDocMessage(bot, msg)
else else
message.showFeeMessage(bot, msg) message.showFeeMessage(bot, msg)
......
...@@ -83,28 +83,53 @@ async function createRequest(data) { ...@@ -83,28 +83,53 @@ async function createRequest(data) {
} }
function runCurrency(data, user) { function runCurrency(data, user) {
if (data.action === 'variz') { if (data.action === 'variz') {
switch (data.vahed) {
case 'toman':
user.toman_balance = parseFloat(user.toman_balance) + (-1 * parseFloat(data.count))
break
case 'dollar':
user.dollar_balance = user.dollar_balance + (-1 * parseFloat(data.count))
break
case 'euro':
user.euro_balance = user.euro_balance + (-1 * parseFloat(data.count))
break
case 'lir':
user.lir_balance = user.lir_balance + (-1 * parseFloat(data.count))
break
case 'aed':
user.aed_balance = user.aed_balance + (-1 * parseFloat(data.count))
break
}
return user
}
if (data.action === 'daryaft') {
switch (data.vahed) { switch (data.vahed) {
case 'toman': case 'toman':
user.toman_balance = parseFloat(user.toman_balance) + (-1* parseFloat(data.count)) user.toman_balance = parseFloat(user.toman_balance) + (parseFloat(data.count))
break break
case 'dollar': case 'dollar':
user.dollar_balance = user.dollar_balance + (-1* parseFloat(data.count)) user.dollar_balance = user.dollar_balance + (parseFloat(data.count))
break break
case 'euro': case 'euro':
user.euro_balance = user.euro_balance +(-1 * parseFloat(data.count)) user.euro_balance = user.euro_balance + (parseFloat(data.count))
break break
case 'lir': case 'lir':
user.lir_balance = user.lir_balance + (-1 *parseFloat(data.count)) user.lir_balance = user.lir_balance + (parseFloat(data.count))
break break
case 'aed': case 'aed':
user.aed_balance = user.aed_balance + (-1 * parseFloat(data.count)) user.aed_balance = user.aed_balance + (parseFloat(data.count))
break break
......
...@@ -244,6 +244,14 @@ async function userSubmitRequest(bot, msg, user) { ...@@ -244,6 +244,14 @@ async function userSubmitRequest(bot, msg, user) {
callback_data: 'variz_' + user.id callback_data: 'variz_' + user.id
} }
],
[
{
text: 'دریافت',
callback_data: 'daryaft_' + user.id
}
] ]
...@@ -266,7 +274,7 @@ async function showCountMessage(bot, msg, variz) { ...@@ -266,7 +274,7 @@ async function showCountMessage(bot, msg, variz) {
}; };
await db.updateStatus(msg, constant.input1) await db.updateStatus(msg, constant.input1)
if (variz) if (variz)
bot.editMessageText('لطفا مبلغ فیش واریزی را وارد نمایید.', opts) bot.editMessageText('لطفا مبلغ فیش واریزی یا دریافتی را وارد نمایید.', opts)
else else
bot.editMessageText('لطفا مقدار مورد نیاز را وارد نمایید.', opts) bot.editMessageText('لطفا مقدار مورد نیاز را وارد نمایید.', opts)
...@@ -387,10 +395,10 @@ async function listRequest(bot, msg, reqs) { ...@@ -387,10 +395,10 @@ async function listRequest(bot, msg, reqs) {
for (let i = 0; i < reqs.length; i++) { for (let i = 0; i < reqs.length; i++) {
let text = '' let text = ''
text += reqs[i].type.replace("variz", "واریز").replace("buy", "خرید").replace("sell", "فروش") + " " text += reqs[i].type.replace("variz", "واریز").replace("daryaft", "دریافت").replace("buy", "خرید").replace("sell", "فروش") + " "
text += reqs[i].count + " " text += reqs[i].count + " "
text += reqs[i].unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم') + " " text += reqs[i].unit.replace('toman', 'تومان').replace('dollar', 'دلار').replace('euro', 'یورو').replace('lir', 'لیر').replace('aed', 'درهم') + " "
if (reqs[i].type !== 'variz') { if (reqs[i].type !== 'variz' && reqs[i].type !== 'daryaft' ) {
text += 'با مبلغ ' text += 'با مبلغ '
text += ' ' text += ' '
text += reqs[i].fee text += reqs[i].fee
...@@ -422,7 +430,7 @@ async function showRequest(bot, msg, req) { ...@@ -422,7 +430,7 @@ async function showRequest(bot, msg, req) {
let text = '' let text = ''
if (req.type !== 'variz') { if (req.type !== 'variz' && req.type !== 'daryaft') {
text += 'تعداد ' text += 'تعداد '
text += req.type.replace("sell", 'فروش').replace("buy", "خرید") text += req.type.replace("sell", 'فروش').replace("buy", "خرید")
......
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