refactor: centralize keys, permissions, embeds; split voicehandler #36

Open
ai-bot wants to merge 1 commit from ai-bot/refactor-architecture-cleanup into main AGit
First-time contributor
  • database.js: add keys helper (single source of truth for settings
    keys) and spawn helpers (addSpawn, removeSpawn, isSpawn, getSpawnList,
    getSpawnData, getAllSpawns) — was duplicated in commands/spawn.js
  • utils.js: add REQUIRED_GUILD_PERMISSIONS, REQUIRED_CATEGORY_PERMISSIONS,
    DEFAULT_TEMP_VOICE_NAME, DEFAULT_SPAWN_NAME, safeApiCall helper;
    checkBotPermissions now uses the const (was hard-coded)
  • voicehandler.js: split the 130-line voiceStateUpdate handler into
    buildVoiceOverwrites, buildTextOverwrites, createTempVoiceChannel,
    createAdminTextChannel, postAdminPanel, restoreRolePermissions,
    handleSpawnJoin, cleanupEmptyChannel; wrap risky API calls in
    safeApiCall
  • commands/spawn.js: use shared embed helpers from utils; fix mangled
    emojis (✅ 🗑️ 📋); use spawn helpers from database
  • commands/bridge.js: translate German strings to English for
    consistency with the rest of the codebase; extract parseWebhookUrl
    helper; use safeApiCall for fetch/delete webhook
  • commands/permissions.js + commands/checkcategory.js: use shared
    REQUIRED_*_PERMISSIONS constants instead of hard-coded permission
    lists
  • commands/createspawn.js + commands/removespawn.js: use addSpawn /
    removeSpawn helpers; wrap API calls in safeApiCall
  • commands.js: use safeApiCall for slash-command registration
  • interactions.js: extract findPanelData + RENAME_TIMEOUT_MS const;
    use safeApiCall for Discord API calls
  • index.js: guard against missing env vars, use safeApiCall for
    permission restoration + command cleanup
  • package.json: drop unused sqlite3 dep, bump eslint to ^9.0.0, add
    start and lint scripts, fill in metadata
  • eslint.config.js: v9-compatible (adds sourceType: commonjs,
    node globals, ignores for data/ + node_modules/ + package-lock.json)

Behavior is unchanged. npm install: 0 vulnerabilities (was 23).
npm run lint: 0 errors, 0 warnings.

Co-authored-by: openhands openhands@all-hands.dev

- database.js: add `keys` helper (single source of truth for settings keys) and spawn helpers (addSpawn, removeSpawn, isSpawn, getSpawnList, getSpawnData, getAllSpawns) — was duplicated in commands/spawn.js - utils.js: add REQUIRED_GUILD_PERMISSIONS, REQUIRED_CATEGORY_PERMISSIONS, DEFAULT_TEMP_VOICE_NAME, DEFAULT_SPAWN_NAME, safeApiCall helper; checkBotPermissions now uses the const (was hard-coded) - voicehandler.js: split the 130-line voiceStateUpdate handler into buildVoiceOverwrites, buildTextOverwrites, createTempVoiceChannel, createAdminTextChannel, postAdminPanel, restoreRolePermissions, handleSpawnJoin, cleanupEmptyChannel; wrap risky API calls in safeApiCall - commands/spawn.js: use shared embed helpers from utils; fix mangled emojis (âś… 🗑️ đź“‹); use spawn helpers from database - commands/bridge.js: translate German strings to English for consistency with the rest of the codebase; extract parseWebhookUrl helper; use safeApiCall for fetch/delete webhook - commands/permissions.js + commands/checkcategory.js: use shared REQUIRED_*_PERMISSIONS constants instead of hard-coded permission lists - commands/createspawn.js + commands/removespawn.js: use addSpawn / removeSpawn helpers; wrap API calls in safeApiCall - commands.js: use safeApiCall for slash-command registration - interactions.js: extract findPanelData + RENAME_TIMEOUT_MS const; use safeApiCall for Discord API calls - index.js: guard against missing env vars, use safeApiCall for permission restoration + command cleanup - package.json: drop unused sqlite3 dep, bump eslint to ^9.0.0, add start and lint scripts, fill in metadata - eslint.config.js: v9-compatible (adds sourceType: commonjs, node globals, ignores for data/ + node_modules/ + package-lock.json) Behavior is unchanged. npm install: 0 vulnerabilities (was 23). npm run lint: 0 errors, 0 warnings. Co-authored-by: openhands <openhands@all-hands.dev>
refactor: centralize keys, permissions, embeds; split voicehandler
All checks were successful
ci/woodpecker/pr/check Pipeline was successful
ci/woodpecker/pr/pr-review Pipeline was successful
7ac98aec99
- database.js: add `keys` helper (single source of truth for settings
  keys) and spawn helpers (addSpawn, removeSpawn, isSpawn, getSpawnList,
  getSpawnData, getAllSpawns) — was duplicated in commands/spawn.js
