diff --git a/.eslintrc.json b/.eslintrc.json index d0acadf..11a55b9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -23,7 +23,7 @@ "key-spacing": 2, "keyword-spacing": 2, "max-statements-per-line": 2, - "max-len": [2, { "code": 280 }], + "max-len": [2, { "code": 250 }], "new-parens": 2, "no-array-constructor": 2, "no-compare-neg-zero": 2, diff --git a/README.md b/README.md index 28ccdee..90aa1bc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,18 @@ # Bundbot Discord-Bot, welcher die [bund.dev-API](https://bund.dev/) nutzt, um mehr (oder weniger) hilfreiche Informationen anzuzeigen -## Autobahn +## Setup + +`config.json`: +```json +{ + "token": "" +} +``` + +## Features + +### Autobahn - Alle Autobahnen auflisten (`-list`) - Webcams einer Autobahn auflisten (`-listwebcams `) - Webcams einer Autobahn auflisten (`-listwarnings `) @@ -10,10 +21,10 @@ Discord-Bot, welcher die [bund.dev-API](https://bund.dev/) nutzt, um mehr (oder - Rastplätze einer Autobahn auflisten (`-listrastplätze `) - Elektrische Ladestationen einer Autobahn auflisten (`-listladestationen `) -## NINA +### NINA - Katwarn-Meldungen anzeigen (`-katwarn`) - Biwapp-Meldungen anzeigen (`-biwapp`) - Mowas-Meldungen anzeigen (`-mowas`) -## Lebensmittel- und Produktwarnungen +### Lebensmittel- und Produktwarnungen - Lebensmittel- und Produktwarnungen anzeigen (`-produktwarn`) diff --git a/index.js b/index.js index 59b232d..2755430 100644 --- a/index.js +++ b/index.js @@ -28,9 +28,18 @@ function migrateSlashOptions(options) { return options } +let roads = [] bot.on("ready", async () => { - bot.user.setPresence({activities: [{name: "Custom Status", state: "/help", type: Discord.ActivityType.Custom}]}) - console.log("Bot wurde gestartet .-.") + bot.user.setPresence({activities: [{name: "Custom Status", state: "bund.dev-Bot - Slashcommands", type: Discord.ActivityType.Custom}]}) + console.log("Bot wurde als " + bot.user.tag + " gestartet!") + + const res = await fetch("https://verkehr.autobahn.de/o/autobahn", { + headers: { + Accept: "application/json" + } + }) + const json = await res.json() + roads = json.roads const commands = [ { @@ -60,6 +69,7 @@ bot.on("ready", async () => { name: "id", type: "STRING", description: "Der Name der Autobahn", + autocomplete: true, required: true }] },{ @@ -70,6 +80,7 @@ bot.on("ready", async () => { name: "id", type: "STRING", description: "Der Name der Autobahn", + autocomplete: true, required: true }] },{ @@ -80,6 +91,7 @@ bot.on("ready", async () => { name: "id", type: "STRING", description: "Der Name der Autobahn", + autocomplete: true, required: true }] },{ @@ -90,6 +102,7 @@ bot.on("ready", async () => { name: "id", type: "STRING", description: "Der Name der Autobahn", + autocomplete: true, required: true }] },{ @@ -100,6 +113,7 @@ bot.on("ready", async () => { name: "id", type: "STRING", description: "Der Name der Autobahn", + autocomplete: true, required: true }] },{ @@ -110,6 +124,7 @@ bot.on("ready", async () => { name: "id", type: "STRING", description: "Der Name der Autobahn", + autocomplete: true, required: true }] }] @@ -137,6 +152,11 @@ const checkAutobahn = str => /A\d{1,3}/g.test(str) bot.on("interactionCreate", async interaction => { if (interaction.user.bot || interaction.channel.type == Discord.ChannelType.DM) return + if (interaction.type == Discord.InteractionType.ApplicationCommandAutocomplete) { + const input = interaction.options.getFocused(true) + return interaction.respond(roads.filter(road => road.toLowerCase().includes(input.value)).map(road => ({name: road, value: road})).slice(0, 25)) + } + const reply = data => { if (typeof data == "string" && data.length > 2000) data = data.substring(0, 1997) + "..." interaction.reply(data) @@ -145,14 +165,7 @@ bot.on("interactionCreate", async interaction => { if (interaction.commandName == "autobahn") { const args = [interaction.options.getSubcommand(), interaction.options.getString("id", false)] if (args[0] == "list") { - const res = await fetch("https://verkehr.autobahn.de/o/autobahn", { - headers: { - Accept: "application/json" - } - }) - const json = await res.json() - - interaction.reply("Liste aller Autobahnen in Deutschland:\n\n" + json.roads.join(" ")) + interaction.reply("Liste aller Autobahnen in Deutschland:\n\n" + roads.join(" ")) } else if (args[0] == "webcams") { if (!checkAutobahn(args.join(" "))) return interaction.reply("Du musst eine gültige Autobahn angeben!") const res = await fetch("https://verkehr.autobahn.de/o/autobahn/" + args[1] + "/services/webcam", { @@ -220,7 +233,7 @@ bot.on("interactionCreate", async interaction => { const rastplatze = [] json.parking_lorry.forEach(rastplatz => { - rastplatze.push(rastplatz.title + ": " + rastplatz.description.join(", ").trim()) + rastplatze.push(rastplatz.title + ": " + rastplatz.description.map(desc => desc.trim()).join(", ")) }) reply("Liste aller Rastplätze der **" + args[1] + "**:\n\n" + rastplatze.join("\n")) } else if (args[0] == "ladestationen") { diff --git a/package-lock.json b/package-lock.json index ac902ca..048b217 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,12 +27,12 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.22.13", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz", - "integrity": "sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.23.4.tgz", + "integrity": "sha512-r1IONyb6Ia+jYR2vvIDhdWdlTGhqbBoFqLTQidzZ4kepUFH15ejXvFHxCVbtl7BOXIudsIubf4E81xeA3h3IXA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.22.13", + "@babel/highlight": "^7.23.4", "chalk": "^2.4.2" }, "engines": { @@ -120,9 +120,9 @@ } }, "node_modules/@babel/highlight": { - "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.20.tgz", - "integrity": "sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.23.4.tgz", + "integrity": "sha512-acGdbYSfp2WheJoJm/EBBBLh/ID8KDc64ISZ9DYtBmC8/Q204PZJLHyzeB5qMzJ5trcOkybd78M4x2KWsUq++A==", "dev": true, "dependencies": { "@babel/helper-validator-identifier": "^7.22.20", @@ -241,9 +241,9 @@ } }, "node_modules/@discordjs/rest": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-2.1.0.tgz", - "integrity": "sha512-5gFWFkZX2JCFSRzs8ltx8bWmyVi0wPMk6pBa9KGIQSDPMmrP+uOrZ9j9HOwvmVWGe+LmZ5Bov0jMnQd6/jVReg==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-2.2.0.tgz", + "integrity": "sha512-nXm9wT8oqrYFRMEqTXQx9DUTeEtXUDMmnUKIhZn6O2EeDY9VCdwj23XCPq7fkqMPKdF7ldAfeVKyxxFdbZl59A==", "dependencies": { "@discordjs/collection": "^2.0.0", "@discordjs/util": "^1.0.2", @@ -318,9 +318,9 @@ } }, "node_modules/@eslint-community/regexpp": { - "version": "4.9.1", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.9.1.tgz", - "integrity": "sha512-Y27x+MBLjXa+0JWDhykM3+JE+il3kHKAEqabfEWq3SDhZjLYb6/BHL/JKFnH3fe207JaXkyDo685Oc2Glt6ifA==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.10.0.tgz", + "integrity": "sha512-Cu96Sd2By9mCNTx2iyKOmq10v22jUVQv0lQnlGNy16oE9589yE+QADPbrMGCkA51cKZSg3Pu/aTJVTGfL/qjUA==", "dev": true, "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" @@ -466,17 +466,17 @@ } }, "node_modules/@types/node": { - "version": "20.9.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.9.0.tgz", - "integrity": "sha512-nekiGu2NDb1BcVofVcEKMIwzlx4NjHlcjhoxxKBNLtz15Y1z7MYf549DFvkHSId02Ax6kGwWntIBPC3l/JZcmw==", + "version": "20.10.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.0.tgz", + "integrity": "sha512-D0WfRmU9TQ8I9PFx9Yc+EBHw+vSpIub4IDvQivcp26PtPrdMGAq5SDcpXEo/epqa/DXotVpekHiLNTg3iaKXBQ==", "dependencies": { "undici-types": "~5.26.4" } }, "node_modules/@types/normalize-package-data": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.3.tgz", - "integrity": "sha512-ehPtgRgaULsFG8x0NeYJvmyH1hmlfsNLujHe9dQEia/7MAJYdzMSi19JtchUHjmBA6XC/75dK55mzZH+RyieSg==", + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz", + "integrity": "sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==", "dev": true }, "node_modules/@types/ws": { @@ -1021,9 +1021,9 @@ } }, "node_modules/flat-cache": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.1.1.tgz", - "integrity": "sha512-/qM2b3LUIaIgviBQovTLvijfyOQXPtSRnRK26ksj2J7rzPIecePUIpJsZ4T02Qg+xiAEKIs5K8dsHEd+VaKa/Q==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.2.0.tgz", + "integrity": "sha512-CYcENa+FtcUKLmhhqyctpclsq7QF38pKjZHsGNiSQF5r4FtoKDWabFDl3hzaEQMvT1LHEysw5twgLvpYYb4vbw==", "dev": true, "dependencies": { "flatted": "^3.2.9", @@ -1031,7 +1031,7 @@ "rimraf": "^3.0.2" }, "engines": { - "node": ">=12.0.0" + "node": "^10.12.0 || >=12.0.0" } }, "node_modules/flatted": { @@ -1046,6 +1046,15 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", @@ -1099,15 +1108,6 @@ "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", "dev": true }, - "node_modules/has": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.4.tgz", - "integrity": "sha512-qdSAmqLF6209RFj4VVItywPMbm3vWylknmB3nvNiUIs72xAimcM8nVYxYr7ncvZq5qzk9MKIZR8ijqD/1QuYjQ==", - "dev": true, - "engines": { - "node": ">= 0.4.0" - } - }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -1117,6 +1117,18 @@ "node": ">=8" } }, + "node_modules/hasown": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.0.tgz", + "integrity": "sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==", + "dev": true, + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/hosted-git-info": { "version": "2.8.9", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", @@ -1124,9 +1136,9 @@ "dev": true }, "node_modules/ignore": { - "version": "5.2.4", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz", - "integrity": "sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.0.tgz", + "integrity": "sha512-g7dmpshy+gD7mh88OC9NwSGTKoc3kyLAZQRU1mt53Aw/vnvfXnbC+F/7F7QoYVKbV+KNvJx8wArewKy1vXMtlg==", "dev": true, "engines": { "node": ">= 4" @@ -1204,12 +1216,12 @@ } }, "node_modules/is-core-module": { - "version": "2.13.0", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.0.tgz", - "integrity": "sha512-Z7dk6Qo8pOCp3l4tsX2C5ZVas4V+UxwQodwZhLopL91TX8UyyHEXafPcyoeeWuLrwzHcr3igO78wNLwHJHsMCQ==", + "version": "2.13.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.1.tgz", + "integrity": "sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==", "dev": true, "dependencies": { - "has": "^1.0.3" + "hasown": "^2.0.0" }, "funding": { "url": "https://github.com/sponsors/ljharb" diff --git a/package.json b/package.json index 43e3bef..c04c091 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,6 @@ "type": "git", "url": "git+https://github.com/DEVTomatoCake/Bundbot.git" }, - "bugs": { - "url": "https://github.com/DEVTomatoCake/Bundbot/issues" - }, "homepage": "https://github.com/DEVTomatoCake/Bundbot#readme", "dependencies": { "discord.js": "^14.14.1"