Skip to content

Refactor Discord gateway and add auto-threading#5

Open
coreymull wants to merge 1 commit into
p2arthur:mainfrom
coreymull:bounty-13-complete-discord-refactor
Open

Refactor Discord gateway and add auto-threading#5
coreymull wants to merge 1 commit into
p2arthur:mainfrom
coreymull:bounty-13-complete-discord-refactor

Conversation

@coreymull
Copy link
Copy Markdown

Closes #1

Summary

  • reduced discord.gateway.ts from 689 lines to 220 lines by moving command routing, proposal voting, channel moderation, verify-channel boot setup, and weekly Chef scheduling into injectable services
  • replaced untyped interaction handler entrypoints with Discord.js types across gateway handlers, commands, setup, and verification
  • added proposal auto-threading with threadCreated persistence, plus bounty-feed thread creation after notification posts
  • replaced random negative githubId stub user creation with a safe skip for unlinked Discord users
  • typed OpenRouter/GitHub/Discord API responses so the existing lint command passes cleanly

Before / After Structure

Before: discord.gateway.ts handled client setup, slash routing, button handling, message moderation, reaction voting, verify-channel setup, sync-points, and Chef scheduling.

After:

  • src/discord/discord.gateway.ts: client initialization, slash-command registration, event wiring
  • src/discord/services/discord-command-router.service.ts: slash/button routing, sync-points, admin Chef command
  • src/discord/services/proposal-vote.service.ts: reaction vote handling
  • src/discord/services/channel-moderation.service.ts: bot-only channel cleanup and quest message hooks
  • src/discord/services/chef-scheduler.service.ts: weekly Chef interval
  • src/discord/services/discord-thread.service.ts: proposal and bounty notification thread creation
  • src/discord/handlers/discord-setup.service.ts: setup-server plus verify-channel bootstrapping

Verification

  • npm run build
  • DATABASE_URL=postgresql://devloot:devloot@localhost:5432/devloot npx prisma generate
  • DATABASE_URL=postgresql://devloot:devloot@localhost:5432/devloot npm run lint
  • wc -l src/discord/discord.gateway.ts -> 220
  • rg -n "eslint-disable|\bany\b" src/discord -> no matches

Payout

Algorand payout address: R7NHEHQY6DZJM74L442ML3REU66F7XFZ6FVHGUH4MI7FXPPLMMRFUJBHEM

Disclosure: this contribution was prepared by an autonomous coding agent under the coreymull account.

Copilot AI review requested due to automatic review settings May 11, 2026 01:10
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Discord gateway from a monolithic handler into multiple NestJS injectable services, improves type-safety across Discord interaction entrypoints, and adds auto-threading for proposals and bounty-feed notifications.

Changes:

  • Extracts interaction routing, proposal voting, message moderation, chef scheduling, and thread creation into dedicated services wired by a slimmer DiscordGateway.
  • Replaces any-typed Discord handlers/commands with Discord.js v14 interaction types.
  • Adds proposal auto-thread creation (persisted via Proposal.threadCreated) and bounty-feed thread creation after posting notifications.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/main.ts Uses void bootstrap() to satisfy linting around unhandled promises.
src/discord/services/proposal-vote.service.ts New service handling reaction-based proposal voting + XP.
src/discord/services/discord-xp.service.ts Removes stub user creation; skips XP for unlinked Discord users.
src/discord/services/discord-thread.service.ts New service to create proposal threads (discord.js) and bounty threads (REST).
src/discord/services/discord-role.service.ts Adds response typing + centralized axios error formatting.
src/discord/services/discord-notification.service.ts Adds messageId return for embeds and creates bounty threads after posting.
src/discord/services/discord-guild.service.ts Removes any from channel lookup.
src/discord/services/discord-command-router.service.ts New central router for slash commands + button interactions.
src/discord/services/chef-scheduler.service.ts New interval-based weekly “Chef” check scheduler.
src/discord/services/channel-moderation.service.ts New service for bot-only channel cleanup + quest hooks.
src/discord/handlers/discord-verify.service.ts Types button interaction and improves channel narrowing.
src/discord/handlers/discord-setup.service.ts Types setup interaction, adds verify-channel bootstrap helper, and improves permission/channel typing.
src/discord/discord.module.ts Registers newly extracted services/providers in the module.
src/discord/discord.gateway.ts Slimmed gateway: registers slash commands, wires events to services, and runs boot tasks on ready.
src/discord/commands/rank.ts Types interaction as ChatInputCommandInteraction.
src/discord/commands/quest.ts Types interaction + return types for quest methods.
src/discord/commands/propose.ts Types interaction, types GitHub API response, and triggers proposal thread creation + persistence.
src/discord/commands/proposals.ts Types interaction as ChatInputCommandInteraction.
src/discord/commands/onboarding.ts Types interaction as ChatInputCommandInteraction.
src/discord/commands/leaderboard.ts Types interaction as ChatInputCommandInteraction.
src/discord/commands/daily.ts Removes eslint-disables and types interaction as ChatInputCommandInteraction.
src/ai/ai.service.ts Types OpenRouter responses and hardens parsing/joins.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

});
await this.prisma.proposal.update({
where: { id: proposal.id },
data: { upvotes: { decrement: isUpvote ? 1 : 0 } },

this.client.on('error', (err) => {
this.logger.error(`Discord client error: ${err.message}`);
this.client.on('clientReady', () => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Devloot Discord bot Bounty #1 — Gateway Refactor, Type Safety & Auto-Threading

2 participants