Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require("fs");
  2. const cooldown = new Set();
  3. const { writeFile } = require('fs');
  4. const { promisify } = require('util');
  5. const writeFilePromise = promisify(writeFile);
  6. const fetch = require("node-fetch");
  7. cooldown.time = 5;
  8. var active = new Map();
  9. module.exports = async (client, message) => {
  10.     if (message.author.bot) return;
  11.     if (message.content === `${client.user.username} setup`) {
  12.         if (!await message.member.permissions.has("ADMINISTRATOR")) return message.channel.send(":warning: You do not have the valid permissions to run this command.");
  13.         if (fs.existsSync(`./data/servers/configurations/${message.guild.id}.json`)) return message.channel.send(":warning: This server has already been set up.");
  14.         var fileConfiguration = {
  15.             permissions: {
  16.                 administrators: [
  17.                     message.author.id,
  18.                     message.guild.ownerID
  19.                 ]
  20.             }
  21.         };
  22.         if (message.author.id === message.guild.ownerID) fileConfiguration = {
  23.             permissions: {
  24.                 administrators: [
  25.                     message.author.id
  26.                 ]
  27.             }
  28.         };
  29.         fileConfiguration = await JSON.stringify(fileConfiguration);
  30.         var configurationFile = fs.writeFileSync(`./data/servers/configurations/${message.guild.id}.json`, fileConfiguration);
  31.         return message.channel.send(`:ballot_box_with_check: Success! Edit the configuration file to set up your bot. To get that file, use \`${client.user.username} get configuration\`.`);
  32.     } else if (message.content === `${client.user.username} get configuration`) {
  33.         if (!fs.existsSync(`./data/servers/configurations/${message.guild.id}.json`)) return message.channel.send(":warning: This server has not been set up.");
  34.         var file = fs.readFileSync(`./data/servers/configurations/${message.guild.id}.json`);
  35.         file = await JSON.parse(file);
  36.         if (!file.permissions.administrators.includes(message.author.id)) return message.channel.send(":warning: Invalid permissions. You are not a configuration administrator.");
  37.         return message.channel.send(":ballot_box_with_check: Here is your configuration file.", {
  38.             files: [{
  39.                 attachment: `./data/servers/configurations/${message.guild.id}.json`,
  40.                 name: `${message.guild.id}.json`
  41.             }]
  42.         });
  43.     } else if (message.content === "Aspeboat set configuration") {
  44.         if (!fs.existsSync(`./data/servers/configurations/${message.guild.id}.json`)) return message.channel.send(":warning: This server has not yet been configured. Use `Aspeboat setup` to configure this server.");
  45.         var file = fs.readFileSync(`./data/servers/configurations/${message.guild.id}.json`);
  46.         file = await JSON.parse(file);
  47.         if (!file.permissions.administrators.includes(message.author.id)) return message.channel.send(":warning: Invalid permissions. You are not a configuration administrator.");
  48.         var attachment = message.attachments.first();
  49.         if (!message.attachments.first()) return message.channel.send(":warning: Please attach a JSON file attachment to your message.");
  50.         if (!attachment.filename.endsWith(".json")) return message.channel.send(":warning: Your configuration file must be a JSON file.");
  51.         if (attachment.filename !== `${message.guild.id}.json`) return message.channel.send(`:warning: For this bot to recognise this configuration file, it must be named \`${message.guild.id}.json\`.`);
  52.         async function downloadFile() {
  53.             return fetch(message.attachments.first().url)
  54.                 .then(result => result.arrayBuffer())
  55.                 .then(result => writeFilePromise(`./data/servers/configurations/${message.guild.id}.json`, Buffer.from(result)));
  56.         };
  57.         downloadFile().then(async () => message.channel.send(":ballot_box_with_check: Success! Your guild configuration has successfully been set."));
  58.     } else if (message.content === "Aspeboat reset") {
  59.         if (!fs.existsSync(`./data/servers/configurations/${message.guild.id}.json`)) return message.channel.send(":warning: This server has not yet been configured.");
  60.         if (message.author.id !== message.guild.ownerID) return message.channel.send(":warning: Only the owner of this server can run this command.");
  61.         await message.channel.send(":warning: Are you sure that you would like to reset your server's configuration? This action cannot be reversed. Reply with \"yes\" if your answer is yes and \"no\" if your answer is no. Reply within 60 seconds or else this command with automatically cancel itself.");
  62.         await message.channel.awaitMessages(async message => {
  63.             if (message.content === "yes") {
  64.                 fs.unlinkSync(`./data/servers/configurations/${message.guild.id}.json`);
  65.                 return message.channel.send(":ballot_box_with_check: Your server's configuration has successfully been reset.");
  66.             } else if (message.content === "no") {
  67.                 return message.channel.send(":ballot_box_with_check: Operation successfully cancelled.");
  68.             };
  69.         }, { max: 1, time: 60000, errors: ["time"] }).catch(collected => {
  70.             return message.channel.send(":warning: The timer is up and no responses were given. The command has been cancelled.");
  71.         });
  72.     };
  73.     if (!fs.existsSync(`./data/servers/configurations/${message.guild.id}.json`)) return;
  74.     var guildconfiguration = fs.readFileSync(`./data/servers/configurations/${message.guild.id}.json`);
  75.     guildconfiguration = await JSON.parse(guildconfiguration);
  76.     if (!guildconfiguration.commands) return;
  77.     if (!guildconfiguration.commands.prefix) return;
  78.     var prefix = guildconfiguration.commands.prefix;
  79.     const arguments = message.content.slice(prefix.length).trim().split(/ +/g);
  80.     const options = {
  81.         active: active
  82.     };
  83.     if (!message.content.startsWith(prefix)) return;
  84.     var command = arguments.shift().toLowerCase();
  85.     if (!require(`../commands/${command}.js`)) return;
  86.     var file = require(`../commands/${command}.js`);
  87.     file.run(client, message, arguments, options);
  88. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement