Intégration MongoDB + Fix export et amp
This commit is contained in:
55
src/events/client/ready.ts
Executable file
55
src/events/client/ready.ts
Executable file
@@ -0,0 +1,55 @@
|
||||
import { Events, Client, ActivityType } from 'discord.js'
|
||||
import { useMainPlayer } from 'discord-player'
|
||||
import { connect } from 'mongoose'
|
||||
import chalk from 'chalk'
|
||||
import 'dotenv/config'
|
||||
|
||||
import dbGuildInit from '../../utils/dbGuildInit'
|
||||
import dbGuild from '../../schemas/guild'
|
||||
import replay from '../../utilsPlayer/replay'
|
||||
import disco from '../../utilsPlayer/disco'
|
||||
import rss from '../../utils/rss'
|
||||
|
||||
|
||||
export default {
|
||||
name: Events.ClientReady,
|
||||
once: true,
|
||||
async execute(client: Client) {
|
||||
console.log(chalk.blue(`[DiscordJS] Connected to Discord ! Logged in as ${client.user?.tag ?? 'unknown'}`))
|
||||
client.user?.setActivity('some bangers...', { type: ActivityType.Listening })
|
||||
|
||||
await useMainPlayer().extractors.loadDefault(ext => ext === 'YouTubeExtractor' || ext === 'SpotifyExtractor').then(() => console.log(chalk.blue('[Discord-Player] YouTube and Spotify extractors loaded.'))).catch(console.error)
|
||||
|
||||
let mongo_url = `mongodb://${process.env.MONGOOSE_USER}:${process.env.MONGOOSE_PASSWORD}@${process.env.MONGOOSE_HOST}/${process.env.MONGOOSE_DATABASE}`
|
||||
await connect(mongo_url).catch(console.error)
|
||||
|
||||
|
||||
let guilds = client.guilds.cache
|
||||
guilds.forEach(async guild => {
|
||||
let guildProfile = await dbGuild.findOne({ guildId: guild.id })
|
||||
|
||||
if (!guildProfile) guildProfile = await dbGuildInit(guild)
|
||||
if (guildProfile.guildPlayer?.replay?.enabled && guildProfile.guildPlayer?.replay?.textChannelId) await replay(client, guildProfile)
|
||||
|
||||
client.disco = { interval: {} as NodeJS.Timeout }
|
||||
client.disco.interval = setInterval(async () => {
|
||||
let guildProfile = await dbGuild.findOne({ guildId: guild.id })
|
||||
|
||||
if (guildProfile?.guildPlayer?.disco?.enabled) {
|
||||
let state = await disco(client, guildProfile)
|
||||
if (state === 'clear') clearInterval(client.disco.interval)
|
||||
}
|
||||
}, 3000)
|
||||
|
||||
client.rss = { interval: {} as NodeJS.Timeout }
|
||||
client.rss.interval = setInterval(async () => {
|
||||
let guildProfile = await dbGuild.findOne({ guildId: guild.id })
|
||||
|
||||
if (guildProfile?.guildRss?.enabled) {
|
||||
let state = await rss(client, guildProfile)
|
||||
if (state === 'clear') clearInterval(client.rss.interval)
|
||||
}
|
||||
}, 30000)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user