From 0216ab3a3b272e2c78fb11c6a5e4bbfa201f9420 Mon Sep 17 00:00:00 2001 From: JonnyBro Date: Wed, 18 Jan 2023 00:56:25 +0500 Subject: [PATCH] checkjar --- commands/IAT/checkjar.js | 79 +++++++++++++++++++++++++++++++ languages/uk-UA/iat/checkjar.json | 5 ++ 2 files changed, 84 insertions(+) create mode 100644 commands/IAT/checkjar.js create mode 100644 languages/uk-UA/iat/checkjar.json diff --git a/commands/IAT/checkjar.js b/commands/IAT/checkjar.js new file mode 100644 index 00000000..47c17f36 --- /dev/null +++ b/commands/IAT/checkjar.js @@ -0,0 +1,79 @@ +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")) + .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) { + if (!interaction.member.roles.cache.has("1039467712633638962")) return interaction.reply({ content: "error", ephemeral: true }); + + await interaction.deferReply(); + + const jar = "x3VtgmqMXYJ6k-vqdlhmGCejFH9Ej3Y"; + const data = await fetch(`https://api.monobank.ua/personal/statement/${jar}/${Date.now() - (7 * 24 * 60 * 60 * 1000)}/${Date.now()}`, { + method: "GET", + headers: { + "X-Token": "ugBCz115wxv4VPdtfIlkZtb1lvV2FglPrppAaphVpKwU", + }, + }).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", + }) + .setDescription(`Текущий баланс: **${data[0].balance / Math.pow(10, 2)} грн**`); + + data.length = 10; + + data.forEach(t => { + 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; \ No newline at end of file diff --git a/languages/uk-UA/iat/checkjar.json b/languages/uk-UA/iat/checkjar.json new file mode 100644 index 00000000..57956aef --- /dev/null +++ b/languages/uk-UA/iat/checkjar.json @@ -0,0 +1,5 @@ +{ + "DESCRIPTION": "Перевірити баланс банки", + "USAGE": "", + "EXAMPLES": "checkjar" +} \ No newline at end of file