From e8aac8497a70a8f1870175dbeac4feb1a10b390f Mon Sep 17 00:00:00 2001 From: Puechberty Arthur Date: Sat, 11 Apr 2026 14:19:08 +0200 Subject: [PATCH] apply maintainer review feedback --- .env.example | 12 ++++++------ README.md | 8 ++++---- docker-compose.yml | 4 ++-- framework/Client.js | 14 ++++---------- structures/JeopardyScrape.js | 13 ++----------- util/Util.js | 11 +++++++++++ 6 files changed, 29 insertions(+), 33 deletions(-) diff --git a/.env.example b/.env.example index b90e6676..52746750 100644 --- a/.env.example +++ b/.env.example @@ -11,7 +11,7 @@ JOIN_LEAVE_CHANNEL_ID= # Redis info # For docker-compose, keep REDIS_HOST=redis REDIS_HOST=redis -REDIS_PASS=change_me_redis_password +REDIS_PASS= # Runtime TZ=UTC @@ -22,16 +22,16 @@ XIAO_STATE_DIR=/data SUCCESS_EMOJI_ID= FAILURE_EMOJI_ID= GOLD_FISH_EMOJI_ID= -GOLD_FISH_EMOJI_NAME=Gold Fish +GOLD_FISH_EMOJI_NAME= MOCKING_EMOJI_ID= MOCKING_EMOJI_NAME= SILVER_FISH_EMOJI_ID= -SILVER_FISH_EMOJI_NAME=Silver Fish +SILVER_FISH_EMOJI_NAME= PORTAL_EMOJI_ID= -PORTAL_EMOJI_NAME=PORTAL +PORTAL_EMOJI_NAME= LOADING_EMOJI_ID= MEGA_EVOLVE_EMOJI_ID= -MEGA_EVOLVE_EMOJI_NAME=MEGA +MEGA_EVOLVE_EMOJI_NAME= NAME_RATER_EMOJI_ID= NAME_RATER_EMOJI_NAME= @@ -41,7 +41,7 @@ BITLY_KEY=your_bitly_key CLEVERBOT_KEY=your_cleverbot_key GITHUB_ACCESS_TOKEN=your_github_token GOV_KEY=your_nasa_api_key -IDIOT_URL=https://en.wikipedia.org/wiki/Idiot +IDIOT_URL= REMOVEBG_KEY=your_removebg_key SAUCENAO_KEY=your_saucenao_key THECATAPI_KEY=your_thecatapi_key diff --git a/README.md b/README.md index 13fed66b..cdba75b1 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ I don't really care, but please give credit in some form if you do so. You'll al > Can I host Xiao myself? -Yes. It is much easier to deploy now, especially with Docker Compose. +If you want. Docker Compose makes it simple, or you can do it the old-fashioned way. > Do I need every API key, emoji ID, etc.? @@ -43,8 +43,8 @@ Only if you want to use the DECTalk command. ## Installing -There are now two ways to run Xiao: -1. **Quick deploy (recommended):** Docker Compose. +There are two ways to run Xiao: +1. **Quick deploy:** Docker Compose. 2. **Manual deploy:** direct Linux setup. ### Quick Deploy (Docker Compose) @@ -114,7 +114,7 @@ There are now two ways to run Xiao: 1. Run `npm i -g @dotenvx/dotenvx`. 2. Run `dotenvx encrypt`. -### Run without Docker (Linux) +### Manual Deploy (Linux) > Install instructions below are for Linux. She should work on Windows, but I can't guarantee anything. diff --git a/docker-compose.yml b/docker-compose.yml index 19f2da19..c9cc45da 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: - --appendonly - "yes" - --requirepass - - ${REDIS_PASS:-change_me_redis_password} + - ${REDIS_PASS} volumes: - redis-data:/data @@ -24,7 +24,7 @@ services: - .env environment: REDIS_HOST: ${REDIS_HOST:-redis} - REDIS_PASS: ${REDIS_PASS:-change_me_redis_password} + REDIS_PASS: ${REDIS_PASS} TZ: ${TZ:-UTC} XIAO_STATE_DIR: ${XIAO_STATE_DIR:-/data} volumes: diff --git a/framework/Client.js b/framework/Client.js index 41859b89..52fcc096 100644 --- a/framework/Client.js +++ b/framework/Client.js @@ -7,13 +7,7 @@ const Registry = require('./Registry'); const Dispatcher = require('./Dispatcher'); require('./Extensions'); -const STATE_DIR = process.env.XIAO_STATE_DIR - ? path.resolve(process.env.XIAO_STATE_DIR) - : path.join(__dirname, '..'); - -function resolveStatePath(fileName) { - return path.join(STATE_DIR, fileName); -} +const { getStateDir, resolveStatePath } = require('../util/Util'); function writeJsonFile(filePath, data) { fs.mkdirSync(path.dirname(filePath), { recursive: true }); @@ -210,7 +204,7 @@ module.exports = class CommandClient extends Client { } text += '\n ]\n}\n'; const buf = Buffer.from(text); - fs.mkdirSync(STATE_DIR, { recursive: true }); + fs.mkdirSync(getStateDir(), { recursive: true }); fs.writeFileSync(resolveStatePath('blacklist.json'), buf, { encoding: 'utf8' }); return buf; } @@ -245,7 +239,7 @@ module.exports = class CommandClient extends Client { text = text.slice(0, -1); text += '\n}\n'; const buf = Buffer.from(text); - fs.mkdirSync(STATE_DIR, { recursive: true }); + fs.mkdirSync(getStateDir(), { recursive: true }); fs.writeFileSync(resolveStatePath('command-leaderboard.json'), buf, { encoding: 'utf8' }); @@ -283,7 +277,7 @@ module.exports = class CommandClient extends Client { text = text.slice(0, -1); text += '\n}\n'; const buf = Buffer.from(text); - fs.mkdirSync(STATE_DIR, { recursive: true }); + fs.mkdirSync(getStateDir(), { recursive: true }); fs.writeFileSync(resolveStatePath('command-last-run.json'), buf, { encoding: 'utf8' }); diff --git a/structures/JeopardyScrape.js b/structures/JeopardyScrape.js index 5ff331eb..418bbca8 100644 --- a/structures/JeopardyScrape.js +++ b/structures/JeopardyScrape.js @@ -4,18 +4,9 @@ const fs = require('fs'); const { parser } = require('stream-json'); const { pick } = require('stream-json/filters/Pick'); const { streamArray } = require('stream-json/streamers/StreamArray'); -const path = require('path'); -const { checkFileExists } = require('../util/Util'); +const { checkFileExists, getStateDir, resolveStatePath } = require('../util/Util'); const rounds = ['jeopardy_round', 'double_jeopardy_round', 'final_jeopardy_round']; -const STATE_DIR = process.env.XIAO_STATE_DIR - ? path.resolve(process.env.XIAO_STATE_DIR) - : path.join(__dirname, '..'); - -function resolveStatePath(fileName) { - return path.join(STATE_DIR, fileName); -} - module.exports = class JeopardyScrape { constructor(client) { Object.defineProperty(this, 'client', { value: client }); @@ -104,7 +95,7 @@ module.exports = class JeopardyScrape { gameIDs: this.gameIDs, seasons: this.seasons })); - fs.mkdirSync(STATE_DIR, { recursive: true }); + fs.mkdirSync(getStateDir(), { recursive: true }); fs.writeFileSync(resolveStatePath('jeopardy.json'), buf, { encoding: 'utf8' }); return buf; } diff --git a/util/Util.js b/util/Util.js index 246a7425..3bd2fa89 100644 --- a/util/Util.js +++ b/util/Util.js @@ -2,6 +2,7 @@ const { ActionRowBuilder, ButtonBuilder, PermissionFlagsBits, ButtonStyle, Compo const crypto = require('crypto'); const request = require('node-superfetch'); const fs = require('fs'); +const path = require('path'); let parseDomain; let ParseResultType; import('parse-domain').then(loadedModule => { @@ -203,6 +204,16 @@ module.exports = class Util { return new Promise(res => fs.access(filepath, fs.constants.F_OK, error => res(!error))); } + static getStateDir() { + return process.env.XIAO_STATE_DIR + ? path.resolve(process.env.XIAO_STATE_DIR) + : path.join(__dirname, '..'); + } + + static resolveStatePath(fileName) { + return path.join(Util.getStateDir(), fileName); + } + static stripInvites(str, { guild = true, bot = true, text = '[redacted invite]' } = {}) { if (!str) return ''; if (guild) str = str.replace(inviteRegex, text);