Ajout RSS + Tentative fix lecture de musique HS
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
.dockerignore
|
||||
.git
|
||||
.gitignore
|
||||
.vscode
|
||||
Dockerfile
|
||||
node_modules
|
||||
public/cracks
|
||||
.dockerignore
|
||||
.gitignore
|
||||
Dockerfile
|
||||
README.md
|
||||
tsconfig.json
|
||||
.ncurc.json
|
||||
.env
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
dist/
|
||||
node_modules/
|
||||
public/cracks/
|
||||
dist/
|
||||
.env*
|
||||
.ncurc.json
|
||||
@@ -1,10 +1,11 @@
|
||||
FROM node:alpine as base
|
||||
FROM node:lts-alpine as base
|
||||
|
||||
ENV NODE_ENV=production
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY ["package.json", "package-lock.json*", "./"]
|
||||
RUN apk add --no-cache ffmpeg python3 make g++
|
||||
RUN npm install -g ts-node
|
||||
RUN npm install --production --verbose && mv node_modules ../
|
||||
|
||||
COPY . .
|
||||
|
||||
650
package-lock.json
generated
650
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
25
package.json
25
package.json
@@ -1,41 +1,42 @@
|
||||
{
|
||||
"name": "bot_tamiseur",
|
||||
"description": "Listen to music and use fun commands with your friends!",
|
||||
"version": "2.0.0",
|
||||
"version": "2.1.0",
|
||||
"author": {
|
||||
"name": "Zachary Guénot"
|
||||
},
|
||||
"main": "src/index.ts",
|
||||
"scripts": {
|
||||
"format": "prettier --write .",
|
||||
"start": "node src/index.ts",
|
||||
"start": "ts-node src/index.ts",
|
||||
"dev": "nodemon -e ts src/index.ts",
|
||||
"build": "tsc"
|
||||
"build": "ncc build src/index.ts -o dist"
|
||||
},
|
||||
"dependencies": {
|
||||
"@discord-player/equalizer": "^0.2.3",
|
||||
"@discord-player/extractor": "^4.4.6",
|
||||
"@discordjs/opus": "^0.9.0",
|
||||
"@discordjs/voice": "^0.16.1",
|
||||
"axios": "^1.6.5",
|
||||
"@types/parse-torrent": "^5.8.7",
|
||||
"axios": "^1.6.7",
|
||||
"bufferutil": "^4.0.8",
|
||||
"discord-player": "^6.6.7",
|
||||
"discord.js": "^14.14.1",
|
||||
"dotenv": "^16.3.1",
|
||||
"dotenv": "^16.4.5",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"jsdom": "^23.2.0",
|
||||
"jsdom": "^24.0.0",
|
||||
"libsodium-wrappers": "^0.7.13",
|
||||
"mariadb": "^3.2.3",
|
||||
"parse-torrent": "^9.1.5",
|
||||
"play-dl": "^1.9.7",
|
||||
"require-all": "^3.0.0",
|
||||
"rss-parser": "^3.13.0",
|
||||
"sqlite3": "^5.1.7",
|
||||
"utf-8-validate": "^6.0.3",
|
||||
"youtube-ext": "^1.1.16"
|
||||
"utf-8-validate": "^6.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/parse-torrent": "^5.8.7",
|
||||
"eslint": "^8.56.0",
|
||||
"nodemon": "^3.0.2",
|
||||
"prettier": "^3.2.1"
|
||||
"eslint": "^8.57.0",
|
||||
"nodemon": "^3.1.0",
|
||||
"prettier": "^3.2.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@ import { Events, Client, ActivityType } from 'discord.js'
|
||||
import { useMainPlayer } from 'discord-player'
|
||||
import replay from '../utilsPlayer/replay'
|
||||
import disco from '../utilsPlayer/disco'
|
||||
import rss from '../utils/rss'
|
||||
import 'dotenv/config'
|
||||
|
||||
declare module "discord.js" {
|
||||
export interface Client {
|
||||
disco: { interval: NodeJS.Timeout }
|
||||
disco: { interval: NodeJS.Timeout },
|
||||
rss: { interval: NodeJS.Timeout }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +21,19 @@ module.exports = {
|
||||
|
||||
await useMainPlayer().extractors.loadDefault(ext => ext === 'YouTubeExtractor' || ext === 'SpotifyExtractor').then(() => console.log('YouTube and Spotify extractors loaded.')).catch(console.error)
|
||||
|
||||
if (process.env.DISCORD_MUSIC_CURRENT_TRACK) await replay(client)
|
||||
//if (process.env.DISCORD_MUSIC_CURRENT_TRACK) await replay(client)
|
||||
|
||||
client.disco = { interval: {} as NodeJS.Timeout }
|
||||
client.disco.interval = setInterval(async () => {
|
||||
let state = await disco(client)
|
||||
if (state === 'clear') clearInterval(client.disco.interval)
|
||||
}, 2000)
|
||||
|
||||
client.rss = { interval: {} as NodeJS.Timeout }
|
||||
client.rss.interval = setInterval(async () => {
|
||||
let state = await rss(client)
|
||||
if (state === 'clear') clearInterval(client.rss.interval)
|
||||
}, 30000)
|
||||
rss(client)
|
||||
}
|
||||
}
|
||||
11
src/index.ts
11
src/index.ts
@@ -42,6 +42,7 @@ eventFiles.forEach(file => {
|
||||
// COMMANDS HANDLING
|
||||
client.commands = new Collection()
|
||||
|
||||
const commands = [] as Command[]
|
||||
const commandFolders = fs.readdirSync(path.join(__dirname, './commands'))
|
||||
commandFolders.forEach(folder => {
|
||||
let folderPath = path.join(__dirname, './commands', folder)
|
||||
@@ -50,17 +51,17 @@ commandFolders.forEach(folder => {
|
||||
let command = require(path.join(folderPath, file))
|
||||
if ('data' in command && 'execute' in command) {
|
||||
const commandData = command.data.toJSON()
|
||||
if (commandData) client.commands.set(commandData.name, command)
|
||||
if (commandData) { client.commands.set(commandData.name, command); commands.push(commandData) }
|
||||
} else console.log(`[WARNING] The command at ${`${folderPath}/${file}`} is missing a required "data" or "execute" property.`)
|
||||
})
|
||||
})
|
||||
|
||||
// COMMANDS REGISTERING
|
||||
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN as string)
|
||||
async () => {
|
||||
try { await rest.put(Routes.applicationCommands(process.env.DISCORD_APP_ID as string), { body: client.commands }) }
|
||||
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN as string);
|
||||
(async () => {
|
||||
try { await rest.put(Routes.applicationCommands(process.env.DISCORD_APP_ID as string), { body: commands }) }
|
||||
catch (error) { console.error(error) }
|
||||
}
|
||||
})()
|
||||
|
||||
// BUTTONS HANDLING
|
||||
client.buttons = new Collection()
|
||||
|
||||
105
src/utils/rss.ts
Normal file
105
src/utils/rss.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
import { Client, TextChannel } from 'discord.js'
|
||||
import Parser from 'rss-parser'
|
||||
import 'dotenv/config'
|
||||
|
||||
export default async (client: Client) => {
|
||||
try {
|
||||
let guild = client.guilds.cache.get(process.env.DISCORD_GUILD_ID as string)
|
||||
if (!guild) {
|
||||
clearInterval(client.disco.interval)
|
||||
console.log(`Aucun serveur trouvé avec l'id \`${process.env.DISCORD_GUILD_ID}\`, veuillez utiliser la commande \`/setchannel\` !`)
|
||||
return 'clear'
|
||||
}
|
||||
let channel = client.channels.cache.get(process.env.DISCORD_RSSCHANNEL_ID as string) as TextChannel
|
||||
if (!channel) {
|
||||
clearInterval(client.disco.interval)
|
||||
console.log(`Aucun channel trouvé avec l'id \`${process.env.DISCORD_RSSCHANNEL_ID}\`, veuillez utiliser la commande \`/setchannel\` !`)
|
||||
return 'clear'
|
||||
}
|
||||
let feeds = [
|
||||
{
|
||||
name: 'Nautiljon - Actualités',
|
||||
url: 'https://www.nautiljon.com/actualite/rss.php'
|
||||
},
|
||||
{
|
||||
name: 'Nautiljon - Les Brèves',
|
||||
url: 'https://www.nautiljon.com/breves/rss.php'
|
||||
},
|
||||
{
|
||||
name: 'YGG - Application',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2144&passkey='
|
||||
},
|
||||
{
|
||||
name: 'YGG - Audio',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2139&passkey='
|
||||
},
|
||||
{
|
||||
name: 'YGG - eBook',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2140&passkey='
|
||||
},
|
||||
{
|
||||
name: 'YGG - Emulation',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2141&passkey='
|
||||
},
|
||||
{
|
||||
name: 'YGG - Flim/Vidéo',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2145&passkey='
|
||||
},
|
||||
{
|
||||
name: 'YGG - GPS',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2143&passkey='
|
||||
},
|
||||
{
|
||||
name: 'YGG - Imprimante 3D',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2200&passkey='
|
||||
},
|
||||
{
|
||||
name: 'YGG - Jeu Vidéo',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2142&passkey='
|
||||
},
|
||||
{
|
||||
name: 'YGG - Nulled',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2300&passkey='
|
||||
},
|
||||
{
|
||||
name: 'YGG - XXX',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2188&passkey='
|
||||
}
|
||||
]
|
||||
|
||||
feeds.forEach((feed, i) => { setTimeout(async () => {
|
||||
let parser = new Parser()
|
||||
let url = feed.url
|
||||
if (feed.name.includes('YGG')) url += process.env.YGG_PASSKEY
|
||||
let feedData = await parser.parseURL(url)
|
||||
|
||||
let thread = await channel.threads.cache.find(thread => thread.name === feed.name)
|
||||
if (!thread) {
|
||||
thread = await channel.threads.create({
|
||||
name: feed.name,
|
||||
autoArchiveDuration: 60,
|
||||
reason: 'Création du fil RSS'
|
||||
})
|
||||
await thread.send({ content: 'Fil RSS créé !'})
|
||||
await thread.send({ content: `Visionnage de **${feedData.title}** sur ${feedData.link}...` })
|
||||
|
||||
if (feed.name.includes('YGG')) {
|
||||
let lastItem = feedData.items[0]
|
||||
await thread.send({ content: `**${lastItem.title}**\n${lastItem.link}` })
|
||||
}
|
||||
else feedData.items.forEach(async (item, i) => { setTimeout(async () => {
|
||||
await thread?.send({ content: `**${item.title}**\n${item.link}` })
|
||||
}, i * 1000) })
|
||||
}
|
||||
|
||||
let lastItem = feedData.items[0]
|
||||
let messages = await thread.messages.fetch({ limit: 1 })
|
||||
|
||||
let lastMessage = messages.first()
|
||||
if (!lastMessage) return console.log('No last message found for ' + feed.name)
|
||||
|
||||
if (lastMessage.content !== `**${lastItem.title}**\n${lastItem.link}`) await thread.send({ content: `**${lastItem.title}**\n${lastItem.link}` })
|
||||
//else console.log('No new item found for ' + feed.name)
|
||||
}, i * 1000) })
|
||||
} catch (error: any) { console.error(error); return 'clear' }
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import writeEnv from '../utils/writeEnv'
|
||||
import generate from './generate'
|
||||
|
||||
export default async (client: Client) => {
|
||||
try {
|
||||
let guild = client.guilds.cache.get(process.env.DISCORD_GUILD_ID as string)
|
||||
if (!guild) {
|
||||
clearInterval(client.disco.interval)
|
||||
@@ -16,10 +17,10 @@ export default async (client: Client) => {
|
||||
let queue = useQueue(guild.id)
|
||||
if (queue) if (queue.isPlaying()) writeEnv('DISCORD_MUSIC_CURRENT_PROGRESS', queue.node.playbackTime.toString())
|
||||
|
||||
let channel = client.channels.cache.get(process.env.DISCORD_PLAYERCHANNEL_ID as string) as TextChannel
|
||||
let channel = client.channels.cache.get(process.env.DISCORD_DISCOCHANNEL_ID as string) as TextChannel
|
||||
if (!channel) {
|
||||
clearInterval(client.disco.interval)
|
||||
console.log(`Aucun channel trouvé avec l'id \`${process.env.DISCORD_PLAYERCHANNEL_ID}\`, veuillez utiliser la commande \`/setchannel\` !`)
|
||||
console.log(`Aucun channel trouvé avec l'id \`${process.env.DISCORD_DISCOCHANNEL_ID}\`, veuillez utiliser la commande \`/setchannel\` !`)
|
||||
return 'clear'
|
||||
}
|
||||
|
||||
@@ -37,4 +38,5 @@ export default async (client: Client) => {
|
||||
return channel.send({ embeds: [embed] })
|
||||
} else if (components) return botMessage.edit({ embeds: [embed], components })
|
||||
} else return channel.send({ embeds: [embed] })
|
||||
} catch (error: any) { console.error(error); return 'clear' }
|
||||
}
|
||||
@@ -35,7 +35,7 @@ export default async (client: Client) => {
|
||||
|
||||
try {
|
||||
await queue.node.play()
|
||||
await queue.node.seek(Number(process.env.DISCORD_MUSIC_CURRENT_PROGRESS))
|
||||
await queue.node.seek(Number(process.env.DISCORD_MUSIC_CURRENT_PROGRESS) / 1000)
|
||||
await textChannel.send(`Relancement de la musique suite à mon redémarrage...`)
|
||||
} catch (error: any) { console.error(error); await textChannel.send(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) }
|
||||
finally { queue.tasksQueue.release() }
|
||||
|
||||
@@ -11,5 +11,6 @@
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
},
|
||||
"include": ["./src/**/*"]
|
||||
"include": ["./src/**/*"],
|
||||
"exclude": ["./src/utilsAMP/**/*", "./src/utilsCrack/**/*"]
|
||||
}
|
||||
Reference in New Issue
Block a user