summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-05-26 16:20:14 +0200
committerLinnea Gräf <nea@nea.moe>2024-05-26 16:20:14 +0200
commit19b5b4bbe0ced6bb140759b0d9ace73546aad8b0 (patch)
tree7a067c3d2b0bed8c617e08bbdd7c88d5c88f6bbc
downloadmycelium-warning-19b5b4bbe0ced6bb140759b0d9ace73546aad8b0.tar.gz
mycelium-warning-19b5b4bbe0ced6bb140759b0d9ace73546aad8b0.tar.bz2
mycelium-warning-19b5b4bbe0ced6bb140759b0d9ace73546aad8b0.zip
Initial
-rw-r--r--Dockerfile3
-rw-r--r--app.js69
-rw-r--r--mycelium-warning.xml22
3 files changed, 94 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..5288b27
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,3 @@
+FROM node:22
+COPY app.js app.js
+ENTRYPOINT ["node", "app.js"]
diff --git a/app.js b/app.js
new file mode 100644
index 0000000..a319dcd
--- /dev/null
+++ b/app.js
@@ -0,0 +1,69 @@
+const HYPIXEL_API_KEY =process.env.HYPIXEL_API_KEY;
+const DISCORD_WEBHOOK_URL =process.env.DISCORD_WEBHOOK_URL;
+const CHECK_INTERVAL = 60 * 10; // 10 minutes
+const WARN_AFTER = 60 * 60 * 9; // 9 hours
+
+const profiles = [
+ {
+ profile: "Tomato",
+ playerId: "4154a5602654493094d3497d2ad6849f",
+ ping: "281489313840103426",
+ },
+];
+
+function getProfile(p) {
+ return fetch(
+ `https://api.hypixel.net/v2/skyblock/profiles?key=${HYPIXEL_API_KEY}&uuid=${p.playerId}`,
+ )
+ .then((it) => it.json())
+ .then((it) =>
+ it.profiles.find((profile) => profile.cute_name === p.profile),
+ );
+}
+function warn(userid) {
+ return fetch(DISCORD_WEBHOOK_URL+"?wait=true", {
+ headers: {
+ "content-type": "application/json",
+ },
+ body: JSON.stringify({
+ content: `<@${userid}> RATE MAL WER GERADE KEINE MYCELIUM COLLECTION BEKOMMT? DU!`,
+ allowed_mentions: {
+ users: [userid],
+ },
+ }),
+ method: "POST",
+ });
+}
+
+const lastCollectionGain = [];
+const lastCollection = [];
+for (i in profiles) {
+ lastCollectionGain[i] = Date.now();
+ lastCollection[i] = 0;
+}
+
+async function checkCollections() {
+ for (i in profiles) {
+ const p = profiles[i];
+ const data = await getProfile(p);
+ console.log(data)
+ let collectionTotal = 0;
+ for (memberid in data.members) {
+ const member = data.members[memberid]
+ const collectionOne = member.collection?.MYCEL;
+ if (collectionOne) collectionTotal += collectionOne;
+ }
+ const last = lastCollection[i];
+ if (last !== collectionTotal) {
+ lastCollection[i] = collectionTotal;
+ lastCollectionGain[i] = Date.now();
+ }
+ console.log("last: "+last)
+ console.log("current: "+collectionTotal)
+ if (Date.now() - lastCollectionGain[i] > WARN_AFTER * 1000) {
+ warn(p.ping).then(it => it.json()).then(console.log, console.error);
+ }
+ }
+}
+setInterval(checkCollections, CHECK_INTERVAL * 1000);
+checkCollections()
diff --git a/mycelium-warning.xml b/mycelium-warning.xml
new file mode 100644
index 0000000..12cbdc4
--- /dev/null
+++ b/mycelium-warning.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+ <Container version="2">
+ <Name>mycelium-warning</Name>
+ <Repository>nea89o/mycelium-warning</Repository>
+ <Registry>ghcr.io</Registry>
+ <Network>bridge</Network>
+ <Privileged>false</Privileged>
+ <Support>64pFP94AWA</Support>
+ <Project>https://github.com/nea89o/mycelium-warning</Project>
+ <Overview>Allows to spam ping alea when he is sleeping too much and risks getting mycelium cubes.</Overview>
+ <WebUI>https://www.youtube.com/watch?v=dQw4w9WgXcQ</WebUI>
+ <TemplateURL>https://raw.githubusercontent.com/nea89o/mycelium-warning/master/mycelium-warning.xml</TemplateURL>
+ <Icon>https://minecraft.wiki/images/Mycelium_JE5_BE3.png</Icon>
+ <ExtraParams/>
+ <PostArgs/>
+ <DonateText>Please give me SkyBlock coins</DonateText>
+ <DonateLink>https://sky.shiiyu.moe/stats/lrg89/</DonateLink>
+
+ <Config Name="Hypixel API key" Target="HYPIXEL_API_KEY" Default="" Mode="" Description="Your Hypixel API key" Type="Variable" Display="always" Required="true" Mask="true"/>
+
+ <Config Name="Discord WebHook URL" Target="DISCORD_WEBHOOK_URL" Default="" Mode="" Description="Where to send your pings too. Must be a webhook." Type="Variable" Display="always" Required="true" Mask="true"/>
+</Container>