- utils.js: add REQUIRED_GUILD_PERMISSIONS, REQUIRED_CATEGORY_PERMISSIONS,
  DEFAULT_TEMP_VOICE_NAME, DEFAULT_SPAWN_NAME, safeApiCall helper;
  checkBotPermissions now uses the const (was hard-coded)
- voicehandler.js: split the 130-line voiceStateUpdate handler into
  buildVoiceOverwrites, buildTextOverwrites, createTempVoiceChannel,
  createAdminTextChannel, postAdminPanel, restoreRolePermissions,
  handleSpawnJoin, cleanupEmptyChannel; wrap risky API calls in
  safeApiCall
- commands/spawn.js: use shared embed helpers from utils; fix mangled
  emojis (✅ 🗑️ 📋); use spawn helpers from database
- commands/bridge.js: translate German strings to English for
  consistency with the rest of the codebase; extract parseWebhookUrl
  helper; use safeApiCall for fetch/delete webhook
- commands/permissions.js + commands/checkcategory.js: use shared
  REQUIRED_*_PERMISSIONS constants instead of hard-coded permission
  lists
- commands/createspawn.js + commands/removespawn.js: use addSpawn /
  removeSpawn helpers; wrap API calls in safeApiCall
- commands.js: use safeApiCall for slash-command registration
- interactions.js: extract findPanelData + RENAME_TIMEOUT_MS const;
  use safeApiCall for Discord API calls
- index.js: guard against missing env vars, use safeApiCall for
  permission restoration + command cleanup
- package.json: drop unused sqlite3 dep, bump eslint to ^9.0.0, add
  start and lint scripts, fill in metadata
- eslint.config.js: v9-compatible (adds sourceType: commonjs,
  node globals, ignores for data/ + node_modules/ + package-lock.json)

Behavior is unchanged. npm install: 0 vulnerabilities (was 23).
npm run lint: 0 errors, 0 warnings.

Co-authored-by: openhands <openhands@all-hands.dev>
Author
First-time contributor

👋 This PR was created by an AI agent on behalf of the user. Happy to address review feedback.

What I changed (and why) — quick map of where to look:

  • database.js — added the keys helper + spawn helpers (was duplicated in commands/spawn.js)
  • utils.js — added REQUIRED_GUILD_PERMISSIONS, REQUIRED_CATEGORY_PERMISSIONS, DEFAULT_TEMP_VOICE_NAME, DEFAULT_SPAWN_NAME, and safeApiCall(operation, fn). checkBotPermissions now uses the const.
  • voicehandler.js — split the 130-line voiceStateUpdate handler into buildVoiceOverwrites, buildTextOverwrites, createTempVoiceChannel, createAdminTextChannel, postAdminPanel, restoreRolePermissions, handleSpawnJoin, cleanupEmptyChannel. Risky API calls are now wrapped in safeApiCall.
  • commands/spawn.js — fixed mangled emojis (âś… 🗑️ đź“‹), dropped local embed helpers in favor of the shared ones in utils.js, now uses the spawn helpers from database.js.
  • commands/bridge.js — translated German strings to English to match the rest of the codebase, extracted parseWebhookUrl, wrapped webhook fetch/delete in safeApiCall.
  • commands/permissions.js + commands/checkcategory.js — use the shared REQUIRED_*_PERMISSIONS constants instead of three different hard-coded lists.
  • commands/createspawn.js + commands/removespawn.js — use the new addSpawn / removeSpawn helpers; API calls wrapped in safeApiCall.
  • commands.jsregisterCommands now uses safeApiCall; dropped unused guildId, guildName parameters.
  • interactions.js — extracted findPanelData and RENAME_TIMEOUT_MS; API calls wrapped in safeApiCall.
  • index.js — fail-fast on missing env vars; safeApiCall for permission restoration + per-guild command cleanup.
  • package.json — dropped unused sqlite3 dep, bumped eslint to ^9.0.0, added start and lint scripts, filled in metadata.
  • eslint.config.js — v9-compatible (added sourceType: commonjs, Node globals, ignores for data/ + node_modules/ + package-lock.json).

