diff --git a/commands/message/dev/deploy.js b/commands/message/dev/deploy.js index b9b8129..392c78c 100644 --- a/commands/message/dev/deploy.js +++ b/commands/message/dev/deploy.js @@ -1,35 +1,29 @@ const { createEmbed } = require('#utils/embed') const { editOrReply } = require('#utils/message') -const superagent = require('superagent') +const { execSync } = require('child_process'); module.exports = { - name: "deploy", + name: "reboot", label: "flags", metadata: { - description: `Queries pb manager to trigger a deploy and restart flow`, - description_short: '[MANAGER] Query deploy', - examples: ['deploy'], + description: `Reboot the bot.`, + description_short: 'Reboot the bot.', + examples: ['reboot'], category: 'dev', - usage: 'deploy' + usage: 'reboot' }, onBefore: context => context.user.isClientOwner, onCancel: () => { }, run: async (context) => { - if (!["production","prod","prodnew"].includes(process.env.environment)) return await editOrReply(context, createEmbed("error", context, "Cannot update on this instance.")) - await editOrReply(context, createEmbed("loading", context, "Querying deploy...")) - - try { - const t = Date.now() - - // Call server to query update - await superagent.post(`${process.env.PB_MANAGER_HOST}_pbs/v1/DeployPbService`) - .set("Authorization", process.env.PB_MANAGER_KEY) - - return await editOrReply(context, createEmbed("success", context, "Deployment queried at manager. Shutting down.")) - } catch (e) { + try{ + await editOrReply(context, createEmbed("loading", context, "Updating bot...")); + execSync("git pull"); + await editOrReply(context, createEmbed("success", context, "Rebooting bot...")); + execSync("pm2 restart labscore-prd"); + }catch(e){ console.log(e) - return await editOrReply(context, createEmbed("error", context, "Manager reported error during deploy query.")) + await editOrReply(context, createEmbed("error", context, "Unable to reboot.")) } } }; \ No newline at end of file diff --git a/commands/message/dev/update.js b/commands/message/dev/update.js index 48ca326..cc64585 100644 --- a/commands/message/dev/update.js +++ b/commands/message/dev/update.js @@ -1,32 +1,32 @@ const { createEmbed } = require('#utils/embed') const { editOrReply } = require('#utils/message') -const superagent = require('superagent') +const { execSync } = require('child_process'); module.exports = { name: "update", label: "flags", metadata: { - description: `Queries pb manager to trigger an update flow`, - description_short: '[MANAGER] Query update', + description: `Updates bot code from git.\nUse ${smallPill('-f')} to force an update.`, + description_short: 'Update bot code.', examples: ['update'], category: 'dev', usage: 'update' }, onBefore: context => context.user.isClientOwner, onCancel: () => { }, - run: async (context) => { - if (!["production","prod","prodnew"].includes(process.env.environment)) return await editOrReply(context, createEmbed("error", context, "Cannot update on this instance.")) - await editOrReply(context, createEmbed("loading", context, "Querying manager...")) - + run: async (context, args) => { + await editOrReply(context, createEmbed("loading", context, "Updating bot...")) + try { const t = Date.now() + if(args.flags.includes('-force') || args.flags.includes('-f')) execSync("git checkout .") + const r = execSync("git pull") + if(r.toString().includes("Already up to date.")) return await editOrReply(context, createEmbed("warning", context, "Already up to date.")) - // Call server to query update - await superagent.post(`${process.env.PB_MANAGER_HOST}_pbs/v1/UpdatePbService`) - .set("Authorization", process.env.PB_MANAGER_KEY) - - return await editOrReply(context, createEmbed("success", context, "Update queried at manager")) + let com = r.toString().match(/([a-z0-9]{7})\.\.([a-z0-9]{7})/) + + return await editOrReply(context, createEmbed("success", context, `Updated ${com[1]} -> ${com[2]} in ${((Date.now() - t) / 1000).toFixed(2)}s`)) } catch (e) { console.log(e) return await editOrReply(context, createEmbed("error", context, "Manager reported error during update query."))