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:
20
src/selectmenus/index.ts
Normal file
20
src/selectmenus/index.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import player from "./player"
|
||||
import twitch from "./twitch"
|
||||
|
||||
import type { SelectMenu, SelectMenuFolder } from "@/types"
|
||||
|
||||
export const buttonFolders = [
|
||||
{
|
||||
name: "player",
|
||||
commands: player
|
||||
},
|
||||
{
|
||||
name: "twitch",
|
||||
commands: twitch
|
||||
}
|
||||
] as SelectMenuFolder[]
|
||||
|
||||
export default [
|
||||
...player,
|
||||
...twitch
|
||||
] as SelectMenu[]
|
||||
28
src/selectmenus/player/disco_channel.ts
Normal file
28
src/selectmenus/player/disco_channel.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { MessageFlags } from "discord.js"
|
||||
import type { ChannelSelectMenuInteraction } 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_channel"
|
||||
export async function execute(interaction: ChannelSelectMenuInteraction) {
|
||||
const channel = interaction.channels.first()
|
||||
if (!channel) return interaction.reply({ content: t(interaction.locale, "common.no_channel_selected"), flags: MessageFlags.Ephemeral })
|
||||
|
||||
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.channelId = channel.id
|
||||
|
||||
guildProfile.set("guildPlayer.disco", dbData)
|
||||
guildProfile.markModified("guildPlayer.disco")
|
||||
await guildProfile.save().catch(console.error)
|
||||
|
||||
// Générer l'embed mis à jour avec la fonction utilitaire
|
||||
const { embed, components } = generateDiscoEmbed(dbData, interaction.client, interaction.guild?.id ?? "", interaction.locale)
|
||||
|
||||
// Mettre à jour l'embed original avec les nouvelles données
|
||||
return interaction.update({ content: t(interaction.locale, "common.channel_configured_success"), embeds: [embed], components })
|
||||
}
|
||||
7
src/selectmenus/player/index.ts
Normal file
7
src/selectmenus/player/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import * as disco_channel from "./disco_channel"
|
||||
|
||||
import type { SelectMenu } from "@/types"
|
||||
|
||||
export default [
|
||||
disco_channel
|
||||
] as SelectMenu[]
|
||||
32
src/selectmenus/twitch/channel.ts
Normal file
32
src/selectmenus/twitch/channel.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { MessageFlags } from "discord.js"
|
||||
import type { ChannelSelectMenuInteraction } from "discord.js"
|
||||
import { generateTwitchEmbed } from "@/utils/twitch"
|
||||
import type { GuildTwitch } from "@/types/schemas"
|
||||
import dbGuild from "@/schemas/guild"
|
||||
import { t } from "@/utils/i18n"
|
||||
|
||||
export const id = "twitch_channel"
|
||||
export async function execute(interaction: ChannelSelectMenuInteraction) {
|
||||
const channel = interaction.channels.first()
|
||||
if (!channel) return interaction.reply({ content: t(interaction.locale, "common.no_channel_selected"), flags: MessageFlags.Ephemeral })
|
||||
|
||||
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("guildTwitch") as GuildTwitch
|
||||
dbData.channelId = channel.id
|
||||
|
||||
guildProfile.set("guildTwitch", dbData)
|
||||
guildProfile.markModified("guildTwitch")
|
||||
await guildProfile.save().catch(console.error)
|
||||
|
||||
// Générer l'embed mis à jour avec la fonction utilitaire
|
||||
const { embed, components } = generateTwitchEmbed(dbData, interaction.client, interaction.guild?.id ?? "", interaction.locale)
|
||||
|
||||
// Mettre à jour l'embed original avec les nouvelles données
|
||||
return interaction.update({
|
||||
content: t(interaction.locale, "common.channel_configured_success") + ` ${t(interaction.locale, "twitch.notifications_sent_to", { channel: `<#${channel.id}>` })}`,
|
||||
embeds: [embed],
|
||||
components
|
||||
})
|
||||
}
|
||||
9
src/selectmenus/twitch/index.ts
Normal file
9
src/selectmenus/twitch/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as channel from "./channel"
|
||||
import * as streamer_remove from "./streamer_remove"
|
||||
|
||||
import type { SelectMenu } from "@/types"
|
||||
|
||||
export default [
|
||||
channel,
|
||||
streamer_remove
|
||||
] as SelectMenu[]
|
||||
52
src/selectmenus/twitch/streamer_remove.ts
Normal file
52
src/selectmenus/twitch/streamer_remove.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { MessageFlags } from "discord.js"
|
||||
import type { StringSelectMenuInteraction } from "discord.js"
|
||||
import { twitchClient } from "@/utils/twitch"
|
||||
import type { GuildTwitch } from "@/types/schemas"
|
||||
import dbGuild from "@/schemas/guild"
|
||||
import { t } from "@/utils/i18n"
|
||||
import { logConsole } from "@/utils/console"
|
||||
|
||||
export const id = "twitch_streamer_remove"
|
||||
export async function execute(interaction: StringSelectMenuInteraction) {
|
||||
const twitchUserId = interaction.values[0]
|
||||
if (!twitchUserId) return interaction.reply({ content: t(interaction.locale, "twitch.no_streamer_selected"), flags: MessageFlags.Ephemeral })
|
||||
|
||||
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("guildTwitch") as GuildTwitch
|
||||
|
||||
// Trouver et supprimer le streamer
|
||||
const streamerIndex = dbData.streamers.findIndex(s => s.twitchUserId === twitchUserId)
|
||||
if (streamerIndex === -1) return interaction.reply({ content: t(interaction.locale, "twitch.streamer_not_found_list"), flags: MessageFlags.Ephemeral })
|
||||
|
||||
// Récupérer le nom du streamer avant suppression
|
||||
let streamerName = `ID: ${twitchUserId}`
|
||||
try {
|
||||
const user = await twitchClient.users.getUserById(twitchUserId)
|
||||
if (user) streamerName = user.displayName
|
||||
} catch {
|
||||
logConsole('twitch', 'user_fetch_error_buttons', { id: twitchUserId })
|
||||
}
|
||||
|
||||
// Supprimer le streamer
|
||||
dbData.streamers.splice(streamerIndex, 1)
|
||||
guildProfile.set("guildTwitch", dbData)
|
||||
guildProfile.markModified("guildTwitch")
|
||||
await guildProfile.save().catch(console.error)
|
||||
|
||||
// Vérifier s'il faut supprimer les listeners
|
||||
if (!await dbGuild.exists({ "guildTwitch.streamers.twitchUserId": twitchUserId })) {
|
||||
try {
|
||||
const userSubs = await twitchClient.eventSub.getSubscriptionsForUser(twitchUserId)
|
||||
await Promise.all(userSubs.data.map(async sub => {
|
||||
if (sub.transportMethod === "webhook" && (sub.type === "stream.online" || sub.type === "stream.offline")) await sub.unsubscribe()
|
||||
}))
|
||||
logConsole('twitch', 'listener_removed', { name: streamerName, id: twitchUserId })
|
||||
} catch {
|
||||
logConsole('twitch', 'listener_removal_error', { streamerName })
|
||||
}
|
||||
}
|
||||
|
||||
return interaction.update({ content: t(interaction.locale, "twitch.streamer_removed_success", { streamer: streamerName }), components: [] })
|
||||
}
|
||||
Reference in New Issue
Block a user