feat: new motd engine

This commit is contained in:
dvelo 2024-12-21 09:27:41 -06:00
parent 1b04481bea
commit eaece10ec6
8 changed files with 160 additions and 97 deletions

@ -57,9 +57,11 @@
"react-fast-marquee": "^1.6.5", "react-fast-marquee": "^1.6.5",
"react-hot-toast": "^2.4.1", "react-hot-toast": "^2.4.1",
"react-qr-code": "^2.0.15", "react-qr-code": "^2.0.15",
"react-snowfall": "^2.2.0",
"rehype-slug": "^6.0.0", "rehype-slug": "^6.0.0",
"remark-gfm": "^4.0.0", "remark-gfm": "^4.0.0",
"sonner": "^1.7.0", "sonner": "^1.7.0",
"stripe-gradient": "^1.0.1",
"tailwind-merge": "^2.3.0", "tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7", "tailwindcss-animate": "^1.0.7",
"tailwindcss-patch": "^4.0.0", "tailwindcss-patch": "^4.0.0",

@ -512,12 +512,25 @@ export function ServerCommandBar() {
} }
function timeConverter(UNIX_timestamp: any) { function timeConverter(UNIX_timestamp: any) {
var a = new Date(UNIX_timestamp); const a = new Date(UNIX_timestamp);
var months = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]; const months = [
var year = a.getFullYear(); "1",
var month = months[a.getMonth()]; "2",
var date = a.getDate(); "3",
var time = month + "/" + date + "/" + year; "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; return time;
} }
@ -842,6 +855,7 @@ export function CommandBarer() {
<ServerCommandBar /> <ServerCommandBar />
<OfflineServerCB /> <OfflineServerCB />
<RandomServerDialog /> <RandomServerDialog />
<SnowfallController />
</> </>
); );
} }

@ -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 && (
<Snowfall
style={{
position: "fixed",
width: "100vw",
height: "100vh",
}}
/>
)}
</>
);
}

@ -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 }[] = [ export const changelog: { name: string; id: string; changelog: ReactNode }[] = [
{
id: "dut6hx3f2paswzjve4yg9r",
name: "v1.6.5",
changelog: (
<FeatureList
features={[
"New MOTD engine that is over 3,000% faster, runs client-side, and doesn't need any requests to run.",
"Fixed issue where GitHub link was broken if you were signed-out",
"",
]}
title={
<strong className="flex items-center">
Version 1.6.5 (December 20th 2024)
</strong>
}
/>
),
},
{ {
id: "h9jr2cbxn7qwfvt5uypsdg", id: "h9jr2cbxn7qwfvt5uypsdg",
name: "v1.6.0", name: "v1.6.0",

@ -28,7 +28,7 @@
* OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
*/ */
class CommandEvents { export class CommandEvents {
eventTarget; eventTarget;
constructor() { constructor() {

@ -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 { toast } from "sonner";
import { getMOTDFromServer } from "./api"; import { OnlineServer } from "./types/mh-server";
import MiniMessage from "minimessage-js";
var numberOfItemsInView = 20; var numberOfItemsInView = 20;
@ -148,7 +118,20 @@ export default class ServersList {
async getMOTDs( async getMOTDs(
list: Array<{ server: string; motd: string }> list: Array<{ server: string; motd: string }>
): Promise<Array<{ server: string; motd: string }>> { ): Promise<Array<{ server: string; motd: string }>> {
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;
} }
} }

@ -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 { NextApiRequest, NextApiResponse } from "next";
import parseToHTML from "@/lib/motdEngine";
export default async function handler( export default async function handler(
req: NextApiRequest, req: NextApiRequest,
res: NextApiResponse res: NextApiResponse
) { ) {
const initalList: Array<{ server: string; motd: string }> = req.body.motd; // Deprecated - moved exclusively to the client
const resultedList: Array<{ server: string; motd: string }> = []; // const initalList: Array<{ server: string; motd: string }> = req.body.motd;
var interval = 0; // const resultedList: Array<{ server: string; motd: string }> = [];
if (initalList != undefined && initalList.forEach != undefined) { // var interval = 0;
initalList.forEach((c, i) => { // if (initalList != undefined && initalList.forEach != undefined) {
parseToHTML(c.motd) // initalList.forEach((c, i) => {
.then((m) => { // parseToHTML(c.motd)
interval++; // .then((m) => {
resultedList.push({ motd: m, server: c.server }); // interval++;
if (interval == initalList.length) { // resultedList.push({ motd: m, server: c.server });
res.send({ result: resultedList }); // if (interval == initalList.length) {
} // res.send({ result: resultedList });
}) // }
.catch(() => { // })
resultedList.push({ motd: "Error to grab MOTD", server: c.server }); // .catch(() => {
if (i == initalList.length - 1) { // resultedList.push({ motd: "Error to grab MOTD", server: c.server });
res.send({ result: resultedList }); // if (i == initalList.length - 1) {
} // res.send({ result: resultedList });
}); // }
}); // });
} else { // });
res.status(400).send({ // } else {
message: "Wrong structure.. you might be using the legacy MOTD.", // res.status(400).send({
}); // message: "Wrong structure.. you might be using the legacy MOTD.",
} // });
// }
} }

@ -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" resolved "https://registry.yarnpkg.com/react-fade-in/-/react-fade-in-2.0.1.tgz#b4bcd7dac63d6857ebcd68facbff2f5f9616278f"
integrity sha512-oqS/WT4znaXEHmL+yo0IDUDY7uC9K4RP35j1SdRUEBspR09B2iIC0i8oJ28tPOr6Ez/L2aktF9p89j+DbsTVNw== 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: react-fast-marquee@^1.6.5:
version "1.6.5" version "1.6.5"
resolved "https://registry.yarnpkg.com/react-fast-marquee/-/react-fast-marquee-1.6.5.tgz#98929ae93eef087a607a71e9d45ab76bba97dc16" 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" prop-types "^15.8.1"
react-transition-group "^4.4.5" 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: react-style-singleton@^2.2.1:
version "2.2.1" version "2.2.1"
resolved "https://registry.npmjs.org/react-style-singleton/-/react-style-singleton-2.2.1.tgz" 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" resolved "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz"
integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== 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: style-to-object@^0.4.1:
version "0.4.4" version "0.4.4"
resolved "https://registry.yarnpkg.com/style-to-object/-/style-to-object-0.4.4.tgz#266e3dfd56391a7eefb7770423612d043c3f33ec" resolved "https://registry.yarnpkg.com/style-to-object/-/style-to-object-0.4.4.tgz#266e3dfd56391a7eefb7770423612d043c3f33ec"