From 4f11342db8de1a2daccb3c9359895f5fff3d954b Mon Sep 17 00:00:00 2001 From: Stanislaw <62724833+BoberITman@users.noreply.github.com> Date: Tue, 29 Mar 2022 22:00:05 +0200 Subject: [PATCH] Badges download --- .gitignore | 1 + src/cmds/dodajodznake.js | 37 +++++++++++++++++++++++++++++++++++++ src/functions/postgres.js | 2 ++ 3 files changed, 40 insertions(+) create mode 100644 src/cmds/dodajodznake.js diff --git a/.gitignore b/.gitignore index 8f5ca7e..fdda6d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /node_modules .env package-lock.json +/src/badges \ No newline at end of file diff --git a/src/cmds/dodajodznake.js b/src/cmds/dodajodznake.js new file mode 100644 index 0000000..2dd161b --- /dev/null +++ b/src/cmds/dodajodznake.js @@ -0,0 +1,37 @@ +module.exports = { + name: "dodajodznake", + async execute(cl, msg, args) { + const { get } = require("https"); + const { createWriteStream, exists } = require("fs"); + if (msg.member.permissions.has(0x20)) { + if (msg.attachments.at(0) != null) { + console.log("attachmentadded"); + msg.attachments.each((x) => { + if (x.contentType.startsWith("application/json")) { + exists(`src/badges/json/${x.name}`, (e) => { + if (!e) { + const file = createWriteStream(`src/badges/json/${x.name}`); + get(x.url, (res) => { + res.pipe(file); + }); + } else { + msg.channel.send("nuda"); + } + }); + } else if (x.contentType.startsWith("image/")) { + exists(`src/badges/img/${x.name}`, (e) => { + if (!e) { + const file = createWriteStream(`src/badges/img/${x.name}`); + get(x.url, (res) => { + res.pipe(file); + }); + } else { + msg.channel.send("nuda"); + } + }); + } + }); + } + } + }, +}; diff --git a/src/functions/postgres.js b/src/functions/postgres.js index adf2885..a6431b7 100644 --- a/src/functions/postgres.js +++ b/src/functions/postgres.js @@ -32,4 +32,6 @@ module.exports = { } return check.rows; }, + addBadge: async function (args) {}, + giveBadge: async function (args) {}, };