hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/bot
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-29 02:17:12 +0200
committerhachem <im@hachem.wtf>2026-08-29 02:17:12 +0200
commite56d21fa04450d118f76347a96a12d1d5477958f (patch)
tree06d590ef64153e2ab92306a4a7cc63d6fef47286 /bot
parent43d92fd60d75c4a1260757c75b1e1eefc0ea8952 (diff)
setup: prepare go workspace
Diffstat (limited to 'bot')
-rw-r--r--bot/app.js162
1 files changed, 0 insertions, 162 deletions
diff --git a/bot/app.js b/bot/app.js
deleted file mode 100644
index 59219eb..0000000
--- a/bot/app.js
+++ /dev/null
@@ -1,162 +0,0 @@
-const
-{
- Client,
- Events,
- GatewayIntentBits
-} = require("discord.js")
-
-const { LoadConfig, LoadApi, LoadCache, SaveCache } = require("../lib/config")
-const { GetModVersions, GetLatestVersion, GetCompatibleVersion } = require("../lib/modrinth")
-
-const config = LoadConfig()
-const api = LoadApi()
-
-const
-{
- channel_id,
- check_interval_minutes,
- minecraft_version,
- modrinth_mods
-} = config
-
-const { token } = api
-
-const client = new Client
-({
- intents:
- [
- GatewayIntentBits.Guilds,
- GatewayIntentBits.GuildMessages
- ]
-})
-
-const CheckMods = async () =>
-{
- const cache = await LoadCache()
- const newCache = { ...cache }
-
- const noCompatible = []
- const newlyCompatible = []
- const stillCompatibleUpdate = []
-
- for (const slug of modrinth_mods)
- {
- const versions = await GetModVersions(slug)
- if (!versions)
- continue
-
- const latest = GetLatestVersion(versions)
- const compatible = GetCompatibleVersion(versions, minecraft_version)
-
- const cached = cache[slug] ||
- {
- compatible: null,
- latest: null
- }
-
- newCache[slug] =
- {
- compatible: compatible ? compatible.id : null,
- latest: latest ? latest.id : null
- }
-
- if (!compatible)
- {
- noCompatible.push(slug)
- continue
- }
-
- if (!cached.compatible && compatible)
- {
- newlyCompatible.push(slug)
- continue
- }
-
- if (latest && latest.id !== cached.latest)
- stillCompatibleUpdate.push(slug)
- }
-
- await SaveCache(newCache)
-
- return { noCompatible, newlyCompatible, stillCompatibleUpdate }
-}
-
-const SendUpdate = async (channel, noCompatible, newlyCompatible, stillCompatibleUpdate) =>
-{
- if (!noCompatible.length && !newlyCompatible.length && !stillCompatibleUpdate.length)
- return
-
- let msg = `**Modrinth Compatibility — ${minecraft_version}**\n\n`
-
- if (noCompatible.length)
- {
- msg += `**❌ No compatible version available:**\n`
- for (const slug of noCompatible)
- msg += `❌ ${slug}\n`
- msg += `\n`
- }
-
- if (newlyCompatible.length)
- {
- msg += `**🎉 Now Compatible:**\n`
- for (const slug of newlyCompatible)
- msg += `🎉 ${slug}\n`
- msg += `\n`
- }
-
- if (stillCompatibleUpdate.length)
- {
- msg += `**🟢 Updated (still compatible):**\n`
- for (const slug of stillCompatibleUpdate)
- msg += `🟢 ${slug}\n`
- msg += `\n`
- }
-
- await channel.send
- ({
- content: msg,
- allowedMentions: { parse: [] }
- })
-
- console.log("[Discord] Update message sent.")
-}
-
-client.once(Events.ClientReady, async c =>
-{
- console.log(`[OK] Logged in as ${c.user.tag}`)
-
- let channel = null
- try
- {
- channel = await client.channels.fetch(channel_id)
- console.log("Fetched channel:", channel.name, "type:", channel.type)
- }
- catch
- {
- console.error("❌ Failed to fetch channel:", channel_id)
- return
- }
-
- const
- {
- noCompatible,
- newlyCompatible,
- stillCompatibleUpdate
- } = await CheckMods()
-
- await SendUpdate(channel, noCompatible, newlyCompatible, stillCompatibleUpdate)
-
- setInterval(async () =>
- {
- const
- {
- noCompatible,
- newlyCompatible,
- stillCompatibleUpdate
- } = await CheckMods()
-
- await SendUpdate(channel, noCompatible, newlyCompatible, stillCompatibleUpdate)
- }, check_interval_minutes * 60 * 1000)
-})
-
-client.login(token)