diff options
Diffstat (limited to 'bot')
| -rw-r--r-- | bot/app.js | 162 |
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) |
