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:
@@ -1,79 +1,84 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction, GuildMember } from 'discord.js'
|
||||
import { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus, EndBehaviorType } from '@discordjs/voice'
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('parle')
|
||||
.setDescription('Fais moi parler par dessus quelqu\'un de chiant dans le vocal')
|
||||
.addUserOption(option => option.setName('user').setDescription('La personne en question').setRequired(true)),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
if (interaction.user.id !== '223831938346123275') return await interaction.reply({ content: 'Tu n\'as pas le droit d\'utiliser cette commande !', ephemeral: true })
|
||||
|
||||
let user = interaction.options.getUser('user')
|
||||
if (!user) return
|
||||
let guild = interaction.guild
|
||||
if (!guild) return
|
||||
let member = guild.members.cache.get(user.id) as GuildMember
|
||||
if (!member) return
|
||||
let caller = interaction.member as GuildMember
|
||||
if (!caller) return
|
||||
|
||||
if (!caller.voice.channel) return await interaction.reply({ content: 'You must be in a voice channel to use this command.', ephemeral: true })
|
||||
if (!member.voice.channel) return await interaction.reply({ content: 'The member must be in a voice channel to use this command.', ephemeral: true })
|
||||
if (caller.voice.channelId !== member.voice.channelId) return await interaction.reply({ content: 'You must be in the same voice channel than the member to use this command.', ephemeral: true })
|
||||
|
||||
await interaction.reply({ content: 'Je vais parler par dessus cette personne !', ephemeral: true })
|
||||
|
||||
/*
|
||||
// Searches for audio files uploaded in the channel
|
||||
let messages = await interaction.channel.messages.fetch({ limit: 10, cache: false })
|
||||
messages = messages.filter(m => m.attachments.size > 0)
|
||||
|
||||
let files = []
|
||||
await messages.forEach(m => m.attachments.forEach(a => {
|
||||
if (a.contentType === 'audio/mpeg') files.push(a)
|
||||
}))
|
||||
if (files.size === 0) return await interaction.editReply({ content: 'Aucun fichier audio trouvé dans ce channel.', ephemeral: true })
|
||||
|
||||
// Limit the number of files to the last 10
|
||||
//files = files.sort((a, b) => b.createdTimestamp - a.createdTimestamp).first(10)
|
||||
|
||||
// Ask the user to choose a file
|
||||
let file = await interaction.channel.send({ content: 'Choisissez un fichier audio :', files: files })
|
||||
let filter = m => m.author.id === interaction.user.id && !isNaN(m.content) && parseInt(m.content) > 0 && parseInt(m.content) <= files.size
|
||||
let response = await interaction.channel.awaitMessages({ filter, max: 1, time: 30000, errors: ['time'] })
|
||||
file = files.get(files.keyArray()[response.first().content - 1])
|
||||
*/
|
||||
|
||||
let playing = false
|
||||
let player = createAudioPlayer()
|
||||
player.on(AudioPlayerStatus.Idle, () => { playing = false })
|
||||
|
||||
let connection = joinVoiceChannel({
|
||||
channelId: caller.voice.channelId as string,
|
||||
guildId: interaction.guildId as string,
|
||||
adapterCreator: guild.voiceAdapterCreator,
|
||||
selfDeaf: false
|
||||
})
|
||||
connection.subscribe(player)
|
||||
|
||||
let stream = connection.receiver.subscribe(user.id, { end: { behavior: EndBehaviorType.Manual } })
|
||||
stream.on('data', () => {
|
||||
if (!user) return
|
||||
if (connection.receiver.speaking.users.has(user.id) && !playing) {
|
||||
playing = true
|
||||
let resource = createAudioResource('../../static/parle.mp3', { inlineVolume: true })
|
||||
//let resource = createAudioResource(file.attachments.first().url, { inlineVolume: true })
|
||||
if (resource.volume) resource.volume.setVolume(0.2)
|
||||
player.play(resource)
|
||||
}
|
||||
})
|
||||
|
||||
interaction.client.on('voiceStateUpdate', (oldState, newState) => {
|
||||
if (oldState.id === member.id && newState.channelId !== caller.voice.channelId) {
|
||||
stream.destroy()
|
||||
connection.disconnect()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
import { SlashCommandBuilder, MessageFlags } from "discord.js"
|
||||
import type { ChatInputCommandInteraction, GuildMember } from "discord.js"
|
||||
import { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus, EndBehaviorType } from "@discordjs/voice"
|
||||
import { t } from "@/utils/i18n"
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName("speak")
|
||||
.setDescription("Make me talk over someone annoying in voice chat")
|
||||
.setNameLocalizations({ fr: "parle" })
|
||||
.setDescriptionLocalizations({ fr: "Fais moi parler par dessus quelqu'un d'ennuyant dans le vocal" })
|
||||
.addUserOption(option => option
|
||||
.setName("user")
|
||||
.setDescription("The person in question")
|
||||
.setNameLocalizations({ fr: "utilisateur" })
|
||||
.setDescriptionLocalizations({ fr: "La personne en question" })
|
||||
.setRequired(true)
|
||||
)
|
||||
|
||||
export async function execute(interaction: ChatInputCommandInteraction) {
|
||||
const guild = interaction.guild
|
||||
if (!guild) return
|
||||
|
||||
const user = interaction.options.getUser("user", true)
|
||||
const member = await guild.members.fetch(user.id)
|
||||
const caller = interaction.member as GuildMember
|
||||
|
||||
if (!caller.voice.channel) return interaction.reply({ content: t(interaction.locale, "salonpostam.parle.not_in_voice"), flags: MessageFlags.Ephemeral })
|
||||
if (!member.voice.channel) return interaction.reply({ content: t(interaction.locale, "salonpostam.parle.member_not_in_voice"), flags: MessageFlags.Ephemeral })
|
||||
if (caller.voice.channelId !== member.voice.channelId) return interaction.reply({ content: t(interaction.locale, "salonpostam.parle.not_same_channel"), flags: MessageFlags.Ephemeral })
|
||||
|
||||
await interaction.reply({ content: t(interaction.locale, "salonpostam.parle.will_speak_over"), flags: MessageFlags.Ephemeral })
|
||||
|
||||
/*
|
||||
// Searches for audio files uploaded in the channel
|
||||
const messages = await interaction.channel.messages.fetch({ limit: 10, cache: false }).filter(m => m.attachments.size > 0)
|
||||
|
||||
const files = []
|
||||
await messages.forEach(m => m.attachments.forEach(a => {
|
||||
if (a.contentType === 'audio/mpeg') files.push(a)
|
||||
}))
|
||||
if (files.size === 0) return interaction.editReply({ content: t(interaction.locale, "player.no_audio_found"), flags: MessageFlags.Ephemeral })
|
||||
|
||||
// Limit the number of files to the last 10
|
||||
//files = files.sort((a, b) => b.createdTimestamp - a.createdTimestamp).first(10)
|
||||
|
||||
// Ask the user to choose a file
|
||||
let file = await interaction.channel.send({ content: 'Choisissez un fichier audio :', files })
|
||||
const filter = m => m.author.id === interaction.user.id && !isNaN(m.content) && parseInt(m.content) > 0 && parseInt(m.content) <= files.size
|
||||
const response = await interaction.channel.awaitMessages({ filter, max: 1, time: 30000, errors: ['time'] })
|
||||
file = files.get(files.keyArray()[response.first().content - 1])
|
||||
*/
|
||||
|
||||
let playing = false
|
||||
const player = createAudioPlayer()
|
||||
player.on(AudioPlayerStatus.Idle, () => { playing = false })
|
||||
|
||||
const connection = joinVoiceChannel({
|
||||
channelId: caller.voice.channelId ?? "",
|
||||
guildId: interaction.guildId ?? "",
|
||||
adapterCreator: guild.voiceAdapterCreator,
|
||||
selfDeaf: false
|
||||
})
|
||||
connection.subscribe(player)
|
||||
|
||||
const stream = connection.receiver.subscribe(user.id, {
|
||||
end: { behavior: EndBehaviorType.Manual }
|
||||
})
|
||||
stream.on("data", () => {
|
||||
if (connection.receiver.speaking.users.has(user.id) && !playing) {
|
||||
playing = true
|
||||
const resource = createAudioResource("@/static/parle.mp3", { inlineVolume: true })
|
||||
//const resource = createAudioResource(file.attachments.first().url, { inlineVolume: true })
|
||||
if (resource.volume) resource.volume.setVolume(0.2)
|
||||
player.play(resource)
|
||||
}
|
||||
})
|
||||
|
||||
interaction.client.on("voiceStateUpdate", (oldState, newState) => {
|
||||
if (oldState.id === member.id && newState.channelId !== caller.voice.channelId ) {
|
||||
stream.destroy()
|
||||
connection.disconnect()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user