avocadi-bot/src/actions/greeting/greeting.service.ts
2024-12-28 20:09:43 +01:00

35 lines
878 B
TypeScript

import config from "config";
import client from "lib/client";
import { getRandomInt } from "lib/utils";
import { greetContent, sleepContent } from "./greeting.components.ts";
export class GreetingService {
async greet() {
const channels = client.channels;
const channel = channels.cache.get(config.discord.channelId);
if (channel?.isTextBased && channel?.isSendable()) {
await channel.send({ content: this.getContent(false) });
}
}
async sleep() {
const channels = client.channels;
const channel = channels.cache.get(config.discord.channelId);
if (channel?.isTextBased && channel?.isSendable()) {
await channel.send({ content: this.getContent(true) });
}
}
getContent(asleep: boolean) {
if (asleep) {
return sleepContent[getRandomInt(0, sleepContent.length - 1)];
}
return greetContent[getRandomInt(0, greetContent.length - 1)];
}
}