Refactor Discord gateway and bounty workflow for issue #1#4
Open
nellupop wants to merge 19 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the Discord bot gateway to delegate interaction/message/member handling to dedicated NestJS services, improves type safety across command/handler entrypoints, and introduces auto-thread creation for proposals and bounty feed notifications.
Changes:
- Split
discord.gateway.tsinto smaller services (DiscordInteractionService,DiscordMessageService,DiscordMemberService) and simplified slash-command registration. - Added
DiscordThreadServiceand integrated auto-thread creation for proposals and bounty feed posts. - Removed unsafe
anyusage / eslint disables from multiple handlers and commands; improved Discord/GitHub API typing and error logging.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/discord/discord.gateway.ts | Reduced gateway responsibilities; wires Discord.js events to injected services; slash command registration refactor. |
| src/discord/discord.module.ts | Registers new Discord services/providers in the Nest module. |
| src/discord/services/discord-interaction.service.ts | Centralized interaction routing (commands/buttons) with typed Discord.js interactions. |
| src/discord/services/discord-message.service.ts | Centralized message moderation + quest auto-completion + verify channel bootstrapping. |
| src/discord/services/discord-member.service.ts | Centralized guild member join handling. |
| src/discord/services/discord-thread.service.ts | New service to create Discord threads from messages via Discord REST API. |
| src/discord/services/discord-notification.service.ts | Refactored notification posting and added bounty-feed auto-threading. |
| src/discord/commands/propose.ts | Added proposal auto-thread creation and persisted threadCreated on Proposal record. |
| src/discord/services/discord-xp.service.ts | Removed stub-user creation; now skips XP awards when no user record exists. |
| src/discord/services/discord-role.service.ts | Improved typing for Discord REST responses and centralized error formatting. |
| src/discord/services/discord-guild.service.ts | Removed any usage in channel lookup and improved error formatting. |
| src/discord/handlers/discord-verify.service.ts | Removed eslint disables; typed ButtonInteraction; improved ephemeral replies and error formatting. |
| src/discord/handlers/discord-setup.service.ts | Removed eslint disable; typed ChatInputCommandInteraction; switched to ChannelType constants; improved error formatting. |
| src/discord/commands/daily.ts | Removed eslint disables; typed interaction; minor constant cleanup. |
| src/discord/commands/rank.ts | Typed interaction and fixed display-name handling. |
| src/discord/commands/quest.ts | Typed interaction; minor naming cleanup; explicit return types. |
| src/discord/commands/proposals.ts | Typed interaction; minor constant cleanup. |
| src/discord/commands/onboarding.ts | Typed interaction; uses ephemeral: true instead of flags. |
| src/discord/commands/leaderboard.ts | Typed interaction; cleaned up emoji logic and variable naming. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+290
to
+295
| threadCreated = await this.threadService.createThreadFromMessage({ | ||
| channelId: suggestionsChannelId, | ||
| messageId: channelMsg.id, | ||
| name: `proposal-${issueNumber}-${issueTitle || repo}`, | ||
| reason: 'DevLoot proposal discussion thread', | ||
| }); |
Comment on lines
+44
to
54
| private async postMessage(payload: unknown): Promise<string | null> { | ||
| if (!this.isConfigured) { | ||
| this.logger.warn('Discord not configured — skipping notification'); | ||
| return; | ||
| return null; | ||
| } | ||
|
|
||
| this.logger.debug( | ||
| `Sending Discord message to channel ${this.channelId}: ${content.slice(0, 80)}`, | ||
| ); | ||
|
|
||
| try { | ||
| const response = await axios.post( | ||
| `https://discord.com/api/v10/channels/${this.channelId}/messages`, | ||
| { content }, | ||
| payload, | ||
| { |
Comment on lines
+181
to
184
| ], | ||
| }, | ||
| `bounty-${issueNumber}`, | ||
| ); |
|
|
||
| const everyoneId = guild.id; | ||
| const verifiedId = createdRoles['Verified']; | ||
| const verifiedId = createdRoles.Verified!; |
| import { DiscordGuildService } from './services/discord-guild.service'; | ||
| import { DiscordMessageService } from './services/discord-message.service'; | ||
| import { DiscordInteractionService } from './services/discord-interaction.service'; | ||
| import { DiscordReactionService } from './services/discord-reaction.service'; |
Comment on lines
+12
to
+15
| import { DiscordInteractionService } from './services/discord-interaction.service'; | ||
| import { DiscordMessageService } from './services/discord-message.service'; | ||
| import { DiscordReactionService } from './services/discord-reaction.service'; | ||
| import { DiscordMemberService } from './services/discord-member.service'; |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 19 out of 19 changed files in this pull request and generated 6 comments.
Comments suppressed due to low confidence (1)
src/discord/handlers/discord-setup.service.ts:75
createdRoles.Verified!will throw later if the Verified role fails to create (or if Discord API errors), but the code continues even after pushing a failure message. Prefer handling the missing role explicitly (e.g., abort early with an error reply) instead of using a non-null assertion here, sinceverifiedIdis required for permission overwrites.
}
const everyoneId = guild.id;
const verifiedId = createdRoles.Verified!;
const categories = [
{
name: '🚪 ONBOARDING',
permissionOverwrites: [
{ id: everyoneId, allow: ['ViewChannel'], deny: ['SendMessages'] },
{ id: verifiedId, allow: ['ViewChannel', 'SendMessages'] },
],
Comment on lines
+8
to
+11
| import { DiscordMessageService } from './services/discord-message.service'; | ||
| import { DiscordInteractionService } from './services/discord-interaction.service'; | ||
| import { DiscordReactionService } from './services/discord-reaction.service'; | ||
| import { DiscordMemberService } from './services/discord-member.service'; |
Comment on lines
+44
to
54
| private async postMessage(payload: unknown): Promise<string | null> { | ||
| if (!this.isConfigured) { | ||
| this.logger.warn('Discord not configured — skipping notification'); | ||
| return; | ||
| return null; | ||
| } | ||
|
|
||
| this.logger.debug( | ||
| `Sending Discord message to channel ${this.channelId}: ${content.slice(0, 80)}`, | ||
| ); | ||
|
|
||
| try { | ||
| const response = await axios.post( | ||
| `https://discord.com/api/v10/channels/${this.channelId}/messages`, | ||
| { content }, | ||
| payload, | ||
| { |
Comment on lines
+290
to
+295
| threadCreated = await this.threadService.createThreadFromMessage({ | ||
| channelId: suggestionsChannelId, | ||
| messageId: channelMsg.id, | ||
| name: `proposal-${issueNumber}-${issueTitle || repo}`, | ||
| reason: 'DevLoot proposal discussion thread', | ||
| }); |
Comment on lines
+171
to
184
| await this.postFeedMessage( | ||
| { | ||
| embeds: [ | ||
| { | ||
| title: '🎯 New Bounty Created', | ||
| description: `[${owner}/${repo}](https://github.com/${owner}/${repo})`, | ||
| fields, | ||
| color: 0x2ecc71, | ||
| timestamp: new Date().toISOString(), | ||
| }, | ||
| ], | ||
| }, | ||
| `bounty-${issueNumber}`, | ||
| ); |
Comment on lines
+21
to
+24
| if (!threadName) { | ||
| this.logger.warn('Thread name resolved to empty string — skipping'); | ||
| return false; | ||
| } |
| `[xp] Created stub user for ${userId} (githubId: ${user.githubId}), +${amount} XP`, | ||
| if (!user) { | ||
| this.logger.warn( | ||
| `[xp] Skipping +${amount} for ${userId} — no onboarded user record found`, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1
Payout address: S7XOQVE3KZMMICA4WULHYDONGJ3DGM3IR24OQJ3CK35YPCERSGFWSCZMUQ