diff --git a/api/routes/knowledge.js b/api/routes/knowledge.js new file mode 100644 index 0000000..4acfa8c --- /dev/null +++ b/api/routes/knowledge.js @@ -0,0 +1,48 @@ +const knowledge = [ + { + topic: "cv", + title: "CV Explanation", + content: + "[Theoran's video if you don't want to read](https://www.youtube.com/watch?v=BqNyES4hCTw)\n", + }, + { + topic: "stacking", + title: "How to stack", + content: "Test", + }, + { + topic: "lm secret", + title: "Love Machine Secret Waves", + content: + "Splits are counted as seperate players, so keep that in mind.\n1 player = Reach Wave 17\n2 players = Reach Wave 21\n3 players = Reach Wave 25\n4 players = Reach Wave 29\n5 and 6 players = Reach Wave 33", + }, + { + topic: "old one resistances", + title: "Old One resistances", + content: + "From Thales.\nTavern Incursion Old One:\nFeet - generic 35% nerf\nChest - 50% fire\nLeft Hand - 50% electric\nRight Hand - 50% poison\nHead - 80% nerf all\n\nGreat Old One - Ruthless TBR\nFeet - 35% generic\nChest - 50% fire\nLeft Hand - 50% electric\nRight Hand - 50% poison", + }, +]; + +export const get = async (req, res) => { + const topic = req.query.topic; + if (!topic) { + return res.status(400).json({ error: "no-topic" }); + } + if (topic == "list") { + const topics = knowledge.map((v) => { + return v.topic; + }); + return res.json({ topics }); + } + + for (let idx = 0; idx < knowledge.length; idx++) { + const t = knowledge[idx]; + if (t.topic != topic) continue; + return res.json({ + title: t.title, + content: t.content, + }); + } + res.status(400).json({ error: "topic-not-found" }); +}; diff --git a/bot/commands/kb.js b/bot/commands/kb.js new file mode 100644 index 0000000..3ba8de5 --- /dev/null +++ b/bot/commands/kb.js @@ -0,0 +1,48 @@ +const { EmbedBuilder } = require("discord.js"); +exports.name = "kb"; +exports.description = + ":notebook_with_decorative_cover: Quickly access useful data regarding Dungeon Defenders."; +exports.usage = "CLIENT_PREFIX:kb "; +exports.example = + "CLIENT_PREFIX:kb list (lists available topics)\nCLIENT_PREFIX:kb stacking\nCLIENT_PREFIX:kb cv"; +exports.hidden = false; +exports.run = (client, message, args) => { + const topic = args.join(" "); + if (!topic) { + return message.channel.send( + "Topic argument missing, consult `CLIENT_PREFIX:help kb`.".replaceAll( + "CLIENT_PREFIX:", + client.prefix + ) + ); + } + fetch(client.sharedEndpoint + "knowledge?topic=" + topic) + .then((d) => d.json()) + .then((data) => { + console.log(data); + if (data.error == "topic-not-found") { + return message.channel.send( + "Could not find data entry for the given topic. consult `CLIENT_PREFIX:help kb`.".replaceAll( + "CLIENT_PREFIX:", + client.prefix + ) + ); + } + if (data.topics) { + return message.channel.send( + `List of topics:\n\`\`\`\n${data.topics.join( + "\n" + )}\`\`\`\nUsage: \`CLIENT_PREFIX:kb \``.replaceAll( + "CLIENT_PREFIX:", + client.prefix + ) + ); + } + const { title, content } = data; + const embed = new EmbedBuilder(); + embed.setTitle(title); + embed.setDescription(content); + embed.setColor("Green"); + message.channel.send({ embeds: [embed] }); + }); +}; diff --git a/bot/index.js b/bot/index.js index d1606d2..8c4a846 100644 --- a/bot/index.js +++ b/bot/index.js @@ -21,13 +21,16 @@ const client = new Client({ const DDRNG_GUILD_ID = 148849688722800640; const DDRNG_ALLOWED_CHANNELS = [ 496061346446835732, 499656239572058132, 771329671953776661, + 556864412338749440, ]; client.commands = new Collection(); client.ownerID = 263247134147608578; client.prefix = prefix; client.sharedEndpoint = process.env.SHARED_ENDPOINT; if (!client.sharedEndpoint) - return log.error("client.sharedEndpoint is undefined."); + return log.error( + "client.sharedEndpoint (process.env.SHARED_ENDPOINT) is undefined." + ); fs.readdir("./commands/", (err, files) => { if (err) return console.error(err); @@ -68,7 +71,6 @@ client.on(Events.MessageCreate, async (message) => { try { await message.react(item.emoji); } catch (err) { - message.channel.send("FAILED TO REACT TO MESSAGE! " + err); console.error("Failed to react to message:", err); } } diff --git a/build.bat b/build.bat deleted file mode 100644 index 6993be0..0000000 --- a/build.bat +++ /dev/null @@ -1,7 +0,0 @@ -docker build -t dd-multitool-bot:latest ./bot -docker build -t dd-multitool-api:latest ./api -docker build -t dd-multitool-web:latest ./web - -docker save -o bot.tar dd-multitool-bot:latest -docker save -o api.tar dd-multitool-api:latest -docker save -o web.tar dd-multitool-web:latest \ No newline at end of file