Réécriture complète 4.0
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 6m16s
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 6m16s
This commit is contained in:
15
src/buttons/player/disco_channel.ts
Normal file
15
src/buttons/player/disco_channel.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { MessageFlags, ChannelType, ActionRowBuilder, ChannelSelectMenuBuilder } from "discord.js"
|
||||
import type { ButtonInteraction } from "discord.js"
|
||||
import { t } from "@/utils/i18n"
|
||||
|
||||
export const id = "player_disco_channel"
|
||||
export async function execute(interaction: ButtonInteraction) {
|
||||
const channelSelect = new ChannelSelectMenuBuilder()
|
||||
.setCustomId("player_disco_channel")
|
||||
.setPlaceholder(t(interaction.locale, "selectmenus.placeholders.select_channel_disco"))
|
||||
.addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement)
|
||||
|
||||
const row = new ActionRowBuilder<ChannelSelectMenuBuilder>().addComponents(channelSelect)
|
||||
|
||||
return interaction.reply({ content: t(interaction.locale, "player.disco.select_channel"), components: [row], flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
24
src/buttons/player/disco_disable.ts
Normal file
24
src/buttons/player/disco_disable.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { MessageFlags } from "discord.js"
|
||||
import type { ButtonInteraction } from "discord.js"
|
||||
import { generateDiscoEmbed } from "@/utils/player"
|
||||
import type { Disco } from "@/types/schemas"
|
||||
import dbGuild from "@/schemas/guild"
|
||||
import { t } from "@/utils/i18n"
|
||||
|
||||
export const id = "player_disco_disable"
|
||||
export async function execute(interaction: ButtonInteraction) {
|
||||
const guildProfile = await dbGuild.findOne({ guildId: interaction.guild?.id })
|
||||
if (!guildProfile) return interaction.reply({ content: t(interaction.locale, "common.database_not_found"), flags: MessageFlags.Ephemeral })
|
||||
|
||||
const dbData = guildProfile.get("guildPlayer.disco") as Disco
|
||||
dbData.enabled = false
|
||||
|
||||
guildProfile.set("guildPlayer.disco", dbData)
|
||||
guildProfile.markModified("guildPlayer.disco")
|
||||
await guildProfile.save().catch(console.error)
|
||||
|
||||
// Utiliser la fonction utilitaire pour générer l'embed et les composants mis à jour
|
||||
const { embed, components } = generateDiscoEmbed(dbData, interaction.client, interaction.guild?.id ?? "", interaction.locale)
|
||||
|
||||
return interaction.update({ embeds: [embed], components: components })
|
||||
}
|
||||
31
src/buttons/player/disco_enable.ts
Normal file
31
src/buttons/player/disco_enable.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { MessageFlags } from "discord.js"
|
||||
import type { ButtonInteraction } from "discord.js"
|
||||
import { generateDiscoEmbed } from "@/utils/player"
|
||||
import type { Disco } from "@/types/schemas"
|
||||
import dbGuild from "@/schemas/guild"
|
||||
import { t } from "@/utils/i18n"
|
||||
|
||||
export const id = "player_disco_enable"
|
||||
export async function execute(interaction: ButtonInteraction) {
|
||||
const guildProfile = await dbGuild.findOne({ guildId: interaction.guild?.id })
|
||||
if (!guildProfile) return interaction.reply({ content: t(interaction.locale, "common.database_not_found"), flags: MessageFlags.Ephemeral })
|
||||
|
||||
const dbData = guildProfile.get("guildPlayer.disco") as Disco
|
||||
|
||||
// Vérifier qu'un canal est configuré avant d'activer
|
||||
if (!dbData.channelId) return interaction.reply({
|
||||
content: t(interaction.locale, "player.disco.configure_channel_first"),
|
||||
flags: MessageFlags.Ephemeral
|
||||
})
|
||||
|
||||
dbData.enabled = true
|
||||
|
||||
guildProfile.set("guildPlayer.disco", dbData)
|
||||
guildProfile.markModified("guildPlayer.disco")
|
||||
await guildProfile.save().catch(console.error)
|
||||
|
||||
// Utiliser la fonction utilitaire pour générer l'embed et les composants mis à jour
|
||||
const { embed, components } = generateDiscoEmbed(dbData, interaction.client, interaction.guild?.id ?? "", interaction.locale)
|
||||
|
||||
return interaction.update({ embeds: [embed], components: components })
|
||||
}
|
||||
29
src/buttons/player/index.ts
Normal file
29
src/buttons/player/index.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import * as disco_disable from "./disco_disable"
|
||||
import * as disco_enable from "./disco_enable"
|
||||
import * as disco_channel from "./disco_channel"
|
||||
import * as loop from "./loop"
|
||||
import * as pause from "./pause"
|
||||
import * as previous from "./previous"
|
||||
import * as resume from "./resume"
|
||||
import * as shuffle from "./shuffle"
|
||||
import * as skip from "./skip"
|
||||
import * as stop from "./stop"
|
||||
import * as volume_down from "./volume_down"
|
||||
import * as volume_up from "./volume_up"
|
||||
|
||||
import type { Button } from "@/types"
|
||||
|
||||
export default [
|
||||
disco_channel,
|
||||
disco_disable,
|
||||
disco_enable,
|
||||
loop,
|
||||
pause,
|
||||
previous,
|
||||
resume,
|
||||
shuffle,
|
||||
skip,
|
||||
stop,
|
||||
volume_down,
|
||||
volume_up
|
||||
] as Button[]
|
||||
22
src/buttons/player/loop.ts
Normal file
22
src/buttons/player/loop.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { MessageFlags } from "discord.js"
|
||||
import type { ButtonInteraction } from "discord.js"
|
||||
import { useQueue } from "discord-player"
|
||||
import { t } from "@/utils/i18n"
|
||||
|
||||
export const id = "player_loop"
|
||||
export async function execute(interaction: ButtonInteraction) {
|
||||
const queue = useQueue(interaction.guild?.id ?? "")
|
||||
if (!queue) return
|
||||
|
||||
const loop = queue.repeatMode === 0 ? 1 : queue.repeatMode === 1 ? 2 : queue.repeatMode === 2 ? 3 : 0
|
||||
queue.setRepeatMode(loop)
|
||||
|
||||
const loopModes = {
|
||||
0: t(interaction.locale, "player.loop_off"),
|
||||
1: t(interaction.locale, "player.loop_track"),
|
||||
2: t(interaction.locale, "player.loop_queue"),
|
||||
3: t(interaction.locale, "player.loop_autoplay")
|
||||
}
|
||||
|
||||
return interaction.followUp({ content: loopModes[loop], flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
13
src/buttons/player/pause.ts
Normal file
13
src/buttons/player/pause.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { MessageFlags } from "discord.js"
|
||||
import type { ButtonInteraction } from "discord.js"
|
||||
import { useQueue } from "discord-player"
|
||||
import { t } from "@/utils/i18n"
|
||||
|
||||
export const id = "player_pause"
|
||||
export async function execute(interaction: ButtonInteraction) {
|
||||
const queue = useQueue(interaction.guild?.id ?? "")
|
||||
if (!queue) return
|
||||
|
||||
queue.node.setPaused(!queue.node.isPaused())
|
||||
return interaction.followUp({ content: t(interaction.locale, "player.paused"), flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
13
src/buttons/player/previous.ts
Normal file
13
src/buttons/player/previous.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { MessageFlags } from "discord.js"
|
||||
import type { ButtonInteraction } from "discord.js"
|
||||
import { useHistory } from "discord-player"
|
||||
import { t } from "@/utils/i18n"
|
||||
|
||||
export const id = "player_previous"
|
||||
export async function execute(interaction: ButtonInteraction) {
|
||||
const history = useHistory(interaction.guild?.id ?? "")
|
||||
if (!history) return
|
||||
|
||||
await history.previous()
|
||||
return interaction.followUp({ content: t(interaction.locale, "player.previous_played"), flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
13
src/buttons/player/resume.ts
Normal file
13
src/buttons/player/resume.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { MessageFlags } from "discord.js"
|
||||
import type { ButtonInteraction } from "discord.js"
|
||||
import { useQueue } from "discord-player"
|
||||
import { t } from "@/utils/i18n"
|
||||
|
||||
export const id = "player_resume"
|
||||
export async function execute(interaction: ButtonInteraction) {
|
||||
const queue = useQueue(interaction.guild?.id ?? "")
|
||||
if (!queue) return
|
||||
|
||||
queue.node.setPaused(!queue.node.isPaused())
|
||||
return interaction.followUp({ content: t(interaction.locale, "player.resumed"), flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
13
src/buttons/player/shuffle.ts
Normal file
13
src/buttons/player/shuffle.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { MessageFlags } from "discord.js"
|
||||
import type { ButtonInteraction } from "discord.js"
|
||||
import { useQueue } from "discord-player"
|
||||
import { t } from "@/utils/i18n"
|
||||
|
||||
export const id = "player_shuffle"
|
||||
export async function execute(interaction: ButtonInteraction) {
|
||||
const queue = useQueue(interaction.guild?.id ?? "")
|
||||
if (!queue) return
|
||||
|
||||
queue.tracks.shuffle()
|
||||
return interaction.followUp({ content: t(interaction.locale, "player.shuffled"), flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
13
src/buttons/player/skip.ts
Normal file
13
src/buttons/player/skip.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { MessageFlags } from "discord.js"
|
||||
import type { ButtonInteraction } from "discord.js"
|
||||
import { useQueue } from "discord-player"
|
||||
import { t } from "@/utils/i18n"
|
||||
|
||||
export const id = "player_skip"
|
||||
export async function execute(interaction: ButtonInteraction) {
|
||||
const queue = useQueue(interaction.guild?.id ?? "")
|
||||
if (!queue) return
|
||||
|
||||
queue.node.skip()
|
||||
return interaction.followUp({ content: t(interaction.locale, "player.skipped"), flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
16
src/buttons/player/stop.ts
Normal file
16
src/buttons/player/stop.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { MessageFlags } from "discord.js"
|
||||
import type { ButtonInteraction } from "discord.js"
|
||||
import { useQueue } from "discord-player"
|
||||
import { stopProgressSaving } from "@/utils/player"
|
||||
import { t } from "@/utils/i18n"
|
||||
|
||||
export const id = "player_stop"
|
||||
export async function execute(interaction: ButtonInteraction) {
|
||||
await stopProgressSaving(interaction.guild?.id ?? "", interaction.client.user.id)
|
||||
|
||||
const queue = useQueue(interaction.guild?.id ?? "")
|
||||
if (!queue) return
|
||||
|
||||
queue.delete()
|
||||
return interaction.followUp({ content: t(interaction.locale, "player.stopped"), flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
14
src/buttons/player/volume_down.ts
Normal file
14
src/buttons/player/volume_down.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { MessageFlags } from "discord.js"
|
||||
import type { ButtonInteraction } from "discord.js"
|
||||
import { useQueue } from "discord-player"
|
||||
import { t } from "@/utils/i18n"
|
||||
|
||||
export const id = "player_volume_down"
|
||||
export async function execute(interaction: ButtonInteraction) {
|
||||
const queue = useQueue(interaction.guild?.id ?? "")
|
||||
if (!queue) return
|
||||
|
||||
const volume = queue.node.volume - 10
|
||||
queue.node.setVolume(volume)
|
||||
return interaction.followUp({ content: t(interaction.locale, "player.volume_changed_down", { volume: volume.toString() }), flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
14
src/buttons/player/volume_up.ts
Normal file
14
src/buttons/player/volume_up.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { MessageFlags } from "discord.js"
|
||||
import type { ButtonInteraction } from "discord.js"
|
||||
import { useQueue } from "discord-player"
|
||||
import { t } from "@/utils/i18n"
|
||||
|
||||
export const id = "player_volume_up"
|
||||
export async function execute(interaction: ButtonInteraction) {
|
||||
const queue = useQueue(interaction.guild?.id ?? "")
|
||||
if (!queue) return
|
||||
|
||||
const volume = queue.node.volume + 10
|
||||
queue.node.setVolume(volume)
|
||||
return interaction.followUp({ content: t(interaction.locale, "player.volume_changed", { volume: volume.toString() }), flags: MessageFlags.Ephemeral })
|
||||
}
|
||||
Reference in New Issue
Block a user