From adab3831fac1175af12a2b4015d3c115183e3ee5 Mon Sep 17 00:00:00 2001 From: Isaac Date: Thu, 23 Feb 2023 22:40:14 +0000 Subject: [PATCH] feat: add `PUBLISH_COMMANDS` environment variable --- docker-compose.yml | 5 +++-- scripts/preinstall.js | 1 + src/env.js | 1 + src/listeners/client/ready.js | 8 ++++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 287fdeb..a865563 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,11 +39,12 @@ services: HTTP_HOST: 0.0.0.0 HTTP_PORT: 80 HTTP_TRUST_PROXY: false # set to true if you're using a reverse proxy - PUBLIC_BOT: false OVERRIDE_ARCHIVE: null + PUBLIC_BOT: false + PUBLISH_COMMANDS: false SETTINGS_PORT: 8169 SETTINGS_HOST: 127.0.0.1 - SUPER: !!str 319467558166069248 # optionally add `,youruseridhere` + SUPER: 319467558166069248 # optionally add `,youruseridhere` networks: discord-tickets: diff --git a/scripts/preinstall.js b/scripts/preinstall.js index 517be0e..783c47d 100644 --- a/scripts/preinstall.js +++ b/scripts/preinstall.js @@ -24,6 +24,7 @@ const env = { HTTP_TRUST_PROXY: false, OVERRIDE_ARCHIVE: '', PUBLIC_BOT: false, + PUBLISH_COMMANDS: false, SETTINGS_HOST: '127.0.0.1', SETTINGS_PORT: 8169, SUPER: '319467558166069248', diff --git a/src/env.js b/src/env.js index 99824a5..787e975 100644 --- a/src/env.js +++ b/src/env.js @@ -35,6 +35,7 @@ const env = { HTTP_TRUST_PROXY: () => true, // optional OVERRIDE_ARCHIVE: () => true, // optional PUBLIC_BOT: () => true, // optional + PUBLISH_COMMANDS: () => true, // optional SETTINGS_HOST: v => (!!v && !v.startsWith('http')) || new Error('is required and must be an address, not a URL'), diff --git a/src/listeners/client/ready.js b/src/listeners/client/ready.js index a736f20..880ee6a 100644 --- a/src/listeners/client/ready.js +++ b/src/listeners/client/ready.js @@ -23,8 +23,16 @@ module.exports = class extends Listener { process.title = 'tickets'; client.log.success('Connected to Discord as "%s"', client.user.tag); + // fill cache await sync(client); + if (process.env.PUBLISH_COMMANDS === 'true') { + client.log.info('Automatically publishing commands...'); + client.commands.publish() + .then(commands => client.log.success('Published %d commands', commands?.size)) + .catch(client.log.error); + } + // presence/activity let next = 0; const setPresence = async () => {