Skip to content

Commit

Permalink
3.6.0-dev-4
Browse files Browse the repository at this point in the history
Added BOT_MAX_SONGS_HISTORY_SIZE env var.
If BOT_MAX_SONGS_HISTORY_SIZE is zero, the history will be not written in a database and also command /history is disabling.
Command /history now supports pagination for a song list.
Fixed mess in Setup.md
Update linters packages.
  • Loading branch information
AlexInCube committed Aug 12, 2024
1 parent f7152a1 commit 05bf192
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 74 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ BOT_COMMAND_PREFIX=$
BOT_LANGUAGE=en

BOT_MAX_SONGS_IN_QUEUE=500
BOT_MAX_SONGS_HISTORY_SIZE=60

BOT_DISCORD_TOKEN=undefined
BOT_DISCORD_CLIENT_ID=undefined
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "build/main.js",
"scripts": {
"build": "tsc",
"development": "tsc&& cross-env NODE_ENV=development node build/main.js",
"development": "tsc&& cross-env NODE_ENV=development node --trace-deprecation 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",
Expand Down Expand Up @@ -59,8 +59,8 @@
"@types/node-cron": "^3.0.11",
"@types/node-os-utils": "^1.3.4",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@typescript-eslint/eslint-plugin": "^8.0.1",
"@typescript-eslint/parser": "^8.0.1",
"eslint": "^9.9.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
Expand Down
146 changes: 142 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/EnvironmentVariables.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
Read wiki if you want to know what all of this variable do.
Or if you are too smart, you can continue to read the code
*/

import { z } from 'zod';
import * as dotenv from 'dotenv';
import { loggerSend } from './utilities/logger.js';
Expand Down Expand Up @@ -51,6 +56,7 @@ const envVariables = z.object({
BOT_COMMAND_PREFIX: z.string().min(1),

BOT_MAX_SONGS_IN_QUEUE: z.coerce.number().positive().min(1).optional().default(500),
BOT_MAX_SONGS_HISTORY_SIZE: z.coerce.number().nonnegative().optional().default(60),

MONGO_URI: z.string(),
MONGO_DATABASE_NAME: z.string(),
Expand Down
16 changes: 9 additions & 7 deletions src/audioplayer/AudioPlayersManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { generateErrorEmbed } from '../utilities/generateErrorEmbed.js';
import i18next from 'i18next';
import { loggerError, loggerSend } from '../utilities/logger.js';
import { ENV } from '../EnvironmentVariables.js';
import { LoadPlugins } from './LoadPlugins.js';
import { DistubePlugin } from './LoadPlugins.js';
import { generateAddedPlaylistMessage } from './util/generateAddedPlaylistMessage.js';
import { generateAddedSongMessage } from './util/generateAddedSongMessage.js';
import {
Expand All @@ -37,13 +37,11 @@ import { addSongToGuildSongsHistory } from '../schemas/SchemaSongsHistory.js';

export const loggerPrefixAudioplayer = `Audioplayer`;

const plugins = await LoadPlugins();

export class AudioPlayersManager {
client: Client;
playersManager: AudioPlayersStore;
distube: DisTube;
constructor(client: Client) {
constructor(client: Client, plugins: Array<DistubePlugin>) {
this.client = client;
this.client.audioPlayer = this;
this.playersManager = new AudioPlayersStore(this.client);
Expand All @@ -53,7 +51,7 @@ export class AudioPlayersManager {
emitAddSongWhenCreatingQueue: true,
savePreviousSongs: true,
joinNewVoiceChannel: true,
plugins: plugins
plugins
});

this.setupEvents();
Expand Down Expand Up @@ -373,15 +371,19 @@ export class AudioPlayersManager {
await queue.textChannel.send({ embeds: [generateAddedSongMessage(song)] });
}

await addSongToGuildSongsHistory(queue.id, song);
if (ENV.BOT_MAX_SONGS_HISTORY_SIZE > 0) {
await addSongToGuildSongsHistory(queue.id, song);
}

const player = this.playersManager.get(queue.id);
if (player) {
await player.update();
}
})
.on(DistubeEvents.ADD_LIST, async (queue, playlist) => {
await addSongToGuildSongsHistory(queue.id, playlist);
if (ENV.BOT_MAX_SONGS_HISTORY_SIZE > 0) {
await addSongToGuildSongsHistory(queue.id, playlist);
}

if (!queue.textChannel) return;

Expand Down
Loading

0 comments on commit 05bf192

Please sign in to comment.