refactor water me service
remove "text-based-feature" improve messages service interface implement more features for fluxer
This commit is contained in:
@@ -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...");
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -4,9 +4,7 @@ import {
|
||||
ButtonBuilder,
|
||||
type ButtonInteraction,
|
||||
ButtonStyle,
|
||||
type CacheType,
|
||||
type ChatInputCommandInteraction,
|
||||
type Interaction,
|
||||
} from "discord.js";
|
||||
import { waterMeService } from "./water-me.service";
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user