add greeting

add locales
This commit is contained in:
mo
2026-02-22 00:09:27 +01:00
parent 453577f1b2
commit bc0a6f2526
25 changed files with 183 additions and 449 deletions

View File

@@ -0,0 +1,71 @@
import type { MessagesServiceInterface } from "@avocadi/bot-core/entities/messages/messages.service";
import { createLogger } from "@avocadi/bot-core/lib/logger";
import {
type Channel,
ChannelType,
type DMChannel,
type Message,
type MessagePayload,
type PartialDMChannel,
type User,
} from "discord.js";
import { logChannelService } from "features/log-channel/log-channel.service";
import client from "lib/client";
export class MessagesService
implements MessagesServiceInterface<User, Message, Channel, MessagePayload>
{
private logger = createLogger("MessagesService");
async sendToUser(userInput: User, message: MessagePayload): Promise<void> {
const user = await client.users.fetch(userInput.id);
if (user) {
await user.send(message);
} else {
this.logger.error(`User with ID ${userInput.id} not found.`);
}
}
async logMessage(message: Message): Promise<void> {
let recipient: User | null = null;
if (
message.channel.isDMBased() &&
message.channel.type !== ChannelType.GroupDM
) {
const channel = message.channel as DMChannel | PartialDMChannel;
recipient = channel.recipient;
}
let logMessage: string;
if (recipient) {
logMessage = `<@${message.author.id}> sent a message to <@${recipient.id}>:\n"${message.content}"`;
} else {
logMessage = `<@${message.author.id}> sent a message:\n"${message.content}"`;
}
await logChannelService.sendLogMessage(logMessage);
}
async sendToChannel(
channel: Channel,
createMessageInput: MessagePayload,
): Promise<void> {
const fetchedChannel = await client.channels.fetch(channel.id);
if (fetchedChannel?.isTextBased() && fetchedChannel.isSendable()) {
await fetchedChannel.send(createMessageInput);
} else {
this.logger.error(
`Channel with ID ${channel.id} not found or is not text-based.`,
);
throw new Error("Channel not found or is not text-based.");
}
}
}
export const messagesService = new MessagesService();