1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
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)
|