From 0db25f4478deafd9f34a5f9867b478b17d400222 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Thu, 19 Nov 2020 20:41:59 -0700 Subject: [PATCH] add n?pull --- commands/pull.js | 29 +++++++++++++++++++++++++++++ commands/reload.js | 4 ++++ 2 files changed, 33 insertions(+) create mode 100644 commands/pull.js diff --git a/commands/pull.js b/commands/pull.js new file mode 100644 index 0000000..eac43a0 --- /dev/null +++ b/commands/pull.js @@ -0,0 +1,29 @@ +const Discord = require('discord.js'); +const fs = require('fs'); +const chalk = require('chalk'); +const UserData = require('../models/user'); +const cp = require('child_process'); + +module.exports = { + name: "pull", + help: new Discord.MessageEmbed() + .setTitle("Help -> VCS Pull") + .setDescription("Pulls new commits from VCS") + .addField("Syntax", "`refresh`") + .addField("Notice", "This command is only available to Natsuki developers."), + async execute(message, msg, args, cmd, prefix, mention, client) { + const tu = await UserData.findOne({uid: message.author.id}); + if (!tu || !tu.developer) {return message.channel.send("You must be a Natsuki developer in order to do this!");} + + console.log(`\n${chalk.yellow('[WARN]')} >> ${chalk.gray('VCS:')} ${chalk.white('Initiating remote->local VCS sync/refresh!')}`); + + cp.exec("git pull origin master", function(error, stdout, stderr) { + if (stderr || error) { + let date = new Date; date = date.toString().slice(date.toString().search(":") - 2, date.toString().search(":") + 6); + console.error(`\n${chalk.red('[ERROR]')} >> ${chalk.yellow(`At [${date}] | Occurred while trying to pull from VCS`)}`, stderr || error); + } else { + console.log(`\n${chalk.gray('[INFO]')} >> ${chalk.hex('ff4fd0')(`VCS Pull successful`)}\n`); + } + }); + } +}; \ No newline at end of file diff --git a/commands/reload.js b/commands/reload.js index 80511e9..9793385 100644 --- a/commands/reload.js +++ b/commands/reload.js @@ -1,6 +1,7 @@ const Discord = require('discord.js'); const fs = require('fs'); const chalk = require('chalk'); +const UserData = require("../models/user"); module.exports = { name: "reload", @@ -12,6 +13,9 @@ module.exports = { .addField("Notice", "This command is only available to Natsuki developers."), async execute(message, msg, args, cmd, prefix, mention, client) { if (!args.length) { + const tu = await UserData.findOne({uid: message.author.id}); + if (!tu || !tu.developer) {return message.channel.send("You must be a Natsuki developer in order to do this!");} + var commands = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); console.log(`\n${chalk.yellow('[WARN]')} >> ${chalk.gray('Reload:')} ${chalk.white('All commands and events are being reloaded!')}`); console.log(`${chalk.gray('[INFO]')} >> ${chalk.hex('ff4fd0')(`Developer ${message.author.username} initiated the system refresh`)}\n`);