JaBa/commands/IAT/checkjar.js

92 lines
2.5 KiB
JavaScript
Raw Normal View History

2023-01-18 00:56:25 +05:00
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand"),
fetch = require("node-fetch"),
moment = require("moment");
class Checkjar extends BaseCommand {
/**
*
* @param {import("../base/JaBa")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("checkjar")
.setDescription(client.translate("iat/checkjar:DESCRIPTION"))
.setDescriptionLocalizations({
"uk": client.translate("iat/checkjar:DESCRIPTION", null, "uk-UA"),
"ru": client.translate("iat/checkjar:DESCRIPTION", null, "ru-RU"),
})
2023-01-18 00:56:25 +05:00
.setDMPermission(false),
aliases: [],
dirname: __dirname,
ownerOnly: false,
});
}
/**
*
* @param {import("../../base/JaBa")} client
*/
async onLoad() {
//...
}
/**
*
* @param {import("../../base/JaBa")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
* @param {Object} data
*/
async execute(client, interaction) {
2023-06-15 22:07:31 +05:00
if (!interaction.guildId === "1039187019957555252") return interaction.reply({ content: "error", ephemeral: true });
2023-01-18 00:56:25 +05:00
await interaction.deferReply();
2023-06-15 22:05:30 +05:00
const jarsList = await fetch("https://api.monobank.ua/personal/client-info", {
2023-01-18 00:56:25 +05:00
method: "GET",
headers: {
2023-03-30 11:51:13 +05:00
"X-Token": client.config.apiKeys.monobankApiKey,
2023-06-15 22:05:30 +05:00
"Content-Type": "application/json",
},
}).then(res => res.json());
const jar = jarsList.jars[1];
const jarTransactions = await fetch(`https://api.monobank.ua/personal/statement/${jar.id}/${Date.now() - (7 * 24 * 60 * 60 * 1000)}/${Date.now()}`, {
method: "GET",
headers: {
"X-Token": client.config.apiKeys.monobankApiKey,
"Content-Type": "application/json",
2023-01-18 00:56:25 +05:00
},
}).then(res => res.json());
const embed = new EmbedBuilder()
.setColor(client.config.embed.color)
.setFooter({
text: client.config.embed.footer,
})
.setAuthor({
name: "Monobank API",
iconURL: "https://api.monobank.ua/docs/logo.png",
})
2023-06-15 22:05:30 +05:00
.setDescription(`Текущий баланс: **${jar.balance / Math.pow(10, 2)}** грн\nТребуется на след. месяц: ~**381** грн (по курсу евро на 15.06.2023)`);
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);
embed.addFields([
{
name: `${t.description}`,
value: `Дата: ${time.locale("uk-UA").format("DD MMMM YYYY, HH:mm")}\nСумма: ${t.amount / Math.pow(10, 2)} грн`,
inline: true,
},
]);
});
interaction.editReply({
embeds: [embed],
});
}
}
module.exports = Checkjar;