refactor: centralize keys, permissions, embeds; split voicehandler #36
No reviewers
Labels
No labels
breaking
bug
dependency
docs
enhancement
feature
misc
refactor
security
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ElZeckos/Temp-Voice-URC!36
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "ai-bot/refactor-architecture-cleanup"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
keyshelper (single source of truth for settingskeys) and spawn helpers (addSpawn, removeSpawn, isSpawn, getSpawnList,
getSpawnData, getAllSpawns) — was duplicated in commands/spawn.js
DEFAULT_TEMP_VOICE_NAME, DEFAULT_SPAWN_NAME, safeApiCall helper;
checkBotPermissions now uses the const (was hard-coded)
buildVoiceOverwrites, buildTextOverwrites, createTempVoiceChannel,
createAdminTextChannel, postAdminPanel, restoreRolePermissions,
handleSpawnJoin, cleanupEmptyChannel; wrap risky API calls in
safeApiCall
emojis (✅ 🗑️ 📋); use spawn helpers from database
consistency with the rest of the codebase; extract parseWebhookUrl
helper; use safeApiCall for fetch/delete webhook
REQUIRED_*_PERMISSIONS constants instead of hard-coded permission
lists
removeSpawn helpers; wrap API calls in safeApiCall
use safeApiCall for Discord API calls
permission restoration + command cleanup
start and lint scripts, fill in metadata
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
👋 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 thekeyshelper + spawn helpers (was duplicated incommands/spawn.js)utils.js— addedREQUIRED_GUILD_PERMISSIONS,REQUIRED_CATEGORY_PERMISSIONS,DEFAULT_TEMP_VOICE_NAME,DEFAULT_SPAWN_NAME, andsafeApiCall(operation, fn).checkBotPermissionsnow uses the const.voicehandler.js— split the 130-linevoiceStateUpdatehandler intobuildVoiceOverwrites,buildTextOverwrites,createTempVoiceChannel,createAdminTextChannel,postAdminPanel,restoreRolePermissions,handleSpawnJoin,cleanupEmptyChannel. Risky API calls are now wrapped insafeApiCall.commands/spawn.js— fixed mangled emojis (âś… 🗑️ đź“‹), dropped local embed helpers in favor of the shared ones inutils.js, now uses the spawn helpers fromdatabase.js.commands/bridge.js— translated German strings to English to match the rest of the codebase, extractedparseWebhookUrl, wrapped webhook fetch/delete insafeApiCall.commands/permissions.js+commands/checkcategory.js— use the sharedREQUIRED_*_PERMISSIONSconstants instead of three different hard-coded lists.commands/createspawn.js+commands/removespawn.js— use the newaddSpawn/removeSpawnhelpers; API calls wrapped insafeApiCall.commands.js—registerCommandsnow usessafeApiCall; dropped unusedguildId, guildNameparameters.interactions.js— extractedfindPanelDataandRENAME_TIMEOUT_MS; API calls wrapped insafeApiCall.index.js— fail-fast on missing env vars;safeApiCallfor permission restoration + per-guild command cleanup.package.json— dropped unusedsqlite3dep, bumpedeslintto^9.0.0, addedstartandlintscripts, filled in metadata.eslint.config.js— v9-compatible (addedsourceType: commonjs, Node globals, ignores fordata/+node_modules/+package-lock.json).Verified:
node --checkon all 15 JS files: ✅npm install: 0 vulnerabilities (was 23)npm run lint: 0 errors, 0 warningskeys,addSpawn,isSpawn,getAllSpawnssmoke-testedBehavior is intended to be unchanged. Please test with a real bot token before merging.
Summary: This PR centralizes permission constants, database key generation, and embed builders while adding consistent error handling via
safeApiCall. It also extracts spawn management fromcommands/spawn.jsintodatabase.jsand refactorsvoicehandler.jsinto smaller, focused functions.Issues: None found.
Recommendations: None.
Score (Code Quality): 92
Result: 👍 Good
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.