Skip to content

Refactor Discord gateway and bounty workflow for issue #1#4

Open
nellupop wants to merge 19 commits into
p2arthur:mainfrom
nellupop:bounty-13-issue-1-refactor
Open

Refactor Discord gateway and bounty workflow for issue #1#4
nellupop wants to merge 19 commits into
p2arthur:mainfrom
nellupop:bounty-13-issue-1-refactor

Conversation

@nellupop
Copy link
Copy Markdown

@nellupop nellupop commented May 1, 2026

Closes #1

Payout address: S7XOQVE3KZMMICA4WULHYDONGJ3DGM3IR24OQJ3CK35YPCERSGFWSCZMUQ

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

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.ts into smaller services (DiscordInteractionService, DiscordMessageService, DiscordMemberService) and simplified slash-command registration.
  • Added DiscordThreadService and integrated auto-thread creation for proposals and bounty feed posts.
  • Removed unsafe any usage / 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';
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

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, since verifiedId is 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`,
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