From eaece10ec6ccd3d997d40dd5af33ffa4e69e853f Mon Sep 17 00:00:00 2001
From: dvelo <52332868+DeveloLongScript@users.noreply.github.com>
Date: Sat, 21 Dec 2024 09:27:41 -0600
Subject: [PATCH] feat: new motd engine
---
package.json | 2 +
src/components/CommandBar.tsx | 26 +++++--
src/components/misc/SnowfallController.tsx | 59 ++++++++++++++++
src/config/version.tsx | 20 +++++-
src/lib/commandEvent.ts | 2 +-
src/lib/list.ts | 49 +++++--------
src/pages/api/v1/motd.ts | 82 +++++++---------------
yarn.lock | 17 +++++
8 files changed, 160 insertions(+), 97 deletions(-)
create mode 100644 src/components/misc/SnowfallController.tsx
diff --git a/package.json b/package.json
index f246ad1..36afd69 100644
--- a/package.json
+++ b/package.json
@@ -57,9 +57,11 @@
"react-fast-marquee": "^1.6.5",
"react-hot-toast": "^2.4.1",
"react-qr-code": "^2.0.15",
+ "react-snowfall": "^2.2.0",
"rehype-slug": "^6.0.0",
"remark-gfm": "^4.0.0",
"sonner": "^1.7.0",
+ "stripe-gradient": "^1.0.1",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"tailwindcss-patch": "^4.0.0",
diff --git a/src/components/CommandBar.tsx b/src/components/CommandBar.tsx
index 7a973e5..86cff29 100644
--- a/src/components/CommandBar.tsx
+++ b/src/components/CommandBar.tsx
@@ -512,12 +512,25 @@ export function ServerCommandBar() {
}
function timeConverter(UNIX_timestamp: any) {
- var a = new Date(UNIX_timestamp);
- var months = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
- var year = a.getFullYear();
- var month = months[a.getMonth()];
- var date = a.getDate();
- var time = month + "/" + date + "/" + year;
+ const a = new Date(UNIX_timestamp);
+ const months = [
+ "1",
+ "2",
+ "3",
+ "4",
+ "5",
+ "6",
+ "7",
+ "8",
+ "9",
+ "10",
+ "11",
+ "12",
+ ];
+ const year = a.getFullYear();
+ const month = months[a.getMonth()];
+ const date = a.getDate();
+ const time = month + "/" + date + "/" + year;
return time;
}
@@ -842,6 +855,7 @@ export function CommandBarer() {
+
>
);
}
diff --git a/src/components/misc/SnowfallController.tsx b/src/components/misc/SnowfallController.tsx
new file mode 100644
index 0000000..02f77f0
--- /dev/null
+++ b/src/components/misc/SnowfallController.tsx
@@ -0,0 +1,59 @@
+/*
+ * MHSF, Minehut Server List
+ * All external content is rather licensed under the ECA Agreement
+ * located here: https://mhsf.app/docs/legal/external-content-agreement
+ *
+ * All code under MHSF is licensed under the MIT License
+ * by open source contributors
+ *
+ * Copyright (c) 2024 dvelo
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+"use client";
+
+import { CommandEvents } from "@/lib/commandEvent";
+import { useEffectOnce } from "@/lib/useEffectOnce";
+import { useState } from "react";
+import Snowfall from "react-snowfall";
+
+export const snowfallEvents = new CommandEvents();
+export default function SnowfallController() {
+ const [visible, setVisible] = useState(true);
+
+ useEffectOnce(() => {
+ snowfallEvents.on("toggle", () => setVisible(!visible));
+ });
+
+ return (
+ <>
+ {visible && (
+
+ )}
+ >
+ );
+}
diff --git a/src/config/version.tsx b/src/config/version.tsx
index d76dd17..77238eb 100644
--- a/src/config/version.tsx
+++ b/src/config/version.tsx
@@ -55,8 +55,26 @@ const FeatureList = ({
);
};
-export const version = "1.6.0";
+export const version = "1.6.50";
export const changelog: { name: string; id: string; changelog: ReactNode }[] = [
+ {
+ id: "dut6hx3f2paswzjve4yg9r",
+ name: "v1.6.5",
+ changelog: (
+
+ Version 1.6.5 (December 20th 2024)
+
+ }
+ />
+ ),
+ },
{
id: "h9jr2cbxn7qwfvt5uypsdg",
name: "v1.6.0",
diff --git a/src/lib/commandEvent.ts b/src/lib/commandEvent.ts
index 4060655..32210a5 100644
--- a/src/lib/commandEvent.ts
+++ b/src/lib/commandEvent.ts
@@ -28,7 +28,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
-class CommandEvents {
+export class CommandEvents {
eventTarget;
constructor() {
diff --git a/src/lib/list.ts b/src/lib/list.ts
index c72eaab..8be16ea 100644
--- a/src/lib/list.ts
+++ b/src/lib/list.ts
@@ -1,36 +1,6 @@
-/*
- * MHSF, Minehut Server List
- * All external content is rather licensed under the ECA Agreement
- * located here: https://list.mlnehut.com/docs/legal/external-content-agreement
- *
- * All code under MHSF is licensed under the MIT License
- * by open source contributors
- *
- * Copyright (c) 2024 dvelo
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-import { OnlineServer } from "./types/mh-server";
import { toast } from "sonner";
-import { getMOTDFromServer } from "./api";
+import { OnlineServer } from "./types/mh-server";
+import MiniMessage from "minimessage-js";
var numberOfItemsInView = 20;
@@ -148,7 +118,20 @@ export default class ServersList {
async getMOTDs(
list: Array<{ server: string; motd: string }>
): Promise> {
- return await getMOTDFromServer(list);
+ const result: Array<{ server: string; motd: string }> = [];
+ const mm = MiniMessage.miniMessage();
+ list.forEach((c) => {
+ try {
+ result.push({
+ server: c.server,
+ motd: mm.toHTML(mm.deserialize(c.motd)),
+ });
+ } catch (e) {
+ console.log(e);
+ }
+ });
+
+ return result;
}
}
diff --git a/src/pages/api/v1/motd.ts b/src/pages/api/v1/motd.ts
index b1ef18e..a60ab26 100644
--- a/src/pages/api/v1/motd.ts
+++ b/src/pages/api/v1/motd.ts
@@ -1,63 +1,33 @@
-/*
- * MHSF, Minehut Server List
- * All external content is rather licensed under the ECA Agreement
- * located here: https://list.mlnehut.com/docs/legal/external-content-agreement
- *
- * All code under MHSF is licensed under the MIT License
- * by open source contributors
- *
- * Copyright (c) 2024 dvelo
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
import { NextApiRequest, NextApiResponse } from "next";
-import parseToHTML from "@/lib/motdEngine";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
- const initalList: Array<{ server: string; motd: string }> = req.body.motd;
- const resultedList: Array<{ server: string; motd: string }> = [];
- var interval = 0;
- if (initalList != undefined && initalList.forEach != undefined) {
- initalList.forEach((c, i) => {
- parseToHTML(c.motd)
- .then((m) => {
- interval++;
- resultedList.push({ motd: m, server: c.server });
- if (interval == initalList.length) {
- res.send({ result: resultedList });
- }
- })
- .catch(() => {
- resultedList.push({ motd: "Error to grab MOTD", server: c.server });
- if (i == initalList.length - 1) {
- res.send({ result: resultedList });
- }
- });
- });
- } else {
- res.status(400).send({
- message: "Wrong structure.. you might be using the legacy MOTD.",
- });
- }
+ // Deprecated - moved exclusively to the client
+ // const initalList: Array<{ server: string; motd: string }> = req.body.motd;
+ // const resultedList: Array<{ server: string; motd: string }> = [];
+ // var interval = 0;
+ // if (initalList != undefined && initalList.forEach != undefined) {
+ // initalList.forEach((c, i) => {
+ // parseToHTML(c.motd)
+ // .then((m) => {
+ // interval++;
+ // resultedList.push({ motd: m, server: c.server });
+ // if (interval == initalList.length) {
+ // res.send({ result: resultedList });
+ // }
+ // })
+ // .catch(() => {
+ // resultedList.push({ motd: "Error to grab MOTD", server: c.server });
+ // if (i == initalList.length - 1) {
+ // res.send({ result: resultedList });
+ // }
+ // });
+ // });
+ // } else {
+ // res.status(400).send({
+ // message: "Wrong structure.. you might be using the legacy MOTD.",
+ // });
+ // }
}
diff --git a/yarn.lock b/yarn.lock
index 0b8bbf4..5e7f4c8 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -6945,6 +6945,11 @@ react-fade-in@^2.0.1:
resolved "https://registry.yarnpkg.com/react-fade-in/-/react-fade-in-2.0.1.tgz#b4bcd7dac63d6857ebcd68facbff2f5f9616278f"
integrity sha512-oqS/WT4znaXEHmL+yo0IDUDY7uC9K4RP35j1SdRUEBspR09B2iIC0i8oJ28tPOr6Ez/L2aktF9p89j+DbsTVNw==
+react-fast-compare@^3.2.2:
+ version "3.2.2"
+ resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.2.tgz#929a97a532304ce9fee4bcae44234f1ce2c21d49"
+ integrity sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ==
+
react-fast-marquee@^1.6.5:
version "1.6.5"
resolved "https://registry.yarnpkg.com/react-fast-marquee/-/react-fast-marquee-1.6.5.tgz#98929ae93eef087a607a71e9d45ab76bba97dc16"
@@ -7058,6 +7063,13 @@ react-smooth@^4.0.0:
prop-types "^15.8.1"
react-transition-group "^4.4.5"
+react-snowfall@^2.2.0:
+ version "2.2.0"
+ resolved "https://registry.yarnpkg.com/react-snowfall/-/react-snowfall-2.2.0.tgz#0856a72c4d29d27a6a14301c0f5deb51296fb4df"
+ integrity sha512-dRk7vEHq/ZUOG+JHk2k/hH3HmliOWGXr4rKRDeW4mjWuHeI1r5h0Lc1r2jnTtUS1im702d6tCmNGymlNTdhXYg==
+ dependencies:
+ react-fast-compare "^3.2.2"
+
react-style-singleton@^2.2.1:
version "2.2.1"
resolved "https://registry.npmjs.org/react-style-singleton/-/react-style-singleton-2.2.1.tgz"
@@ -7694,6 +7706,11 @@ strip-json-comments@^3.1.1:
resolved "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz"
integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==
+stripe-gradient@^1.0.1:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/stripe-gradient/-/stripe-gradient-1.0.1.tgz#27f90ac9c3a90cb3a2771bb43407951aca16bad2"
+ integrity sha512-ttxSoPcJDXoYBPF7yG2TPC9ZZC1bc/ITxP8g0Yx5jo07dFT/wMcGn6CbjbHOtC0NBu8zZgJwJulCpK21WyRJEg==
+
style-to-object@^0.4.1:
version "0.4.4"
resolved "https://registry.yarnpkg.com/style-to-object/-/style-to-object-0.4.4.tgz#266e3dfd56391a7eefb7770423612d043c3f33ec"