From 05bf1923f3bf65efa7d706ec14d5bad215212683 Mon Sep 17 00:00:00 2001 From: AlexInCube Date: Mon, 12 Aug 2024 05:05:02 +0300 Subject: [PATCH] 3.6.0-dev-4 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. --- .env | 1 + package.json | 6 +- pnpm-lock.yaml | 146 ++++++++++++++++++++++++- src/EnvironmentVariables.ts | 6 + src/audioplayer/AudioPlayersManager.ts | 16 +-- src/commands/audio/history.command.ts | 126 +++++++++++++++------ src/main.ts | 11 +- src/schemas/SchemaSongsHistory.ts | 3 +- wiki/Setup.md | 43 ++++---- 9 files changed, 284 insertions(+), 74 deletions(-) diff --git a/.env b/.env index d51677e..f365365 100644 --- a/.env +++ b/.env @@ -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 diff --git a/package.json b/package.json index f153067..d2203b6 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 96d024f..97660cc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -118,11 +118,11 @@ importers: specifier: ^10.0.0 version: 10.0.0 '@typescript-eslint/eslint-plugin': - specifier: ^7.18.0 - version: 7.18.0(@typescript-eslint/parser@7.18.0(eslint@9.9.0)(typescript@5.5.4))(eslint@9.9.0)(typescript@5.5.4) + specifier: ^8.0.1 + version: 8.0.1(@typescript-eslint/parser@8.0.1(eslint@9.9.0)(typescript@5.5.4))(eslint@9.9.0)(typescript@5.5.4) '@typescript-eslint/parser': - specifier: ^7.18.0 - version: 7.18.0(eslint@9.9.0)(typescript@5.5.4) + specifier: ^8.0.1 + version: 8.0.1(eslint@9.9.0)(typescript@5.5.4) eslint: specifier: ^9.9.0 version: 9.9.0 @@ -356,6 +356,17 @@ packages: typescript: optional: true + '@typescript-eslint/eslint-plugin@8.0.1': + resolution: {integrity: sha512-5g3Y7GDFsJAnY4Yhvk8sZtFfV6YNF2caLzjrRPUBzewjPCaj0yokePB4LJSobyCzGMzjZZYFbwuzbfDHlimXbQ==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + peerDependencies: + '@typescript-eslint/parser': ^8.0.0 || ^8.0.0-alpha.0 + eslint: ^8.57.0 || ^9.0.0 + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + '@typescript-eslint/parser@7.18.0': resolution: {integrity: sha512-4Z+L8I2OqhZV8qA132M4wNL30ypZGYOQVBfMgxDH/K5UX0PNqTu1c6za9ST5r9+tavvHiTWmBnKzpCJ/GlVFtg==} engines: {node: ^18.18.0 || >=20.0.0} @@ -366,10 +377,24 @@ packages: typescript: optional: true + '@typescript-eslint/parser@8.0.1': + resolution: {integrity: sha512-5IgYJ9EO/12pOUwiBKFkpU7rS3IU21mtXzB81TNwq2xEybcmAZrE9qwDtsb5uQd9aVO9o0fdabFyAmKveXyujg==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + peerDependencies: + eslint: ^8.57.0 || ^9.0.0 + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + '@typescript-eslint/scope-manager@7.18.0': resolution: {integrity: sha512-jjhdIE/FPF2B7Z1uzc6i3oWKbGcHb87Qw7AWj6jmEqNOfDFbJWtjt/XfwCpvNkpGWlcJaog5vTR+VV8+w9JflA==} engines: {node: ^18.18.0 || >=20.0.0} + '@typescript-eslint/scope-manager@8.0.1': + resolution: {integrity: sha512-NpixInP5dm7uukMiRyiHjRKkom5RIFA4dfiHvalanD2cF0CLUuQqxfg8PtEUo9yqJI2bBhF+pcSafqnG3UBnRQ==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@typescript-eslint/type-utils@7.18.0': resolution: {integrity: sha512-XL0FJXuCLaDuX2sYqZUUSOJ2sG5/i1AAze+axqmLnSkNEVMVYLF+cbwlB2w8D1tinFuSikHmFta+P+HOofrLeA==} engines: {node: ^18.18.0 || >=20.0.0} @@ -380,10 +405,23 @@ packages: typescript: optional: true + '@typescript-eslint/type-utils@8.0.1': + resolution: {integrity: sha512-+/UT25MWvXeDX9YaHv1IS6KI1fiuTto43WprE7pgSMswHbn1Jm9GEM4Txp+X74ifOWV8emu2AWcbLhpJAvD5Ng==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + peerDependencies: + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + '@typescript-eslint/types@7.18.0': resolution: {integrity: sha512-iZqi+Ds1y4EDYUtlOOC+aUmxnE9xS/yCigkjA7XpTKV6nCBd3Hp/PRGGmdwnfkV2ThMyYldP1wRpm/id99spTQ==} engines: {node: ^18.18.0 || >=20.0.0} + '@typescript-eslint/types@8.0.1': + resolution: {integrity: sha512-PpqTVT3yCA/bIgJ12czBuE3iBlM3g4inRSC5J0QOdQFAn07TYrYEQBBKgXH1lQpglup+Zy6c1fxuwTk4MTNKIw==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@typescript-eslint/typescript-estree@7.18.0': resolution: {integrity: sha512-aP1v/BSPnnyhMHts8cf1qQ6Q1IFwwRvAQGRvBFkWlo3/lH29OXA3Pts+c10nxRxIBrDnoMqzhgdwVe5f2D6OzA==} engines: {node: ^18.18.0 || >=20.0.0} @@ -393,16 +431,35 @@ packages: typescript: optional: true + '@typescript-eslint/typescript-estree@8.0.1': + resolution: {integrity: sha512-8V9hriRvZQXPWU3bbiUV4Epo7EvgM6RTs+sUmxp5G//dBGy402S7Fx0W0QkB2fb4obCF8SInoUzvTYtc3bkb5w==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + peerDependencies: + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + '@typescript-eslint/utils@7.18.0': resolution: {integrity: sha512-kK0/rNa2j74XuHVcoCZxdFBMF+aq/vH83CXAOHieC+2Gis4mF8jJXT5eAfyD3K0sAxtPuwxaIOIOvhwzVDt/kw==} engines: {node: ^18.18.0 || >=20.0.0} peerDependencies: eslint: ^8.56.0 + '@typescript-eslint/utils@8.0.1': + resolution: {integrity: sha512-CBFR0G0sCt0+fzfnKaciu9IBsKvEKYwN9UZ+eeogK1fYHg4Qxk1yf/wLQkLXlq8wbU2dFlgAesxt8Gi76E8RTA==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + peerDependencies: + eslint: ^8.57.0 || ^9.0.0 + '@typescript-eslint/visitor-keys@7.18.0': resolution: {integrity: sha512-cDF0/Gf81QpY3xYyJKDV14Zwdmid5+uuENhjH2EqFaF0ni+yAyq/LzMaIJdhNJXZI7uLzwIlA+V7oWoyn6Curg==} engines: {node: ^18.18.0 || >=20.0.0} + '@typescript-eslint/visitor-keys@8.0.1': + resolution: {integrity: sha512-W5E+o0UfUcK5EgchLZsyVWqARmsM7v54/qEq6PY3YI5arkgmCzHiuk0zKSJJbm71V0xdRna4BGomkCTXz2/LkQ==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@vladfrangu/async_event_emitter@2.4.5': resolution: {integrity: sha512-J7T3gUr3Wz0l7Ni1f9upgBZ7+J22/Q1B7dl0X6fG+fTsD+H+31DIosMHj4Um1dWQwqbcQ3oQf+YS2foYkDc9cQ==} engines: {node: '>=v14.0.0', npm: '>=7.0.0'} @@ -2085,6 +2142,24 @@ snapshots: transitivePeerDependencies: - supports-color + '@typescript-eslint/eslint-plugin@8.0.1(@typescript-eslint/parser@8.0.1(eslint@9.9.0)(typescript@5.5.4))(eslint@9.9.0)(typescript@5.5.4)': + dependencies: + '@eslint-community/regexpp': 4.11.0 + '@typescript-eslint/parser': 8.0.1(eslint@9.9.0)(typescript@5.5.4) + '@typescript-eslint/scope-manager': 8.0.1 + '@typescript-eslint/type-utils': 8.0.1(eslint@9.9.0)(typescript@5.5.4) + '@typescript-eslint/utils': 8.0.1(eslint@9.9.0)(typescript@5.5.4) + '@typescript-eslint/visitor-keys': 8.0.1 + eslint: 9.9.0 + graphemer: 1.4.0 + ignore: 5.3.1 + natural-compare: 1.4.0 + ts-api-utils: 1.3.0(typescript@5.5.4) + optionalDependencies: + typescript: 5.5.4 + transitivePeerDependencies: + - supports-color + '@typescript-eslint/parser@7.18.0(eslint@9.9.0)(typescript@5.5.4)': dependencies: '@typescript-eslint/scope-manager': 7.18.0 @@ -2098,11 +2173,29 @@ snapshots: transitivePeerDependencies: - supports-color + '@typescript-eslint/parser@8.0.1(eslint@9.9.0)(typescript@5.5.4)': + dependencies: + '@typescript-eslint/scope-manager': 8.0.1 + '@typescript-eslint/types': 8.0.1 + '@typescript-eslint/typescript-estree': 8.0.1(typescript@5.5.4) + '@typescript-eslint/visitor-keys': 8.0.1 + debug: 4.3.6 + eslint: 9.9.0 + optionalDependencies: + typescript: 5.5.4 + transitivePeerDependencies: + - supports-color + '@typescript-eslint/scope-manager@7.18.0': dependencies: '@typescript-eslint/types': 7.18.0 '@typescript-eslint/visitor-keys': 7.18.0 + '@typescript-eslint/scope-manager@8.0.1': + dependencies: + '@typescript-eslint/types': 8.0.1 + '@typescript-eslint/visitor-keys': 8.0.1 + '@typescript-eslint/type-utils@7.18.0(eslint@9.9.0)(typescript@5.5.4)': dependencies: '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.5.4) @@ -2115,8 +2208,22 @@ snapshots: transitivePeerDependencies: - supports-color + '@typescript-eslint/type-utils@8.0.1(eslint@9.9.0)(typescript@5.5.4)': + dependencies: + '@typescript-eslint/typescript-estree': 8.0.1(typescript@5.5.4) + '@typescript-eslint/utils': 8.0.1(eslint@9.9.0)(typescript@5.5.4) + debug: 4.3.6 + ts-api-utils: 1.3.0(typescript@5.5.4) + optionalDependencies: + typescript: 5.5.4 + transitivePeerDependencies: + - eslint + - supports-color + '@typescript-eslint/types@7.18.0': {} + '@typescript-eslint/types@8.0.1': {} + '@typescript-eslint/typescript-estree@7.18.0(typescript@5.5.4)': dependencies: '@typescript-eslint/types': 7.18.0 @@ -2132,6 +2239,21 @@ snapshots: transitivePeerDependencies: - supports-color + '@typescript-eslint/typescript-estree@8.0.1(typescript@5.5.4)': + dependencies: + '@typescript-eslint/types': 8.0.1 + '@typescript-eslint/visitor-keys': 8.0.1 + debug: 4.3.6 + globby: 11.1.0 + is-glob: 4.0.3 + minimatch: 9.0.5 + semver: 7.6.3 + ts-api-utils: 1.3.0(typescript@5.5.4) + optionalDependencies: + typescript: 5.5.4 + transitivePeerDependencies: + - supports-color + '@typescript-eslint/utils@7.18.0(eslint@9.9.0)(typescript@5.5.4)': dependencies: '@eslint-community/eslint-utils': 4.4.0(eslint@9.9.0) @@ -2143,11 +2265,27 @@ snapshots: - supports-color - typescript + '@typescript-eslint/utils@8.0.1(eslint@9.9.0)(typescript@5.5.4)': + dependencies: + '@eslint-community/eslint-utils': 4.4.0(eslint@9.9.0) + '@typescript-eslint/scope-manager': 8.0.1 + '@typescript-eslint/types': 8.0.1 + '@typescript-eslint/typescript-estree': 8.0.1(typescript@5.5.4) + eslint: 9.9.0 + transitivePeerDependencies: + - supports-color + - typescript + '@typescript-eslint/visitor-keys@7.18.0': dependencies: '@typescript-eslint/types': 7.18.0 eslint-visitor-keys: 3.4.3 + '@typescript-eslint/visitor-keys@8.0.1': + dependencies: + '@typescript-eslint/types': 8.0.1 + eslint-visitor-keys: 3.4.3 + '@vladfrangu/async_event_emitter@2.4.5': {} acorn-jsx@5.3.2(acorn@8.12.1): diff --git a/src/EnvironmentVariables.ts b/src/EnvironmentVariables.ts index 95dbf4a..e174011 100644 --- a/src/EnvironmentVariables.ts +++ b/src/EnvironmentVariables.ts @@ -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'; @@ -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(), diff --git a/src/audioplayer/AudioPlayersManager.ts b/src/audioplayer/AudioPlayersManager.ts index 1060565..93d4c44 100644 --- a/src/audioplayer/AudioPlayersManager.ts +++ b/src/audioplayer/AudioPlayersManager.ts @@ -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 { @@ -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) { this.client = client; this.client.audioPlayer = this; this.playersManager = new AudioPlayersStore(this.client); @@ -53,7 +51,7 @@ export class AudioPlayersManager { emitAddSongWhenCreatingQueue: true, savePreviousSongs: true, joinNewVoiceChannel: true, - plugins: plugins + plugins }); this.setupEvents(); @@ -373,7 +371,9 @@ 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) { @@ -381,7 +381,9 @@ export class AudioPlayersManager { } }) .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; diff --git a/src/commands/audio/history.command.ts b/src/commands/audio/history.command.ts index e64ca06..1f80abe 100644 --- a/src/commands/audio/history.command.ts +++ b/src/commands/audio/history.command.ts @@ -1,18 +1,31 @@ import { ICommand } from '../../CommandTypes.js'; import i18next from 'i18next'; -import { EmbedBuilder, Guild, PermissionsBitField, SlashCommandBuilder } from 'discord.js'; +import { + CommandInteraction, + Embed, + EmbedBuilder, + Guild, + Message, + PermissionsBitField, + SlashCommandBuilder +} from 'discord.js'; import { GroupAudio } from './AudioTypes.js'; -import { getOrCreateGuildSongsHistory } from '../../schemas/SchemaSongsHistory.js'; +import { + getOrCreateGuildSongsHistory, + ISchemaSongsHistory +} from '../../schemas/SchemaSongsHistory.js'; +import { pagination } from '../../utilities/pagination/pagination.js'; +import { ButtonStyles, ButtonTypes } from '../../utilities/pagination/paginationTypes.js'; +import { ENV } from '../../EnvironmentVariables.js'; export default function (): ICommand { return { + disable: ENV.BOT_MAX_SONGS_HISTORY_SIZE === 0, text_data: { name: 'history', description: i18next.t('commands:history_desc'), execute: async (message) => { - await message.reply({ - embeds: [await generateSongHistoryEmbed(message.guild as Guild)] - }); + await replyWithSongHistory(message.guild as Guild, undefined, message); } }, slash_data: { @@ -20,11 +33,7 @@ export default function (): ICommand { .setName('history') .setDescription(i18next.t('commands:history_desc')), execute: async (interaction) => { - await interaction.deferReply(); - - await interaction.editReply({ - embeds: [await generateSongHistoryEmbed(interaction.guild as Guild)] - }); + await replyWithSongHistory(interaction.guild as Guild, interaction); } }, guild_data: { @@ -35,38 +44,91 @@ export default function (): ICommand { }; } -async function generateSongHistoryEmbed(guild: Guild): Promise { - const history = await getOrCreateGuildSongsHistory(guild.id); +async function replyWithSongHistory( + guild: Guild, + interaction?: CommandInteraction, + message?: Message +): Promise { + const history: ISchemaSongsHistory | null = await getOrCreateGuildSongsHistory(guild.id); if (!history) throw Error(`Can't find guild songs history: ${guild.id}`); - const historyEmbed = new EmbedBuilder().setTitle( - `${i18next.t('commands:history_embed_title')} ${guild.name}` - ); - if (history.songsHistory.length === 0) { - historyEmbed.setTitle(i18next.t('commands:history_embed_no_songs')); - return historyEmbed; + await interaction?.reply({ + embeds: [new EmbedBuilder().setTitle(i18next.t('commands:history_embed_no_songs'))] + }); + await message?.reply({ + embeds: [new EmbedBuilder().setTitle(i18next.t('commands:history_embed_no_songs'))] + }); } - let queueList = ''; + function buildPage(history: ISchemaSongsHistory, pageNumber: number, entriesPerPage: number) { + let songsList = ''; + + const startingIndex = pageNumber * entriesPerPage; + + for ( + let i = startingIndex; + i < Math.min(startingIndex + entriesPerPage, history.songsHistory.length); + i++ + ) { + const song = history.songsHistory[i]; - for (let i = 0; i < history.songsHistory.length; i++) { - const song = history.songsHistory[i]; + const songDate = song.createdAt + ? `` + : ''; - const songDate = song.createdAt - ? `` - : ''; + songsList += + `${i + 1}. ` + + `[${song.name}](${song.url})` + + ` - <@${song.requester}>` + + ` - ${songDate}` + + '\n'; + } - queueList += - `${i + 1}. ` + - `[${song.name}](${song.url})` + - ` - <@${song.requester}>` + - ` - ${songDate}` + - '\n'; + return new EmbedBuilder() + .setTitle(`${i18next.t('commands:history_embed_title')} ${guild.name}`) + .setDescription(`${songsList}`.slice(0, 4096)); } - historyEmbed.setDescription(queueList); + const arrayEmbeds: Array = []; + const entriesPerPage = 20; + const pages = Math.ceil(history.songsHistory.length / entriesPerPage); - return historyEmbed; + for (let i = 0; i < pages; i++) { + arrayEmbeds.push(buildPage(history, i, entriesPerPage)); + } + + await pagination({ + embeds: arrayEmbeds as unknown as Embed[], + // @ts-expect-error I need to provide Interaction or Message for different command systems. + author: interaction?.user ?? message?.author, + message: message, + interaction: interaction, + ephemeral: true, + fastSkip: true, + pageTravel: false, + buttons: [ + { + type: ButtonTypes.first, + emoji: '⬅️', + style: ButtonStyles.Secondary + }, + { + type: ButtonTypes.previous, + emoji: '◀️', + style: ButtonStyles.Secondary + }, + { + type: ButtonTypes.next, + emoji: '▶️', + style: ButtonStyles.Secondary + }, + { + type: ButtonTypes.last, + emoji: '➡️', + style: ButtonStyles.Secondary + } + ] + }); } diff --git a/src/main.ts b/src/main.ts index 343d30f..193d235 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,16 +1,15 @@ import { clientIntents } from './ClientIntents.js'; - -loggerSend(`Starting bot on version ${process.env.npm_package_version}`); - import { Client, Partials } from 'discord.js'; import { loggerError, loggerSend } from './utilities/logger.js'; import { loginBot } from './utilities/loginBot.js'; import { AudioPlayersManager } from './audioplayer/AudioPlayersManager.js'; import loadLocale from './locales/Locale.js'; +import { handlersLoad } from './handlersLoad.js'; +import { LoadPlugins } from './audioplayer/LoadPlugins.js'; -await loadLocale(); +loggerSend(`Starting bot on version ${process.env.npm_package_version}`); -import { handlersLoad } from './handlersLoad.js'; +await loadLocale(); const client = new Client({ intents: clientIntents, @@ -21,7 +20,7 @@ client.rest.on('rateLimited', (args) => { loggerError(`Client encountered a rate limit: ${JSON.stringify(args)}`); }); -new AudioPlayersManager(client); +new AudioPlayersManager(client, await LoadPlugins()); await handlersLoad(client); diff --git a/src/schemas/SchemaSongsHistory.ts b/src/schemas/SchemaSongsHistory.ts index 88ba728..79e2f24 100644 --- a/src/schemas/SchemaSongsHistory.ts +++ b/src/schemas/SchemaSongsHistory.ts @@ -1,6 +1,7 @@ import { model, Schema } from 'mongoose'; import { getOrCreateGuildSettings, GuildModelClass } from './SchemaGuild.js'; import { Playlist, Song } from 'distube'; +import { ENV } from '../EnvironmentVariables.js'; interface ISchemaSongHistoryUnit { name: string; @@ -74,7 +75,7 @@ export async function addSongToGuildSongsHistory( }); } - if (history.songsHistory.length > 15) { + if (history.songsHistory.length > ENV.BOT_MAX_SONGS_HISTORY_SIZE) { history.songsHistory.shift(); } diff --git a/wiki/Setup.md b/wiki/Setup.md index 45f07a8..54a4c20 100644 --- a/wiki/Setup.md +++ b/wiki/Setup.md @@ -14,27 +14,28 @@ Also you need retrieve token, client id and enable intents on Discord Developer - (Optional) To get SoundCloud token, follow the [Soundcloud](https://github.com/AlexInCube/AlCoTest/wiki/API-Configure#soundcloud-optional) section. - (Optional) To get Genius token, follow the [Genius](https://github.com/AlexInCube/AlCoTest/wiki/API-Configure#genius-optional) section. -| Name | Example | Description | Required | -|------------------------------|-----------------------|---------------------------------------------------------------------------|----------| -| `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 | ✔️ | -| `BOT_DISCORD_TOKEN` | ODEzNzUwMTY1N... | Token from Discord Developer Portal | ✔️ | -| `BOT_DISCORD_CLIENT_ID` | 813750165783... | Application ID from Discord Developer Portal | ✔️ | -| `BOT_DISCORD_OVERPOWERED_ID` | 29016845994426.... | Discord bot owner user ID, required for having more bot control for owner | ✔️ | -| `BOT_GOOGLE_EMAIL` | | Used to automate cookies fetching for YouTube | ❌ | -| `BOT_GOOGLE_PASSWORD` | | Used to automate cookies fetching for YouTube ❌ | | -| `BOT_SPOTIFY_CLIENT_SECRET` | | Used when the Spotify module cannot get the credentials automatically | ❌ | -| `BOT_SPOTIFY_CLIENT_ID` | | Used when the Spotify module get the credentials automatically | ❌ | -| `BOT_YANDEXMUSIC_TOKEN` | | Provide to enable Yandex Music module | ❌ | -| `BOT_YANDEXMUSIC_UID` | | Provide to enable Yandex Music module | ❌ | -| `BOT_SOUNDCLOUD_CLIENT_ID` | | Provide to fetch more data with SoundCloud Go+ account | ❌ | -| `BOT_SOUNDCLOUD_TOKEN` | | Provide to fetch more data with SoundCloud Go+ account | ❌ | -| `BOT_GENIUS_TOKEN` | | Provide to fetch songs lyrics from Genius | | +| Name | Example | Description | Required | +|------------------------------|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------|----------| +| `BOT_VERBOSE_LOGGING` | false | The bot will give more info to the console, useful for debugging | ❌ | +| `BOT_FFMPEG_LOGGING` | 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_MAX_SONGS_HISTORY_SIZE` | 60 | Define max songs history per guild, set to 0 if you want to disable history (this will not delete history in database which already exists) | ❌ | +| `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 | ✔️ | +| `BOT_DISCORD_TOKEN` | ODEzNzUwMTY1N... | Token from Discord Developer Portal | ✔️ | +| `BOT_DISCORD_CLIENT_ID` | 813750165783... | Application ID from Discord Developer Portal | ✔️ | +| `BOT_DISCORD_OVERPOWERED_ID` | 29016845994426.... | Discord bot owner user ID, required for having more bot control for owner | ✔️ | +| `BOT_GOOGLE_EMAIL` | | Used to automate cookies fetching for YouTube | ❌ | +| `BOT_GOOGLE_PASSWORD` | | Used to automate cookies fetching for YouTube | ❌ | +| `BOT_SPOTIFY_CLIENT_SECRET` | | Used when the Spotify module cannot get the credentials automatically | ❌ | +| `BOT_SPOTIFY_CLIENT_ID` | | Used when the Spotify module get the credentials automatically | ❌ | +| `BOT_YANDEXMUSIC_TOKEN` | | Provide to enable Yandex Music module | ❌ | +| `BOT_YANDEXMUSIC_UID` | | Provide to enable Yandex Music module | ❌ | +| `BOT_SOUNDCLOUD_CLIENT_ID` | | Provide to fetch more data with SoundCloud Go+ account | ❌ | +| `BOT_SOUNDCLOUD_TOKEN` | | Provide to fetch more data with SoundCloud Go+ account | ❌ | +| `BOT_GENIUS_TOKEN` | | Provide to fetch songs lyrics from Genius | ❌ | # 🐋 Run in Docker (recommended)