From c673ae27f6b4c00f5a819bf36823d2b9a5a85bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 05:48:34 +0300 Subject: [PATCH 01/27] Bumb version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e3b95e8..49f35ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "eximiabots-radiox", - "version": "0.3.5", + "version": "0.3.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "eximiabots-radiox", - "version": "0.3.5", + "version": "0.3.6", "license": "MIT", "dependencies": { "@discordjs/builders": "^0.6.0", diff --git a/package.json b/package.json index fdf28ac..1e8fe7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eximiabots-radiox", - "version": "0.3.5", + "version": "0.3.6", "description": "Internet Radio to your Discord guild", "main": "index.js", "scripts": { From f9d195788c5e7b7fc1229d07e27cb2cd4903f644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 14:42:49 +0300 Subject: [PATCH 02/27] Changed interaction replies to ephemeral in commands --- src/client/commands/list.js | 5 ++++- src/client/commands/maintenance.js | 5 ++++- src/client/commands/play.js | 15 ++++++++++++--- src/client/commands/statistics.js | 5 ++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/client/commands/list.js b/src/client/commands/list.js index b0ce3fd..b89772e 100644 --- a/src/client/commands/list.js +++ b/src/client/commands/list.js @@ -9,7 +9,10 @@ module.exports = { let message = {}; if(!client.stations) { message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); - return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist); + return interaction.reply({ + content: client.messageEmojis["error"] + message.errorToGetPlaylist, + ephemeral: true + }); } const radio = client.radio.get(interaction.guild.id); diff --git a/src/client/commands/maintenance.js b/src/client/commands/maintenance.js index b76af77..111e04d 100644 --- a/src/client/commands/maintenance.js +++ b/src/client/commands/maintenance.js @@ -11,7 +11,10 @@ module.exports = { async execute(interaction, client) { let message = {}; - if(!client.funcs.isDev(client.config.devId, interaction.user.id)) return interaction.reply(client.messageEmojis["error"] + client.messages.notAllowed); + if(!client.funcs.isDev(client.config.devId, interaction.user.id)) return interaction.reply({ + content: client.messageEmojis["error"] + client.messages.notAllowed, + ephemeral: true + }); let action = interaction.options?.getNumber("action") ?? interaction.values?.[0]; const options = new Array( { diff --git a/src/client/commands/play.js b/src/client/commands/play.js index 3384238..7b996e0 100644 --- a/src/client/commands/play.js +++ b/src/client/commands/play.js @@ -43,10 +43,16 @@ module.exports = { if (!query) return interaction.reply(client.messages.noQuery); const permissions = voiceChannel.permissionsFor(interaction.client.user); if (!permissions.has("CONNECT")) { - return interaction.reply(client.messageEmojis["error"] + client.messages.noPermsConnect); + return interaction.reply({ + content: client.messageEmojis["error"] + client.messages.noPermsConnect, + ephemeral: true + }); } if (!permissions.has("SPEAK")) { - return interaction.reply(client.messageEmojis["error"] + client.messages.noPermsSpeak); + return interaction.reply({ + content: client.messageEmojis["error"] + client.messages.noPermsSpeak, + ephemeral: true + }); } let station; const number = parseInt(query - 1); @@ -129,7 +135,10 @@ module.exports = { } catch (error) { console.log(error); client.radio.delete(interaction.guild.id); - return interaction.reply(client.messageEmojis["error"] + `An error occured: ${error}`); + return interaction.reply({ + content: client.messageEmojis["error"] + `An error occured: ${error}`, + ephemeral: true + }); } } }; \ No newline at end of file diff --git a/src/client/commands/statistics.js b/src/client/commands/statistics.js index 7e87510..d9ba2fe 100644 --- a/src/client/commands/statistics.js +++ b/src/client/commands/statistics.js @@ -15,7 +15,10 @@ module.exports = { if(!client.stations) { message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); - return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist); + return interaction.reply({ + content: client.messageEmojis["error"] + message.errorToGetPlaylist, + ephemeral: true + }); } if(!currentGuild || currentGuild && !currentGuild.statistics){ From 115a2e7589fce69cbfe15d087c4cefbd34e9be30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 16:06:17 +0300 Subject: [PATCH 03/27] Updated Dependencies --- package-lock.json | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 49f35ad..b76f851 100644 --- a/package-lock.json +++ b/package-lock.json @@ -666,9 +666,9 @@ } }, "node_modules/acorn-walk": { - "version": "8.1.1", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.1.1.tgz", - "integrity": "sha512-FbJdceMlPHEAWJOILDk1fXD8lnTlEIWFkqtfk+MvmL5q/qlHfN7GEHcsFZWt/Tea9jRNPWUZG4G976nqAAmU9w==", + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", "dev": true, "engines": { "node": ">=0.4.0" @@ -3549,9 +3549,9 @@ } }, "node_modules/ts-node/node_modules/acorn": { - "version": "8.4.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.4.1.tgz", - "integrity": "sha512-asabaBSkEKosYKMITunzX177CXxQ4Q8BSSzMTKD+FefUhipQC70gfW5SiUDhYQ3vk8G+81HqQk7Fv9OXwwn9KA==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.5.0.tgz", + "integrity": "sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -4358,9 +4358,9 @@ "requires": {} }, "acorn-walk": { - "version": "8.1.1", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.1.1.tgz", - "integrity": "sha512-FbJdceMlPHEAWJOILDk1fXD8lnTlEIWFkqtfk+MvmL5q/qlHfN7GEHcsFZWt/Tea9jRNPWUZG4G976nqAAmU9w==", + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", "dev": true }, "agent-base": { @@ -6516,9 +6516,9 @@ }, "dependencies": { "acorn": { - "version": "8.4.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.4.1.tgz", - "integrity": "sha512-asabaBSkEKosYKMITunzX177CXxQ4Q8BSSzMTKD+FefUhipQC70gfW5SiUDhYQ3vk8G+81HqQk7Fv9OXwwn9KA==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.5.0.tgz", + "integrity": "sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q==", "dev": true } } From 956f1f7b6d8824de4f13df24c5227d9949e2c33c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 16:19:56 +0300 Subject: [PATCH 04/27] Updated README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 53033a4..b40c2b8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Internet Radio to your Discord guild This bot is using Gitea repo to get radio stations from [playlist.json](https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json) file. List is currently maintained by Christer Warén. You can use alternative list with same format when using RADIOX_STATIONSLISTURL environment variable. ## Docker -1. `docker build -t warengroup/eximiabots-radiox .` +1. `docker build -t warengroup/eximiabots-radiox . --pull` 2. `docker run --name radiox-dev -d --net host -e DISCORD_TOKEN= -v "$PWD/datastore":/usr/src/app/datastore/ warengroup/eximiabots-radiox` ## Join our Discord Server From 370701a4b93a2467fb1c98c1e794c0120a1a1155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 16:28:17 +0300 Subject: [PATCH 05/27] Updated Dependencies --- package-lock.json | 16 ++++++++-------- package.json | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index b76f851..68c1e0c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "discord.js": "^13.1.0", "dotenv": "^10.0.0", "libsodium-wrappers": "^0.7.9", - "node-fetch": "^2.6.1", + "node-fetch": "^2.6.2", "path": "^0.12.7" }, "devDependencies": { @@ -36,7 +36,7 @@ "typescript": "^4.4.2" }, "engines": { - "node": ">=16.6.0", + "node": ">=16.8.0", "npm": ">=7.0.0" } }, @@ -2535,9 +2535,9 @@ "dev": true }, "node_modules/node-fetch": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", - "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==", + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz", + "integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA==", "engines": { "node": "4.x || >=6.0.0" } @@ -5797,9 +5797,9 @@ "dev": true }, "node-fetch": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", - "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz", + "integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA==" }, "nodemon": { "version": "2.0.12", diff --git a/package.json b/package.json index 1e8fe7b..9b746c8 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "discord.js": "^13.1.0", "dotenv": "^10.0.0", "libsodium-wrappers": "^0.7.9", - "node-fetch": "^2.6.1", + "node-fetch": "^2.6.2", "path": "^0.12.7" }, "devDependencies": { @@ -45,7 +45,7 @@ "typescript": "^4.4.2" }, "engines": { - "node": ">=16.6.0", + "node": ">=16.8.0", "npm": ">=7.0.0" } } \ No newline at end of file From 45d68ff4ab244527a3dc57082b22478d00a24d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 16:51:53 +0300 Subject: [PATCH 06/27] Added dependabot config --- .github/dependabot.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..6b1750e --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,19 @@ +version: 2 +updates: + # GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + target-branch: "develop" + labels: + - "dependencies" + + # npm + - package-ecosystem: "npm" + directory: "/" + schedule: + interval: "daily" + target-branch: "develop" + labels: + - "dependencies" \ No newline at end of file From 2e402de6bf8f815d4e002872b61dfc8c9527efd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 17:08:34 +0300 Subject: [PATCH 07/27] Added CodeQL Analysis workflow (Github Workflow) --- .github/workflows/codeql-analysis.yml | 71 +++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..161ed25 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,71 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ master, stable ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '24 20 * * 6' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'javascript' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 From 2286815485abb7094ae93a15cb896a904e0e5a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 17:16:05 +0300 Subject: [PATCH 08/27] Renamed CodeQL Analyze workflow (Github Workflows) --- .github/workflows/{codeql-analysis.yml => codeql-analyze.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{codeql-analysis.yml => codeql-analyze.yml} (98%) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analyze.yml similarity index 98% rename from .github/workflows/codeql-analysis.yml rename to .github/workflows/codeql-analyze.yml index 161ed25..ff0f5b0 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analyze.yml @@ -22,7 +22,7 @@ on: jobs: analyze: - name: Analyze + name: CodeQL Analyze runs-on: ubuntu-latest permissions: actions: read From 6e0b2f5092b001f29036f4600a5c0f6fdd36232a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 17:18:08 +0300 Subject: [PATCH 09/27] Updated CodeQL Analyze workflow (Github Workflows) --- .github/workflows/codeql-analyze.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql-analyze.yml b/.github/workflows/codeql-analyze.yml index ff0f5b0..d303165 100644 --- a/.github/workflows/codeql-analyze.yml +++ b/.github/workflows/codeql-analyze.yml @@ -9,7 +9,7 @@ # the `language` matrix defined below to confirm you have the correct set of # supported CodeQL languages. # -name: "CodeQL" +name: "CodeQL Analyze" on: push: From ebeeadd5c3a17267f8b18d5a328dc8726f7d4c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 17:38:43 +0300 Subject: [PATCH 10/27] Added labeler workflow (Github Workflows) --- .github/workflows/labeler.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/labeler.yml diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 0000000..7667ffb --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,15 @@ +name: Labeler +on: [pull_request] + +jobs: + label: + name: Labeler + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - uses: actions/labeler@v3 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" From bb8a36ad5c5f94bf28774e0a9f1c7ca544904853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 17:44:52 +0300 Subject: [PATCH 11/27] Added labeler config --- .github/labeler.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .github/labeler.yml diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 0000000..e65e022 --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,8 @@ +dependencies: +- any: ['package-lock.json'] + all: ['!package.json'] + +documentation: +- README.md +- LICENSE +- .env_example \ No newline at end of file From 12c8b8558f912d231cd5582b7610ccb85367473f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 18:06:44 +0300 Subject: [PATCH 12/27] Updated labeler config --- .github/labeler.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/labeler.yml b/.github/labeler.yml index e65e022..5b27493 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -1,6 +1,5 @@ dependencies: -- any: ['package-lock.json'] - all: ['!package.json'] +- package-lock.json documentation: - README.md From fa4f5e1e09bbaf3ab08bc84d056b39a1278d2056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 18:07:00 +0300 Subject: [PATCH 13/27] Updated labeler workflow (Github Workflows) --- .github/workflows/labeler.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index 7667ffb..4654e30 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -13,3 +13,4 @@ jobs: - uses: actions/labeler@v3 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" + sync-labels: true \ No newline at end of file From 894a1d82f511eb0e6aaab869e5d32f0bf3b11fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 18:38:46 +0300 Subject: [PATCH 14/27] Updated play command --- src/client/commands/play.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/client/commands/play.js b/src/client/commands/play.js index 7b996e0..bd88b01 100644 --- a/src/client/commands/play.js +++ b/src/client/commands/play.js @@ -17,7 +17,10 @@ module.exports = { let message = {}; if(!client.stations) { message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); - return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist); + return interaction.reply({ + content: client.messageEmojis["error"] + message.errorToGetPlaylist, + ephemeral: true + }); } let query = interaction.options?.getString("query") ?? interaction.values?.[0]; @@ -28,7 +31,7 @@ module.exports = { const radio = client.radio.get(interaction.guild.id); const voiceChannel = interaction.member.voice.channel; if (!radio) { - if (!interaction.member.voice.channel) + if (!voiceChannel) return interaction.reply({ content: client.messageEmojis["error"] + client.messages.noVoiceChannel, ephemeral: true From a9857cb34b707f424e1264925af08615755616b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 19:09:34 +0300 Subject: [PATCH 15/27] Updated play function --- src/client/funcs/play.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/client/funcs/play.js b/src/client/funcs/play.js index 24addeb..fe81608 100644 --- a/src/client/funcs/play.js +++ b/src/client/funcs/play.js @@ -27,7 +27,10 @@ module.exports = async function play(interaction, guild, client, url) { radio.connection?.destroy(); radio.audioPlayer?.stop(); client.radio.delete(guild.id); - return interaction.reply(client.messages.errorPlaying); + return interaction.reply({ + content: client.messages.errorPlaying, + ephemeral: true + }); }); message.nowplayingDescription = client.messages.nowplayingDescription.replace("%radio.station.name%", radio.station.name); From f9ce2bfaf9f739b9d41e17db069d43cf1a75c665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 19:10:15 +0300 Subject: [PATCH 16/27] Updated play command --- src/client/commands/play.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/client/commands/play.js b/src/client/commands/play.js index bd88b01..000533e 100644 --- a/src/client/commands/play.js +++ b/src/client/commands/play.js @@ -43,7 +43,10 @@ module.exports = { ephemeral: true }); } - if (!query) return interaction.reply(client.messages.noQuery); + if (!query) return interaction.reply({ + content: client.messages.noQuery, + ephemeral: true + }); const permissions = voiceChannel.permissionsFor(interaction.client.user); if (!permissions.has("CONNECT")) { return interaction.reply({ @@ -75,17 +78,15 @@ module.exports = { station = client.stations[number]; } } else { - if (query.length < 3) - return interaction.reply({ - content: client.messageEmojis["error"] + client.messages.tooShortSearch, - ephemeral: true - }); + if (query.length < 3) return interaction.reply({ + content: client.messageEmojis["error"] + client.messages.tooShortSearch, + ephemeral: true + }); const sstation = await client.funcs.searchStation(query, client); - if (!sstation) - return interaction.reply({ - content: client.messageEmojis["error"] + client.messages.noSearchResults, - ephemeral: true - }); + if (!sstation) return interaction.reply({ + content: client.messageEmojis["error"] + client.messages.noSearchResults, + ephemeral: true + }); url = sstation.stream[sstation.stream.default]; station = sstation; } From 8316723a6a9bad1e6be87ee8d0d75dc147888750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 19:43:14 +0300 Subject: [PATCH 17/27] Added reload stations option in maintenance command --- src/client/commands/maintenance.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/client/commands/maintenance.js b/src/client/commands/maintenance.js index 111e04d..09923e6 100644 --- a/src/client/commands/maintenance.js +++ b/src/client/commands/maintenance.js @@ -41,6 +41,12 @@ module.exports = { description: "", value: "6" }, + { + emoji: "<:RadioXList:688541155519889482>", + label: "Reload Stations", + description: "", + value: "7" + }, { emoji: "<:dnd:746069698139127831>", label: "Enable Maintenance Mode", @@ -108,6 +114,18 @@ module.exports = { require(`../commands.js`).execute(client); client.user.setStatus('online'); break; + case "7": + try { + client.funcs.logger('Stations', 'Started fetching list – ' + client.config.stationslistUrl); + client.stations = await fetch(client.config.stationslistUrl) + .then(client.funcs.checkFetchStatus) + .then(response => response.json()); + + client.funcs.logger('Stations', 'Successfully fetched list'); + } catch (error) { + client.funcs.logger('Stations', 'Fetching list failed'); + } + break; case "8": client.user.setStatus('dnd'); break; From d1fe9177afb762f74dfe20788bcdd137a8d9cc97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 19:43:28 +0300 Subject: [PATCH 18/27] Updated play.js --- src/client/commands/play.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/client/commands/play.js b/src/client/commands/play.js index 000533e..8bca7e7 100644 --- a/src/client/commands/play.js +++ b/src/client/commands/play.js @@ -30,18 +30,15 @@ module.exports = { let url = query ? query.replace(/<(.+)>/g, "$1") : ""; const radio = client.radio.get(interaction.guild.id); const voiceChannel = interaction.member.voice.channel; - if (!radio) { - if (!voiceChannel) - return interaction.reply({ - content: client.messageEmojis["error"] + client.messages.noVoiceChannel, - ephemeral: true - }); - } else { - if (voiceChannel !== radio.voiceChannel) - return interaction.reply({ - content: client.messageEmojis["error"] + client.messages.wrongVoiceChannel, - ephemeral: true - }); + if (!voiceChannel) return interaction.reply({ + content: client.messageEmojis["error"] + client.messages.noVoiceChannel, + ephemeral: true + }); + if (radio) { + if (voiceChannel !== radio.voiceChannel) return interaction.reply({ + content: client.messageEmojis["error"] + client.messages.wrongVoiceChannel, + ephemeral: true + }); } if (!query) return interaction.reply({ content: client.messages.noQuery, From 3ac284e2374dc4ad9e2ec7fb2f7dadd82a5cb8b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 20:42:14 +0300 Subject: [PATCH 19/27] Updated maintenance command --- src/client/commands/maintenance.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/commands/maintenance.js b/src/client/commands/maintenance.js index 09923e6..58fdce7 100644 --- a/src/client/commands/maintenance.js +++ b/src/client/commands/maintenance.js @@ -1,4 +1,5 @@ import Discord from "discord.js"; +import fetch from "node-fetch"; module.exports = { name: 'maintenance', From 884233a938a65ab878e95ee229edc621eee0ffc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 21:44:45 +0300 Subject: [PATCH 20/27] Updated SIGTERM event --- src/client/events/SIGTERM.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/events/SIGTERM.js b/src/client/events/SIGTERM.js index 52daa75..99e7af3 100644 --- a/src/client/events/SIGTERM.js +++ b/src/client/events/SIGTERM.js @@ -1,6 +1,6 @@ module.exports = { name: 'SIGTERM', - async execute(client) { + execute(client) { process.emit('SIGINT'); } } \ No newline at end of file From 4edfe6848c49035574d3c7789cdb1179c0f55215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 21:44:59 +0300 Subject: [PATCH 21/27] Updated SIGINT event --- src/client/events/SIGINT.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/client/events/SIGINT.js b/src/client/events/SIGINT.js index 55d2a0b..a63248a 100644 --- a/src/client/events/SIGINT.js +++ b/src/client/events/SIGINT.js @@ -1,23 +1,18 @@ -const { REST } = require('@discordjs/rest'); -const { Routes } = require('discord-api-types/v9'); -const { token, version } = require('../../config.js'); - module.exports = { name: 'SIGINT', - async execute(client) { + execute(client) { client.user.setStatus('dnd'); console.log("\n"); client.funcs.logger("Bot", "Closing"); console.log("\n"); + + client.funcs.saveRadios(client); - setTimeout(async function () { - let message = {}; - - if (!client.stations) return process.exit(); - - await client.funcs.saveRadios(client); - await process.exit(); - }, 5000); + setInterval(() => { + if(client.radio.size == 0){ + process.exit(); + } + }, 500); } } \ No newline at end of file From 5bf4bd9a1ceef4f448c1a9e128dc6753ee4b68d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 21:45:13 +0300 Subject: [PATCH 22/27] Updated maintenance command --- src/client/commands/maintenance.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/client/commands/maintenance.js b/src/client/commands/maintenance.js index 58fdce7..5de9f58 100644 --- a/src/client/commands/maintenance.js +++ b/src/client/commands/maintenance.js @@ -97,17 +97,13 @@ module.exports = { break; case "4": client.user.setStatus('idle'); - setTimeout(function () { - client.funcs.saveRadios(client); - }, 5000); + client.funcs.saveRadios(client); client.user.setStatus('online'); break; case "5": client.user.setStatus('idle'); let guilds = await client.guilds.fetch(); - setTimeout(function () { - client.funcs.restoreRadios(client, guilds); - }, 5000); + client.funcs.restoreRadios(client, guilds); client.user.setStatus('online'); break; case "6": From 33e4a416a9c5d1e2661a3408192c9d9eb8d8c7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 21:46:59 +0300 Subject: [PATCH 23/27] Updated saveRadios function --- src/client/funcs/saveRadios.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/funcs/saveRadios.js b/src/client/funcs/saveRadios.js index 5311727..30280e1 100644 --- a/src/client/funcs/saveRadios.js +++ b/src/client/funcs/saveRadios.js @@ -1,4 +1,4 @@ -module.exports = async function saveRadios(client) { +module.exports = function saveRadios(client) { let currentRadios = client.radio.keys(); let radio = currentRadios.next(); @@ -7,8 +7,8 @@ module.exports = async function saveRadios(client) { currentRadio.guild = client.datastore.getEntry(radio.value).guild; if (currentRadio) { - await client.funcs.statisticsUpdate(client, currentRadio.guild, currentRadio); - await client.funcs.saveState(client, currentRadio.guild, currentRadio); + client.funcs.statisticsUpdate(client, currentRadio.guild, currentRadio); + client.funcs.saveState(client, currentRadio.guild, currentRadio); currentRadio.connection?.destroy(); currentRadio.audioPlayer?.stop(); currentRadio.message?.delete(); From 1371a83e90b7d7627c860a7cd8aa870831462547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 21:56:19 +0300 Subject: [PATCH 24/27] Removed permissions property from commands --- src/client/commands/bug.js | 1 - src/client/commands/help.js | 1 - src/client/commands/invite.js | 1 - src/client/commands/list.js | 1 - src/client/commands/maintenance.js | 1 - src/client/commands/next.js | 1 - src/client/commands/nowplaying.js | 1 - src/client/commands/play.js | 1 - src/client/commands/prev.js | 1 - src/client/commands/statistics.js | 1 - src/client/commands/status.js | 1 - src/client/commands/stop.js | 1 - src/client/funcs/check.js | 12 ++---------- 13 files changed, 2 insertions(+), 22 deletions(-) diff --git a/src/client/commands/bug.js b/src/client/commands/bug.js index a87a638..48091b1 100644 --- a/src/client/commands/bug.js +++ b/src/client/commands/bug.js @@ -3,7 +3,6 @@ import Discord from "discord.js"; module.exports = { name: 'bug', description: 'Report a bug', - permission: 'none', category: 'info', async execute(interaction, client) { let message = {}; diff --git a/src/client/commands/help.js b/src/client/commands/help.js index 2b7da61..212346b 100644 --- a/src/client/commands/help.js +++ b/src/client/commands/help.js @@ -3,7 +3,6 @@ import Discord from "discord.js"; module.exports = { name: 'help', description: 'Get help using bot', - permission: 'none', category: 'info', execute(interaction, client) { let message = {}; diff --git a/src/client/commands/invite.js b/src/client/commands/invite.js index 38db87a..5c66601 100644 --- a/src/client/commands/invite.js +++ b/src/client/commands/invite.js @@ -3,7 +3,6 @@ import Discord from "discord.js"; module.exports = { name: 'invite', description: 'Invite Bot', - permission: 'none', category: 'info', execute(interaction, client) { let message = {}; diff --git a/src/client/commands/list.js b/src/client/commands/list.js index b89772e..5a18b64 100644 --- a/src/client/commands/list.js +++ b/src/client/commands/list.js @@ -3,7 +3,6 @@ import Discord from "discord.js"; module.exports = { name: 'list', description: 'List radio stations', - permission: 'none', category: 'radio', execute(interaction, client) { let message = {}; diff --git a/src/client/commands/maintenance.js b/src/client/commands/maintenance.js index 5de9f58..86f23e9 100644 --- a/src/client/commands/maintenance.js +++ b/src/client/commands/maintenance.js @@ -4,7 +4,6 @@ import fetch from "node-fetch"; module.exports = { name: 'maintenance', description: 'Bot Maintenance', - permission: 'none', category: 'info', options: [ { type: "NUMBER", name: "action", description: "Select action", required: false} diff --git a/src/client/commands/next.js b/src/client/commands/next.js index 56747d3..94d1f51 100644 --- a/src/client/commands/next.js +++ b/src/client/commands/next.js @@ -1,7 +1,6 @@ module.exports = { name: 'next', description: 'Next Station', - permission: 'none', category: 'radio', async execute(interaction, client, command) { if (client.funcs.check(client, interaction, command)) { diff --git a/src/client/commands/nowplaying.js b/src/client/commands/nowplaying.js index e6b2e62..bf42da9 100644 --- a/src/client/commands/nowplaying.js +++ b/src/client/commands/nowplaying.js @@ -3,7 +3,6 @@ import Discord from "discord.js"; module.exports = { name: 'nowplaying', description: 'Current Radio Station', - permission: 'none', category: 'radio', async execute(interaction, client, command) { if (client.funcs.check(client, interaction, command)) { diff --git a/src/client/commands/play.js b/src/client/commands/play.js index 8bca7e7..fb29976 100644 --- a/src/client/commands/play.js +++ b/src/client/commands/play.js @@ -11,7 +11,6 @@ module.exports = { options: [ { type: "STRING", name: "query", description: "Select station", required: false} ], - permission: "none", category: "radio", async execute(interaction, client) { let message = {}; diff --git a/src/client/commands/prev.js b/src/client/commands/prev.js index eb7e572..ef4393a 100644 --- a/src/client/commands/prev.js +++ b/src/client/commands/prev.js @@ -1,7 +1,6 @@ module.exports = { name: 'prev', description: 'Previous Station', - permission: 'none', category: 'radio', async execute(interaction, client, command) { if (client.funcs.check(client, interaction, command)) { diff --git a/src/client/commands/statistics.js b/src/client/commands/statistics.js index d9ba2fe..df31e33 100644 --- a/src/client/commands/statistics.js +++ b/src/client/commands/statistics.js @@ -4,7 +4,6 @@ import Discord from "discord.js"; module.exports = { name: 'statistics', description: 'Show statistics', - permission: 'none', category: 'info', execute(interaction, client) { let message = {}; diff --git a/src/client/commands/status.js b/src/client/commands/status.js index 6a3ce7b..c40fdbd 100644 --- a/src/client/commands/status.js +++ b/src/client/commands/status.js @@ -3,7 +3,6 @@ import Discord from "discord.js"; module.exports = { name: 'status', description: 'Bot Status', - permission: 'none', category: 'info', async execute(interaction, client) { let message = {}; diff --git a/src/client/commands/stop.js b/src/client/commands/stop.js index 9c53249..fbdb3e9 100644 --- a/src/client/commands/stop.js +++ b/src/client/commands/stop.js @@ -3,7 +3,6 @@ import Discord from "discord.js"; module.exports = { name: 'stop', description: 'Stop radio', - permission: 'none', category: 'radio', async execute(interaction, client, command) { const radio = client.radio.get(interaction.guild.id); diff --git a/src/client/funcs/check.js b/src/client/funcs/check.js index 38fe48a..cfbbbc5 100644 --- a/src/client/funcs/check.js +++ b/src/client/funcs/check.js @@ -24,14 +24,6 @@ module.exports = function (client, interaction, command) { }); return false; } - if(!command.permission == 'none'){ - if (!permissions.has(command.permission)) { - message.noPerms = client.messages.noPerms.replace("%command.permission%", command.permission); - interaction.reply({ - content: client.messageEmojis["error"] + message.noPerms, - ephemeral: true - }); - return false; - } else return true; - } else return true; + + return true; }; From cc8b44db9bce5a67df8579b648cc0be21e1ac6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 22:35:14 +0300 Subject: [PATCH 25/27] Fixed next command --- src/client/commands/next.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/client/commands/next.js b/src/client/commands/next.js index 94d1f51..c4ae658 100644 --- a/src/client/commands/next.js +++ b/src/client/commands/next.js @@ -16,8 +16,6 @@ module.exports = { ephemeral: true }); - interaction.deferUpdate(); - let url = station.stream[station.stream.default]; client.funcs.statisticsUpdate(client, interaction.guild, radio); @@ -27,7 +25,14 @@ module.exports = { radio.station = station; radio.textChannel = interaction.channel; radio.startTime = date.getTime(); - client.funcs.play(null, interaction.guild, client, url); + + if(interaction.isCommand()) { + client.funcs.play(interaction, interaction.guild, client, url); + } + if(interaction.isButton()) { + interaction.deferUpdate(); + client.funcs.play(null, interaction.guild, client, url); + } } } From 984e8aab76ccadc19f0ea45a0bbf89a986025255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 22:35:21 +0300 Subject: [PATCH 26/27] Fixed prev command --- src/client/commands/prev.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/client/commands/prev.js b/src/client/commands/prev.js index ef4393a..df987b8 100644 --- a/src/client/commands/prev.js +++ b/src/client/commands/prev.js @@ -16,8 +16,6 @@ module.exports = { ephemeral: true }); - interaction.deferUpdate(); - let url = station.stream[station.stream.default]; client.funcs.statisticsUpdate(client, interaction.guild, radio); @@ -27,7 +25,14 @@ module.exports = { radio.station = station; radio.textChannel = interaction.channel; radio.startTime = date.getTime(); - client.funcs.play(null, interaction.guild, client, url); + + if(interaction.isCommand()) { + client.funcs.play(interaction, interaction.guild, client, url); + } + if(interaction.isButton()) { + interaction.deferUpdate(); + client.funcs.play(null, interaction.guild, client, url); + } } } From ab950352fab5d80ef8e63cf12278a64f826c5e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 6 Sep 2021 22:35:49 +0300 Subject: [PATCH 27/27] Added uncaughtException event --- src/Client.ts | 4 ++++ src/client/events/uncaughtException.js | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 src/client/events/uncaughtException.js diff --git a/src/Client.ts b/src/Client.ts index 4dc9611..761e7cd 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -85,6 +85,10 @@ class RadioClient extends Client { process.on('SIGTERM', () => { require(`${events}SIGTERM`).execute(this); }); + + process.on('uncaughtException', (error) => { + require(`${events}uncaughtException`).execute(this, error); + }); this.on("error", error => { console.error(error); diff --git a/src/client/events/uncaughtException.js b/src/client/events/uncaughtException.js new file mode 100644 index 0000000..5df8a0b --- /dev/null +++ b/src/client/events/uncaughtException.js @@ -0,0 +1,7 @@ +module.exports = { + name: 'uncaughtException', + execute(client, error) { + console.log(error.stack); + process.emit('SIGINT'); + } +} \ No newline at end of file