Skip to content

Commit

Permalink
3.4.0-dev-19
Browse files Browse the repository at this point in the history
Added BOT_MAX_SONGS_IN_QUEUE env var.
Pushing to Docker does not work only when tests runs not by pull request.
  • Loading branch information
AlexInCube committed Aug 3, 2024
1 parent 122c238 commit 61d0eb8
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish-docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 0 additions & 13 deletions src/ClientIntents.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/EnvironmentVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(),

Expand Down
8 changes: 3 additions & 5 deletions src/audioplayer/AudioPlayerCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/audioplayer/tests/AudioServices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 4 additions & 4 deletions src/commands/audio/play.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
)
]
Expand Down Expand Up @@ -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
)
],
Expand Down Expand Up @@ -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;
}
16 changes: 12 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -13,7 +11,17 @@ await loadLocale();
import { handlersLoad } from './handlers/handlersLoad.js';

const client = new Client<true>({
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]
});

Expand Down
5 changes: 3 additions & 2 deletions wiki/Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 | ✔️ |
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 61d0eb8

Please sign in to comment.