From 1ce360ca278a351dc36004f44ce7a46706228cc2 Mon Sep 17 00:00:00 2001
From: JadlionHD <48410066+JadlionHD@users.noreply.github.com>
Date: Tue, 21 Dec 2021 20:47:53 +0700
Subject: [PATCH] feat(web): update 1.0.1
---
README.md | 25 +++++++--
package.json | 3 +-
src/Saweria.js | 61 +++++++++++++++++++---
src/embed.json | 18 +++++++
src/server.js | 17 +++++--
src/web/public/css/style.css | 39 ++++++++++++++
src/web/views/index.ejs | 69 +++++++++++++++++++++++++
src/web/views/index.html | 69 +++++++++++++++++++++++++
yarn.lock | 99 ++++++++++++++++++++++++++++++++++++
9 files changed, 385 insertions(+), 15 deletions(-)
create mode 100644 src/embed.json
create mode 100644 src/web/public/css/style.css
create mode 100644 src/web/views/index.ejs
create mode 100644 src/web/views/index.html
diff --git a/README.md b/README.md
index b41b6e1..246889e 100644
--- a/README.md
+++ b/README.md
@@ -1,15 +1,34 @@
+
# nyawer-hook
Contoh web server saweria webhook mengirim notifikasi donasi ke discord webhook.
## Contoh
+
## Cara kerjanya?
-Cara kerjanya lumayan mudah, yaitu menggunakan salah satu integrations yang disediakan [Saweria](https://saweria.co) yaitu webhook.
-
+Cara kerjanya menggunakan salah satu integrations yang disediakan [Saweria](https://saweria.co) yaitu webhook.
+
Jadi ini adalah gambaran cara kerjanya:
- Saweria webhook > Website kamu > Discord webhook
## Install
-Untuk sekarang masih belum selesai dibuat.
\ No newline at end of file
+Dokumentasi belum lengkap, tapi ini sedikit instalisasinya sebagai berikut:
+- Buatlah .env file lalu isi beberapa line berikut ini
+```
+SECRET=TOKENRAHASIA // token websitemu
+DISCORD_WEBHOOK=URL // discord webhook url
+PORT=NOMOR // port website yang akan dibuka
+```
+- Lalu install modules yang diperlukan dengan cara:
+```bash
+$ npm install
+```
+- Setelah semuanya selesai, maka untuk memulainya ketik:
+```bash
+$ npm start
+```
+
+## Contribution
+Kalo kalian menemukan sebuah bug, dengan senang hati membuka issues agar dibahas lebih lanjut.
\ No newline at end of file
diff --git a/package.json b/package.json
index e6d148b..4b9ef8a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "nyawer-hook",
- "version": "1.0.0",
+ "version": "1.0.1",
"description": "",
"main": "index.js",
"scripts": {
@@ -16,6 +16,7 @@
"dependencies": {
"axios": "^0.24.0",
"dotenv": "^10.0.0",
+ "ejs": "^3.1.6",
"express": "^4.17.1"
}
}
diff --git a/src/Saweria.js b/src/Saweria.js
index 70fcae8..c0332ca 100644
--- a/src/Saweria.js
+++ b/src/Saweria.js
@@ -1,23 +1,42 @@
const axios = require("axios");
const utils = require("./util.js");
+const fs = require("fs");
function webhookTest(req) {
- axios.post(process.env.DISCORD_WEBHOOK_TEST, {
+ let embed = JSON.parse(fs.readFileSync("src/embed.json", "utf8"));
+
+ let tempEmbed = {
embeds: [{
- title: `Sankyu ${req.body.donator_name}! telah nyawer Rp${utils.format(req.body.amount_raw)}`,
- description: `Pesan:\n \`\`\`${req.body.message}\`\`\``,
+ title: embed.embeds[0].title,
+ description: embed.embeds[0].description,
image: {
- url: "https://c.tenor.com/z89eTLYza68AAAAd/yuudachi-poi.gif"
+ url: embed.embeds[0].image.url
},
thumbnail: {
- url: "https://saweria.co/twitter_card.png"
+ url: embed.embeds[0].thumbnail.url
},
footer: {
- text: "https://saweria.co/JadlionHD"
+ text: embed.embeds[0].footer.text
},
- color: 0x25ba0e
+ color: parseInt(embed.embeds[0].color.replace("#", "0x"))
}]
- })
+ };
+ let embeds = tempEmbed.embeds[0];
+
+
+ for(let [k,v] of Object.entries(tempEmbed.embeds[0])) {
+ if(typeof v !== "object") {
+
+ if(k === "color")
+ continue;
+
+ embeds[k] = embeds[k].replace(/{message}/g, req.body.message);
+ embeds[k] = embeds[k].replace(/{donator_name}/g, req.body.donator_name);
+ embeds[k] = embeds[k].replace(/{amount}/g, utils.format(req.body.amount_raw));
+ }
+
+ }
+ axios.post(process.env.DISCORD_WEBHOOK, tempEmbed);
}
function handlePostReq(req, res) {
@@ -29,8 +48,34 @@ function handlePostReq(req, res) {
}
}
+function handleEditEmbed(req, res) {
+ if(req.body.token !== process.env.SECRET) {
+ return res.status(301).redirect(req.get("host"));
+ }
+ let tempEmbed = {
+ embeds: [{
+ title: req.body.title,
+ description: req.body.description,
+ image: {
+ url: req.body.imageUrl
+ },
+ thumbnail: {
+ url: req.body.thumbnailUrl
+ },
+ footer: {
+ text: req.body.footerText
+ },
+ color: req.body.color
+ }]
+ };
+
+ fs.writeFileSync("src/embed.json", JSON.stringify(tempEmbed, null, 2));
+ return res.status(301).redirect(req.get("host"));
+}
+
module.exports = {
handlePostReq,
+ handleEditEmbed,
webhookTest
};
\ No newline at end of file
diff --git a/src/embed.json b/src/embed.json
new file mode 100644
index 0000000..2fb74dc
--- /dev/null
+++ b/src/embed.json
@@ -0,0 +1,18 @@
+{
+ "embeds": [
+ {
+ "title": "Sankyu {donator_name}! telah nyawer Rp{amount}",
+ "description": "Pesan: ```{message}```",
+ "image": {
+ "url": "https://c.tenor.com/z89eTLYza68AAAAd/yuudachi-poi.gif"
+ },
+ "thumbnail": {
+ "url": "https://saweria.co/twitter_card.png"
+ },
+ "footer": {
+ "text": "https://saweria.co/JadlionHD"
+ },
+ "color": "#d41138"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/server.js b/src/server.js
index 484502d..fc44443 100644
--- a/src/server.js
+++ b/src/server.js
@@ -1,12 +1,23 @@
const express = require("express");
+const path = require("path");
const app = express();
+const fs = require("fs");
require("dotenv").config();
-const { handlePostReq } = require("./Saweria.js");
+const { handlePostReq, handleEditEmbed } = require("./Saweria.js");
app.use(express.json());
+app.use(express.urlencoded({ extended: true }));
+app.set("view engine", "ejs");
+app.set("views", path.join(__dirname, "/web/views"));
+app.use(express.static(path.join(__dirname, "/web/public")));
app.post("/callback/discord", handlePostReq);
+app.get("/", (req, res) => {
+ const embed = JSON.parse(fs.readFileSync("src/embed.json", "utf8"));
+ res.render("index.ejs", {embed: embed.embeds[0]});
+});
+app.post("/edit/embed", handleEditEmbed);
-app.listen(parseInt(process.env.PORT), () => {
- console.log("Server siap!");
+app.listen(process.env.PORT, () => {
+ console.log("Web Server siap!");
})
\ No newline at end of file
diff --git a/src/web/public/css/style.css b/src/web/public/css/style.css
new file mode 100644
index 0000000..8034bb1
--- /dev/null
+++ b/src/web/public/css/style.css
@@ -0,0 +1,39 @@
+body {
+ margin: 0;
+ padding: 0;
+ font-family: "Century Gothic Bold", sans-serif;
+ color: white;
+}
+
+.main {
+ background-color: #151515;
+ padding-top: 2rem;
+}
+
+#titleEmbed {
+ width: 50%;
+}
+#descEmbed {
+ width: 75%;
+}
+
+.container {
+ background-color: #525252;
+ padding: 1.5rem;
+ border-radius: 10px;
+}
+
+.pfooter {
+ padding: 1rem;
+ text-align: center;
+}
+
+.heartd {
+ text-decoration: none;
+ color: white;
+ transition: 0.3s;
+}
+
+.heartd:hover {
+ color: red;
+}
\ No newline at end of file
diff --git a/src/web/views/index.ejs b/src/web/views/index.ejs
new file mode 100644
index 0000000..3b99bc2
--- /dev/null
+++ b/src/web/views/index.ejs
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+ Saweria - Hook
+
+
+
+
+
Nyawer-hook Embed Editor
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/web/views/index.html b/src/web/views/index.html
new file mode 100644
index 0000000..4e10a83
--- /dev/null
+++ b/src/web/views/index.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+ Saweria - Hook
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/yarn.lock b/yarn.lock
index 0801f5e..d01de52 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -10,11 +10,23 @@ accepts@~1.3.7:
mime-types "~2.1.24"
negotiator "0.6.2"
+ansi-styles@^3.2.1:
+ version "3.2.1"
+ resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
+ integrity sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==
+ dependencies:
+ color-convert "^1.9.0"
+
array-flatten@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2"
integrity sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=
+async@0.9.x:
+ version "0.9.2"
+ resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d"
+ integrity sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=
+
axios@^0.24.0:
version "0.24.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.24.0.tgz#804e6fa1e4b9c5288501dd9dff56a7a0940d20d6"
@@ -22,6 +34,11 @@ axios@^0.24.0:
dependencies:
follow-redirects "^1.14.4"
+balanced-match@^1.0.0:
+ version "1.0.2"
+ resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
+ integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==
+
body-parser@1.19.0:
version "1.19.0"
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.19.0.tgz#96b2709e57c9c4e09a6fd66a8fd979844f69f08a"
@@ -38,11 +55,45 @@ body-parser@1.19.0:
raw-body "2.4.0"
type-is "~1.6.17"
+brace-expansion@^1.1.7:
+ version "1.1.11"
+ resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
+ integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==
+ dependencies:
+ balanced-match "^1.0.0"
+ concat-map "0.0.1"
+
bytes@3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"
integrity sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==
+chalk@^2.4.2:
+ version "2.4.2"
+ resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
+ integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
+ dependencies:
+ ansi-styles "^3.2.1"
+ escape-string-regexp "^1.0.5"
+ supports-color "^5.3.0"
+
+color-convert@^1.9.0:
+ version "1.9.3"
+ resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"
+ integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==
+ dependencies:
+ color-name "1.1.3"
+
+color-name@1.1.3:
+ version "1.1.3"
+ resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
+ integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=
+
+concat-map@0.0.1:
+ version "0.0.1"
+ resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
+ integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
+
content-disposition@0.5.3:
version "0.5.3"
resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.3.tgz#e130caf7e7279087c5616c2007d0485698984fbd"
@@ -92,6 +143,13 @@ ee-first@1.1.1:
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
+ejs@^3.1.6:
+ version "3.1.6"
+ resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.6.tgz#5bfd0a0689743bb5268b3550cceeebbc1702822a"
+ integrity sha512-9lt9Zse4hPucPkoP7FHDF0LQAlGyF9JVpnClFLFH3aSSbxmyoqINRpp/9wePWJTUl4KOQwRL72Iw3InHPDkoGw==
+ dependencies:
+ jake "^10.6.1"
+
encodeurl@~1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59"
@@ -102,6 +160,11 @@ escape-html@~1.0.3:
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
integrity sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=
+escape-string-regexp@^1.0.5:
+ version "1.0.5"
+ resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
+ integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
+
etag@~1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
@@ -143,6 +206,13 @@ express@^4.17.1:
utils-merge "1.0.1"
vary "~1.1.2"
+filelist@^1.0.1:
+ version "1.0.2"
+ resolved "https://registry.yarnpkg.com/filelist/-/filelist-1.0.2.tgz#80202f21462d4d1c2e214119b1807c1bc0380e5b"
+ integrity sha512-z7O0IS8Plc39rTCq6i6iHxk43duYOn8uFJiWSewIq0Bww1RNybVHSCjahmcC87ZqAm4OTvFzlzeGu3XAzG1ctQ==
+ dependencies:
+ minimatch "^3.0.4"
+
finalhandler@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.1.2.tgz#b7e7d000ffd11938d0fdb053506f6ebabe9f587d"
@@ -171,6 +241,11 @@ fresh@0.5.2:
resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7"
integrity sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=
+has-flag@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
+ integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0=
+
http-errors@1.7.2:
version "1.7.2"
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.7.2.tgz#4f5029cf13239f31036e5b2e55292bcfbcc85c8f"
@@ -215,6 +290,16 @@ ipaddr.js@1.9.1:
resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz#bff38543eeb8984825079ff3a2a8e6cbd46781b3"
integrity sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==
+jake@^10.6.1:
+ version "10.8.2"
+ resolved "https://registry.yarnpkg.com/jake/-/jake-10.8.2.tgz#ebc9de8558160a66d82d0eadc6a2e58fbc500a7b"
+ integrity sha512-eLpKyrfG3mzvGE2Du8VoPbeSkRry093+tyNjdYaBbJS9v17knImYGNXQCUV0gLxQtF82m3E8iRb/wdSQZLoq7A==
+ dependencies:
+ async "0.9.x"
+ chalk "^2.4.2"
+ filelist "^1.0.1"
+ minimatch "^3.0.4"
+
media-typer@0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
@@ -247,6 +332,13 @@ mime@1.6.0:
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==
+minimatch@^3.0.4:
+ version "3.0.4"
+ resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
+ integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
+ dependencies:
+ brace-expansion "^1.1.7"
+
ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
@@ -356,6 +448,13 @@ setprototypeof@1.1.1:
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c"
integrity sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=
+supports-color@^5.3.0:
+ version "5.5.0"
+ resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
+ integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==
+ dependencies:
+ has-flag "^3.0.0"
+
toidentifier@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"