Fix duplicate streamWatching, locale guild et console log/error
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 3m43s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 3m43s
This commit is contained in:
@@ -9,6 +9,7 @@ import type {
|
||||
import type { GuildFbx } from "@/types/schemas"
|
||||
import dbGuild from "@/schemas/guild"
|
||||
import { t } from "@/utils/i18n"
|
||||
import { logConsole } from "@/utils/console"
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName("freebox")
|
||||
@@ -238,7 +239,7 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||
clearInterval(initCheck)
|
||||
|
||||
return interaction.followUp({ content: t(interaction.locale, "freebox.auth.user_denied_access"), flags: MessageFlags.Ephemeral })
|
||||
} else if (status === "pending") { console.log("Freebox authorization pending...") }
|
||||
} else if (status === "pending") logConsole('freebox', 'authorization_pending')
|
||||
}, 2000)
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as amp from "./amp"
|
||||
import * as boost from "./boost"
|
||||
import * as database from "./database"
|
||||
import * as freebox from "./freebox"
|
||||
import * as locale from "./locale"
|
||||
import * as ping from "./ping"
|
||||
import * as twitch from "./twitch"
|
||||
|
||||
@@ -12,6 +13,7 @@ export default [
|
||||
boost,
|
||||
database,
|
||||
freebox,
|
||||
locale,
|
||||
ping,
|
||||
twitch
|
||||
] as Command[]
|
||||
|
||||
56
src/commands/global/locale.ts
Normal file
56
src/commands/global/locale.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { SlashCommandBuilder, MessageFlags } from "discord.js"
|
||||
import type { ChatInputCommandInteraction } from "discord.js"
|
||||
import dbGuild from "@/schemas/guild"
|
||||
import { t } from "@/utils/i18n"
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName("locale")
|
||||
.setDescription("Manage server language")
|
||||
.setDescriptionLocalizations({ fr: "Gérer la langue du serveur" })
|
||||
.addStringOption(option => option
|
||||
.setName("language")
|
||||
.setDescription("Select the server language")
|
||||
.setNameLocalizations({ fr: "langue" })
|
||||
.setDescriptionLocalizations({ fr: "Sélectionner la langue du serveur" })
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
{ name: "Français", value: "fr" },
|
||||
{ name: "English", value: "en-US" }
|
||||
)
|
||||
)
|
||||
|
||||
export async function execute(interaction: ChatInputCommandInteraction) {
|
||||
const guild = interaction.guild
|
||||
if (!guild) return interaction.reply({ content: t(interaction.locale, "common.command_server_only"), flags: MessageFlags.Ephemeral })
|
||||
|
||||
const language = interaction.options.getString("language", true)
|
||||
|
||||
// Récupération du profil du serveur
|
||||
const guildProfile = await dbGuild.findOne({ guildId: guild.id })
|
||||
if (!guildProfile) return interaction.reply({ content: t(interaction.locale, "common.database_not_found"), flags: MessageFlags.Ephemeral })
|
||||
|
||||
// Sauvegarde de l'ancienne langue pour le message de confirmation
|
||||
const oldLocale = guildProfile.guildLocale
|
||||
|
||||
// Mise à jour de la langue
|
||||
guildProfile.guildLocale = language
|
||||
guildProfile.markModified("guildLocale")
|
||||
await guildProfile.save().catch(console.error)
|
||||
|
||||
// Utilisation de la nouvelle langue pour la réponse
|
||||
const languageNames = {
|
||||
'fr': 'Français',
|
||||
'en-US': 'English'
|
||||
}
|
||||
|
||||
const oldLanguageName = languageNames[oldLocale as keyof typeof languageNames] || oldLocale
|
||||
const newLanguageName = languageNames[language as keyof typeof languageNames] || language
|
||||
|
||||
return interaction.reply({
|
||||
content: t(language, "locale.updated", {
|
||||
oldLanguage: oldLanguageName,
|
||||
newLanguage: newLanguageName
|
||||
}),
|
||||
flags: MessageFlags.Ephemeral
|
||||
})
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import { SlashCommandBuilder, ChannelType, MessageFlags, PermissionFlagsBits } from "discord.js"
|
||||
import type { ChatInputCommandInteraction, AutocompleteInteraction, ApplicationCommandOptionChoiceData } from "discord.js"
|
||||
import chalk from "chalk"
|
||||
import { twitchClient, listener, onlineSub, offlineSub, generateTwitchEmbed } from "@/utils/twitch"
|
||||
import type { GuildTwitch } from "@/types/schemas"
|
||||
import dbGuild from "@/schemas/guild"
|
||||
import { t } from "@/utils/i18n"
|
||||
import { logConsole, logConsoleError } from "@/utils/console"
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName("twitch")
|
||||
@@ -120,8 +120,7 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||
if (user) streamers.push(`- ${user.displayName} (${streamer.twitchUserId})`)
|
||||
else streamers.push(`- ${t(interaction.locale, "twitch.user_not_found_id", { id: streamer.twitchUserId })}`)
|
||||
} catch (error) {
|
||||
console.log(chalk.magenta(`[Twitch] Error fetching user for ID ${streamer.twitchUserId}`))
|
||||
console.error(error)
|
||||
logConsoleError('twitch', 'user_fetch_error', { id: streamer.twitchUserId }, error as Error)
|
||||
}
|
||||
}))
|
||||
const streamerList = streamers.length > 0 ? streamers.join("\n") : t(interaction.locale, "twitch.no_streamers")
|
||||
@@ -167,7 +166,7 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||
if (!await dbGuild.exists({ "guildTwitch.streamers.twitchUserId": user.id })) {
|
||||
const userSubs = await twitchClient.eventSub.getSubscriptionsForUser(user.id)
|
||||
await Promise.all(userSubs.data.map(async sub => { if (sub.transportMethod === "webhook" && (sub.type === "stream.online" || sub.type === "stream.offline")) await sub.unsubscribe() }))
|
||||
console.log(chalk.magenta(`[Twitch] Listener removed for ${user.displayName} (ID ${user.id})`))
|
||||
logConsole('twitch', 'listener_removed', { name: user.displayName, id: user.id })
|
||||
}
|
||||
|
||||
return interaction.reply({ content: t(interaction.locale, "twitch.streamer_removed", { username }), flags: MessageFlags.Ephemeral })
|
||||
|
||||
@@ -8,6 +8,7 @@ import type { TrackSearchResult } from "@/types/player"
|
||||
import type { GuildPlayer } from "@/types/schemas"
|
||||
import dbGuild from "@/schemas/guild"
|
||||
import { t } from "@/utils/i18n"
|
||||
import { logConsoleError } from "@/utils/console"
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName("play")
|
||||
@@ -55,7 +56,7 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||
}
|
||||
|
||||
try { if (!queue.connection) await queue.connect(voiceChannel) }
|
||||
catch (error) { console.error(error) }
|
||||
catch (error) { logConsoleError('discord_player', 'play.connect_error', {}, error as Error) }
|
||||
|
||||
const guildProfile = await dbGuild.findOne({ guildId: queue.guild.id })
|
||||
if (!guildProfile) return interaction.reply({ content: t(interaction.locale, "common.database_not_found"), flags: MessageFlags.Ephemeral })
|
||||
@@ -93,7 +94,7 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||
const track_source = track.source === "spotify" ? t(interaction.locale, "player.sources.spotify") : track.source === "youtube" ? t(interaction.locale, "player.sources.youtube") : t(interaction.locale, "player.sources.unknown")
|
||||
return await interaction.followUp(t(interaction.locale, "player.loading_track", { title: track.title, author: track.author, source: track_source }))
|
||||
}
|
||||
catch (error) { console.error(error) }
|
||||
catch (error) { logConsoleError('discord_player', 'play.execution_error', {}, error as Error) }
|
||||
finally { queue.tasksQueue.release() }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user