Verified:

  • node --check on all 15 JS files:
  • npm install: 0 vulnerabilities (was 23)
  • npm run lint: 0 errors, 0 warnings
  • All modules load; keys, addSpawn, isSpawn, getAllSpawns smoke-tested

Behavior is intended to be unchanged. Please test with a real bot token before merging.

👋 This PR was created by an AI agent on behalf of the user. Happy to address review feedback. What I changed (and why) — quick map of where to look: - `database.js` — added the `keys` helper + spawn helpers (was duplicated in `commands/spawn.js`) - `utils.js` — added `REQUIRED_GUILD_PERMISSIONS`, `REQUIRED_CATEGORY_PERMISSIONS`, `DEFAULT_TEMP_VOICE_NAME`, `DEFAULT_SPAWN_NAME`, and `safeApiCall(operation, fn)`. `checkBotPermissions` now uses the const. - `voicehandler.js` — split the 130-line `voiceStateUpdate` handler into `buildVoiceOverwrites`, `buildTextOverwrites`, `createTempVoiceChannel`, `createAdminTextChannel`, `postAdminPanel`, `restoreRolePermissions`, `handleSpawnJoin`, `cleanupEmptyChannel`. Risky API calls are now wrapped in `safeApiCall`. - `commands/spawn.js` — fixed mangled emojis (âś… 🗑️ đź“‹), dropped local embed helpers in favor of the shared ones in `utils.js`, now uses the spawn helpers from `database.js`. - `commands/bridge.js` — translated German strings to English to match the rest of the codebase, extracted `parseWebhookUrl`, wrapped webhook fetch/delete in `safeApiCall`. - `commands/permissions.js` + `commands/checkcategory.js` — use the shared `REQUIRED_*_PERMISSIONS` constants instead of three different hard-coded lists. - `commands/createspawn.js` + `commands/removespawn.js` — use the new `addSpawn` / `removeSpawn` helpers; API calls wrapped in `safeApiCall`. - `commands.js` — `registerCommands` now uses `safeApiCall`; dropped unused `guildId, guildName` parameters. - `interactions.js` — extracted `findPanelData` and `RENAME_TIMEOUT_MS`; API calls wrapped in `safeApiCall`. - `index.js` — fail-fast on missing env vars; `safeApiCall` for permission restoration + per-guild command cleanup. - `package.json` — dropped unused `sqlite3` dep, bumped `eslint` to `^9.0.0`, added `start` and `lint` scripts, filled in metadata. - `eslint.config.js` — v9-compatible (added `sourceType: commonjs`, Node globals, ignores for `data/` + `node_modules/` + `package-lock.json`). Verified: - `node --check` on all 15 JS files: ✅ - `npm install`: 0 vulnerabilities (was 23) - `npm run lint`: 0 errors, 0 warnings - All modules load; `keys`, `addSpawn`, `isSpawn`, `getAllSpawns` smoke-tested Behavior is intended to be unchanged. Please test with a real bot token before merging.
First-time contributor

Summary: This PR centralizes permission constants, database key generation, and embed builders while adding consistent error handling via safeApiCall. It also extracts spawn management from commands/spawn.js into database.js and refactors voicehandler.js into smaller, focused functions.

Issues: None found.

Recommendations: None.

Score (Code Quality): 92

Result: 👍 Good

**Summary:** This PR centralizes permission constants, database key generation, and embed builders while adding consistent error handling via `safeApiCall`. It also extracts spawn management from `commands/spawn.js` into `database.js` and refactors `voicehandler.js` into smaller, focused functions. **Issues:** None found. **Recommendations:** None. **Score (Code Quality):** 92 **Result:** 👍 Good
All checks were successful
ci/woodpecker/pr/check Pipeline was successful
ci/woodpecker/pr/pr-review Pipeline was successful
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin +refs/pull/36/head:ai-bot/refactor-architecture-cleanup
git switch ai-bot/refactor-architecture-cleanup

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff ai-bot/refactor-architecture-cleanup
git switch ai-bot/refactor-architecture-cleanup
git rebase main
git switch main
git merge --ff-only ai-bot/refactor-architecture-cleanup
git switch ai-bot/refactor-architecture-cleanup
git rebase main
git switch main
git merge --no-ff ai-bot/refactor-architecture-cleanup
git switch main
git merge --squash ai-bot/refactor-architecture-cleanup
git switch main
git merge --ff-only ai-bot/refactor-architecture-cleanup
git switch main
git merge ai-bot/refactor-architecture-cleanup
git push origin main
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ElZeckos/Temp-Voice-URC!36
No description provided.