From 3175e94681319212bb30d4cb05bd05f5f15f054c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20Jurmanovi=C4=87?= Date: Thu, 10 Mar 2022 19:04:04 +0100 Subject: [PATCH] legica --- controllers/Client.controller.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/controllers/Client.controller.ts b/controllers/Client.controller.ts index 6fcbdd5..85bd538 100644 --- a/controllers/Client.controller.ts +++ b/controllers/Client.controller.ts @@ -7,17 +7,20 @@ class ClientController { constructor(private client: Client) {} public register = (): void => { + this.sendMessage(); this.client.on("ready", (): void => { - cron.schedule("0 12 * * *", async () => { - const href = await getFirstHtml(); - const { img, title } = await getImgTitle(href); + cron.schedule("0 12 * * *", this.sendMessage); + }); + }; - this.client.channels.cache.forEach((channel) => { - if (channel.type !== "text") return null; - const embeddedMessage = new MessageEmbed().setTitle(title).setImage(img); - (channel as TextChannel).send(embeddedMessage); - }); - }); + private sendMessage = async (): Promise => { + const href = await getFirstHtml(); + const { img, title } = await getImgTitle(href); + + this.client.channels.cache.forEach((channel) => { + if (channel.type !== "text") return null; + const embeddedMessage = new MessageEmbed().setTitle(title).setImage(img); + (channel as TextChannel).send(embeddedMessage); }); }; }