Intégration MongoDB + Fix export et amp
This commit is contained in:
@@ -1,198 +1,200 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction, AutocompleteInteraction, EmbedBuilder, inlineCode } from 'discord.js'
|
||||
import * as AMP from '../../utils/amp'
|
||||
import 'dotenv/config'
|
||||
|
||||
interface ListInstancesResult {
|
||||
status: string
|
||||
data: {
|
||||
result: [
|
||||
Host: {
|
||||
AvailableInstances: any[]
|
||||
FriendlyName: string
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
interface InstanceFields {
|
||||
name: string
|
||||
value: string
|
||||
inline: boolean
|
||||
}
|
||||
|
||||
interface failData {
|
||||
Title: string
|
||||
Message: string
|
||||
}
|
||||
interface errorData {
|
||||
error_code: string
|
||||
}
|
||||
|
||||
function failMsg(data: any) { return `La commande a échouée !\n${inlineCode(`${data.Title}: ${data.Message}`)}` }
|
||||
function errorMsg(data: any) { return `Y'a eu une erreur !\n${inlineCode(`${data.error_code}`)}` }
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder().setName('amp').setDescription('Accède à mon panel de jeu AMP !')
|
||||
.addSubcommand(subcommand => subcommand.setName('login').setDescription("Connectez-vous avant d'effectuer une autre commande !")
|
||||
.addStringOption(option => option.setName('username').setDescription("Nom d'Utilisateur").setRequired(true))
|
||||
.addStringOption(option => option.setName('password').setDescription('Mot de Passe').setRequired(true))
|
||||
.addBooleanOption(option => option.setName('remember').setDescription('Mémoriser les identifiants').setRequired(true))
|
||||
.addStringOption(option => option.setName('otp').setDescription('Code de double authentification')))
|
||||
|
||||
.addSubcommandGroup(subcommandgroup => subcommandgroup.setName('instances').setDescription('Intéragir avec les instances AMP.')
|
||||
.addSubcommand(subcommand => subcommand.setName('list').setDescription('Liste toutes les instances disponibles.'))
|
||||
|
||||
.addSubcommand(subcommand => subcommand.setName('manage').setDescription('Gérer une instance.')
|
||||
.addStringOption(option => option.setName('instance').setDescription("Nom de l'instance").setRequired(true).setAutocomplete(true)))
|
||||
|
||||
/*.addSubcommand(subcommand => subcommand.setName('restart').setDescription('Redémarre une instance.')
|
||||
.addStringOption(option => option.setName('name').setDescription("Nom de l'instance").setRequired(true)))*/),
|
||||
|
||||
async autocompleteRun(interaction: AutocompleteInteraction) {
|
||||
let query = interaction.options.getString('instance', true)
|
||||
|
||||
// Check if the SessionID is still valid
|
||||
//let sessionID = dotenv.config().parsed.AMP_SESSIONID
|
||||
let sessionID = process.env.AMP_SESSIONID as string
|
||||
let session = await AMP.CheckSession(sessionID)
|
||||
if (session.status === 'fail') {
|
||||
if (process.env.AMP_REMEMBER_TOKEN) {
|
||||
// Refresh the SessionID if the RememberMeToken is available
|
||||
let details = {
|
||||
username: process.env.AMP_USERNAME,
|
||||
password: '',
|
||||
token: process.env.AMP_REMEMBER_TOKEN,
|
||||
rememberMe: true
|
||||
}
|
||||
let result = await AMP.Core.Login(details)
|
||||
console.log(result)
|
||||
if (result.status === 'success') sessionID = result.data.sessionID
|
||||
else if (result.status === 'fail') return interaction.respond([])
|
||||
else if (result.status === 'error') return interaction.respond([])
|
||||
}
|
||||
else {
|
||||
// If no RememberMeToken is available, ask to login
|
||||
//return await interaction.followUp(`Tu dois te connecter avant d'effectuer une autre commande !`)
|
||||
return await interaction.respond([])
|
||||
}
|
||||
}
|
||||
else if (session.status === 'error') return interaction.respond([])
|
||||
|
||||
let choices: any = []
|
||||
let result = await AMP.ADSModule.GetInstances(sessionID)
|
||||
if (result.status === 'success') {
|
||||
let hosts = result.data.result as any[]
|
||||
hosts.forEach(host => {
|
||||
let instances = host.AvailableInstances as any[]
|
||||
instances.forEach(instance => {
|
||||
if (instance.FriendlyName.includes(query)) choices.push({ name: `${host.FriendlyName} - ${instance.FriendlyName}`, value: instance.InstanceID })
|
||||
})
|
||||
})
|
||||
}
|
||||
else if (result.status === 'fail') return interaction.respond([])
|
||||
else if (result.status === 'error') return interaction.respond([])
|
||||
|
||||
return interaction.respond(choices)
|
||||
},
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
// Let the user login
|
||||
if (interaction.options.getSubcommand() == 'login') {
|
||||
// Get a SessionID and a RememberMeToken if wanted
|
||||
await interaction.deferReply({ ephemeral: true })
|
||||
|
||||
let details = {
|
||||
username: interaction.options.getString('username'),
|
||||
password: interaction.options.getString('password'),
|
||||
token: interaction.options.getString('otp') || '',
|
||||
rememberMe: interaction.options.getBoolean('remember')
|
||||
}
|
||||
|
||||
let result = await AMP.Core.Login(details)
|
||||
if (result.status === 'success') return await interaction.followUp(`Tu es connecté au panel sous **${result.data.userInfo.Username}** !`)
|
||||
else if (result.status === 'fail') return await interaction.followUp(failMsg(result.data))
|
||||
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data))
|
||||
}
|
||||
await interaction.deferReply()
|
||||
|
||||
// Check if the SessionID is still valid
|
||||
//let sessionID = dotenv.config().parsed.AMP_SESSIONID
|
||||
let sessionID = process.env.AMP_SESSIONID as string
|
||||
let session = await AMP.CheckSession(sessionID)
|
||||
|
||||
if (session.status === 'fail') {
|
||||
console.log(session)
|
||||
if (process.env.AMP_REMEMBER_TOKEN) {
|
||||
// Refresh the SessionID if the RememberMeToken is available
|
||||
let details = {
|
||||
username: process.env.AMP_USERNAME,
|
||||
password: '',
|
||||
token: process.env.AMP_REMEMBER_TOKEN,
|
||||
rememberMe: true
|
||||
}
|
||||
let result = await AMP.Core.Login(details)
|
||||
console.log(result)
|
||||
if (result.status === 'success') sessionID = result.data.sessionID
|
||||
else if (result.status === 'fail') return await interaction.followUp(failMsg(result.data))
|
||||
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data))
|
||||
}
|
||||
else {
|
||||
// If no RememberMeToken is available, ask to login
|
||||
return await interaction.followUp(`Tu dois te connecter avant d'effectuer une autre commande !`)
|
||||
}
|
||||
}
|
||||
else if (session.status === 'error') return await interaction.followUp(errorMsg(session.data))
|
||||
|
||||
if (interaction.options.getSubcommandGroup() == 'instances') {
|
||||
if (interaction.options.getSubcommand() == 'list') {
|
||||
let result = await AMP.ADSModule.GetInstances(sessionID) as ListInstancesResult
|
||||
|
||||
if (result.status === 'success') {
|
||||
await interaction.followUp({ content: `${result.data.result.length} hôtes trouvés !` })
|
||||
result.data.result.forEach(async host => {
|
||||
let fields = [] as InstanceFields[]
|
||||
host.AvailableInstances.forEach(instance => {
|
||||
fields.push({
|
||||
name: instance.FriendlyName,
|
||||
value: `**Running:** ${instance.Running}\n**Port:** ${instance.Port}\n**Module:** ${instance.Module}`,
|
||||
inline: true
|
||||
})
|
||||
})
|
||||
let embed = new EmbedBuilder()
|
||||
.setTitle(host.FriendlyName)
|
||||
.setDescription(`Liste des ${host.AvailableInstances.length} instances :`)
|
||||
.setColor(interaction.guild?.members.me?.displayColor || '#ffc370')
|
||||
.setTimestamp()
|
||||
.setFields(fields)
|
||||
return await interaction.channel?.send({ embeds: [embed] })
|
||||
})
|
||||
}
|
||||
else if (result.status === 'fail') return await interaction.followUp(failMsg(result.data))
|
||||
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data))
|
||||
}
|
||||
else if (interaction.options.getSubcommand() == 'manage') {
|
||||
let instanceID = interaction.options.getString('instance', true)
|
||||
let result = await AMP.ADSModule.ManageInstance(sessionID, instanceID)
|
||||
|
||||
if (result.status === 'success') {
|
||||
let server = await AMP.ADSModule.Servers(sessionID, instanceID)
|
||||
console.log(server)
|
||||
|
||||
if (server.status === 'success') return await interaction.followUp(`Ok !`)
|
||||
else if (server.status === 'fail') return await interaction.followUp(failMsg(server.data))
|
||||
else if (server.status === 'error') return await interaction.followUp(errorMsg(server.data))
|
||||
}
|
||||
else if (result.status === 'fail') return await interaction.followUp(failMsg(result.data))
|
||||
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data))
|
||||
}
|
||||
else if (interaction.options.getSubcommand() == 'restart') {
|
||||
let query = interaction.options.getString('name')
|
||||
if (!query) return
|
||||
|
||||
let result = await AMP.ADSModule.RestartInstance(sessionID, query)
|
||||
|
||||
if (result.status === 'success') return await interaction.followUp(`Ok !`)
|
||||
else if (result.status === 'fail') return await interaction.followUp(failMsg(result.data))
|
||||
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data))
|
||||
}
|
||||
}
|
||||
}
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction, AutocompleteInteraction, EmbedBuilder, inlineCode } from 'discord.js'
|
||||
import * as AMP from '../../utils/amp'
|
||||
import dbGuild from '../../schemas/guild'
|
||||
|
||||
interface ListInstancesResult {
|
||||
status: string
|
||||
data: [
|
||||
Host: {
|
||||
AvailableInstances: any[]
|
||||
FriendlyName: string
|
||||
}
|
||||
]
|
||||
}
|
||||
interface InstanceFields {
|
||||
name: string
|
||||
value: string
|
||||
inline: boolean
|
||||
}
|
||||
|
||||
interface failData {
|
||||
Title: string
|
||||
Message: string
|
||||
}
|
||||
interface errorData {
|
||||
error_code: string
|
||||
}
|
||||
|
||||
function failMsg(data: any) { return `La commande a échouée !\n${inlineCode(`${data.Title}: ${data.Message}`)}` }
|
||||
function errorMsg(data: any) { return `Y'a eu une erreur !\n${inlineCode(`${data.error_code}`)}` }
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder().setName('amp').setDescription('Accède à mon panel de jeu AMP !')
|
||||
.addSubcommand(subcommand => subcommand.setName('login').setDescription("Connectez-vous avant d'effectuer une autre commande !")
|
||||
.addStringOption(option => option.setName('username').setDescription("Nom d'Utilisateur").setRequired(true))
|
||||
.addStringOption(option => option.setName('password').setDescription('Mot de Passe').setRequired(true))
|
||||
.addBooleanOption(option => option.setName('remember').setDescription('Mémoriser les identifiants').setRequired(true))
|
||||
.addStringOption(option => option.setName('otp').setDescription('Code de double authentification')))
|
||||
.addSubcommandGroup(subcommandgroup => subcommandgroup.setName('instances').setDescription('Intéragir avec les instances AMP.')
|
||||
.addSubcommand(subcommand => subcommand.setName('list').setDescription('Liste toutes les instances disponibles.'))
|
||||
.addSubcommand(subcommand => subcommand.setName('manage').setDescription('Gérer une instance.')
|
||||
.addStringOption(option => option.setName('instance').setDescription("Nom de l'instance").setRequired(true).setAutocomplete(true)))
|
||||
.addSubcommand(subcommand => subcommand.setName('restart').setDescription('Redémarre une instance.')
|
||||
.addStringOption(option => option.setName('name').setDescription("Nom de l'instance").setRequired(true)))
|
||||
),
|
||||
async autocompleteRun(interaction: AutocompleteInteraction) {
|
||||
let query = interaction.options.getString('instance', true)
|
||||
|
||||
let guildProfile = await dbGuild.findOne({ guildId: interaction?.guild?.id })
|
||||
if (!guildProfile) return await interaction.respond([])
|
||||
|
||||
let dbData = guildProfile.get('guildAmp')
|
||||
if (!dbData?.enabled) return await interaction.respond([])
|
||||
|
||||
let host = dbData.host as string
|
||||
let username = dbData.username as string
|
||||
let sessionID = dbData.sessionID as string
|
||||
let rememberMeToken = dbData.rememberMeToken as string
|
||||
|
||||
// Check if the SessionID is still valid
|
||||
let session = await AMP.CheckSession(host, sessionID)
|
||||
if (session.status === 'fail') {
|
||||
if (rememberMeToken) {
|
||||
// Refresh the SessionID if the RememberMeToken is available
|
||||
let details = { username, password: '', token: rememberMeToken, rememberMe: true }
|
||||
let result = await AMP.Core.Login(host, details)
|
||||
|
||||
if (result.status === 'success') sessionID = result.data.sessionID
|
||||
else if (result.status === 'fail') return interaction.respond([])
|
||||
else if (result.status === 'error') return interaction.respond([])
|
||||
} else return await interaction.respond([])
|
||||
}
|
||||
else if (session.status === 'error') return interaction.respond([])
|
||||
|
||||
let choices: any = []
|
||||
let result = await AMP.ADSModule.GetInstances(host, sessionID)
|
||||
if (result.status === 'success') {
|
||||
let hosts = result.data.result as any[]
|
||||
hosts.forEach(host => {
|
||||
let instances = host.AvailableInstances as any[]
|
||||
instances.forEach(instance => {
|
||||
if (instance.FriendlyName.includes(query)) choices.push({ name: `${host.FriendlyName} - ${instance.FriendlyName}`, value: instance.InstanceID })
|
||||
})
|
||||
})
|
||||
}
|
||||
else if (result.status === 'fail') return interaction.respond([])
|
||||
else if (result.status === 'error') return interaction.respond([])
|
||||
|
||||
return interaction.respond(choices)
|
||||
},
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let guildProfile = await dbGuild.findOne({ guildId: interaction?.guild?.id })
|
||||
if (!guildProfile) return interaction.reply({ content: `Database data for **${interaction.guild?.name}** does not exist, please initialize with \`/database init\` !` })
|
||||
|
||||
let dbData = guildProfile.get('guildAmp')
|
||||
if (!dbData?.enabled) return interaction.reply({ content: `AMP module is disabled for **${interaction.guild?.name}**, please activate with \`/database edit guildAmp.enabled True\` !` })
|
||||
|
||||
let host = dbData.host as string
|
||||
let username = dbData.username as string
|
||||
let sessionID = dbData.sessionID as string
|
||||
let rememberMeToken = dbData.rememberMeToken as string
|
||||
|
||||
// Let the user login
|
||||
if (interaction.options.getSubcommand() == 'login') {
|
||||
// Get a SessionID and a RememberMeToken if wanted
|
||||
await interaction.deferReply({ ephemeral: true })
|
||||
|
||||
let details = {
|
||||
username: interaction.options.getString('username'),
|
||||
password: interaction.options.getString('password'),
|
||||
token: interaction.options.getString('otp') || '',
|
||||
rememberMe: interaction.options.getBoolean('remember')
|
||||
}
|
||||
|
||||
let result = await AMP.Core.Login(host, details)
|
||||
if (result.status === 'success') {
|
||||
username = dbData['username'] = result.data.userInfo.Username
|
||||
sessionID = dbData['sessionID'] = result.data.sessionID
|
||||
rememberMeToken = dbData['rememberMeToken'] = result.data.rememberMeToken
|
||||
|
||||
guildProfile.set('guildAmp', dbData)
|
||||
guildProfile.markModified('guildAmp')
|
||||
await guildProfile.save().catch(console.error)
|
||||
|
||||
return await interaction.followUp(`Tu es connecté au panel sous **${username}** !`)
|
||||
}
|
||||
else if (result.status === 'fail') return await interaction.followUp(failMsg(result.data))
|
||||
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data))
|
||||
}
|
||||
await interaction.deferReply()
|
||||
|
||||
// Check if the SessionID is still valid
|
||||
let session = await AMP.CheckSession(host, sessionID)
|
||||
if (session.status === 'fail') {
|
||||
if (rememberMeToken) {
|
||||
// Refresh the SessionID if the RememberMeToken is available
|
||||
let details = { username, password: '', token: rememberMeToken, rememberMe: true }
|
||||
let result = await AMP.Core.Login(host, details)
|
||||
|
||||
if (result.status === 'success') sessionID = result.data.sessionID
|
||||
else if (result.status === 'fail') return await interaction.followUp(failMsg(result.data))
|
||||
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data))
|
||||
}
|
||||
else return await interaction.followUp(`Tu dois te connecter avant d'effectuer une autre commande !`)
|
||||
}
|
||||
else if (session.status === 'error') return await interaction.followUp(errorMsg(session.data))
|
||||
|
||||
if (interaction.options.getSubcommandGroup() == 'instances') {
|
||||
if (interaction.options.getSubcommand() == 'list') {
|
||||
let result = await AMP.ADSModule.GetInstances(host, sessionID) as ListInstancesResult
|
||||
|
||||
if (result.status === 'success') {
|
||||
await interaction.followUp({ content: `${result.data.length} hôte(s) trouvé(s) !` })
|
||||
result.data.forEach(async host => {
|
||||
let fields = [] as InstanceFields[]
|
||||
host.AvailableInstances.forEach(instance => {
|
||||
fields.push({
|
||||
name: instance.FriendlyName,
|
||||
value: `**Running:** ${instance.Running}\n**Port:** ${instance.Port}\n**Module:** ${instance.Module}`,
|
||||
inline: true
|
||||
})
|
||||
})
|
||||
let embed = new EmbedBuilder()
|
||||
.setTitle(host.FriendlyName)
|
||||
.setDescription(`Liste des ${host.AvailableInstances.length} instances :`)
|
||||
.setColor(interaction.guild?.members.me?.displayColor || '#ffc370')
|
||||
.setTimestamp()
|
||||
.setFields(fields)
|
||||
return await interaction.channel?.send({ embeds: [embed] })
|
||||
})
|
||||
}
|
||||
else if (result.status === 'fail') return await interaction.followUp(failMsg(result.data))
|
||||
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data))
|
||||
}
|
||||
else if (interaction.options.getSubcommand() == 'manage') {
|
||||
let instanceID = interaction.options.getString('instance', true)
|
||||
let result = await AMP.ADSModule.ManageInstance(host, sessionID, instanceID)
|
||||
|
||||
if (result.status === 'success') {
|
||||
let server = await AMP.ADSModule.Servers(host, sessionID, instanceID)
|
||||
|
||||
if (server.status === 'success') return await interaction.followUp(`Ok !`)
|
||||
else if (server.status === 'fail') return await interaction.followUp(failMsg(server.data))
|
||||
else if (server.status === 'error') return await interaction.followUp(errorMsg(server.data))
|
||||
}
|
||||
else if (result.status === 'fail') return await interaction.followUp(failMsg(result.data))
|
||||
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data))
|
||||
}
|
||||
else if (interaction.options.getSubcommand() == 'restart') {
|
||||
let query = interaction.options.getString('name')
|
||||
if (!query) return
|
||||
|
||||
let result = await AMP.ADSModule.RestartInstance(host, sessionID, query)
|
||||
|
||||
if (result.status === 'success') return await interaction.followUp(`Ok !`)
|
||||
else if (result.status === 'fail') return await interaction.followUp(failMsg(result.data))
|
||||
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +1,58 @@
|
||||
import { SlashCommandBuilder, EmbedBuilder, ChatInputCommandInteraction, MessageReaction, User }from 'discord.js'
|
||||
import * as crack from '../../utils/crack'
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder().setName('crack').setDescription('Télécharge un crack sur le site online-fix.me !')
|
||||
.addStringOption(option => option.setName('jeu').setDescription('Quel jeu tu veux DL ?').setRequired(true)),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
await interaction.deferReply()
|
||||
|
||||
let query = interaction.options.getString('jeu')
|
||||
if (!query) return
|
||||
|
||||
let games = await crack.search(query) as crack.Game[]
|
||||
if (!Array.isArray(games)) {
|
||||
//if (games.toString() == "TypeError: Cannot read properties of undefined (reading 'split')") return interaction.followUp({ content: `J'ai rien trouvé pour "${query}" !` })
|
||||
//else return interaction.followUp({ content: "Une erreur s'est produite ! ```" + games + "```" })
|
||||
return interaction.followUp({ content: `J'ai rien trouvé pour "${query}" !` })
|
||||
}
|
||||
|
||||
let game = {} as crack.Game
|
||||
if (games.length > 1) {
|
||||
games = games.slice(0, 9)
|
||||
let list = ''
|
||||
for (let i = 0; i < games.length; i++) list += `\n${i + 1}. ${games[i].name} (${games[i].link})`
|
||||
let message = await interaction.followUp({ content: `J'ai trouvé plusieurs jeux pour "${query}" ! ${list}` })
|
||||
|
||||
let emojis = ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣', '9️⃣']
|
||||
for (let i = 0; i < games.length; i++) await message.react(emojis[i])
|
||||
|
||||
// Wait for a reaction to be added by the interaction author.
|
||||
const filter: any = (reaction: MessageReaction, user: User) => { if (reaction.emoji.name) return emojis.includes(reaction.emoji.name) && user.id === interaction.user.id }
|
||||
await message.awaitReactions({ filter, max: 1, time: 5000, errors: ['time'] }).then(collected => {
|
||||
console.log(collected)
|
||||
if (!collected.first) return
|
||||
let reaction = collected.first()
|
||||
let index = emojis.indexOf(reaction?.emoji.name ?? '')
|
||||
game = games[index]
|
||||
}).catch(() => { return interaction.followUp({ content: 'T\'as mis trop de temps à choisir !' }) })
|
||||
}
|
||||
else game = games[0]
|
||||
|
||||
let url = await crack.repo(game)
|
||||
if (!url) return
|
||||
let file = await crack.torrent(url)
|
||||
if (!file) return
|
||||
let filePath = await crack.download(url, file)
|
||||
if (!filePath) return
|
||||
let link = await crack.magnet(filePath)
|
||||
|
||||
let embed = new EmbedBuilder()
|
||||
.setColor('#ffc370')
|
||||
.setTitle(game.name)
|
||||
.setURL(game.link)
|
||||
.setDescription(`Voici ce que j'ai trouvé pour "${query}".\nTu peux aussi cliquer sur [ce lien](https://angels-dev.fr/magnet/${link}) pour pouvoir télécharger le jeu direct !`)
|
||||
|
||||
await interaction.followUp({ embeds: [embed], files: [filePath] })
|
||||
}
|
||||
import { SlashCommandBuilder, EmbedBuilder, ChatInputCommandInteraction, MessageReaction, User }from 'discord.js'
|
||||
import * as crack from '../../utils/crack'
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder().setName('crack').setDescription('Télécharge un crack sur le site online-fix.me !')
|
||||
.addStringOption(option => option.setName('jeu').setDescription('Quel jeu tu veux DL ?').setRequired(true)),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
await interaction.deferReply()
|
||||
|
||||
let query = interaction.options.getString('jeu')
|
||||
if (!query) return
|
||||
|
||||
let games = await crack.search(query) as crack.Game[]
|
||||
if (!Array.isArray(games)) {
|
||||
//if (games.toString() == "TypeError: Cannot read properties of undefined (reading 'split')") return interaction.followUp({ content: `J'ai rien trouvé pour "${query}" !` })
|
||||
//else return interaction.followUp({ content: "Une erreur s'est produite ! ```" + games + "```" })
|
||||
return interaction.followUp({ content: `J'ai rien trouvé pour "${query}" !` })
|
||||
}
|
||||
|
||||
let game = {} as crack.Game
|
||||
if (games.length > 1) {
|
||||
games = games.slice(0, 9)
|
||||
let list = ''
|
||||
for (let i = 0; i < games.length; i++) list += `\n${i + 1}. ${games[i].name} (${games[i].link})`
|
||||
let message = await interaction.followUp({ content: `J'ai trouvé plusieurs jeux pour "${query}" ! ${list}` })
|
||||
|
||||
let emojis = ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣', '9️⃣']
|
||||
for (let i = 0; i < games.length; i++) await message.react(emojis[i])
|
||||
|
||||
// Wait for a reaction to be added by the interaction author.
|
||||
const filter: any = (reaction: MessageReaction, user: User) => { if (reaction.emoji.name) return emojis.includes(reaction.emoji.name) && user.id === interaction.user.id }
|
||||
await message.awaitReactions({ filter, max: 1, time: 5000, errors: ['time'] }).then(collected => {
|
||||
console.log(collected)
|
||||
if (!collected.first) return
|
||||
let reaction = collected.first()
|
||||
let index = emojis.indexOf(reaction?.emoji.name ?? '')
|
||||
game = games[index]
|
||||
}).catch(() => { return interaction.followUp({ content: 'T\'as mis trop de temps à choisir !' }) })
|
||||
}
|
||||
else game = games[0]
|
||||
|
||||
let url = await crack.repo(game)
|
||||
if (!url) return
|
||||
let file = await crack.torrent(url)
|
||||
if (!file) return
|
||||
let filePath = await crack.download(url, file)
|
||||
if (!filePath) return
|
||||
let link = await crack.magnet(filePath)
|
||||
|
||||
let embed = new EmbedBuilder()
|
||||
.setColor('#ffc370')
|
||||
.setTitle(game.name)
|
||||
.setURL(game.link)
|
||||
.setDescription(`Voici ce que j'ai trouvé pour "${query}".\nTu peux aussi cliquer sur [ce lien](https://angels-dev.fr/magnet/${link}) pour pouvoir télécharger le jeu direct !`)
|
||||
|
||||
await interaction.followUp({ embeds: [embed], files: [filePath] })
|
||||
}
|
||||
}
|
||||
73
src/commands/global/database.ts
Executable file
73
src/commands/global/database.ts
Executable file
@@ -0,0 +1,73 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction, EmbedBuilder, APIEmbedField } from 'discord.js'
|
||||
|
||||
import dbGuildInit from '../../utils/dbGuildInit'
|
||||
import dbGuild from '../../schemas/guild'
|
||||
|
||||
const parseObject = (obj: any, prefix = ''): { name: string, value: any }[] => {
|
||||
let fields: { name: string, value: any }[] = []
|
||||
|
||||
for (let [key, value] of Object.entries(obj)) {
|
||||
if (typeof value === 'object') fields.push(...parseObject(value, `${prefix}${key}.`))
|
||||
else {
|
||||
if (typeof value === 'boolean') value = value ? 'True' : 'False'
|
||||
else if (!value) value = 'None'
|
||||
else value = value.toString()
|
||||
|
||||
fields.push({ name: `${prefix}${key}`, value })
|
||||
}
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('database')
|
||||
.setDescription('Communicate with the database')
|
||||
.addSubcommand(subcommand => subcommand.setName('info').setDescription('Returns information about the current guild'))
|
||||
.addSubcommand(subcommand => subcommand.setName('init').setDescription('Force initialize an entry for the current guild in the database'))
|
||||
.addSubcommand(subcommand => subcommand.setName('edit').setDescription('Modify parameters for the current guild')
|
||||
.addStringOption(option => option.setName('key').setDescription('Key to modify').setRequired(true))
|
||||
.addStringOption(option => option.setName('value').setDescription('Value to set').setRequired(true))),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let guild = interaction.guild
|
||||
if (!guild) return await interaction.reply({ content: 'This command must be used in a server.', ephemeral: true })
|
||||
|
||||
let guildProfile = await dbGuild.findOne({ guildId: guild.id })
|
||||
|
||||
if (interaction.options.getSubcommand() === 'info') {
|
||||
if (!guildProfile) return await interaction.reply({ content: `Database data for **${guild.name}** does not exist !` })
|
||||
|
||||
let fields = parseObject(guildProfile.toObject())
|
||||
|
||||
let embed = new EmbedBuilder()
|
||||
.setTitle('Database Information')
|
||||
.setDescription(`Guild **${guildProfile.guildName}** (ID: ${guildProfile.guildId})`)
|
||||
.setThumbnail(guildProfile.guildIcon as string)
|
||||
.setTimestamp()
|
||||
.addFields(fields as APIEmbedField[])
|
||||
return await interaction.reply({ embeds: [embed] })
|
||||
|
||||
} else if (interaction.options.getSubcommand() === 'init') {
|
||||
if (guildProfile) return await interaction.reply({ content: `Database data for **${guildProfile.guildName}** already exists !` })
|
||||
|
||||
guildProfile = await dbGuildInit(guild)
|
||||
if (!guildProfile) return await interaction.reply({ content: `An error occured while initializing database data for **${guild.name}** !` })
|
||||
|
||||
return await interaction.reply({ content: `Database data for **${guildProfile.guildName}** successfully initialized !` })
|
||||
|
||||
} else if (interaction.options.getSubcommand() === 'edit') {
|
||||
if (!guildProfile) return await interaction.reply({ content: `Database data for **${guild.name}** does not exist, please init with \`/database init\` !` })
|
||||
|
||||
let key = interaction.options.getString('key', true)
|
||||
let value = interaction.options.getString('value', true)
|
||||
|
||||
let oldValue = guildProfile.get(key)
|
||||
if (!oldValue) oldValue = 'None'
|
||||
|
||||
guildProfile.set(key, value)
|
||||
await guildProfile.save().catch(console.error)
|
||||
|
||||
return await interaction.reply({ content: `Database data for **${guildProfile.guildName}** successfully updated !\n**${key}**: ${oldValue} -> ${value}` })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,34 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction, GuildMember } from 'discord.js'
|
||||
import { getVoiceConnection, joinVoiceChannel } from '@discordjs/voice'
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('papa')
|
||||
.setDescription('Si papa m\'appelle, je le rejoins !'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
if (interaction.user.id !== '223831938346123275') return interaction.reply({ content: 'T\'es pas mon père, dégage !' })
|
||||
|
||||
let guild = interaction.guild
|
||||
if (!guild) return interaction.reply({ content: 'Je ne peux pas rejoindre ton vocal en message privé, papa !' })
|
||||
|
||||
let member = interaction.member as GuildMember
|
||||
|
||||
let botChannel = guild.members.me?.voice.channel
|
||||
let papaChannel = member.voice.channel
|
||||
|
||||
if (!papaChannel && botChannel) {
|
||||
const voiceConnection = getVoiceConnection(guild.id);
|
||||
if (voiceConnection) voiceConnection.destroy()
|
||||
return interaction.reply({ content: 'Je quitte le vocal, papa !' })
|
||||
}
|
||||
else if (papaChannel && (!botChannel || botChannel.id !== papaChannel.id)) {
|
||||
joinVoiceChannel({
|
||||
channelId: papaChannel.id,
|
||||
guildId: papaChannel.guild.id,
|
||||
adapterCreator: papaChannel.guild.voiceAdapterCreator,
|
||||
})
|
||||
return interaction.reply({ content: 'Je rejoins ton vocal, papa !' })
|
||||
}
|
||||
else return interaction.reply({ content: 'Je suis déjà dans ton vocal, papa !' })
|
||||
}
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction, GuildMember } from 'discord.js'
|
||||
import { getVoiceConnection, joinVoiceChannel } from '@discordjs/voice'
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('papa')
|
||||
.setDescription('Si papa m\'appelle, je le rejoins !'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
if (interaction.user.id !== '223831938346123275') return interaction.reply({ content: 'T\'es pas mon père, dégage !' })
|
||||
|
||||
let guild = interaction.guild
|
||||
if (!guild) return interaction.reply({ content: 'Je ne peux pas rejoindre ton vocal en message privé, papa !' })
|
||||
|
||||
let member = interaction.member as GuildMember
|
||||
|
||||
let botChannel = guild.members.me?.voice.channel
|
||||
let papaChannel = member.voice.channel
|
||||
|
||||
if (!papaChannel && botChannel) {
|
||||
const voiceConnection = getVoiceConnection(guild.id);
|
||||
if (voiceConnection) voiceConnection.destroy()
|
||||
return interaction.reply({ content: 'Je quitte le vocal, papa !' })
|
||||
}
|
||||
else if (papaChannel && (!botChannel || botChannel.id !== papaChannel.id)) {
|
||||
joinVoiceChannel({
|
||||
channelId: papaChannel.id,
|
||||
guildId: papaChannel.guild.id,
|
||||
adapterCreator: papaChannel.guild.voiceAdapterCreator,
|
||||
})
|
||||
return interaction.reply({ content: 'Je rejoins ton vocal, papa !' })
|
||||
}
|
||||
else return interaction.reply({ content: 'Je suis déjà dans ton vocal, papa !' })
|
||||
}
|
||||
}
|
||||
@@ -1,79 +1,79 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction, GuildMember } from 'discord.js'
|
||||
import { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus, EndBehaviorType } from '@discordjs/voice'
|
||||
|
||||
module.exports = {
|
||||
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', (chunk) => {
|
||||
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, 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', (chunk) => {
|
||||
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()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('ping')
|
||||
.setDescription('Check the latency of the bot'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let sent = await interaction.reply({ content: 'Pinging...', fetchReply: true })
|
||||
interaction.editReply(`Websocket heartbeat: ${interaction.client.ws.ping}ms.\nRoundtrip latency: ${sent.createdTimestamp - interaction.createdTimestamp}ms`)
|
||||
}
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('ping')
|
||||
.setDescription('Check the latency of the bot'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let sent = await interaction.reply({ content: 'Pinging...', fetchReply: true })
|
||||
interaction.editReply(`Websocket heartbeat: ${interaction.client.ws.ping}ms.\nRoundtrip latency: ${sent.createdTimestamp - interaction.createdTimestamp}ms`)
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,29 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('spam')
|
||||
.setDescription('Spam')
|
||||
.addUserOption(option => option.setName('user').setDescription('Spam').setRequired(true))
|
||||
.addStringOption(option => option.setName('string').setDescription('Spam').setRequired(true))
|
||||
.addIntegerOption(option => option.setName('integer').setDescription('Spam').setRequired(true)),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let user = interaction.options.getUser('user')
|
||||
let string = interaction.options.getString('string')
|
||||
let integer = interaction.options.getInteger('integer')
|
||||
|
||||
await interaction.reply({ content: 'Spam', ephemeral: true })
|
||||
let i = 0
|
||||
function myLoop() {
|
||||
setTimeout(function () {
|
||||
if (!user) return
|
||||
if (!string) return
|
||||
if (!integer) return
|
||||
user.send(string).catch(error => console.error(error))
|
||||
i++
|
||||
if (i < integer) myLoop()
|
||||
}, 1000)
|
||||
}
|
||||
myLoop()
|
||||
}
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('spam')
|
||||
.setDescription('Spam')
|
||||
.addUserOption(option => option.setName('user').setDescription('Spam').setRequired(true))
|
||||
.addStringOption(option => option.setName('string').setDescription('Spam').setRequired(true))
|
||||
.addIntegerOption(option => option.setName('integer').setDescription('Spam').setRequired(true)),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let user = interaction.options.getUser('user')
|
||||
let string = interaction.options.getString('string')
|
||||
let integer = interaction.options.getInteger('integer')
|
||||
|
||||
await interaction.reply({ content: 'Spam', ephemeral: true })
|
||||
let i = 0
|
||||
function myLoop() {
|
||||
setTimeout(function () {
|
||||
if (!user) return
|
||||
if (!string) return
|
||||
if (!integer) return
|
||||
user.send(string).catch(error => console.error(error))
|
||||
i++
|
||||
if (i < integer) myLoop()
|
||||
}, 1000)
|
||||
}
|
||||
myLoop()
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction, Guild } from 'discord.js'
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('update')
|
||||
.setDescription('Update the member count channel.'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let guild = interaction.guild as Guild
|
||||
|
||||
guild.members.fetch().then(() => {
|
||||
var i = 0
|
||||
guild.members.cache.forEach(async member => { if (!member.user.bot) i++ })
|
||||
let channel = guild.channels.cache.get('1091140609139560508')
|
||||
if (!channel) return
|
||||
channel.setName(`${i} Gens Posés`)
|
||||
interaction.reply(`${i} Gens Posés !`)
|
||||
}).catch(console.error)
|
||||
}
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction, Guild } from 'discord.js'
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('update')
|
||||
.setDescription('Update the member count channel.'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let guild = interaction.guild as Guild
|
||||
|
||||
guild.members.fetch().then(() => {
|
||||
var i = 0
|
||||
guild.members.cache.forEach(async member => { if (!member.user.bot) i++ })
|
||||
let channel = guild.channels.cache.get('1091140609139560508')
|
||||
if (!channel) return
|
||||
channel.setName(`${i} Gens Posés`)
|
||||
interaction.reply(`${i} Gens Posés !`)
|
||||
}).catch(console.error)
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'
|
||||
import { useQueue } from'discord-player'
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('loop')
|
||||
.setDescription('Boucler la musique en cours de lecture.')
|
||||
.addIntegerOption(option => option.setName('loop')
|
||||
.setDescription('Mode de boucle (0 = Off, 1 = Titre, 2 = File d\'Attente; 3 = Autoplay)')
|
||||
.setRequired(true)
|
||||
.setMinValue(0)
|
||||
.setMaxValue(3)),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let loop = interaction.options.getInteger('loop')
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
|
||||
queue.setRepeatMode(loop as number)
|
||||
return await interaction.reply(`Boucle ${loop === 0 ? 'désactivée' : loop === 1 ? 'en mode Titre' : loop === 2 ? 'en mode File d\'Attente' : 'en autoplay'}.`)
|
||||
}
|
||||
import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'
|
||||
import { useQueue } from'discord-player'
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('loop')
|
||||
.setDescription('Boucler la musique en cours de lecture.')
|
||||
.addIntegerOption(option => option.setName('loop')
|
||||
.setDescription('Mode de boucle (0 = Off, 1 = Titre, 2 = File d\'Attente; 3 = Autoplay)')
|
||||
.setRequired(true)
|
||||
.setMinValue(0)
|
||||
.setMaxValue(3)),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let loop = interaction.options.getInteger('loop')
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
|
||||
queue.setRepeatMode(loop as number)
|
||||
return await interaction.reply(`Boucle ${loop === 0 ? 'désactivée' : loop === 1 ? 'en mode Titre' : loop === 2 ? 'en mode File d\'Attente' : 'en autoplay'}.`)
|
||||
}
|
||||
}
|
||||
@@ -1,45 +1,45 @@
|
||||
import { ChatInputCommandInteraction, SlashCommandBuilder, EmbedBuilder } from 'discord.js'
|
||||
import { useQueue } from 'discord-player'
|
||||
import { lyricsExtractor } from '@discord-player/extractor'
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('lyrics')
|
||||
.setDescription('Rechercher les paroles d\'une musique.')
|
||||
.addStringOption(option => option.setName('recherche').setDescription('Chercher une musique spécifique')),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
await interaction.deferReply()
|
||||
|
||||
let query = interaction.options.getString('recherche', false)
|
||||
if (!query) {
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
let track = queue.currentTrack
|
||||
if (!track) return interaction.followUp({ content: 'Aucune musique en cours, recherche en une plutôt !' })
|
||||
|
||||
if (track.raw.source === 'spotify') query = `${track.author} ${track.title}`
|
||||
else query = track.title
|
||||
}
|
||||
|
||||
let lyricsFinder = lyricsExtractor()
|
||||
|
||||
let lyrics = await lyricsFinder.search(query).catch(() => null)
|
||||
if (!lyrics) return interaction.followUp({ content: 'Pas de paroles trouvées !' })
|
||||
|
||||
let trimmedLyrics = lyrics.lyrics.substring(0, 1997)
|
||||
|
||||
let embed = new EmbedBuilder()
|
||||
.setColor('#ffc370')
|
||||
.setTitle(lyrics.title)
|
||||
.setURL(lyrics.url)
|
||||
.setThumbnail(lyrics.thumbnail)
|
||||
.setAuthor({
|
||||
name: lyrics.artist.name,
|
||||
iconURL: lyrics.artist.image,
|
||||
url: lyrics.artist.url
|
||||
})
|
||||
.setDescription(trimmedLyrics.length === 1997 ? `${trimmedLyrics}...` : trimmedLyrics)
|
||||
|
||||
return interaction.followUp({ embeds: [embed] })
|
||||
}
|
||||
import { ChatInputCommandInteraction, SlashCommandBuilder, EmbedBuilder } from 'discord.js'
|
||||
import { useQueue } from 'discord-player'
|
||||
import { lyricsExtractor } from '@discord-player/extractor'
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('lyrics')
|
||||
.setDescription('Rechercher les paroles d\'une musique.')
|
||||
.addStringOption(option => option.setName('recherche').setDescription('Chercher une musique spécifique')),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
await interaction.deferReply()
|
||||
|
||||
let query = interaction.options.getString('recherche', false)
|
||||
if (!query) {
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
let track = queue.currentTrack
|
||||
if (!track) return interaction.followUp({ content: 'Aucune musique en cours, recherche en une plutôt !' })
|
||||
|
||||
if (track.raw.source === 'spotify') query = `${track.author} ${track.title}`
|
||||
else query = track.title
|
||||
}
|
||||
|
||||
let lyricsFinder = lyricsExtractor()
|
||||
|
||||
let lyrics = await lyricsFinder.search(query).catch(() => null)
|
||||
if (!lyrics) return interaction.followUp({ content: 'Pas de paroles trouvées !' })
|
||||
|
||||
let trimmedLyrics = lyrics.lyrics.substring(0, 1997)
|
||||
|
||||
let embed = new EmbedBuilder()
|
||||
.setColor('#ffc370')
|
||||
.setTitle(lyrics.title)
|
||||
.setURL(lyrics.url)
|
||||
.setThumbnail(lyrics.thumbnail)
|
||||
.setAuthor({
|
||||
name: lyrics.artist.name,
|
||||
iconURL: lyrics.artist.image,
|
||||
url: lyrics.artist.url
|
||||
})
|
||||
.setDescription(trimmedLyrics.length === 1997 ? `${trimmedLyrics}...` : trimmedLyrics)
|
||||
|
||||
return interaction.followUp({ embeds: [embed] })
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
import { useQueue } from 'discord-player'
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('pause')
|
||||
.setDescription('Met en pause la musique.'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
|
||||
queue.node.setPaused(!queue.node.isPaused())
|
||||
return await interaction.reply('Musique mise en pause !')
|
||||
}
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
import { useQueue } from 'discord-player'
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('pause')
|
||||
.setDescription('Met en pause la musique.'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
|
||||
queue.node.setPaused(!queue.node.isPaused())
|
||||
return await interaction.reply('Musique mise en pause !')
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction, AutocompleteInteraction, GuildMember } from 'discord.js'
|
||||
import { useMainPlayer, useQueue, QueryType } from 'discord-player'
|
||||
import writeEnv from '../../utils/writeEnv'
|
||||
|
||||
import dbGuild from '../../schemas/guild'
|
||||
|
||||
export interface TrackSearchResult { name: string, value: string }
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('play')
|
||||
.setDescription('Jouer une musique.')
|
||||
@@ -64,18 +65,23 @@ module.exports = {
|
||||
else return
|
||||
}
|
||||
try { if (!queue.connection) await queue.connect(voiceChannel) }
|
||||
catch (error: any) { console.error(error); return interaction.followUp(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) }
|
||||
catch (error: any) { console.error(error) }
|
||||
|
||||
|
||||
let guildProfile = await dbGuild.findOne({ guildId: queue.guild.id })
|
||||
if (!guildProfile) return console.log(`Database data for **${queue.guild.name}** does not exist !`)
|
||||
|
||||
let dbData = guildProfile.get('guildPlayer.replay')
|
||||
dbData['textChannelId'] = interaction.channel?.id
|
||||
dbData['voiceChannelId'] = voiceChannel.id
|
||||
|
||||
guildProfile.set('guildPlayer.replay', dbData)
|
||||
await guildProfile.save().catch(console.error)
|
||||
|
||||
// Write the values in the .env file to recover the player if the bot restarts
|
||||
writeEnv('DISCORD_MUSIC_TEXTCHANNEL_ID', interaction.channel?.id ?? '')
|
||||
writeEnv('DISCORD_MUSIC_VOICECHANNEL_ID', voiceChannel.id)
|
||||
|
||||
// Search the song
|
||||
let result = await player.search(query, { requestedBy: interaction.user })
|
||||
if (!result.hasTracks()) return interaction.followUp(`Aucune musique trouvée pour **${query}** !`)
|
||||
let track = result.tracks[0]
|
||||
console.log(track.duration)
|
||||
console.log(track.durationMS)
|
||||
|
||||
let entry = queue.tasksQueue.acquire()
|
||||
await entry.getTask()
|
||||
@@ -85,7 +91,7 @@ module.exports = {
|
||||
if (!queue.isPlaying()) await queue.node.play()
|
||||
let track_source = track.source === 'youtube' ? 'Youtube' : track.source === 'spotify' ? 'Spotify' : 'Inconnu'
|
||||
return interaction.followUp(`Chargement de la musique **${track.title}** de **${track.author}** sur **${track_source}**...`)
|
||||
} catch (error: any) { console.error(error); return interaction.followUp(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) }
|
||||
} catch (error: any) { console.error(error) }
|
||||
finally { queue.tasksQueue.release() }
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
import { useHistory } from 'discord-player'
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('previous')
|
||||
.setDescription('Joue la musique précédente.'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let history = useHistory(interaction.guild?.id ?? '')
|
||||
if (!history) return await interaction.reply('Il n\'y a pas d\'historique de musique !')
|
||||
|
||||
await history.previous()
|
||||
return await interaction.reply('Musique précédente jouée !')
|
||||
}
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
import { useHistory } from 'discord-player'
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('previous')
|
||||
.setDescription('Joue la musique précédente.'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let history = useHistory(interaction.guild?.id ?? '')
|
||||
if (!history) return await interaction.reply('Il n\'y a pas d\'historique de musique !')
|
||||
|
||||
await history.previous()
|
||||
return await interaction.reply('Musique précédente jouée !')
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
import { useQueue } from 'discord-player'
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('resume')
|
||||
.setDescription('Reprendre la musique.'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
|
||||
queue.node.setPaused(!queue.node.isPaused())
|
||||
return await interaction.reply('Musique reprise !')
|
||||
}
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
import { useQueue } from 'discord-player'
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('resume')
|
||||
.setDescription('Reprendre la musique.'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
|
||||
queue.node.setPaused(!queue.node.isPaused())
|
||||
return await interaction.reply('Musique reprise !')
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
import { useQueue } from 'discord-player'
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('shuffle')
|
||||
.setDescription('Mélange la file d\'attente.'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
|
||||
queue.tracks.shuffle()
|
||||
return await interaction.reply('File d\'attente mélangée !')
|
||||
}
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
import { useQueue } from 'discord-player'
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('shuffle')
|
||||
.setDescription('Mélange la file d\'attente.'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
|
||||
queue.tracks.shuffle()
|
||||
return await interaction.reply('File d\'attente mélangée !')
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
import { useQueue } from 'discord-player'
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('skip')
|
||||
.setDescription('Passer la musique en cours.'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
|
||||
queue.node.skip()
|
||||
return await interaction.reply('Musique passée !')
|
||||
}
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
import { useQueue } from 'discord-player'
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('skip')
|
||||
.setDescription('Passer la musique en cours.'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
|
||||
queue.node.skip()
|
||||
return await interaction.reply('Musique passée !')
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,15 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
import { useQueue } from 'discord-player'
|
||||
import writeEnv from '../../utils/writeEnv'
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('stop')
|
||||
.setDescription('Arrêter la musique.'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
|
||||
queue.delete()
|
||||
writeEnv('DISCORD_MUSIC_TEXTCHANNEL_ID', '')
|
||||
writeEnv('DISCORD_MUSIC_VOICECHANNEL_ID', '')
|
||||
writeEnv('DISCORD_MUSIC_CURRENT_TRACK', '')
|
||||
writeEnv('DISCORD_MUSIC_CURRENT_PROGRESS', '')
|
||||
|
||||
return await interaction.reply('Musique arrêtée !')
|
||||
}
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
import { useQueue } from 'discord-player'
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('stop')
|
||||
.setDescription('Arrêter la musique.'),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
|
||||
queue.delete()
|
||||
return await interaction.reply('Musique arrêtée !')
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
import { useQueue } from 'discord-player'
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('volume')
|
||||
.setDescription('Modifie le volume de la musique.')
|
||||
.addIntegerOption(option => option.setName('volume')
|
||||
.setDescription('Le volume à mettre (%)')
|
||||
.setRequired(true)
|
||||
.setMinValue(1)
|
||||
.setMaxValue(100)),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let volume = interaction.options.getInteger('volume')
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
|
||||
queue.node.setVolume(volume as number)
|
||||
return await interaction.reply(`Volume modifié à ${volume}% !`)
|
||||
}
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'
|
||||
import { useQueue } from 'discord-player'
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('volume')
|
||||
.setDescription('Modifie le volume de la musique.')
|
||||
.addIntegerOption(option => option.setName('volume')
|
||||
.setDescription('Le volume à mettre (%)')
|
||||
.setRequired(true)
|
||||
.setMinValue(1)
|
||||
.setMaxValue(100)),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
let volume = interaction.options.getInteger('volume')
|
||||
let queue = useQueue(interaction.guild?.id ?? '')
|
||||
if (!queue) return interaction.followUp({ content: 'Aucune file d\'attente en cours, recherche une musique plutôt !' })
|
||||
|
||||
queue.node.setVolume(volume as number)
|
||||
return await interaction.reply(`Volume modifié à ${volume}% !`)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user