Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require("fs");
- const settings = require("../data/settings.json");
- const colours = settings.colours;
- const Discord = require("discord.js");
- const https = require("https");
- const cooldown = new Set();
- cooldown.time = 5;
- var active = new Map();
- module.exports = async (client, message) => {
- if (message.author.bot) return;
- if (message.content === `${client.user.username} setup`) {
- if (!await message.member.permissions.has("ADMINISTRATOR")) return message.channel.send(":warning: You do not have the valid permissions to run this command.");
- if (fs.existsSync(`./data/servers/configurations/${message.guild.id}.json`)) return message.channel.send(":warning: This server has already been set up.");
- var fileConfiguration = {
- permissions: {
- administrators: [
- message.author.id,
- message.guild.ownerID
- ]
- }
- };
- if (message.author.id === message.guild.ownerID) fileConfiguration = {
- permissions: {
- administrators: [
- message.author.id
- ]
- }
- };
- fileConfiguration = await JSON.stringify(fileConfiguration);
- var configurationFile = fs.writeFileSync(`./data/servers/configurations/${message.guild.id}.json`, fileConfiguration);
- return message.channel.send(`Success! Edit the configuration file to set up your bot. To get that file, use \`${client.user.username} get configuration\`.`);
- } else if (message.content === `${client.user.username} get configuration`) {
- if (!fs.existsSync(`./data/servers/configurations/${message.guild.id}.json`)) return message.channel.send(":warning: This server has not been set up.");
- var file = fs.readFileSync(`./data/servers/configurations/${message.guild.id}.json`);
- file = await JSON.parse(file);
- if (!file.permissions.administrators.includes(message.author.id)) return message.channel.send(":warning: Invalid permissions. You are not a configuration administrator.");
- fs.unlinkSync(`./data/servers/configurations/${message.guild.id}.json`);
- attachment = await JSON.stringify(attachment);
- fs.writeFileSync(`./data/servers/configuraitons/${message.guild.id}.json`, attachment);
- return message.channel.send(":ballot_box_with_check: Here is your configuration file.", {
- files: [{
- attachment: `./data/servers/configurations/${message.guild.id}.json`,
- name: `${message.guild.id}.json`
- }]
- });
- } else if (message.content === "Aspeboat set configuration") {
- 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.");
- var file = fs.readFileSync(`./data/servers/configurations/${message.guild.id}.json`);
- file = await JSON.parse(file);
- if (!file.permissions.administrators.includes(message.author.id)) return message.channel.send(":warning: Invalid permissions. You are not a configuration administrator.");
- var attachment = message.attachments.first();
- if (!message.attachments.first()) return message.channel.send(":warning: Please attach a JSON file attachment to your message.");
- if (!attachment.filename.endsWith(".json")) return message.channel.send(":warning: Your configuration file must be a JSON file.");
- 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\`.`);
- fs.unlinkSync(`./data/servers/configurations/${message.guild.id}.json`);
- attachment = await JSON.stringify(attachment);
- fs.writeFileSync(`./data/servers/configurations/${message.guild.id}.json`, attachment);
- return message.channel.send(":ballot_box_with_check: Success! Your guild configuration has successfully been set.");
- };
- if (!fs.existsSync(`./data/servers/configurations/${message.guild.id}.json`)) return;
- var guildconfiguration = fs.readFileSync(`./data/servers/configurations/${message.guild.id}.json`);
- guildconfiguration = await JSON.parse(guildconfiguration);
- if (!guildconfiguration.commands) return;
- if (!guildconfiguration.commands.prefix) return;
- var prefix = guildconfiguration.commands.prefix;
- const arguments = message.content.slice(prefix.length).trim().split(/ +/g);
- const options = {
- active: active
- };
- if (!message.content.startsWith(prefix)) return;
- var command = arguments.shift().toLowerCase();
- var file = require(`../commands/${command}.js`);
- if (cooldown.has(`command_cooldown_${message.author.id}`)) {
- cooldown.embed = new Discord.RichEmbed()
- .setAuthor(message.author.tag, message.author.avatarURL)
- .setColor(colours.red)
- .setDescription("You need to cool down. The cool down is 5 seconds between commands.")
- .setTimestamp(new Date());
- message.channel.send(cooldown.embed);
- } else {
- file.run(client, message, arguments, options);
- cooldown.add(`command_cooldown_${message.author.id}`);
- setTimeout(() => {
- cooldown.delete(`command_cooldown_${message.author.id}`);
- }, cooldown.time * 1000);
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement