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.
This commit is contained in:
2026-03-10 20:45:20 -04:00
committed by Kira
parent 63cf36b845
commit 893c2db0c5
5 changed files with 33 additions and 8 deletions

View File

@@ -1,3 +1,4 @@
docker-compose.yml
node_modules node_modules
.git .git
state.json state.json

View File

@@ -1,5 +1,8 @@
let config = {}
try { config = require('../config.json'); }
catch { config.jellyfin = null; }
const { SlashCommandBuilder } = require('discord.js'); const { SlashCommandBuilder } = require('discord.js');
const config = require('../config.json');
const { createClient } = require('../lib/jellyfin'); const { createClient } = require('../lib/jellyfin');
async function sendChunked(interaction, content) { async function sendChunked(interaction, content) {
@@ -73,7 +76,10 @@ module.exports = {
), ),
async execute(interaction) { 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 }); interaction.reply({ content: 'You are not authorized to use this command.', flags: 64 });
return; return;
} else if (interaction.channel.type !== 1) { } else if (interaction.channel.type !== 1) {
@@ -187,4 +193,4 @@ module.exports = {
await interaction.editReply(`Error fetching from Jellyfin: ${err.message}`); await interaction.editReply(`Error fetching from Jellyfin: ${err.message}`);
} }
}, },
}; };

View File

@@ -2,6 +2,11 @@ services:
bot: bot:
restart: unless-stopped restart: unless-stopped
build: . build: .
volumes: environment:
- ./config.json:/app/config.json - DISCORD=TOKEN_HERE
- ./avatars:/app/avatars # 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

View File

@@ -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 // the basic discord setup stuff yoinked from their guide
const { Client, Events, GatewayIntentBits, Partials, ActivityType, MessageFlags, Collection } = require('discord.js'); const { Client, Events, GatewayIntentBits, Partials, ActivityType, MessageFlags, Collection } = require('discord.js');
const client = new Client({ const client = new Client({

View File

@@ -1,6 +1,9 @@
let config = {};
try { config = require('./config.json'); }
catch { config.token = process.env.DISCORD; }
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const config = require('../config.json');
const AVATAR_DIR = path.join(__dirname, '../avatars'); const AVATAR_DIR = path.join(__dirname, '../avatars');
let avatarFiles = []; let avatarFiles = [];