hachem.wtf
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2025-10-24 10:52:20 +0200
committerhachem <im@hachem.wtf>2025-10-24 10:52:20 +0200
commit16c4887eeeae6b43a3313e2e3bfc6274d6a4ab73 (patch)
treeece9024da6eb4be38a76702416c9b00cc0b77bce
parent81d046848f842669149d0a2e0d1a0e9fea1f95d9 (diff)
[fix}: used to print stuff when shit wasnt updated
-rw-r--r--README.md3
-rw-r--r--bot/app.js252
-rw-r--r--package.json2
3 files changed, 129 insertions, 128 deletions
diff --git a/README.md b/README.md
index 3d0cf94..90cfc83 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,8 @@ Mod Manager for Willy World
3. Start the bot:
```bash
-node .
+$ npm i
+$ node .
```
---
diff --git a/bot/app.js b/bot/app.js
index d25b3b6..8f1bfeb 100644
--- a/bot/app.js
+++ b/bot/app.js
@@ -1,161 +1,161 @@
-const { Client, Events, GatewayIntentBits } = require("discord.js")
-const axios = require("axios")
-const fs = require("fs-extra")
-const path = require("path")
-const config = require("../config/config.json")
-const api = require("../config/api.json")
+ const { Client, Events, GatewayIntentBits } = require("discord.js")
+ const axios = require("axios")
+ const fs = require("fs-extra")
+ const path = require("path")
+ const config = require("../config/config.json")
+ const api = require("../config/api.json")
-const { channel_id, minecraft_version, modrinth_mods } = config
-const { token } = api
+ const { channel_id, minecraft_version, modrinth_mods } = config
+ const { token } = api
-const cacheFile = path.join(__dirname, "../cache/mod_versions.json")
-const client = new Client({ intents: [GatewayIntentBits.Guilds] })
+ const cacheFile = path.join(__dirname, "../cache/mod_versions.json")
+ const client = new Client({ intents: [GatewayIntentBits.Guilds] })
-const LoadCache = async () =>
-{
- try
+ const LoadCache = async () =>
{
- if (await fs.pathExists(cacheFile))
- return JSON.parse(await fs.readFile(cacheFile, "utf8"))
- } catch (err)
- {
- console.error("[Cache] Failed to read cache:", err)
+ try
+ {
+ if (await fs.pathExists(cacheFile))
+ return JSON.parse(await fs.readFile(cacheFile, "utf8"))
+ } catch (err)
+ {
+ console.error("[Cache] Failed to read cache:", err)
+ }
+ return {}
}
- return {}
-}
-const SaveCache = async (cache) =>
-{
- try
- {
- await fs.ensureDir(path.dirname(cacheFile))
- await fs.writeFile(cacheFile, JSON.stringify(cache, null, 2))
- } catch (err)
+ const SaveCache = async (cache) =>
{
- console.error("[Cache] Failed to save cache:", err)
+ try
+ {
+ await fs.ensureDir(path.dirname(cacheFile))
+ await fs.writeFile(cacheFile, JSON.stringify(cache, null, 2))
+ } catch (err)
+ {
+ console.error("[Cache] Failed to save cache:", err)
+ }
}
-}
-const GetCompatibleModVersion = async (slug, targetMinecraftVersion) =>
-{
- try
+ const GetCompatibleModVersion = async (slug, targetMinecraftVersion) =>
{
- const res = await axios.get(`https://api.modrinth.com/v2/project/${slug}/version`)
- const fabricVersions = res.data.filter(v => v.loaders.includes("fabric"))
- if (fabricVersions.length === 0)
- return null
+ try
+ {
+ const res = await axios.get(`https://api.modrinth.com/v2/project/${slug}/version`)
+ const fabricVersions = res.data.filter(v => v.loaders.includes("fabric"))
+ if (fabricVersions.length === 0)
+ return null
- const compatible = fabricVersions.find(v => v.game_versions.includes(targetMinecraftVersion))
- const latest = fabricVersions.sort((a, b) =>
- new Date(b.date_published) - new Date(a.date_published)
- )[0]
+ const compatible = fabricVersions.find(v => v.game_versions.includes(targetMinecraftVersion))
+ const latest = fabricVersions.sort((a, b) =>
+ new Date(b.date_published) - new Date(a.date_published)
+ )[0]
- return { latest, compatible: compatible || null }
- } catch (err)
- {
- console.error(`[Modrinth] Error fetching ${slug}:`, err.message)
- return null
+ return { latest, compatible: compatible || null }
+ } catch (err)
+ {
+ console.error(`[Modrinth] Error fetching ${slug}:`, err.message)
+ return null
+ }
}
-}
-const CheckModUpdates = async () =>
-{
- console.log("[Check] Checking for mod compatibility...")
- const cache = await LoadCache()
- const newCache = { ...cache }
- const compatibleReleased = []
- const waitingUpdate = []
- const newlyCompatible = []
-
- for (const slug of modrinth_mods)
+ const CheckModUpdates = async () =>
{
- const modData = await GetCompatibleModVersion(slug, minecraft_version)
- if (!modData) continue
-
- const { latest, compatible } = modData
- const latestId = latest.id
- const cachedId = cache[slug]
+ console.log("[Check] Checking for mod compatibility...")
+ const cache = await LoadCache()
+ const newCache = { ...cache }
+ const compatibleReleased = []
+ const waitingUpdate = []
+ const newlyCompatible = []
- if (compatible)
+ for (const slug of modrinth_mods)
{
- compatibleReleased.push({ slug })
- newCache[slug] = latestId
+ const modData = await GetCompatibleModVersion(slug, minecraft_version)
+ if (!modData) continue
- if (!cachedId || cachedId !== latestId)
+ const { latest, compatible } = modData
+ const latestId = latest.id
+ const cachedId = cache[slug]
+
+ if (compatible)
+ {
+ compatibleReleased.push({ slug })
+ newCache[slug] = latestId
+
+ if (!cachedId || cachedId !== latestId)
+ {
+ newlyCompatible.push({ slug })
+ console.log(`[Update] ${slug} is now compatible with Minecraft ${minecraft_version}`)
+ }
+ } else
{
- newlyCompatible.push({ slug })
- console.log(`[Update] ${slug} is now compatible with Minecraft ${minecraft_version}`)
+ waitingUpdate.push({ slug })
+ console.log(`[Check] ${slug} is waiting for a compatible version`)
}
- } else
- {
- waitingUpdate.push({ slug })
- console.log(`[Check] ${slug} is waiting for a compatible version`)
}
- }
- await SaveCache(newCache)
- return { compatibleReleased, waitingUpdate, newlyCompatible }
-}
-
-const SendUpdateMessages = async (channel, compatibleReleased, waitingUpdate, newlyCompatible) =>
-{
- if (!compatibleReleased.length && !waitingUpdate.length)
- {
- console.log("[Update]: No mods to report.")
- return
+ await SaveCache(newCache)
+ return { compatibleReleased, waitingUpdate, newlyCompatible }
}
- let message = `**Mod Compatibility Check — Minecraft ${minecraft_version}**\n\n`
-
- if (newlyCompatible.length > 0)
+ const SendUpdateMessages = async (channel, compatibleReleased, waitingUpdate, newlyCompatible) =>
{
- message += `**🎉 Mods Recently Updated:**\n`
- for (const { slug } of newlyCompatible)
- message += `✅ ${slug}\n`
- message += `\n`
- }
-
- const stillCompatible = compatibleReleased.filter(
- m => !newlyCompatible.find(n => n.slug === m.slug)
- )
- if (stillCompatible.length > 0)
- {
- message += `**🟢 Mods Compatible:**\n`
- for (const { slug } of stillCompatible)
- message += `✅ ${slug}\n`
- message += `\n`
- }
+ if (!newlyCompatible.length || !waitingUpdate.length)
+ {
+ console.log("[Update]: No mods to report.")
+ return
+ }
+
+ let message = `**Mod Compatibility Check — Minecraft ${minecraft_version}**\n\n`
- if (waitingUpdate.length > 0)
- {
- message += `**⏳ Mods Waiting on Update:**\n`
- for (const { slug } of waitingUpdate)
- message += `❌ ${slug}\n`
- message += `\n`
- }
+ if (newlyCompatible.length > 0)
+ {
+ message += `**🎉 Mods Recently Updated:**\n`
+ for (const { slug } of newlyCompatible)
+ message += `✅ ${slug}\n`
+ message += `\n`
+ }
- await channel.send({ content: message, allowedMentions: { parse: [] }, flags: 4 })
- console.log(`[Discord] Sent update summary (${newlyCompatible.length} updated, ${stillCompatible.length} compatible, ${waitingUpdate.length} waiting).`)
-}
+ const stillCompatible = compatibleReleased.filter(
+ m => !newlyCompatible.find(n => n.slug === m.slug)
+ )
+ if (stillCompatible.length > 0)
+ {
+ message += `**🟢 Mods Compatible:**\n`
+ for (const { slug } of stillCompatible)
+ message += `✅ ${slug}\n`
+ message += `\n`
+ }
-client.once(Events.ClientReady, async readyClient =>
-{
- console.log(`[OK] Logged in as ${readyClient.user.tag}`)
+ if (waitingUpdate.length > 0)
+ {
+ message += `**⏳ Mods Waiting on Update:**\n`
+ for (const { slug } of waitingUpdate)
+ message += `❌ ${slug}\n`
+ message += `\n`
+ }
- const channel = await client.channels.fetch(channel_id).catch(() => null)
- if (!channel) {
- console.error("❌ Could not find channel ID:", channel_id)
- return
+ await channel.send({ content: message, allowedMentions: { parse: [] }, flags: 4 })
+ console.log(`[Discord] Sent update summary (${newlyCompatible.length} updated, ${stillCompatible.length} compatible, ${waitingUpdate.length} waiting).`)
}
- const { compatibleReleased, waitingUpdate, newlyCompatible } = await CheckModUpdates()
- await SendUpdateMessages(channel, compatibleReleased, waitingUpdate, newlyCompatible)
-
- setInterval(async () =>
+ client.once(Events.ClientReady, async readyClient =>
{
+ console.log(`[OK] Logged in as ${readyClient.user.tag}`)
+
+ const channel = await client.channels.fetch(channel_id).catch(() => null)
+ if (!channel) {
+ console.error("❌ Could not find channel ID:", channel_id)
+ return
+ }
+
const { compatibleReleased, waitingUpdate, newlyCompatible } = await CheckModUpdates()
await SendUpdateMessages(channel, compatibleReleased, waitingUpdate, newlyCompatible)
- }, 60 * 60 * 1000)
-})
-client.login(token)
+ setInterval(async () =>
+ {
+ const { compatibleReleased, waitingUpdate, newlyCompatible } = await CheckModUpdates()
+ await SendUpdateMessages(channel, compatibleReleased, waitingUpdate, newlyCompatible)
+ }, 60 * 60 * 1000)
+ })
+
+ client.login(token)
diff --git a/package.json b/package.json
index 58653f4..f2a0b0c 100644
--- a/package.json
+++ b/package.json
@@ -13,7 +13,7 @@
"license": "Apache-2.0",
"author": "hachem",
"type": "commonjs",
- "main": "updater/app.js",
+ "main": "bot/app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},