Ajout RSS + Tentative fix lecture de musique HS
This commit is contained in:
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' }
|
||||
}
|
||||
Reference in New Issue
Block a user