Relance music si crash/reboot + Réécriture /amp
This commit is contained in:
@@ -1,82 +1,124 @@
|
|||||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js')
|
const { SlashCommandBuilder, EmbedBuilder, inlineCode } = require('discord.js')
|
||||||
require('dotenv').config()
|
let dotenv = require('dotenv')
|
||||||
require('require-all')(__dirname + '/../../utilsAMP')
|
dotenv.config()
|
||||||
|
|
||||||
|
const appDir = require('path').dirname(require.main.filename)
|
||||||
|
const API = require('require-all')(appDir + '/utilsAMP')
|
||||||
|
|
||||||
|
function failMsg(data) { return `La commande a échouée !\n${inlineCode(`${data.Title}: ${data.Message}`)}` }
|
||||||
|
function errorMsg(data) { return `Y'a eu une erreur !\n${inlineCode(`${data.error_code}`)}` }
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder().setName('amp').setDescription('Accède à mon panel de jeu AMP !')
|
data: new SlashCommandBuilder().setName('amp').setDescription('Accède à mon panel de jeu AMP !')
|
||||||
//.addSubcommand(subcommand => subcommand.setName('api_info').setDescription('Prints info about the API.'))
|
|
||||||
.addSubcommand(subcommand => subcommand.setName('login').setDescription("Connectez-vous avant d'effectuer une autre commande !")
|
.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('username').setDescription("Nom d'Utilisateur").setRequired(true))
|
||||||
.addStringOption(option => option.setName('password').setDescription('Mot de Passe').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))
|
.addBooleanOption(option => option.setName('remember').setDescription('Mémoriser les identifiants').setRequired(true))
|
||||||
.addStringOption(option => option.setName('otp').setDescription('Code de double authentification')))
|
.addStringOption(option => option.setName('otp').setDescription('Code de double authentification')))
|
||||||
|
|
||||||
.addSubcommandGroup(subcommandgroup => subcommandgroup.setName('instances').setDescription('Intéragir avec les instances AMP.')
|
.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.')
|
.addSubcommand(subcommand => subcommand.setName('manage').setDescription('Gérer une instance.')
|
||||||
.addStringOption(option => option.setName('name').setDescription("Nom de l'instance").setRequired(true)))
|
.addStringOption(option => option.setName('name').setDescription("Nom de l'instance").setRequired(true)))
|
||||||
.addSubcommand(subcommand => subcommand.setName('list').setDescription('Liste toutes les instances disponibles.'))
|
|
||||||
.addSubcommand(subcommand => subcommand.setName('restart').setDescription('Redémarre une instance.')
|
.addSubcommand(subcommand => subcommand.setName('restart').setDescription('Redémarre une instance.')
|
||||||
.addStringOption(option => option.setName('name').setDescription("Nom de l'instance").setRequired(true)))),
|
.addStringOption(option => option.setName('name').setDescription("Nom de l'instance").setRequired(true)))),
|
||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
const base_url = process.env.AMP_HOST + '/API'
|
// Let the user login
|
||||||
|
|
||||||
if (interaction.options.getSubcommand() == 'login') {
|
if (interaction.options.getSubcommand() == 'login') {
|
||||||
|
// Get a SessionID and a RememberMeToken if wanted
|
||||||
await interaction.deferReply({ ephemeral: true })
|
await interaction.deferReply({ ephemeral: true })
|
||||||
|
|
||||||
let result = await login(base_url, interaction.options)
|
let details = {
|
||||||
if (result.status === 'success') return await interaction.editReply(`You are successfully logged in as **${result.data.userInfo.Username}** !`)
|
username: interaction.options.getString('username'),
|
||||||
else if (result.status === 'fail') return await interaction.editReply(`Sorry, something bad happened ! (${result.data.Message})`)
|
password: interaction.options.getString('password'),
|
||||||
else if (result.status === 'error') return await interaction.editReply(`Sorry, there has been an error ! (${result.data.error_code})`)
|
token: interaction.options.getString('otp') || '',
|
||||||
}
|
rememberMe: interaction.options.getBoolean('remember')
|
||||||
else if (interaction.options.getSubcommandGroup() == 'instances') {
|
}
|
||||||
if (interaction.options.getSubcommand() == 'list') {
|
|
||||||
await interaction.deferReply()
|
|
||||||
|
|
||||||
let result = await getInstances(base_url)
|
let result = await API.Core.Login(details)
|
||||||
if (result.status === 'success') {
|
if (result.status === 'success') return await interaction.followUp(`Tu es connecté au panel sous **${result.data.userInfo.Username}** !`)
|
||||||
let fields = []
|
else if (result.status === 'fail') return await interaction.followUp(failMsg(result.data))
|
||||||
result.instances.forEach(instance => {
|
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data))
|
||||||
fields.push({
|
}
|
||||||
name: instance.FriendlyName,
|
await interaction.deferReply()
|
||||||
value: `**ID:** ${instance.InstanceID}
|
|
||||||
**Running:** ${instance.Running}
|
// Check if the SessionID is still valid
|
||||||
**IP:** ${instance.IP}
|
let sessionID = dotenv.config().parsed.AMP_SESSIONID
|
||||||
**Port:** ${instance.Port}
|
|
||||||
**Module:** ${instance.Module}`,
|
let session = await API.CheckSession(sessionID)
|
||||||
inline: true
|
if (session.status === 'fail') {
|
||||||
})
|
console.log(session)
|
||||||
})
|
if (process.env.AMP_REMEMBER_TOKEN) {
|
||||||
let embed = new EmbedBuilder()
|
// Refresh the SessionID if the RememberMeToken is available
|
||||||
.setTitle('Instances')
|
let details = {
|
||||||
.setDescription('Liste de toutes les instances disponibles.')
|
username: process.env.AMP_USERNAME,
|
||||||
.setColor(interaction.guild.members.me.displayColor)
|
password: '',
|
||||||
.setTimestamp()
|
token: process.env.AMP_REMEMBER_TOKEN,
|
||||||
.setFields(fields)
|
rememberMe: true
|
||||||
return await interaction.followUp({ embeds: [embed] })
|
|
||||||
}
|
}
|
||||||
|
let result = await API.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 API.ADSModule.GetInstances(sessionID)
|
||||||
|
|
||||||
|
if (result.status === 'success') {
|
||||||
|
await interaction.followUp({ content: `${result.data.result.length} hôtes trouvés !` })
|
||||||
|
result.data.result.forEach(async host => {
|
||||||
|
let fields = []
|
||||||
|
host.AvailableInstances.forEach(instance => {
|
||||||
|
fields.push({
|
||||||
|
name: instance.FriendlyName,
|
||||||
|
value: `**ID:** ${instance.InstanceID}
|
||||||
|
**Running:** ${instance.Running}
|
||||||
|
**IP:** ${instance.IP}
|
||||||
|
**Port:** ${instance.Port}
|
||||||
|
**Module:** ${instance.Module}`,
|
||||||
|
inline: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
let embed = new EmbedBuilder()
|
||||||
|
.setTitle('Instances')
|
||||||
|
.setDescription(`Liste des instances de l'hôte **${host.FriendlyName}** :`)
|
||||||
|
.setColor(interaction.guild.members.me.displayColor)
|
||||||
|
.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') {
|
else if (interaction.options.getSubcommand() == 'manage') {
|
||||||
await interaction.deferReply()
|
let query = interaction.options.getString('name')
|
||||||
|
let result = await API.ADSModule.ManageInstance(sessionID, query)
|
||||||
let result = await manageInstance(base_url, interaction.options.getString('name'))
|
|
||||||
if (result.status === 'success') return await interaction.followUp(`Ok !`)
|
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))
|
||||||
}
|
}
|
||||||
else if (interaction.options.getSubcommand() == 'restart') {
|
else if (interaction.options.getSubcommand() == 'restart') {
|
||||||
await interaction.deferReply()
|
let query = interaction.options.getString('name')
|
||||||
|
let result = await API.ADSModule.RestartInstance(sessionID, query)
|
||||||
|
|
||||||
let result = await restartInstance(base_url, interaction.options.getString('name'))
|
|
||||||
if (result.status === 'success') return await interaction.followUp(`Ok !`)
|
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))
|
||||||
}
|
}
|
||||||
/*else if (interaction.options.getSubcommand() == 'api_info') {
|
|
||||||
await interaction.deferReply()
|
|
||||||
let url = `${base_url}/Core/GetAPISpec`
|
|
||||||
let headers = { headers: { SESSIONID: localStorage.getItem("AMP_sessionID") } }
|
|
||||||
try {
|
|
||||||
let response = await axios.post(url, headers)
|
|
||||||
console.log(response.data)
|
|
||||||
await interaction.editReply('Ok !')
|
|
||||||
} catch (error) { console.log(error), await interaction.editReply("HTTP Error !") }
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
const { SlashCommandBuilder } = require('discord.js')
|
const { SlashCommandBuilder } = require('discord.js')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
require('require-all')(__dirname + '/../../utilsCrack')
|
|
||||||
|
const appDir = require('path').dirname(require.main.filename)
|
||||||
|
require('require-all')(appDir + '/utilsCrack')
|
||||||
|
|
||||||
var headers1 = {
|
var headers1 = {
|
||||||
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||||
|
|||||||
@@ -70,6 +70,12 @@ module.exports = {
|
|||||||
await entry.getTask()
|
await entry.getTask()
|
||||||
queue.addTrack(track)
|
queue.addTrack(track)
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
writeEnv('DISCORD_MUSIC_CURRENT_TRACK', track.url)
|
||||||
|
writeEnv('DISCORD_MUSIC_CURRENT_PROGRESS', 0)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!queue.isPlaying()) await queue.node.play()
|
if (!queue.isPlaying()) await queue.node.play()
|
||||||
track.source = track.source === 'youtube' ? 'Youtube' : track.source === 'spotify' ? 'Spotify' : 'Inconnu'
|
track.source = track.source === 'youtube' ? 'Youtube' : track.source === 'spotify' ? 'Spotify' : 'Inconnu'
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
const { SlashCommandBuilder } = require('discord.js')
|
const { SlashCommandBuilder } = require('discord.js')
|
||||||
const generatePlayer = require('../../utilsPlayer/generate.js')
|
|
||||||
|
const appDir = require('path').dirname(require.main.filename)
|
||||||
|
const generatePlayer = require(appDir + '/utilsPlayer/generate.js')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ module.exports = {
|
|||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
let queue = useQueue(interaction.guild.id)
|
let queue = useQueue(interaction.guild.id)
|
||||||
queue.delete()
|
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 !')
|
return await interaction.reply('Musique arrêtée !')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
const { Events } = require('discord.js')
|
const { Events } = require('discord.js')
|
||||||
const editPlayer = require('../utilsPlayer/edit.js')
|
|
||||||
const playerButtons = require('../utilsPlayer/buttons.js')
|
const appDir = require('path').dirname(require.main.filename)
|
||||||
|
const editPlayer = require(appDir + '/utilsPlayer/edit.js')
|
||||||
|
const playerButtons = require(appDir + '/utilsPlayer/buttons.js')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: Events.InteractionCreate,
|
name: Events.InteractionCreate,
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
const { Events } = require('discord.js')
|
const { Events } = require('discord.js')
|
||||||
|
const { useMasterPlayer, useQueue } = require('discord-player')
|
||||||
|
require('dotenv').config()
|
||||||
|
|
||||||
//const { DataTypes } = require("sequelize")
|
//const { DataTypes } = require("sequelize")
|
||||||
//const sequelize = require('../utils/initSequelize.js')
|
//const sequelize = require('../utils/initSequelize.js')
|
||||||
const generatePlayer = require('../utilsPlayer/generate.js')
|
|
||||||
const getUptime = require('../utils/getUptime.js')
|
const appDir = require('path').dirname(require.main.filename)
|
||||||
require('dotenv').config()
|
const generatePlayer = require(appDir + '/utilsPlayer/generate.js')
|
||||||
|
const getUptime = require(appDir + '/utils/getUptime.js')
|
||||||
|
|
||||||
const dance = async function (bot_id, channel, embed, components) {
|
const dance = async function (bot_id, channel, embed, components) {
|
||||||
let messages = await channel.messages.fetch()
|
let messages = await channel.messages.fetch()
|
||||||
@@ -17,9 +21,50 @@ const dance = async function (bot_id, channel, embed, components) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
name: Events.ClientReady,
|
name: Events.ClientReady,
|
||||||
once: true,
|
once: true,
|
||||||
execute(client) {
|
async execute(client) {
|
||||||
console.log(`\u001b[1;35m Ready! Logged in as ${client.user.tag}`)
|
console.log(`\u001b[1;35m Ready! Logged in as ${client.user.tag}`)
|
||||||
|
|
||||||
|
// Check if a music session was active before the bot was restarted
|
||||||
|
if (process.env.DISCORD_MUSIC_CURRENT_TRACK) {
|
||||||
|
let textChannel = client.channels.cache.get(process.env.DISCORD_MUSIC_TEXTCHANNEL_ID)
|
||||||
|
let voiceChannel = client.channels.cache.get(process.env.DISCORD_MUSIC_VOICECHANNEL_ID)
|
||||||
|
|
||||||
|
let player = useMasterPlayer()
|
||||||
|
let queue = player.nodes.create(textChannel.guild, {
|
||||||
|
metadata: {
|
||||||
|
channel: voiceChannel,
|
||||||
|
client: textChannel.guild.members.me,
|
||||||
|
requestedBy: client.user
|
||||||
|
},
|
||||||
|
selfDeaf: true,
|
||||||
|
volume: 20,
|
||||||
|
leaveOnEmpty: true,
|
||||||
|
leaveOnEmptyCooldown: 300000,
|
||||||
|
leaveOnEnd: true,
|
||||||
|
leaveOnEndCooldown: 300000,
|
||||||
|
skipOnNoStream: true
|
||||||
|
})
|
||||||
|
|
||||||
|
try { if (!queue.connection) await queue.connect(voiceChannel) }
|
||||||
|
catch (error) { console.error(error); await textChannel.send(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) }
|
||||||
|
|
||||||
|
let result = await player.search(process.env.DISCORD_MUSIC_CURRENT_TRACK, { requestedBy: client.user })
|
||||||
|
if (!result.hasTracks()) await textChannel.send(`Aucune musique trouvée pour **${query}** !`)
|
||||||
|
let track = result.tracks[0]
|
||||||
|
|
||||||
|
let entry = queue.tasksQueue.acquire()
|
||||||
|
await entry.getTask()
|
||||||
|
queue.addTrack(track)
|
||||||
|
|
||||||
|
try {
|
||||||
|
await queue.node.play()
|
||||||
|
queue.node.seek(process.env.DISCORD_MUSIC_CURRENT_PROGRESS)
|
||||||
|
queue.setRepeatMode(1)
|
||||||
|
await textChannel.send(`Relancement de la musique suite à mon redémarrage...`)
|
||||||
|
} catch (error) { console.error(error); await textChannel.send(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) }
|
||||||
|
finally { queue.tasksQueue.release() }
|
||||||
|
}
|
||||||
|
|
||||||
//try {
|
//try {
|
||||||
// sequelize.authenticate()
|
// sequelize.authenticate()
|
||||||
// console.log('Connection has been established successfully.')
|
// console.log('Connection has been established successfully.')
|
||||||
@@ -45,8 +90,11 @@ module.exports = {
|
|||||||
return console.log(`\u001b[1;31m Error: Aucun channel trouvé avec l'id \`${process.env.DISCORD_PLAYERCHANNEL_ID}\`, veuillez utiliser la commande \`/setchannel\` !`)
|
return console.log(`\u001b[1;31m Error: Aucun channel trouvé avec l'id \`${process.env.DISCORD_PLAYERCHANNEL_ID}\`, veuillez utiliser la commande \`/setchannel\` !`)
|
||||||
}
|
}
|
||||||
|
|
||||||
let { embed, components } = await generatePlayer(guild)
|
// Keep track of the music progress if the bot reboots
|
||||||
|
let queue = useQueue(guild.id)
|
||||||
|
if (queue) if (queue.isPlaying()) writeEnv('DISCORD_MUSIC_CURRENT_PROGRESS', queue.node.playbackTime)
|
||||||
|
|
||||||
|
let { embed, components } = await generatePlayer(guild)
|
||||||
if (components) {
|
if (components) {
|
||||||
embed.setFooter({ text: `Uptime: ${getUptime(client.uptime)} / ${embed.data.footer.text}` })
|
embed.setFooter({ text: `Uptime: ${getUptime(client.uptime)} / ${embed.data.footer.text}` })
|
||||||
await dance(client.user.id, channel, embed, components)
|
await dance(client.user.id, channel, embed, components)
|
||||||
|
|||||||
@@ -3,5 +3,10 @@ module.exports = {
|
|||||||
async execute(queue, track) {
|
async execute(queue, track) {
|
||||||
// Emitted when the bot leaves the voice channel
|
// Emitted when the bot leaves the voice channel
|
||||||
queue.metadata.channel.send("J'ai quitté le vocal !")
|
queue.metadata.channel.send("J'ai quitté le vocal !")
|
||||||
|
|
||||||
|
writeEnv('DISCORD_MUSIC_TEXTCHANNEL_ID', '')
|
||||||
|
writeEnv('DISCORD_MUSIC_VOICECHANNEL_ID', '')
|
||||||
|
writeEnv('DISCORD_MUSIC_CURRENT_TRACK', '')
|
||||||
|
writeEnv('DISCORD_MUSIC_CURRENT_PROGRESS', '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
14
utilsAMP/ADSModule/GetInstances.js
Normal file
14
utilsAMP/ADSModule/GetInstances.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
const axios = require('axios')
|
||||||
|
|
||||||
|
module.exports = (async (SESSIONID) => {
|
||||||
|
return await axios.post(`${process.env.AMP_HOST}/API/${__filename.split('utilsAMP/')[1].split('.js')[0]}`, {
|
||||||
|
SESSIONID
|
||||||
|
}).then(response => {
|
||||||
|
console.log(response.data)
|
||||||
|
if (!response.data.result) return { status: 'fail', data: response.data }
|
||||||
|
return { status: 'success', data: response.data }
|
||||||
|
}).catch(error => {
|
||||||
|
console.error(error)
|
||||||
|
return { status: 'error', data: error }
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
require('dotenv').config()
|
|
||||||
|
|
||||||
module.exports = manageInstance = (async (url, FriendlyName) => {
|
module.exports = (async (SESSIONID, FriendlyName) => {
|
||||||
let result = await axios.post(`${url}/ADSModule/GetInstances`, {
|
require('dotenv').config()
|
||||||
SESSIONID: process.env.AMP_SESSIONID
|
|
||||||
|
return await axios.post(`${process.env.AMP_HOST}/API/${__filename.split('utilsAMP/')[1].split('.js')[0]}`, {
|
||||||
|
SESSIONID
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
console.log(response.data)
|
console.log(response.data)
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ module.exports = manageInstance = (async (url, FriendlyName) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (result.status === 'success') return await axios.post(`${url}/ADSModule/ManageInstance`, {
|
if (result.status === 'success') return await axios.post(`${url}/ADSModule/ManageInstance`, {
|
||||||
SESSIONID: process.env.AMP_SESSIONID,
|
SESSIONID,
|
||||||
InstanceId: result.data.instance_id
|
InstanceId: result.data.instance_id
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
console.log(response.data)
|
console.log(response.data)
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
require('dotenv').config()
|
|
||||||
|
|
||||||
module.exports = restartInstance = (async (url, InstanceName) => {
|
module.exports = (async (SESSIONID, InstanceName) => {
|
||||||
return await axios.post(`${url}/ADSModule/RestartInstance`, {
|
require('dotenv').config()
|
||||||
SESSIONID: process.env.AMP_SESSIONID,
|
|
||||||
|
return await axios.post(`${process.env.AMP_HOST}/API/${__filename.split('utilsAMP/')[1].split('.js')[0]}`, {
|
||||||
|
SESSIONID,
|
||||||
InstanceName
|
InstanceName
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
console.log(response.data)
|
console.log(response.data)
|
||||||
13
utilsAMP/CheckSession.js
Normal file
13
utilsAMP/CheckSession.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
const axios = require('axios')
|
||||||
|
|
||||||
|
module.exports = (async (SESSIONID) => {
|
||||||
|
return await axios.post(`${process.env.AMP_HOST}/API/ADSModule/GetInstances`, {
|
||||||
|
SESSIONID
|
||||||
|
}).then(response => {
|
||||||
|
if (!response.data.result) return { status: 'fail', data: response.data }
|
||||||
|
return { status: 'success', data: response.data }
|
||||||
|
}).catch(error => {
|
||||||
|
console.error(error)
|
||||||
|
return { status: 'error', data: error }
|
||||||
|
})
|
||||||
|
})
|
||||||
23
utilsAMP/Core/Login.js
Normal file
23
utilsAMP/Core/Login.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
const axios = require('axios')
|
||||||
|
|
||||||
|
const appDir = require('path').dirname(require.main.filename)
|
||||||
|
const writeEnv = require(appDir + '/utils/writeEnv')
|
||||||
|
|
||||||
|
module.exports = (async (details) => {
|
||||||
|
require('dotenv').config()
|
||||||
|
console.log(details)
|
||||||
|
return await axios.post(`${process.env.AMP_HOST}/API/${__filename.split('utilsAMP/')[1].split('.js')[0]}`,
|
||||||
|
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)
|
||||||
|
return { status: 'error', data: error }
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
const axios = require('axios')
|
|
||||||
require('dotenv').config()
|
|
||||||
|
|
||||||
module.exports = getInstances = (async (url) => {
|
|
||||||
return await axios.post(`${url}/ADSModule/GetInstances`, {
|
|
||||||
SESSIONID: process.env.AMP_SESSIONID
|
|
||||||
}).then(response => {
|
|
||||||
console.log(response.data)
|
|
||||||
console.log(response.data.result[0].AvailableInstances)
|
|
||||||
|
|
||||||
//if (!response.data.success) return { status: 'fail', data: response.data }
|
|
||||||
return { status: 'success', data: response.data, instances: response.data.result[0].AvailableInstances }
|
|
||||||
}).catch(error => {
|
|
||||||
console.error(error)
|
|
||||||
return { status: 'error', data: error }
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
const axios = require('axios')
|
|
||||||
const writeEnv = require('../utils/writeEnv')
|
|
||||||
|
|
||||||
module.exports = login = (async (url, options) => {
|
|
||||||
return await axios.post(`${url}/Core/Login`, {
|
|
||||||
username: options.getString('username'),
|
|
||||||
password: options.getString('password'),
|
|
||||||
token: options.getString('otp') || '',
|
|
||||||
rememberMe: options.getBoolean('remember')
|
|
||||||
}).then(response => {
|
|
||||||
console.log(response.data)
|
|
||||||
if (!response.data.success) return { status: 'fail', data: response.data }
|
|
||||||
|
|
||||||
writeEnv('AMP_SESSIONID', response.data.sessionID)
|
|
||||||
if (options.getBoolean('remember')) writeEnv('AMP_REMEMBER_TOKEN', response.data.rememberMeToken)
|
|
||||||
|
|
||||||
return { status: 'success', data: response.data }
|
|
||||||
}).catch(error => {
|
|
||||||
console.error(error)
|
|
||||||
return { status: 'error', data: error }
|
|
||||||
})
|
|
||||||
})
|
|
||||||
Reference in New Issue
Block a user