2024-02-06 21:45:53 +05:00
const { SlashCommandBuilder } = require ( "discord.js" ) ;
2023-01-18 00:56:25 +05:00
const BaseCommand = require ( "../../base/BaseCommand" ) ,
fetch = require ( "node-fetch" ) ,
moment = require ( "moment" ) ;
class Checkjar extends BaseCommand {
/ * *
*
2023-11-05 16:03:23 +05:00
* @ param { import ( "../base/Client" ) } client
2023-01-18 00:56:25 +05:00
* /
constructor ( client ) {
super ( {
command : new SlashCommandBuilder ( )
. setName ( "checkjar" )
. setDescription ( client . translate ( "iat/checkjar:DESCRIPTION" ) )
2023-06-15 19:46:27 +05:00
. setDescriptionLocalizations ( {
2023-07-05 00:58:06 +05:00
uk : client . translate ( "iat/checkjar:DESCRIPTION" , null , "uk-UA" ) ,
ru : client . translate ( "iat/checkjar:DESCRIPTION" , null , "ru-RU" ) ,
2023-06-15 19:46:27 +05:00
} )
2023-01-18 00:56:25 +05:00
. setDMPermission ( false ) ,
dirname : _ _dirname ,
ownerOnly : false ,
} ) ;
}
2024-02-06 21:45:53 +05:00
2023-01-18 00:56:25 +05:00
/ * *
*
2023-11-05 16:03:23 +05:00
* @ param { import ( "../../base/Client" ) } client
2023-01-18 00:56:25 +05:00
* @ param { import ( "discord.js" ) . ChatInputCommandInteraction } interaction
* @ param { Object } data
* /
async execute ( client , interaction ) {
await interaction . deferReply ( ) ;
2023-07-02 00:02:31 +05:00
const clientInfo = await fetch ( "https://api.monobank.ua/personal/client-info" , {
2023-01-18 00:56:25 +05:00
method : "GET" ,
headers : {
2023-11-06 18:38:38 +05:00
"X-Token" : client . config . apiKeys . monobank . key ,
2023-06-15 22:05:30 +05:00
"Content-Type" : "application/json" ,
} ,
} ) . then ( res => res . json ( ) ) ;
2023-11-06 18:38:38 +05:00
const jar = clientInfo . jars . find ( j => j . id === client . config . apiKeys . monobank . jar ) ;
2023-07-05 00:58:06 +05:00
const jarTransactions = await fetch ( ` https://api.monobank.ua/personal/statement/ ${ jar . id } / ${ Date . now ( ) - 7 * 24 * 60 * 60 * 1000 } / ${ Date . now ( ) } ` , {
2023-06-15 22:05:30 +05:00
method : "GET" ,
headers : {
2023-11-06 18:38:38 +05:00
"X-Token" : client . config . apiKeys . monobank . key ,
2023-06-15 22:05:30 +05:00
"Content-Type" : "application/json" ,
2023-01-18 00:56:25 +05:00
} ,
} ) . then ( res => res . json ( ) ) ;
2024-02-06 21:45:53 +05:00
const embed = client . embed ( {
description : ` Текущий баланс: ** ${ jar . balance / Math . pow ( 10 , 2 ) } ** грн \n Требуется на след. месяц: **379,18** грн (по курсу евро на 02.07.2023). \n Здесь указаны последние 10 транзакций. ` ,
} ) ;
2023-01-18 00:56:25 +05:00
2023-06-15 22:05:30 +05:00
jarTransactions . length = 10 ;
2023-01-18 00:56:25 +05:00
2023-06-15 22:05:30 +05:00
jarTransactions . forEach ( t => {
2023-01-18 00:56:25 +05:00
const time = moment . unix ( t . time ) ;
2024-02-06 21:45:53 +05:00
embed . data . fields . push ( [
2023-01-18 00:56:25 +05:00
{
name : ` ${ t . description } ` ,
2024-02-09 23:26:57 +05:00
value : ` Дата: <t: ${ time } :D> \n Сумма: ${ t . amount / Math . pow ( 10 , 2 ) } грн ` ,
2023-01-18 00:56:25 +05:00
} ,
] ) ;
} ) ;
interaction . editReply ( {
embeds : [ embed ] ,
} ) ;
}
}
2023-07-05 00:58:06 +05:00
module . exports = Checkjar ;