Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions application/command/onlyCodeQuestionsCommand.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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()
Copy link
Copy Markdown
Contributor

@diomonogatari diomonogatari Sep 4, 2025

Choose a reason for hiding this comment

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

image embeds are overkill imo.

We normally use this command when someone joins and starts asking if someone can help them with some PC problem or GTA Cheat or whatever.

If you want to think of a styling improvement, maybe markdown in the message body would be enough

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes Markdown is another easy solution, i usually use embeds because you can input footers and/or icons on them, i usually produce hundreds of them and they are not THAT heavy, but they are simple to edit and manipulate
The idea was to get rid of simple texting, which can introduce ping flaws, but Markdown also solves it yes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

adding !oc @someUserToBeMentioned would be a lukewarm feature but I can see some general value in case the chat is too long already.

Maybe it's a nice-to-have and nice-to-have's aren't that problematic for this community-based bot.

As for the embed, shouldn't be a problem as long as it doesn't occupy a lot of the user-space.

Just my 2 cents. I'm not a maintainer, just a casual contributor

.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." })
.setTimestamp();

await this.chatService.sendEmbedToChannel(embed, channelId, content);
}
}
3 changes: 3 additions & 0 deletions domain/service/chatService.ts
Original file line number Diff line number Diff line change
@@ -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;
}
21 changes: 15 additions & 6 deletions infrastructure/service/discordChatService.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -7,14 +7,23 @@ export default class DiscordChatService implements ChatService {
async sendMessageToChannel(message: string, channelId: string): Promise<void> {
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<void> {
const channel = await this.client.channels.fetch(channelId);

if (!channel || !channel.isTextBased()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

there's code duplication in l.20-22 and l.10-12

Could improve with a function that always returns a TextChannel or throws an Error

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,
});
}
}