From 75ec77a8802377b304ca8053e662d363688cac51 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 31 Oct 2024 18:59:32 +0100 Subject: [PATCH] add constants --- src/commands/music/play.ts | 12 ++++++++---- src/utils/commands/music.ts | 4 ++-- src/utils/constants.ts | 11 +++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 src/utils/constants.ts diff --git a/src/commands/music/play.ts b/src/commands/music/play.ts index 349323c..8afeaae 100644 --- a/src/commands/music/play.ts +++ b/src/commands/music/play.ts @@ -9,6 +9,10 @@ import { import { getLocale, getLocalizations } from "../../utils/locales"; import { Metadata } from "../../utils/metadata"; import { getFilename } from "../../utils/misc"; +import { + discord_limit_autocompletion_list_length, + discord_limit_autocompletion_value_length, +} from "../../utils/constants"; export default { scope: () => [], @@ -192,8 +196,8 @@ export default { const player = useMainPlayer(); const query = interaction.options.getString(loc_default!.get(`c_${filename}_opt1_name`)!, true); - const limit_value_discord = 100; - const limit_element_discord = 25; + const limit_value_discord = discord_limit_autocompletion_value_length; + const limit_element_discord = discord_limit_autocompletion_list_length; const query_discord = query.slice(0, limit_value_discord); @@ -238,8 +242,8 @@ export default { let author = t.author; let name = `${title} • ${author}`; - // Slice returned data if needed to not exceed the length limit (100) - if (name.length > 100) { + // Slice returned data if needed to not exceed the length limit + if (name.length > limit_value_discord) { const newTitle = title.substring(0, 40); if (title.length != newTitle.length) { title = `${newTitle}...`; diff --git a/src/utils/commands/music.ts b/src/utils/commands/music.ts index c49f0b9..4b9c534 100644 --- a/src/utils/commands/music.ts +++ b/src/utils/commands/music.ts @@ -3,6 +3,7 @@ import { GuildQueue, QueueRepeatMode } from "discord-player"; import { Client } from "discord.js"; import { getLocale } from "../locales"; import { blank } from "../misc"; +import { discord_limit_embed_field } from "../constants"; export const embedListQueue = ( client: Client, @@ -17,8 +18,7 @@ export const embedListQueue = ( // Add the current song at the top of the list tracks.unshift(queue.history.currentTrack!); - // Limit of discord is 25 - const limit_fields = 25; + const limit_fields = discord_limit_embed_field; const pageMax = Math.ceil(tracks.length / limit_fields); diff --git a/src/utils/constants.ts b/src/utils/constants.ts new file mode 100644 index 0000000..75353a1 --- /dev/null +++ b/src/utils/constants.ts @@ -0,0 +1,11 @@ +/** Max message length */ +export const discord_limit_message = 2000; + +/** Max embed field an embed can have */ +export const discord_limit_embed_field = 25; + +/** Max element the autocompletion of slash commands can have */ +export const discord_limit_autocompletion_list_length = 25; + +/** Max length of an element in autocompletion of slash commands */ +export const discord_limit_autocompletion_value_length = 100;