From 1422101939ab5fd96a4d06e7b9aa1969a3f65f9a Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 01:37:17 +0300 Subject: [PATCH 01/24] 3.4.0-dev-0 Added tests for audio services Added GitHub Action for running tests. Now Docker Image building depends on tests completion. --- .github/workflows/publish-docker-image.yaml | 10 +- .github/workflows/tests.yaml | 53 ++++++++ package.json | 5 +- src/ClientIntents.ts | 13 ++ src/EnvironmentVariables.ts | 9 +- src/audioplayer/AudioPlayerCore.ts | 22 +++- src/audioplayer/tests/AudioServices.test.ts | 126 ++++++++++++++++++++ src/main.ts | 19 ++- 8 files changed, 228 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/tests.yaml create mode 100644 src/ClientIntents.ts create mode 100644 src/audioplayer/tests/AudioServices.test.ts diff --git a/.github/workflows/publish-docker-image.yaml b/.github/workflows/publish-docker-image.yaml index d22d8bc..020b685 100644 --- a/.github/workflows/publish-docker-image.yaml +++ b/.github/workflows/publish-docker-image.yaml @@ -1,14 +1,10 @@ name: Publish Docker image on: - push: + workflow_run: + workflows: [ "tests" ] + types: ['completed'] branches: ['master'] - paths-ignore: - - '**/wiki/**' - - '/wiki/**' - - 'docker-compose.yml' - - '.env' - - '*.sh' env: IMAGE_TAG: alexincube/aicotest diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..4558d24 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,53 @@ +name: Tests + +on: + push: + branches: ['**'] + paths-ignore: + - '**/wiki/**' + - '/wiki/**' + - 'docker-compose.yml' + - '.env' + - '*.sh' + pull_request: + branches: ['**'] + paths-ignore: + - '**/wiki/**' + - '/wiki/**' + - 'docker-compose.yml' + - '.env' + - '*.sh' + +jobs: + tests: + runs-on: ubuntu-latest + + steps: + - name: Make env file + uses: SpicyPizza/create-envfile@v2.0 + with: + envkey_DEBUG: true + envkey_SECRET_KEY: ${{ secrets.ENV_DEVELOPMENT }} + file_name: .env.development + fail_on_empty: true + sort_keys: false + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PNPM + uses: pnpm/action-setup@v4 + with: + version: 9 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 22.x + cache: "pnpm" + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Run tests + run: pnpm run test diff --git a/package.json b/package.json index f25166b..5e7f68b 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,14 @@ { "name": "aicbot", - "version": "3.3.1", + "version": "3.4.0", "description": "Discord Bot for playing music", "main": "build/main.js", "scripts": { "build": "tsc", "development": "tsc&& cross-env NODE_ENV=development node build/main.js", "production": "cross-env NODE_ENV=production node build/main.js", - "cookies_grabbing": "cross-env NODE_ENV=development node build/Script_getCookie.js" + "cookies_grabbing": "cross-env NODE_ENV=development node build/Script_getCookie.js", + "test": "tsc&& cross-env NODE_ENV=development node --test" }, "type": "module", "keywords": [], diff --git a/src/ClientIntents.ts b/src/ClientIntents.ts new file mode 100644 index 0000000..2507409 --- /dev/null +++ b/src/ClientIntents.ts @@ -0,0 +1,13 @@ +import { GatewayIntentBits } from 'discord.js'; + +export const clientIntents: Array = [ + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildPresences, + GatewayIntentBits.GuildMembers, + GatewayIntentBits.GuildVoiceStates, + GatewayIntentBits.GuildMessages, + GatewayIntentBits.MessageContent, + GatewayIntentBits.DirectMessages, + GatewayIntentBits.DirectMessageTyping, + GatewayIntentBits.GuildModeration +]; diff --git a/src/EnvironmentVariables.ts b/src/EnvironmentVariables.ts index 34348ed..0861caa 100644 --- a/src/EnvironmentVariables.ts +++ b/src/EnvironmentVariables.ts @@ -1,10 +1,15 @@ import { z } from 'zod'; import * as dotenv from 'dotenv'; import { loggerSend } from './utilities/logger.js'; +import path from 'path'; const loggerPrefixEnv = 'ENV'; -dotenv.config({ path: `.env.${process.env.NODE_ENV}` }); +const envPath = path.resolve(process.cwd(), `.env.${process.env.NODE_ENV}`); + +loggerSend(`Checking environment variables for ${envPath}`, loggerPrefixEnv); + +dotenv.config({ path: envPath }); const envVariables = z.object({ NODE_ENV: z.enum(['development', 'production']), @@ -61,4 +66,4 @@ const envVariables = z.object({ export const ENV = envVariables.parse(process.env); -loggerSend(`Loaded .env.${process.env.NODE_ENV}`, loggerPrefixEnv); +loggerSend(`Loaded variables from ${envPath}`, loggerPrefixEnv); diff --git a/src/audioplayer/AudioPlayerCore.ts b/src/audioplayer/AudioPlayerCore.ts index 98704d0..1ef853f 100644 --- a/src/audioplayer/AudioPlayerCore.ts +++ b/src/audioplayer/AudioPlayerCore.ts @@ -1,4 +1,12 @@ -import { DisTube, PlayOptions, Queue, RepeatMode, Song, Events as DistubeEvents, Playlist } from 'distube'; +import { + DisTube, + PlayOptions, + Queue, + RepeatMode, + Song, + Events as DistubeEvents, + Playlist +} from 'distube'; import { AudioPlayersManager } from './AudioPlayersManager.js'; import { pagination } from '../utilities/pagination/pagination.js'; import { ButtonStyles, ButtonTypes } from '../utilities/pagination/paginationTypes.js'; @@ -58,7 +66,7 @@ export class AudioPlayerCore { options?: PlayOptions ) { try { - const playableThing: Song | Playlist = await this.distube.handler.resolve(song) + const playableThing: Song | Playlist = await this.distube.handler.resolve(song); // I am need manual connect user to a voice channel, because when I am using only Distube "play" // method, getVoiceConnection in @discordjs/voice is not working @@ -72,13 +80,15 @@ export class AudioPlayerCore { } catch (e) { if (ENV.BOT_VERBOSE_LOGGING) loggerError(e); await textChannel.send({ - embeds: [generateErrorEmbed(`${song}\n${e.message}`, i18next.t('audioplayer:play_error') as string)] + embeds: [ + generateErrorEmbed(`${song}\n${e.message}`, i18next.t('audioplayer:play_error') as string) + ] }); - const queue = this.distube.getQueue(voiceChannel.guildId) + const queue = this.distube.getQueue(voiceChannel.guildId); - if (!queue) return - if (queue.songs.length === 0) await this.stop(voiceChannel.guild) + if (!queue) return; + if (queue.songs.length === 0) await this.stop(voiceChannel.guild); } } diff --git a/src/audioplayer/tests/AudioServices.test.ts b/src/audioplayer/tests/AudioServices.test.ts new file mode 100644 index 0000000..d570f7e --- /dev/null +++ b/src/audioplayer/tests/AudioServices.test.ts @@ -0,0 +1,126 @@ +import * as assert from 'node:assert'; +import { describe, it, before } from 'node:test'; +import { DisTube } from 'distube'; +import { Client } from 'discord.js'; +import { clientIntents } from '../../ClientIntents.js'; +import { LoadPlugins } from '../LoadPlugins.js'; +import '../../EnvironmentVariables.js'; +import { loggerWarn } from '../../utilities/logger.js'; + +let distube: DisTube; +const djsClient: Client = new Client({ intents: clientIntents }); + +before(async () => { + loggerWarn('If you want to run all this tests successfully, provide all optional .env variables'); + + distube = new DisTube(djsClient, { + nsfw: true, + plugins: await LoadPlugins() + }); +}); + +describe('Audio Services', () => { + describe('Youtube', () => { + it('Video', async () => { + const song = await distube.handler.resolve('https://www.youtube.com/watch?v=atgjKEgSqSU'); + + assert.ok(song); + }); + + it('Video 18+', async () => { + const song = await distube.handler.resolve('https://www.youtube.com/watch?v=T1UbWo70Uto'); + + assert.ok(song); + }); + + it('Playlist', async () => { + const playlist = await distube.handler.resolve( + 'https://www.youtube.com/watch?v=qq-RGFyaq0U&list=PLefKpFQ8Pvy5aCLAGHD8Zmzsdljos-t2l' + ); + + assert.ok(playlist); + }); + }); + + describe(`Spotify`, () => { + it('Song', async () => { + const song = await distube.handler.resolve( + 'https://open.spotify.com/track/2vBIOyCqBAoZ4Fxc4JOKL3?si=7088fe2f13c840cd' + ); + + assert.ok(song); + }); + + it('Playlist', async () => { + const playlist = await distube.handler.resolve( + 'https://open.spotify.com/playlist/4Ip3oQJlyl9Zvzp33h1GSe?si=ce13625f480e44ff' + ); + + assert.ok(playlist); + }); + }); + + describe(`SoundCloud`, () => { + it('Song', async () => { + const song = await distube.handler.resolve( + 'https://soundcloud.com/u6lg5vfbfely/ninja-gaiden-2-ost-a-long-way' + ); + + assert.ok(song); + }); + + it('Playlist', async () => { + const playlist = await distube.handler.resolve( + 'https://soundcloud.com/u6lg5vfbfely/sets/music' + ); + + assert.ok(playlist); + }); + }); + + describe(`Yandex Music`, () => { + it('Song', async () => { + const song = await distube.handler.resolve( + 'https://music.yandex.com/album/10030/track/38634572' + ); + + assert.ok(song); + }); + + it('Playlist', async () => { + const song = await distube.handler.resolve( + 'https://music.yandex.ru/users/alexander.tsimbalistiy/playlists/1000' + ); + + assert.ok(song); + }); + + it('Album', async () => { + const song = await distube.handler.resolve('https://music.yandex.ru/album/5307396'); + + assert.ok(song); + }); + }); + + describe('Apple Music', () => { + it('Song', async () => { + const song = await distube.handler.resolve( + 'https://music.apple.com/us/album/v/1544457960?i=1544457962' + ); + + assert.ok(song); + }); + + it( + 'Playlist', + { skip: 'Playlists in Apple Music is not correct implemented right now, so skip this test' }, + async () => { + const playlist = await distube.handler.resolve( + 'https://music.apple.com/us/album/cyberpunk-2077-original-score/1544457960' + ); + + assert.ok(playlist); + } + ); + }); +}); diff --git a/src/main.ts b/src/main.ts index 85db499..0632094 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,8 @@ +import { clientIntents } from './ClientIntents.js'; + loggerSend(`Starting bot on version ${process.env.npm_package_version}`); -import { Client, GatewayIntentBits, Partials } from 'discord.js'; +import { Client, Partials } from 'discord.js'; import { loggerError, loggerSend } from './utilities/logger.js'; import { loginBot } from './utilities/loginBot.js'; import { AudioPlayerCore } from './audioplayer/AudioPlayerCore.js'; @@ -11,25 +13,18 @@ await loadLocale(); import { handlersLoad } from './handlers/handlersLoad.js'; const client = new Client({ - intents: [ - GatewayIntentBits.Guilds, - GatewayIntentBits.GuildPresences, - GatewayIntentBits.GuildMembers, - GatewayIntentBits.GuildVoiceStates, - GatewayIntentBits.GuildMessages, - GatewayIntentBits.MessageContent, - GatewayIntentBits.DirectMessages, - GatewayIntentBits.DirectMessageTyping, - GatewayIntentBits.GuildModeration - ], + intents: clientIntents, partials: [Partials.Message, Partials.Channel, Partials.Reaction] }); client.rest.on('rateLimited', (args) => { loggerError(`Client encountered a rate limit: ${JSON.stringify(args)}`); }); + new AudioPlayerCore(client); + await handlersLoad(client); + loginBot(client); process.on('uncaughtException', (err) => { From f02d6ae0bda4226fc6761d7c3c0242a41c8a3632 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 01:47:37 +0300 Subject: [PATCH 02/24] 3.4.0-dev-1 Fix a wrong path in test action for creating .env file --- .github/workflows/tests.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 4558d24..2cc002d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -23,17 +23,17 @@ jobs: runs-on: ubuntu-latest steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Make env file uses: SpicyPizza/create-envfile@v2.0 with: - envkey_DEBUG: true envkey_SECRET_KEY: ${{ secrets.ENV_DEVELOPMENT }} file_name: .env.development fail_on_empty: true sort_keys: false - - - name: Checkout code - uses: actions/checkout@v4 + directory: '${{ github.workspace }}/AlCoTest/AlCoTest' - name: Setup PNPM uses: pnpm/action-setup@v4 From b6d433f55fe38939ba8f9d0702b3d2a7bd6c5c87 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 01:49:22 +0300 Subject: [PATCH 03/24] 3.4.0-dev-1 Fix a wrong path in test action for creating .env file 2 --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 2cc002d..881b94d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -33,7 +33,7 @@ jobs: file_name: .env.development fail_on_empty: true sort_keys: false - directory: '${{ github.workspace }}/AlCoTest/AlCoTest' + directory: '/AlCoTest/AlCoTest' - name: Setup PNPM uses: pnpm/action-setup@v4 From ec1d59517352101f5d61f786e068e473a146f6a3 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 01:50:28 +0300 Subject: [PATCH 04/24] 3.4.0-dev-3 Fix a wrong path in test action for creating .env file 3 --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 881b94d..8f44fe4 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -33,7 +33,7 @@ jobs: file_name: .env.development fail_on_empty: true sort_keys: false - directory: '/AlCoTest/AlCoTest' + directory: './AlCoTest/AlCoTest' - name: Setup PNPM uses: pnpm/action-setup@v4 From b3ca269e984f2cb23919cacaaf0cdd05bdccc53e Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 01:52:32 +0300 Subject: [PATCH 05/24] 3.4.0-dev-4 Fix a wrong path in test action for creating .env file 4 --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 8f44fe4..649ca50 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -33,7 +33,7 @@ jobs: file_name: .env.development fail_on_empty: true sort_keys: false - directory: './AlCoTest/AlCoTest' + directory: 'AlCoTest/AlCoTest' - name: Setup PNPM uses: pnpm/action-setup@v4 From 77f3370042e85af24d8f0bb13b0bdf19787d0fcd Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 01:53:17 +0300 Subject: [PATCH 06/24] 3.4.0-dev-5 Fix a wrong path in test action for creating .env file 5 --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 649ca50..e0ecfdc 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -33,7 +33,7 @@ jobs: file_name: .env.development fail_on_empty: true sort_keys: false - directory: 'AlCoTest/AlCoTest' + directory: '.' - name: Setup PNPM uses: pnpm/action-setup@v4 From 3b6a5655b252397ea39fc69b5571ea2b487c65d1 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 01:58:23 +0300 Subject: [PATCH 07/24] 3.4.0-dev-6 Changed "make env file" code in tests action. --- .github/workflows/tests.yaml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index e0ecfdc..f640141 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -27,13 +27,9 @@ jobs: uses: actions/checkout@v4 - name: Make env file - uses: SpicyPizza/create-envfile@v2.0 - with: - envkey_SECRET_KEY: ${{ secrets.ENV_DEVELOPMENT }} - file_name: .env.development - fail_on_empty: true - sort_keys: false - directory: '.' + run: | + touch .env.development + echo ${{ secrets.ENV_DEVELOPMENT }} >> .env.development - name: Setup PNPM uses: pnpm/action-setup@v4 From 5751238c2d6299335beb180e3e3bcdcabddea875 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 02:01:58 +0300 Subject: [PATCH 08/24] 3.4.0-dev-7 Added display of a current path of making env file --- .github/workflows/tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f640141..25d7940 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -28,6 +28,7 @@ jobs: - name: Make env file run: | + pwd touch .env.development echo ${{ secrets.ENV_DEVELOPMENT }} >> .env.development From c71d47050da57919258906dfae509c154368e451 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 02:06:34 +0300 Subject: [PATCH 09/24] 3.4.0-dev-8 Added display of files in bot directory in tests action. --- .github/workflows/tests.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 25d7940..87837e7 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -46,5 +46,8 @@ jobs: - name: Install dependencies run: pnpm install --frozen-lockfile + - name: Display files + run: ls -a + - name: Run tests run: pnpm run test From 2b61d3e96c3f57e542ccc70e968826151bb8e95e Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 02:19:37 +0300 Subject: [PATCH 10/24] 3.4.0-dev-9 Process of loading environment variables now is cleaner --- src/EnvironmentVariables.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/EnvironmentVariables.ts b/src/EnvironmentVariables.ts index 0861caa..8e5d568 100644 --- a/src/EnvironmentVariables.ts +++ b/src/EnvironmentVariables.ts @@ -2,14 +2,22 @@ import { z } from 'zod'; import * as dotenv from 'dotenv'; import { loggerSend } from './utilities/logger.js'; import path from 'path'; +import fs from 'fs'; const loggerPrefixEnv = 'ENV'; const envPath = path.resolve(process.cwd(), `.env.${process.env.NODE_ENV}`); -loggerSend(`Checking environment variables for ${envPath}`, loggerPrefixEnv); - -dotenv.config({ path: envPath }); +loggerSend(`Checking environment variables in ${envPath}`, loggerPrefixEnv); +if (fs.existsSync(envPath)) { + dotenv.config({ path: envPath }); + loggerSend(`Environment variables is found in ${envPath}`, loggerPrefixEnv); +} else { + loggerSend( + `Environment variables are not found in ${envPath}, trying to load variables from OS environment variables`, + loggerPrefixEnv + ); +} const envVariables = z.object({ NODE_ENV: z.enum(['development', 'production']), @@ -66,4 +74,8 @@ const envVariables = z.object({ export const ENV = envVariables.parse(process.env); -loggerSend(`Loaded variables from ${envPath}`, loggerPrefixEnv); +if (fs.existsSync(envPath)) { + loggerSend(`Environment variables is loaded from ${envPath}`, loggerPrefixEnv); +} else { + loggerSend(`Environment variables is loaded from OS environment variables`, loggerPrefixEnv); +} From 376443623ba468f88de73156a354b007a15cc637 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 02:26:59 +0300 Subject: [PATCH 11/24] 3.4.0-dev-10 Fix in test action --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 87837e7..f922c3e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -30,7 +30,7 @@ jobs: run: | pwd touch .env.development - echo ${{ secrets.ENV_DEVELOPMENT }} >> .env.development + echo ${{ secrets.ENV_DEVELOPMENT }} > .env.development - name: Setup PNPM uses: pnpm/action-setup@v4 From e6d2fb6baeca0e09207a8ad67ed9edc702bb9d24 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 02:58:23 +0300 Subject: [PATCH 12/24] 3.4.0-dev-11 Fix in test action --- .github/workflows/tests.yaml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f922c3e..1ed308c 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -23,14 +23,13 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Make env file run: | - pwd touch .env.development - echo ${{ secrets.ENV_DEVELOPMENT }} > .env.development + echo '${{ secrets.ENV_DEVELOPMENT }}' > .env.development + + - name: Checkout code + uses: actions/checkout@v4 - name: Setup PNPM uses: pnpm/action-setup@v4 @@ -46,8 +45,5 @@ jobs: - name: Install dependencies run: pnpm install --frozen-lockfile - - name: Display files - run: ls -a - - name: Run tests run: pnpm run test From 56e7835a22f96f845a975805d31d0ac338b9a1bc Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 03:00:16 +0300 Subject: [PATCH 13/24] 3.4.0-dev-12 Fix in test action --- .github/workflows/tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 1ed308c..609f30b 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -25,6 +25,7 @@ jobs: steps: - name: Make env file run: | + pwd touch .env.development echo '${{ secrets.ENV_DEVELOPMENT }}' > .env.development From c2c28ec11399ced293a313593bc5489eae8fd0c3 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 03:01:53 +0300 Subject: [PATCH 14/24] 3.4.0-dev-13 Fix in test action --- .github/workflows/tests.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 609f30b..b48c7d2 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -23,12 +23,6 @@ jobs: runs-on: ubuntu-latest steps: - - name: Make env file - run: | - pwd - touch .env.development - echo '${{ secrets.ENV_DEVELOPMENT }}' > .env.development - - name: Checkout code uses: actions/checkout@v4 @@ -46,5 +40,11 @@ jobs: - name: Install dependencies run: pnpm install --frozen-lockfile + - name: Make env file + run: | + pwd + touch .env.development + echo '${{ secrets.ENV_DEVELOPMENT }}' > .env.development + - name: Run tests run: pnpm run test From e569e2da4b8f92c17799b0f154b165b5a33a36bd Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 03:06:17 +0300 Subject: [PATCH 15/24] 3.4.0-dev-14 Added yt-cookies to action --- .github/workflows/tests.yaml | 5 +++++ src/CookiesAutomation.ts | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index b48c7d2..81b9b9d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -46,5 +46,10 @@ jobs: touch .env.development echo '${{ secrets.ENV_DEVELOPMENT }}' > .env.development + - name: Make yt-cookies.json + run: + touch yt-cookies.json + echo '${{ secrets.YOUTUBE_COOKIES }}' > yt-cookies.json + - name: Run tests run: pnpm run test diff --git a/src/CookiesAutomation.ts b/src/CookiesAutomation.ts index a1a2ded..c4b3614 100644 --- a/src/CookiesAutomation.ts +++ b/src/CookiesAutomation.ts @@ -21,7 +21,6 @@ export async function getYoutubeCookie() { const browser = await puppeteer.launch({ headless: true, - slowMo: 2000, args: ['--remote-debugging-port=9222', '--remote-debugging-address=0.0.0.0', '--no-sandbox'] }); const page = await browser.newPage(); From 9cb0095166a34bf66ac996968c29fd86997a2a6a Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 03:11:18 +0300 Subject: [PATCH 16/24] 3.4.0-dev-15 Fix in action --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 81b9b9d..475f557 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -47,7 +47,7 @@ jobs: echo '${{ secrets.ENV_DEVELOPMENT }}' > .env.development - name: Make yt-cookies.json - run: + run: | touch yt-cookies.json echo '${{ secrets.YOUTUBE_COOKIES }}' > yt-cookies.json From 6fafd0eed5cf3d812d191406fd48db5262a9ec43 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 03:23:06 +0300 Subject: [PATCH 17/24] 3.4.0-dev-16 Fix never ending tests --- src/audioplayer/tests/AudioServices.test.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/audioplayer/tests/AudioServices.test.ts b/src/audioplayer/tests/AudioServices.test.ts index d570f7e..ab469a8 100644 --- a/src/audioplayer/tests/AudioServices.test.ts +++ b/src/audioplayer/tests/AudioServices.test.ts @@ -1,11 +1,12 @@ import * as assert from 'node:assert'; -import { describe, it, before } from 'node:test'; +import { describe, it, before, after } from 'node:test'; import { DisTube } from 'distube'; import { Client } from 'discord.js'; import { clientIntents } from '../../ClientIntents.js'; import { LoadPlugins } from '../LoadPlugins.js'; import '../../EnvironmentVariables.js'; import { loggerWarn } from '../../utilities/logger.js'; +import * as process from 'node:process'; let distube: DisTube; const djsClient: Client = new Client({ intents: clientIntents }); @@ -124,3 +125,9 @@ describe('Audio Services', () => { ); }); }); + +after(() => { + setTimeout(() => { + process.exit(0); + }, 1000); +}); From a544dc961d5ee378786fdd00531e5e7f4af96694 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 03:26:00 +0300 Subject: [PATCH 18/24] 3.4.0-dev-17 Test failing test --- src/audioplayer/tests/AudioServices.test.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/audioplayer/tests/AudioServices.test.ts b/src/audioplayer/tests/AudioServices.test.ts index ab469a8..efacbdc 100644 --- a/src/audioplayer/tests/AudioServices.test.ts +++ b/src/audioplayer/tests/AudioServices.test.ts @@ -112,17 +112,13 @@ describe('Audio Services', () => { assert.ok(song); }); - it( - 'Playlist', - { skip: 'Playlists in Apple Music is not correct implemented right now, so skip this test' }, - async () => { - const playlist = await distube.handler.resolve( - 'https://music.apple.com/us/album/cyberpunk-2077-original-score/1544457960' - ); - - assert.ok(playlist); - } - ); + it('Playlist', async () => { + const playlist = await distube.handler.resolve( + 'https://music.apple.com/us/album/cyberpunk-2077-original-score/1544457960' + ); + + assert.ok(playlist); + }); }); }); From 122c2385da31f308210cf1dcfdd75c92f8b9054d Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 03:27:08 +0300 Subject: [PATCH 19/24] 3.4.0-dev-18 Remove failing test --- src/audioplayer/tests/AudioServices.test.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/audioplayer/tests/AudioServices.test.ts b/src/audioplayer/tests/AudioServices.test.ts index efacbdc..ab469a8 100644 --- a/src/audioplayer/tests/AudioServices.test.ts +++ b/src/audioplayer/tests/AudioServices.test.ts @@ -112,13 +112,17 @@ describe('Audio Services', () => { assert.ok(song); }); - it('Playlist', async () => { - const playlist = await distube.handler.resolve( - 'https://music.apple.com/us/album/cyberpunk-2077-original-score/1544457960' - ); - - assert.ok(playlist); - }); + it( + 'Playlist', + { skip: 'Playlists in Apple Music is not correct implemented right now, so skip this test' }, + async () => { + const playlist = await distube.handler.resolve( + 'https://music.apple.com/us/album/cyberpunk-2077-original-score/1544457960' + ); + + assert.ok(playlist); + } + ); }); }); From 61d0eb8282ccdb01d49385473fd25177711184f9 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 19:21:07 +0300 Subject: [PATCH 20/24] 3.4.0-dev-19 Added BOT_MAX_SONGS_IN_QUEUE env var. Pushing to Docker does not work only when tests runs not by pull request. --- .env | 2 ++ .github/workflows/publish-docker-image.yaml | 1 + src/ClientIntents.ts | 13 ------------- src/EnvironmentVariables.ts | 4 +++- src/audioplayer/AudioPlayerCore.ts | 8 +++----- src/audioplayer/tests/AudioServices.test.ts | 3 +-- src/commands/audio/play.command.ts | 8 ++++---- src/main.ts | 16 ++++++++++++---- wiki/Setup.md | 5 +++-- 9 files changed, 29 insertions(+), 31 deletions(-) delete mode 100644 src/ClientIntents.ts diff --git a/.env b/.env index 99d56c0..64f6d58 100644 --- a/.env +++ b/.env @@ -4,6 +4,8 @@ BOT_FFMPEG_LOGGING=false BOT_COMMAND_PREFIX=// BOT_LANGUAGE=en +BOT_MAX_SONGS_IN_QUEUE=500 + BOT_DISCORD_TOKEN=undefined BOT_DISCORD_CLIENT_ID=undefined BOT_DISCORD_OVERPOWERED_ID=undefined diff --git a/.github/workflows/publish-docker-image.yaml b/.github/workflows/publish-docker-image.yaml index 020b685..efbee77 100644 --- a/.github/workflows/publish-docker-image.yaml +++ b/.github/workflows/publish-docker-image.yaml @@ -11,6 +11,7 @@ env: jobs: push_to_registry: + if: github.event.workflow_run.event == 'push' name: Push Docker image to Docker Hub runs-on: ubuntu-latest steps: diff --git a/src/ClientIntents.ts b/src/ClientIntents.ts deleted file mode 100644 index 2507409..0000000 --- a/src/ClientIntents.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { GatewayIntentBits } from 'discord.js'; - -export const clientIntents: Array = [ - GatewayIntentBits.Guilds, - GatewayIntentBits.GuildPresences, - GatewayIntentBits.GuildMembers, - GatewayIntentBits.GuildVoiceStates, - GatewayIntentBits.GuildMessages, - GatewayIntentBits.MessageContent, - GatewayIntentBits.DirectMessages, - GatewayIntentBits.DirectMessageTyping, - GatewayIntentBits.GuildModeration -]; diff --git a/src/EnvironmentVariables.ts b/src/EnvironmentVariables.ts index 8e5d568..95dbf4a 100644 --- a/src/EnvironmentVariables.ts +++ b/src/EnvironmentVariables.ts @@ -20,7 +20,7 @@ if (fs.existsSync(envPath)) { } const envVariables = z.object({ - NODE_ENV: z.enum(['development', 'production']), + NODE_ENV: z.enum(['development', 'production']).default('development'), BOT_VERBOSE_LOGGING: z .preprocess( @@ -50,6 +50,8 @@ const envVariables = z.object({ BOT_LANGUAGE: z.enum(['en', 'ru']).optional().default('en'), BOT_COMMAND_PREFIX: z.string().min(1), + BOT_MAX_SONGS_IN_QUEUE: z.coerce.number().positive().min(1).optional().default(500), + MONGO_URI: z.string(), MONGO_DATABASE_NAME: z.string(), diff --git a/src/audioplayer/AudioPlayerCore.ts b/src/audioplayer/AudioPlayerCore.ts index 1ef853f..e5c5a8c 100644 --- a/src/audioplayer/AudioPlayerCore.ts +++ b/src/audioplayer/AudioPlayerCore.ts @@ -33,8 +33,6 @@ import { joinVoiceChannel } from '@discordjs/voice'; import { generateWarningEmbed } from '../utilities/generateWarningEmbed.js'; import { generateLyricsEmbed } from './Lyrics.js'; -export const queueSongsLimit = 500; - export const loggerPrefixAudioplayer = `Audioplayer`; const plugins = await LoadPlugins(); @@ -372,17 +370,17 @@ export class AudioPlayerCore { if (!queue.textChannel) return; await queue.textChannel.send({ embeds: [generateAddedPlaylistMessage(playlist)] }); - if (queue.songs.length >= queueSongsLimit) { + if (queue.songs.length >= ENV.BOT_MAX_SONGS_IN_QUEUE) { await queue.textChannel.send({ embeds: [ generateWarningEmbed( i18next.t('audioplayer:event_add_list_limit', { - queueLimit: queueSongsLimit + queueLimit: ENV.BOT_MAX_SONGS_IN_QUEUE }) as string ) ] }); - queue.songs.length = queueSongsLimit; + queue.songs.length = ENV.BOT_MAX_SONGS_IN_QUEUE; } const player = this.playersManager.get(queue.id); diff --git a/src/audioplayer/tests/AudioServices.test.ts b/src/audioplayer/tests/AudioServices.test.ts index ab469a8..7bb3e73 100644 --- a/src/audioplayer/tests/AudioServices.test.ts +++ b/src/audioplayer/tests/AudioServices.test.ts @@ -2,14 +2,13 @@ import * as assert from 'node:assert'; import { describe, it, before, after } from 'node:test'; import { DisTube } from 'distube'; import { Client } from 'discord.js'; -import { clientIntents } from '../../ClientIntents.js'; import { LoadPlugins } from '../LoadPlugins.js'; import '../../EnvironmentVariables.js'; import { loggerWarn } from '../../utilities/logger.js'; import * as process from 'node:process'; let distube: DisTube; -const djsClient: Client = new Client({ intents: clientIntents }); +const djsClient: Client = new Client({ intents: [] }); before(async () => { loggerWarn('If you want to run all this tests successfully, provide all optional .env variables'); diff --git a/src/commands/audio/play.command.ts b/src/commands/audio/play.command.ts index d202c8b..ceedbe4 100644 --- a/src/commands/audio/play.command.ts +++ b/src/commands/audio/play.command.ts @@ -17,8 +17,8 @@ import { truncateString } from '../../utilities/truncateString.js'; import i18next from 'i18next'; import { SearchResultType } from '@distube/youtube'; import ytsr from '@distube/ytsr'; -import { queueSongsLimit } from '../../audioplayer/AudioPlayerCore.js'; import { generateWarningEmbed } from '../../utilities/generateWarningEmbed.js'; +import { ENV } from '../../EnvironmentVariables.js'; export const services = 'Youtube, Spotify, Soundcloud, Yandex Music, Apple Music, HTTP-stream'; export default function (): ICommand { @@ -42,7 +42,7 @@ export default function (): ICommand { embeds: [ generateWarningEmbed( i18next.t('commands:play_error_songs_limit', { - queueLimit: queueSongsLimit + queueLimit: ENV.BOT_MAX_SONGS_IN_QUEUE }) as string ) ] @@ -83,7 +83,7 @@ export default function (): ICommand { embeds: [ generateWarningEmbed( i18next.t('commands:play_error_songs_limit', { - queueLimit: queueSongsLimit + queueLimit: ENV.BOT_MAX_SONGS_IN_QUEUE }) as string ) ], @@ -162,5 +162,5 @@ function queueSongsIsFull(client: Client, guild: Guild): boolean { if (!queue) return false; - return queue.songs.length >= queueSongsLimit; + return queue.songs.length >= ENV.BOT_MAX_SONGS_IN_QUEUE; } diff --git a/src/main.ts b/src/main.ts index 0632094..57e6d70 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,6 @@ -import { clientIntents } from './ClientIntents.js'; - loggerSend(`Starting bot on version ${process.env.npm_package_version}`); -import { Client, Partials } from 'discord.js'; +import { Client, GatewayIntentBits, Partials } from 'discord.js'; import { loggerError, loggerSend } from './utilities/logger.js'; import { loginBot } from './utilities/loginBot.js'; import { AudioPlayerCore } from './audioplayer/AudioPlayerCore.js'; @@ -13,7 +11,17 @@ await loadLocale(); import { handlersLoad } from './handlers/handlersLoad.js'; const client = new Client({ - intents: clientIntents, + intents: [ + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildPresences, + GatewayIntentBits.GuildMembers, + GatewayIntentBits.GuildVoiceStates, + GatewayIntentBits.GuildMessages, + GatewayIntentBits.MessageContent, + GatewayIntentBits.DirectMessages, + GatewayIntentBits.DirectMessageTyping, + GatewayIntentBits.GuildModeration + ], partials: [Partials.Message, Partials.Channel, Partials.Reaction] }); diff --git a/wiki/Setup.md b/wiki/Setup.md index dd12bb5..45f07a8 100644 --- a/wiki/Setup.md +++ b/wiki/Setup.md @@ -6,7 +6,7 @@ But in both cases, you need to configure .env file. Also you need retrieve token, client id and enable intents on Discord Developer Portal. - Create file .env.production (if you developer create .env.development) -- Fill all fields in .env.* If the field is marked as (Optional), you can skip it. +- Fill all fields in .env.\* If the field is marked as (Optional), you can skip it. - (Required) To get Discord Token and enable intents, follow the [Discord Developer Portal](https://github.com/AlexInCube/AlCoTest/wiki/API-Configure#discord-developer-portal-required) section. - (Optional) To get YouTube cookies and bypass different errors with YouTube, follow the [YouTube](https://github.com/AlexInCube/AlCoTest/wiki/API-Configure#-youtube-cookie-optional) section - (Optional) To get Spotify Secret and ID, follow the [Spotify](https://github.com/AlexInCube/AlCoTest/wiki/API-Configure#spotify-optional) section. @@ -19,6 +19,7 @@ Also you need retrieve token, client id and enable intents on Discord Developer | `BOT_VERBOSE_LOGGING` | false | The bot will give more info to the console, useful for debugging | ❌ | | `BOT_FFMPEG_LOGGING=false` | false | The bot will give info about FFMPEGto the console, useful for debugging | | | `BOT_COMMAND_PREFIX` | // | Used only for text commands | ✔️ | +| `BOT_MAX_SONGS_IN_QUEUE` | 500 | Define max songs count per queue | ❌ | | `BOT_LANGUAGE` | en | Supported values: en ru | ❌ | | `MONGO_URI` | mongodb://mongo:27017 | The public key for sending notifications | ✔️ | | `MONGO_DATABASE_NAME` | aicbot | Database name in MongoDB | ✔️ | @@ -55,7 +56,7 @@ AICoTest/ > [!NOTE] > If you use terminal, Linux or Git Bash etc..., > you can copy runInDocker.sh or updateAndRunInDocker.sh to folder with other files. -> And run command ```sh updateAndRunInDocker.sh``` to update bot image and restart containers. +> And run command `sh updateAndRunInDocker.sh` to update bot image and restart containers. # 🖥️ Run locally (if you are not a developer, this way is no sense) From 12232257068033f15f0871faa3afb6fb9158d209 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 19:23:16 +0300 Subject: [PATCH 21/24] 3.4.0-dev-20 Client intents now is separated from the main.ts file --- src/ClientIntents.ts | 13 +++++++++++++ src/audioplayer/tests/AudioServices.test.ts | 3 ++- src/main.ts | 16 ++++------------ 3 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 src/ClientIntents.ts diff --git a/src/ClientIntents.ts b/src/ClientIntents.ts new file mode 100644 index 0000000..2507409 --- /dev/null +++ b/src/ClientIntents.ts @@ -0,0 +1,13 @@ +import { GatewayIntentBits } from 'discord.js'; + +export const clientIntents: Array = [ + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildPresences, + GatewayIntentBits.GuildMembers, + GatewayIntentBits.GuildVoiceStates, + GatewayIntentBits.GuildMessages, + GatewayIntentBits.MessageContent, + GatewayIntentBits.DirectMessages, + GatewayIntentBits.DirectMessageTyping, + GatewayIntentBits.GuildModeration +]; diff --git a/src/audioplayer/tests/AudioServices.test.ts b/src/audioplayer/tests/AudioServices.test.ts index 7bb3e73..13b4050 100644 --- a/src/audioplayer/tests/AudioServices.test.ts +++ b/src/audioplayer/tests/AudioServices.test.ts @@ -6,9 +6,10 @@ import { LoadPlugins } from '../LoadPlugins.js'; import '../../EnvironmentVariables.js'; import { loggerWarn } from '../../utilities/logger.js'; import * as process from 'node:process'; +import { clientIntents } from '../../ClientIntents.js'; let distube: DisTube; -const djsClient: Client = new Client({ intents: [] }); +const djsClient: Client = new Client({ intents: clientIntents }); before(async () => { loggerWarn('If you want to run all this tests successfully, provide all optional .env variables'); diff --git a/src/main.ts b/src/main.ts index 57e6d70..0632094 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,8 @@ +import { clientIntents } from './ClientIntents.js'; + loggerSend(`Starting bot on version ${process.env.npm_package_version}`); -import { Client, GatewayIntentBits, Partials } from 'discord.js'; +import { Client, Partials } from 'discord.js'; import { loggerError, loggerSend } from './utilities/logger.js'; import { loginBot } from './utilities/loginBot.js'; import { AudioPlayerCore } from './audioplayer/AudioPlayerCore.js'; @@ -11,17 +13,7 @@ await loadLocale(); import { handlersLoad } from './handlers/handlersLoad.js'; const client = new Client({ - intents: [ - GatewayIntentBits.Guilds, - GatewayIntentBits.GuildPresences, - GatewayIntentBits.GuildMembers, - GatewayIntentBits.GuildVoiceStates, - GatewayIntentBits.GuildMessages, - GatewayIntentBits.MessageContent, - GatewayIntentBits.DirectMessages, - GatewayIntentBits.DirectMessageTyping, - GatewayIntentBits.GuildModeration - ], + intents: clientIntents, partials: [Partials.Message, Partials.Channel, Partials.Reaction] }); From 2f95e76c35ce97f89e498c14f4e9042a1cfde02a Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sat, 3 Aug 2024 19:42:00 +0300 Subject: [PATCH 22/24] 3.4.0-dev-21 Added linter action --- .github/workflows/lint.yaml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/lint.yaml diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..f2acf93 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,36 @@ +name: Lint + +on: + push: + branches: ['**'] + pull_request: + branches: ['**'] + +jobs: + run-linters: + name: Run linters + runs-on: ubuntu-latest + + steps: + - name: Check out Git repository + uses: actions/checkout@v4 + + - name: Setup PNPM + uses: pnpm/action-setup@v4 + with: + version: 9 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 22.x + cache: "pnpm" + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Run linters + uses: wearerequired/lint-action@v2 + with: + eslint: true + prettier: true From 5fb00cd14038d772be68e67022c56222add62f80 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sun, 4 Aug 2024 00:41:20 +0300 Subject: [PATCH 23/24] 3.4.0-dev-22 Linter fixes --- .github/workflows/{lint.yaml => quality.yaml} | 10 +++++----- eslint.config.js | 11 ++++++----- package.json | 5 ++++- 3 files changed, 15 insertions(+), 11 deletions(-) rename .github/workflows/{lint.yaml => quality.yaml} (80%) diff --git a/.github/workflows/lint.yaml b/.github/workflows/quality.yaml similarity index 80% rename from .github/workflows/lint.yaml rename to .github/workflows/quality.yaml index f2acf93..9bdafc5 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/quality.yaml @@ -29,8 +29,8 @@ jobs: - name: Install dependencies run: pnpm install --frozen-lockfile - - name: Run linters - uses: wearerequired/lint-action@v2 - with: - eslint: true - prettier: true + - name: Run Prettier + run: pnpm run prettier:check + + - name: Run ESLint + run: pnpm run eslint diff --git a/eslint.config.js b/eslint.config.js index 9364915..de11cd7 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -9,7 +9,8 @@ export default tseslint.config(eslint.configs.recommended, ...tseslint.configs.r plugins: { 'typescript-eslint': ParserTypeScript, prettier: prettierPlugin - }, ignores: ['build', 'node_modules', 'coverage', 'eslint.config.js'], + }, + ignores: ['build', 'node_modules', 'coverage', 'eslint.config.js'], languageOptions: { globals: { ...globals.node, @@ -20,12 +21,12 @@ export default tseslint.config(eslint.configs.recommended, ...tseslint.configs.r } }, rules: { - ...prettierPlugin.configs.recommended.rules, - ...eslintConfigPrettier.rules, + ...prettierPlugin.configs.recommended.rules, + ...eslintConfigPrettier.rules, '@typescript-eslint/no-var-requires': 0, '@typescript-eslint/no-non-null-assertion': 0, - '@typescript-eslint/no-explicit-any': "warn", + '@typescript-eslint/no-explicit-any': 'warn', 'prettier/prettier': ['error', { endOfLine: 'auto' }], - 'no-constant-binary-expression': "off" + 'no-constant-binary-expression': 'off' } }); diff --git a/package.json b/package.json index 5e7f68b..f7d9edf 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,10 @@ "development": "tsc&& cross-env NODE_ENV=development node build/main.js", "production": "cross-env NODE_ENV=production node build/main.js", "cookies_grabbing": "cross-env NODE_ENV=development node build/Script_getCookie.js", - "test": "tsc&& cross-env NODE_ENV=development node --test" + "test": "tsc&& cross-env NODE_ENV=development node --test", + "eslint": "eslint \"src/**/*.{ts,js}\"", + "prettier:format": "prettier --write \"**/*.{ts,js}\"", + "prettier:check": "prettier --check \"**/*.{ts,js}\"" }, "type": "module", "keywords": [], From c9e761b44af95d4f937a58dc4416f5cc87f1c617 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Sun, 4 Aug 2024 00:57:48 +0300 Subject: [PATCH 24/24] 3.4.0-dev-23 Linter fixes 2 --- .github/workflows/publish-docker-image.yaml | 2 +- .github/workflows/quality.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-docker-image.yaml b/.github/workflows/publish-docker-image.yaml index efbee77..326f756 100644 --- a/.github/workflows/publish-docker-image.yaml +++ b/.github/workflows/publish-docker-image.yaml @@ -2,7 +2,7 @@ name: Publish Docker image on: workflow_run: - workflows: [ "tests" ] + workflows: [ "tests", "linters" ] types: ['completed'] branches: ['master'] diff --git a/.github/workflows/quality.yaml b/.github/workflows/quality.yaml index 9bdafc5..9d7f041 100644 --- a/.github/workflows/quality.yaml +++ b/.github/workflows/quality.yaml @@ -1,4 +1,4 @@ -name: Lint +name: Code Quality on: push: @@ -7,7 +7,7 @@ on: branches: ['**'] jobs: - run-linters: + linters: name: Run linters runs-on: ubuntu-latest