This commit is contained in:
moriese 2024-12-27 02:39:06 +01:00
parent c06ac10d09
commit 06ef16581c
7 changed files with 49 additions and 6 deletions

View File

@ -10,6 +10,7 @@ import client from "lib/client";
import EventEmitter from "node:events";
import DiscordService from "services/discord.service";
import { WaterMeService } from "services/water-me.service";
import config from "config";
export default class DiscordController extends EventEmitter {
private discordService!: DiscordService;
@ -20,8 +21,17 @@ export default class DiscordController extends EventEmitter {
this.discordService = new DiscordService();
this.waterMeService = new WaterMeService();
// log when running
client.once("ready", () => {
console.log("Listening...");
client.once("ready", async () => {
console.log("hello :)");
/*const channels = client.channels;
const channel = channels.cache.get(config.discord.channelId);
if (channel?.isTextBased && channel?.isSendable()) {
await channel.send({
content: "bin gerade erst aufgewacht :o",
});
}*/
});
// listen for interactions
client.on("interactionCreate", this.handleInteraction.bind(this));

View File

@ -1,7 +1,18 @@
import config from "config";
import client from "lib/client";
import { getRandomInt } from "lib/utils";
export class GreetingService {
private greetContent = ["HALLOOOO"] as const;
private sleepContent = ["zzzzZZ..", "*schnarch*"] as const;
getContent(asleep: boolean) {
if (asleep) {
return this.sleepContent[getRandomInt(0, this.sleepContent.length - 1)];
}
return this.greetContent[getRandomInt(0, this.greetContent.length - 1)];
}
async greet() {
const channels = client.channels;
@ -11,4 +22,14 @@ export class GreetingService {
await channel.send({ content: "HALLOOOO" });
}
}
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) });
}
}
}

View File

View File

@ -22,7 +22,7 @@ export class WaterMeService {
getReply() {
const thirstyReplies = [
"... wow das wars schon???",
"... wow das wars schon??? ich brauche noch mehr wasser :(",
"dankeeeee!!!! ich waer fast verdurstet :(((",
"*roelpssssss*",
];
@ -67,6 +67,7 @@ export class WaterMeService {
const reply = this.getReply();
this.waterLevel++;
console.log(this.waterLevel);
return {
reply,
@ -77,7 +78,7 @@ export class WaterMeService {
const result = this.waterMe();
const moreButton = new ButtonBuilder()
.setCustomId("more")
.setCustomId("moreWater")
.setLabel("mehr")
.setStyle(ButtonStyle.Secondary);

View File

@ -4,7 +4,7 @@ import { GreetingService } from "services/greeting.service";
const greetingService = new GreetingService();
new CronJob(
"0 */1 * * * *", // cronTime
"0 */30 7-23 * * *", // cronTime
async () => {
console.log("called greeting");
await greetingService.greet();
@ -13,4 +13,15 @@ new CronJob(
true, // start
"Europe/Berlin", // timeZone
);
new CronJob(
"0 */30 0-6 * * *", // cronTime
async () => {
console.log("called greeting");
await greetingService.sleep();
}, // onTick
null, // onComplete
true, // start
"Europe/Berlin", // timeZone
);
// job.start() is optional here because of the fourth parameter set to true.

View File

View File

@ -4,7 +4,7 @@ import { WaterMeService } from "services/water-me.service";
const waterMeService = new WaterMeService();
new CronJob(
"0 0 */2 * * *", // cronTime
"0 0 0 */1 * *", // cronTime
async () => {
console.log("isThirsty()");
await waterMeService.isThirsty();