From 95777bb389134ce5c42d45d5bddcd69d9017eb5a Mon Sep 17 00:00:00 2001 From: Cesium Date: Tue, 10 Mar 2026 20:45:20 -0400 Subject: [PATCH] accept discord token as env we only really need that to function anyway, other things like jellyfin will just not do anything and we have default value for avatar reset. --- .dockerignore | 1 + commands/jellyfin.js | 12 +++++++++--- docker-compose.yml.default | 10 ++++++++-- index.js | 12 +++++++++++- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/.dockerignore b/.dockerignore index e7d5a68..bdcae77 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ +docker-compose.yml node_modules .git state.json diff --git a/commands/jellyfin.js b/commands/jellyfin.js index 43ff589..f8d83e2 100644 --- a/commands/jellyfin.js +++ b/commands/jellyfin.js @@ -1,5 +1,8 @@ +let config = {} +try { config = require('../config.json'); } +catch { config.jellyfin = null; } + const { SlashCommandBuilder } = require('discord.js'); -const config = require('../config.json'); const { createClient } = require('../lib/jellyfin'); async function sendChunked(interaction, content) { @@ -73,7 +76,10 @@ module.exports = { ), async execute(interaction) { - if (!config.jellyfin.users.includes(interaction.user.id)) { + if (!config.jellyfin) { + interaction.reply({ content: 'This bot is not configured with a Jellyfin instance.', flags: 64 }); + return; + } else if (!config.jellyfin.users.includes(interaction.user.id)) { interaction.reply({ content: 'You are not authorized to use this command.', flags: 64 }); return; } else if (interaction.channel.type !== 1) { @@ -187,4 +193,4 @@ module.exports = { await interaction.editReply(`Error fetching from Jellyfin: ${err.message}`); } }, -}; \ No newline at end of file +}; diff --git a/docker-compose.yml.default b/docker-compose.yml.default index a989153..e6d1cdd 100644 --- a/docker-compose.yml.default +++ b/docker-compose.yml.default @@ -2,5 +2,11 @@ services: bot: restart: unless-stopped build: . - volumes: - - ./config.json:/app/config.json + environment: + - DISCORD=TOKEN_HERE +# volumes: +# Uncomment the config for advanced configuration like Jellyfin. +# - ./config.json:/app/config.json +# Uncomment avatars for an avatars folder it can rotate through. +# - ./avatars:/app/avatars + diff --git a/index.js b/index.js index 48affec..b08fae2 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,14 @@ -const config = require('./config.json'); +let config = {}; +try { + config = require('./config.json'); +} catch { + if (process.env.DISCORD && process.env.DISCORD != "TOKEN_HERE") { + config.token = process.env.DISCORD; + } else { + console.error("FATAL: Discord token required. Either pass it as an environment variable \"DISCORD\", or fill out config.json.default."); + process.exit(1); + } +} // the basic discord setup stuff yoinked from their guide const { Client, Events, GatewayIntentBits, Partials, ActivityType, MessageFlags, Collection } = require('discord.js'); const client = new Client({