refactor water me service

remove "text-based-feature"
improve messages service interface
implement more features for fluxer
This commit is contained in:
2026-02-18 18:38:09 +01:00
parent 84b851f60f
commit 0a460800b6
20 changed files with 202 additions and 56 deletions

View File

@@ -3,5 +3,5 @@ import { logger } from "lib/common-logger";
export const handleShutdown = async () => {
logger.info("bot is shutting down...");
await logChannelService.sendLogMessage("bot is shutting down...");
await logChannelService.sendLogMessage("ich geh schlafen...");
};

View File

@@ -1,9 +1,11 @@
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";
@@ -11,11 +13,11 @@ import { logChannelService } from "features/log-channel/log-channel.service";
import client from "lib/client";
export class MessagesService
implements MessagesServiceInterface<User, Message>
implements MessagesServiceInterface<User, Message, Channel, MessagePayload>
{
private logger = createLogger("MessagesService");
async sendToUser(userInput: User, message: string): Promise<void> {
async sendToUser(userInput: User, message: MessagePayload): Promise<void> {
const user = await client.users.fetch(userInput.id);
if (user) {
@@ -47,6 +49,23 @@ export class MessagesService
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();

View File

@@ -4,9 +4,7 @@ import {
ButtonBuilder,
type ButtonInteraction,
ButtonStyle,
type CacheType,
type ChatInputCommandInteraction,
type Interaction,
} from "discord.js";
import { waterMeService } from "./water-me.service";

View File

@@ -1,8 +1,4 @@
import { WaterMeService } from "@avocadi/bot-core/features/water-me/water-me.service";
import { messagesService } from "entitites/messages/messages.service";
export const waterMeService = new WaterMeService({
channelId: "123",
handleMessageSend: async (message, channelId) => {
console.log(`Sending message to channel ${channelId}: ${message}`);
},
});
export const waterMeService = new WaterMeService(messagesService);