mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 06:03:04 -04:00
rework updates and deployments
This commit is contained in:
parent
3676dfaf70
commit
4639d11a7e
2 changed files with 51 additions and 19 deletions
|
@ -1,34 +1,33 @@
|
|||
const { createEmbed } = require('../../../labscore/utils/embed')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
|
||||
const { execSync } = require("child_process");
|
||||
const { icon, highlight, smallPill } = require('../../../labscore/utils/markdown');
|
||||
|
||||
module.exports = {
|
||||
name: "update",
|
||||
label: "flags",
|
||||
metadata: {
|
||||
description: `Fetches latest bot version.\nUse ${smallPill('-f')} to force an update.`,
|
||||
description_short: 'Bot update',
|
||||
examples: ['update -f'],
|
||||
description: `Queries pb manager to trigger an update flow`,
|
||||
description_short: '[MANAGER] Query update',
|
||||
examples: ['update'],
|
||||
category: 'dev',
|
||||
usage: 'update [-f]'
|
||||
usage: 'update'
|
||||
},
|
||||
onBefore: context => context.user.isClientOwner,
|
||||
onCancel: ()=>{},
|
||||
run: async (context, args) => {
|
||||
let response = 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, {embeds: [createEmbed("warning", context, "Already up to date.")]})
|
||||
onCancel: () => { },
|
||||
run: async (context) => {
|
||||
if (process.env.environment == "prodnew") return await editOrReply(context, createEmbed("error", "Cannot update on this instance."))
|
||||
await editOrReply(context, createEmbed("loading", context, "Querying manager..."))
|
||||
|
||||
let com = r.toString().match(/([a-z0-9]{7})\.\.([a-z0-9]{7})/)
|
||||
return await editOrReply(context, { content: `${icon("success_simple")} Updated ${highlight(com[1] + ' -> ' + com[2])} in ${((Date.now() - t) / 1000).toFixed(2)}s`, embeds: []})
|
||||
}catch(e){
|
||||
try {
|
||||
const t = Date.now()
|
||||
|
||||
// Call server to query update
|
||||
await superagent.post(`${process.env.PB_MANAGER_HOST}_pbs/UpdatePbService`)
|
||||
.set("Authorization", process.env.PB_MANAGER_KEY)
|
||||
|
||||
return await editOrReply(context, createEmbed("success", "Update queried at manager"))
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return await editOrReply(context, createEmbed("error", context, "Update failed. Use -f to force update."))
|
||||
return await editOrReply(context, createEmbed("error", "Manager reported error during update query."))
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue