Intégration MongoDB + Fix export et amp
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import axios from 'axios'
|
||||
import writeEnv from './writeEnv'
|
||||
|
||||
export const ADSModule = {
|
||||
async GetInstances(SESSIONID: string) {
|
||||
return await axios.post(`${process.env.AMP_HOST}/API/ADSModule/GetInstances`, {
|
||||
async GetInstances(host: string, SESSIONID: string) {
|
||||
return await axios.post(host + '/API/ADSModule/GetInstances', {
|
||||
SESSIONID
|
||||
}).then(response => {
|
||||
if (!response.data.result) return { status: 'fail', data: response.data }
|
||||
if (!Array.isArray(response.data)) return { status: 'fail', data: response.data }
|
||||
return { status: 'success', data: response.data }
|
||||
}).catch(error => {
|
||||
console.error(error)
|
||||
@@ -14,13 +13,11 @@ export const ADSModule = {
|
||||
})
|
||||
},
|
||||
|
||||
async ManageInstance(SESSIONID: string, InstanceId: string) {
|
||||
return await axios.post(`${process.env.AMP_HOST}/API/ADSModule/ManageInstance`, {
|
||||
async ManageInstance(host: string, SESSIONID: string, InstanceId: string) {
|
||||
return await axios.post(host + '/API/ADSModule/ManageInstance', {
|
||||
SESSIONID,
|
||||
InstanceId
|
||||
}).then(response => {
|
||||
console.log(response.data)
|
||||
|
||||
if (!response.data.result) return { status: 'fail', data: response.data }
|
||||
return { status: 'success', data: response.data }
|
||||
}).catch(error => {
|
||||
@@ -29,13 +26,11 @@ export const ADSModule = {
|
||||
})
|
||||
},
|
||||
|
||||
async RestartInstance(SESSIONID: string, InstanceName: string) {
|
||||
return await axios.post(`${process.env.AMP_HOST}/API/ADSModule/RestartInstance`, {
|
||||
async RestartInstance(host: string, SESSIONID: string, InstanceName: string) {
|
||||
return await axios.post(host + '/API/ADSModule/RestartInstance', {
|
||||
SESSIONID,
|
||||
InstanceName
|
||||
}).then(response => {
|
||||
console.log(response.data)
|
||||
|
||||
//if (!response.data.success) return { status: 'fail', data: response.data }
|
||||
return { status: 'success', data: response.data }
|
||||
}).catch(error => {
|
||||
@@ -44,16 +39,13 @@ export const ADSModule = {
|
||||
})
|
||||
},
|
||||
|
||||
async Servers(SESSIONID: string, InstanceId: string) {
|
||||
return await axios.get(`${process.env.AMP_HOST}/API/ADSModule/Servers`, {
|
||||
async Servers(host: string, SESSIONID: string, InstanceId: string) {
|
||||
return await axios.get(host + '/API/ADSModule/Servers', {
|
||||
data: {
|
||||
SESSIONID,
|
||||
InstanceId
|
||||
}
|
||||
}).then(response => {
|
||||
console.log(response)
|
||||
console.log(response.data)
|
||||
|
||||
if (!response.data.result) return { status: 'fail', data: response.data }
|
||||
return { status: 'success', data: response.data }
|
||||
}).catch(error => {
|
||||
@@ -64,16 +56,11 @@ export const ADSModule = {
|
||||
}
|
||||
|
||||
export const Core = {
|
||||
async Login(details: any) {
|
||||
return await axios.post(`${process.env.AMP_HOST}/API/Core/Login`,
|
||||
async Login(host: string, details: any) {
|
||||
return await axios.post(host + '/API/Core/Login',
|
||||
details
|
||||
).then(response => {
|
||||
if (!response.data.success) return { status: 'fail', data: response.data }
|
||||
|
||||
writeEnv('AMP_USERNAME', response.data.userInfo.Username)
|
||||
writeEnv('AMP_SESSIONID', response.data.sessionID)
|
||||
writeEnv('AMP_REMEMBER_TOKEN', response.data.rememberMeToken)
|
||||
|
||||
return { status: 'success', data: response.data }
|
||||
}).catch(error => {
|
||||
console.error(error)
|
||||
@@ -82,11 +69,11 @@ export const Core = {
|
||||
}
|
||||
}
|
||||
|
||||
export async function CheckSession(SESSIONID: string) {
|
||||
return await axios.post(`${process.env.AMP_HOST}/API/ADSModule/GetInstances`, {
|
||||
export async function CheckSession(host: string, SESSIONID: string) {
|
||||
return await axios.post(host + '/API/ADSModule/GetInstances', {
|
||||
SESSIONID
|
||||
}).then(response => {
|
||||
if (!response.data.result) return { status: 'fail', data: response.data }
|
||||
if (!Array.isArray(response.data)) return { status: 'fail', data: response.data }
|
||||
return { status: 'success', data: response.data }
|
||||
}).catch(error => {
|
||||
console.error(error)
|
||||
|
||||
20
src/utils/dbGuildInit.ts
Normal file
20
src/utils/dbGuildInit.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Guild } from 'discord.js'
|
||||
import { Types } from 'mongoose'
|
||||
import dbGuild from '../schemas/guild'
|
||||
|
||||
export default async (guild: Guild) => {
|
||||
let guildProfile = new dbGuild({
|
||||
_id: new Types.ObjectId(),
|
||||
guildId: guild.id,
|
||||
guildName: guild.name,
|
||||
guildIcon: guild.iconURL() ?? 'None',
|
||||
guildPlayer: {
|
||||
replay: { enabled: false },
|
||||
disco: { enabled: false }
|
||||
},
|
||||
guildRss: { enabled: false, feeds: [] },
|
||||
guildAmp: { enabled: false }
|
||||
})
|
||||
await guildProfile.save().catch(console.error)
|
||||
return guildProfile
|
||||
}
|
||||
@@ -1,21 +1,31 @@
|
||||
import { Client, TextChannel } from 'discord.js'
|
||||
import { Document } from 'mongoose'
|
||||
import Parser from 'rss-parser'
|
||||
import 'dotenv/config'
|
||||
|
||||
export default async (client: Client) => {
|
||||
export interface Feed {
|
||||
name: string
|
||||
url: string
|
||||
token?: string
|
||||
}
|
||||
|
||||
export default async (client: Client, guildProfile: Document) => {
|
||||
try {
|
||||
let guild = client.guilds.cache.get(process.env.DISCORD_GUILD_ID as string)
|
||||
let guild = client.guilds.cache.get(guildProfile.get('guildId'))
|
||||
if (!guild) {
|
||||
clearInterval(client.disco.interval)
|
||||
console.log(`Aucun serveur trouvé avec l'id \`${process.env.DISCORD_GUILD_ID}\`, veuillez utiliser la commande \`/setchannel\` !`)
|
||||
console.log(`Aucun serveur trouvé avec l'id \`${guildProfile.get('guildId')}\`, veuillez utiliser la commande \`/setchannel\` !`)
|
||||
return 'clear'
|
||||
}
|
||||
let channel = client.channels.cache.get(process.env.DISCORD_RSSCHANNEL_ID as string) as TextChannel
|
||||
|
||||
let dbData = guildProfile.get('guildRss')
|
||||
let channel = client.channels.cache.get(dbData.channelId) 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\` !`)
|
||||
console.log(`Aucun channel trouvé avec l'id \`${dbData.channelId}\`, veuillez utiliser la commande \`/setchannel\` !`)
|
||||
return 'clear'
|
||||
}
|
||||
|
||||
let feeds = [
|
||||
{
|
||||
name: 'Nautiljon - Actualités',
|
||||
@@ -27,79 +37,87 @@ export default async (client: Client) => {
|
||||
},
|
||||
{
|
||||
name: 'YGG - Application',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2144&passkey='
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2144&passkey=',
|
||||
token: process.env.YGG_PASSKEY
|
||||
},
|
||||
{
|
||||
name: 'YGG - Audio',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2139&passkey='
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2139&passkey=',
|
||||
token: process.env.YGG_PASSKEY
|
||||
},
|
||||
{
|
||||
name: 'YGG - eBook',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2140&passkey='
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2140&passkey=',
|
||||
token: process.env.YGG_PASSKEY
|
||||
},
|
||||
{
|
||||
name: 'YGG - Emulation',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2141&passkey='
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2141&passkey=',
|
||||
token: process.env.YGG_PASSKEY
|
||||
},
|
||||
{
|
||||
name: 'YGG - Flim/Vidéo',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2145&passkey='
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2145&passkey=',
|
||||
token: process.env.YGG_PASSKEY
|
||||
},
|
||||
{
|
||||
name: 'YGG - GPS',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2143&passkey='
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2143&passkey=',
|
||||
token: process.env.YGG_PASSKEY
|
||||
},
|
||||
{
|
||||
name: 'YGG - Imprimante 3D',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2200&passkey='
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2200&passkey=',
|
||||
token: process.env.YGG_PASSKEY
|
||||
},
|
||||
{
|
||||
name: 'YGG - Jeu Vidéo',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2142&passkey='
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2142&passkey=',
|
||||
token: process.env.YGG_PASSKEY
|
||||
},
|
||||
{
|
||||
name: 'YGG - Nulled',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2300&passkey='
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2300&passkey=',
|
||||
token: process.env.YGG_PASSKEY
|
||||
},
|
||||
{
|
||||
name: 'YGG - XXX',
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2188&passkey='
|
||||
url: 'https://www3.yggtorrent.qa/rss?action=generate&type=cat&id=2188&passkey=',
|
||||
token: process.env.YGG_PASSKEY
|
||||
}
|
||||
]
|
||||
|
||||
feeds.forEach((feed, i) => { setTimeout(async () => {
|
||||
if (!dbData.feeds) dbData.feeds = feeds
|
||||
dbData.feeds.forEach((feed: Feed, i: Number) => { 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)
|
||||
if (feed.token) feed.url += feed.token
|
||||
let feedData = await parser.parseURL(feed.url)
|
||||
|
||||
let thread = await channel.threads.cache.find(thread => thread.name === feed.name)
|
||||
let thread = 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}...` })
|
||||
await thread.send({ content: `Fil RSS créé !\nVisionnage 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) })
|
||||
feedData.items.reverse().forEach(async (item, i) => {
|
||||
setTimeout(async () => await thread?.send({ content: `**${item.title}**\n${item.link}` }), i * 1000)
|
||||
})
|
||||
}
|
||||
|
||||
let lastItem = feedData.items[0]
|
||||
if (!lastItem) return console.log('No last item found for ' + feed.name)
|
||||
|
||||
let messages = await thread.messages.fetch({ limit: 1 })
|
||||
if (!messages) return console.log('No messages found for ' + feed.name)
|
||||
|
||||
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) })
|
||||
}, Number(i) * 1000) })
|
||||
} catch (error: any) { console.error(error); return 'clear' }
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import fs from 'fs'
|
||||
|
||||
export default ((variable: string, value: string) => {
|
||||
let parsedFile = fs.readFileSync('./.env', 'utf8')
|
||||
parsedFile = parsedFile.replace(new RegExp(`${variable} = .*`, 'g'), `${variable} = ${value}`)
|
||||
fs.writeFileSync('./.env', parsedFile)
|
||||
})
|
||||
Reference in New Issue
Block a user