2022-01-13 00:56:24 +05:00
|
|
|
const Command = require("../../base/Command"),
|
2022-01-04 02:18:28 +05:00
|
|
|
Discord = require("discord.js"),
|
2022-01-05 00:24:57 +05:00
|
|
|
backup = require("discord-backup");
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-01-16 20:30:28 +05:00
|
|
|
backup.setStorageFolder(__dirname + "/../../backups");
|
2022-01-04 23:54:12 +05:00
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
class Backup extends Command {
|
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
|
|
name: "backup",
|
|
|
|
dirname: __dirname,
|
|
|
|
enabled: true,
|
|
|
|
guildOnly: true,
|
|
|
|
aliases: ["ba"],
|
|
|
|
memberPermissions: ["MANAGE_GUILD"],
|
|
|
|
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS", "ADMINISTRATOR"],
|
|
|
|
nsfw: false,
|
|
|
|
ownerOnly: false,
|
2022-01-04 23:56:29 +05:00
|
|
|
cooldown: 20000
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async run(message, args, data) {
|
|
|
|
const status = args[0];
|
|
|
|
if (!status) return message.error("administration/backup:MISSING_STATUS");
|
|
|
|
|
|
|
|
if (status === "create") {
|
|
|
|
const m = await message.sendT("misc:PLEASE_WAIT", null, {
|
|
|
|
prefixEmoji: "loading"
|
|
|
|
});
|
|
|
|
backup.create(message.guild).then((backup) => {
|
|
|
|
m.delete();
|
|
|
|
message.success("administration/backup:SUCCESS_PUBLIC");
|
|
|
|
message.author.send(message.translate("administration/backup:SUCCESS_PRIVATE", {
|
|
|
|
backupID: backup.id
|
|
|
|
})).catch(() => {
|
|
|
|
backup.remove(backup.id);
|
|
|
|
message.error("misc:CANNOT_DM");
|
|
|
|
});
|
|
|
|
}).catch((err) => {
|
2022-01-05 00:24:57 +05:00
|
|
|
console.error(err);
|
2022-01-04 02:18:28 +05:00
|
|
|
return message.error("misc:ERR_OCCURRED");
|
|
|
|
});
|
|
|
|
} else if (status === "load") {
|
|
|
|
const backupID = args[1];
|
|
|
|
if (!backupID) return message.error("administration/backup:MISSING_BACKUP_ID");
|
|
|
|
|
|
|
|
backup.fetch(backupID).then(async () => {
|
|
|
|
message.sendT("administration/backup:CONFIRMATION");
|
|
|
|
await message.channel.awaitMessages(m => (m.author.id === message.author.id) && (m.content === "confirm"), {
|
|
|
|
max: 1,
|
|
|
|
time: 20000,
|
|
|
|
errors: ["time"]
|
2022-01-04 23:54:12 +05:00
|
|
|
}).catch((err) => {
|
|
|
|
console.error(err);
|
2021-12-10 21:39:54 +05:00
|
|
|
return message.error("administration/backup:TIMES_UP");
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
|
|
|
message.author.send(message.translate("administration/backup:START_LOADING"));
|
2022-01-04 23:54:12 +05:00
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
backup.load(backupID, message.guild).then(() => {
|
|
|
|
backup.remove(backupID);
|
|
|
|
message.author.send(message.translate("administration/backup:LOAD_SUCCESS"));
|
|
|
|
}).catch((err) => {
|
2022-01-04 01:32:49 +05:00
|
|
|
console.error(err);
|
2022-01-04 02:18:28 +05:00
|
|
|
return message.error("misc:ERR_OCCURRED");
|
|
|
|
});
|
2022-01-04 23:54:12 +05:00
|
|
|
}).catch((err) => {
|
|
|
|
console.error(err);
|
2022-01-04 02:18:28 +05:00
|
|
|
return message.error("administration/backup:NO_BACKUP_FOUND", {
|
|
|
|
backupID
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else if (status === "info") {
|
|
|
|
const backupID = args[1];
|
|
|
|
if (!backupID) return message.error("administration/backup:MISSING_BACKUP_ID");
|
|
|
|
|
2022-01-04 23:54:12 +05:00
|
|
|
backup.fetch(backupID).then(async (backupInfo) => {
|
2022-01-04 02:18:28 +05:00
|
|
|
const embed = new Discord.MessageEmbed()
|
2022-01-04 00:35:11 +05:00
|
|
|
.setAuthor({
|
|
|
|
name: message.translate("administration/backup:TITLE_INFO")
|
|
|
|
})
|
2022-01-04 23:54:12 +05:00
|
|
|
.addField(message.translate("administration/backup:TITLE_ID"), backupInfo.id, true)
|
|
|
|
.addField(message.translate("administration/backup:TITLE_SERVER_ID"), backupInfo.data.guildID.toString(), true)
|
|
|
|
.addField(message.translate("administration/backup:TITLE_SIZE"), `${backupInfo.size} kb`, true)
|
|
|
|
.addField(message.translate("administration/backup:TITLE_CREATED_AT"), message.printDate(new Date(backupInfo.data.createdTimestamp)), true)
|
2022-01-04 02:18:28 +05:00
|
|
|
.setColor(data.config.embed.color)
|
2022-01-04 00:35:11 +05:00
|
|
|
.setFooter({
|
|
|
|
text: data.config.embed.footer
|
|
|
|
});
|
|
|
|
message.channel.send({
|
|
|
|
embeds: [embed]
|
|
|
|
});
|
2022-01-04 01:32:49 +05:00
|
|
|
}).catch((err) => {
|
|
|
|
console.error(err);
|
2022-01-04 00:35:11 +05:00
|
|
|
return message.error("administration/backup:NO_BACKUP_FOUND", {
|
|
|
|
backupID
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else if (status === "remove") {
|
|
|
|
const backupID = args[1];
|
|
|
|
if (!backupID) return message.error("administration/backup:MISSING_BACKUP_ID");
|
|
|
|
|
|
|
|
backup.fetch(backupID).then(async () => {
|
2022-01-04 01:22:45 +05:00
|
|
|
message.sendT("administration/backup:REMOVE_CONFIRMATION");
|
2022-01-04 00:35:11 +05:00
|
|
|
await message.channel.awaitMessages(m => (m.author.id === message.author.id) && (m.content === "confirm"), {
|
|
|
|
max: 1,
|
|
|
|
time: 20000,
|
|
|
|
errors: ["time"]
|
|
|
|
}).catch(() => {
|
|
|
|
return message.error("administration/backup:TIMES_UP");
|
|
|
|
});
|
|
|
|
|
2022-01-04 01:22:45 +05:00
|
|
|
backup.remove(backupID).then(async () => {
|
|
|
|
message.success("administration/backup:SUCCESS_REMOVED");
|
|
|
|
});
|
2022-01-04 23:54:12 +05:00
|
|
|
}).catch((err) => {
|
|
|
|
console.error(err);
|
2022-01-04 02:18:28 +05:00
|
|
|
return message.error("administration/backup:NO_BACKUP_FOUND", {
|
|
|
|
backupID
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return message.error("administration/backup:MISSING_STATUS");
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
}
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
module.exports = Backup;
|