From a11ac4080f3d1dfbbb723ae9a2441ceaa2715dfd Mon Sep 17 00:00:00 2001 From: Master Chief <64928908+MrProSpectrumPT@users.noreply.github.com> Date: Thu, 4 Sep 2025 14:47:18 +0100 Subject: [PATCH 1/4] Update onlyCodeQuestionsCommand.ts --- .../command/onlyCodeQuestionsCommand.ts | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/application/command/onlyCodeQuestionsCommand.ts b/application/command/onlyCodeQuestionsCommand.ts index 2aea596..ebad016 100644 --- a/application/command/onlyCodeQuestionsCommand.ts +++ b/application/command/onlyCodeQuestionsCommand.ts @@ -1,19 +1,31 @@ import { Command, Context } from "../../types"; import ChatService from "../../domain/service/chatService"; +import { EmbedBuilder } from "discord.js"; export default class OnlyCodeQuestionsCommand implements Command { readonly name = "!oc"; private chatService: ChatService; - private readonly message: string = - ":warning: Este servidor é APENAS para questões relacionadas com programação! :warning:"; - constructor(chatService: ChatService) { this.chatService = chatService; } async execute(context: Context): Promise { - await this.chatService.sendMessageToChannel(this.message, context.channelId); + const { message, channelId } = context; + + const mentionedUser = message.mentions.users.first(); + const userIdMatch = message.content.match(/<@!?(\d+)>|(\d{17,20})/); + const userId = mentionedUser?.id || userIdMatch?.[1] || userIdMatch?.[2]; + const content = userId ? `<@${userId}>` : undefined; + + const embed = new EmbedBuilder() + .setTitle("🚫 Canal Exclusivo para Programação") + .setDescription("Este servidor é **APENAS** para questões relacionadas com **programação**!") + .setColor(0xFF0000) + .setFooter({ text: "Por favor mantém o foco no tema certo." }) + .setTimestamp(); + + await this.chatService.sendEmbedToChannel(embed, channelId, content); } } From 25f98bca92356f6eb645e178b9c5432b783e9240 Mon Sep 17 00:00:00 2001 From: Master Chief <64928908+MrProSpectrumPT@users.noreply.github.com> Date: Thu, 4 Sep 2025 14:49:42 +0100 Subject: [PATCH 2/4] Update chatService.ts --- domain/service/chatService.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/domain/service/chatService.ts b/domain/service/chatService.ts index 0133401..5ea749a 100644 --- a/domain/service/chatService.ts +++ b/domain/service/chatService.ts @@ -1,3 +1,6 @@ +import { EmbedBuilder } from "discord.js"; + export default interface ChatService { sendMessageToChannel(message: string, channelId: string): void; + sendEmbedToChannel(embed: EmbedBuilder, channelId: string, content?: string): void; } From 209852afa8de9f9aefbf3dff9b90151da2874795 Mon Sep 17 00:00:00 2001 From: Master Chief <64928908+MrProSpectrumPT@users.noreply.github.com> Date: Thu, 4 Sep 2025 14:54:20 +0100 Subject: [PATCH 3/4] Update discordChatService.ts --- infrastructure/service/discordChatService.ts | 21 ++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/infrastructure/service/discordChatService.ts b/infrastructure/service/discordChatService.ts index 90228eb..255c029 100644 --- a/infrastructure/service/discordChatService.ts +++ b/infrastructure/service/discordChatService.ts @@ -1,4 +1,4 @@ -import { Client } from "discord.js"; +import { Client, EmbedBuilder, TextChannel } from "discord.js"; import ChatService from "../../domain/service/chatService"; export default class DiscordChatService implements ChatService { @@ -7,14 +7,23 @@ export default class DiscordChatService implements ChatService { async sendMessageToChannel(message: string, channelId: string): Promise { const channel = await this.client.channels.fetch(channelId); - if (channel === null) { - throw new Error(`Channel with id ${channelId} not found!`); + if (!channel || !channel.isTextBased()) { + throw new Error(`Channel with id ${channelId} is not a text channel or was not found!`); } - if (!channel.isText()) { - throw new Error(`Channel with id ${channelId} is not a text channel!`); + await (channel as TextChannel).send(message); + } + + async sendEmbedToChannel(embed: EmbedBuilder, channelId: string, content?: string): Promise { + const channel = await this.client.channels.fetch(channelId); + + if (!channel || !channel.isTextBased()) { + throw new Error(`Channel with id ${channelId} is not a text channel or was not found!`); } - channel.send(message); + await (channel as TextChannel).send({ + embeds: [embed], + content: content ?? undefined, + }); } } From 8077af74e789df7f2c31d698327500b1938983fd Mon Sep 17 00:00:00 2001 From: Master Chief <64928908+MrProSpectrumPT@users.noreply.github.com> Date: Thu, 4 Sep 2025 16:06:45 +0100 Subject: [PATCH 4/4] Update onlyCodeQuestionsCommand.ts --- application/command/onlyCodeQuestionsCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/command/onlyCodeQuestionsCommand.ts b/application/command/onlyCodeQuestionsCommand.ts index ebad016..4d63369 100644 --- a/application/command/onlyCodeQuestionsCommand.ts +++ b/application/command/onlyCodeQuestionsCommand.ts @@ -20,7 +20,7 @@ export default class OnlyCodeQuestionsCommand implements Command { const content = userId ? `<@${userId}>` : undefined; const embed = new EmbedBuilder() - .setTitle("🚫 Canal Exclusivo para Programação") + .setTitle("🚫 Servidor Exclusivo para Programação") .setDescription("Este servidor é **APENAS** para questões relacionadas com **programação**!") .setColor(0xFF0000) .setFooter({ text: "Por favor mantém o foco no tema certo." })