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 EventEmitter from "node:events";
import DiscordService from "services/discord.service"; import DiscordService from "services/discord.service";
import { WaterMeService } from "services/water-me.service"; import { WaterMeService } from "services/water-me.service";
import config from "config";
export default class DiscordController extends EventEmitter { export default class DiscordController extends EventEmitter {
private discordService!: DiscordService; private discordService!: DiscordService;
@ -20,8 +21,17 @@ export default class DiscordController extends EventEmitter {
this.discordService = new DiscordService(); this.discordService = new DiscordService();
this.waterMeService = new WaterMeService(); this.waterMeService = new WaterMeService();
// log when running // log when running
client.once("ready", () => { client.once("ready", async () => {
console.log("Listening..."); 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 // listen for interactions
client.on("interactionCreate", this.handleInteraction.bind(this)); client.on("interactionCreate", this.handleInteraction.bind(this));

View File

@ -1,7 +1,18 @@
import config from "config"; import config from "config";
import client from "lib/client"; import client from "lib/client";
import { getRandomInt } from "lib/utils";
export class GreetingService { 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() { async greet() {
const channels = client.channels; const channels = client.channels;
@ -11,4 +22,14 @@ export class GreetingService {
await channel.send({ content: "HALLOOOO" }); 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() { getReply() {
const thirstyReplies = [ const thirstyReplies = [
"... wow das wars schon???", "... wow das wars schon??? ich brauche noch mehr wasser :(",
"dankeeeee!!!! ich waer fast verdurstet :(((", "dankeeeee!!!! ich waer fast verdurstet :(((",
"*roelpssssss*", "*roelpssssss*",
]; ];
@ -67,6 +67,7 @@ export class WaterMeService {
const reply = this.getReply(); const reply = this.getReply();
this.waterLevel++; this.waterLevel++;
console.log(this.waterLevel);
return { return {
reply, reply,
@ -77,7 +78,7 @@ export class WaterMeService {
const result = this.waterMe(); const result = this.waterMe();
const moreButton = new ButtonBuilder() const moreButton = new ButtonBuilder()
.setCustomId("more") .setCustomId("moreWater")
.setLabel("mehr") .setLabel("mehr")
.setStyle(ButtonStyle.Secondary); .setStyle(ButtonStyle.Secondary);

View File

@ -4,7 +4,7 @@ import { GreetingService } from "services/greeting.service";
const greetingService = new GreetingService(); const greetingService = new GreetingService();
new CronJob( new CronJob(
"0 */1 * * * *", // cronTime "0 */30 7-23 * * *", // cronTime
async () => { async () => {
console.log("called greeting"); console.log("called greeting");
await greetingService.greet(); await greetingService.greet();
@ -13,4 +13,15 @@ new CronJob(
true, // start true, // start
"Europe/Berlin", // timeZone "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. // 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(); const waterMeService = new WaterMeService();
new CronJob( new CronJob(
"0 0 */2 * * *", // cronTime "0 0 0 */1 * *", // cronTime
async () => { async () => {
console.log("isThirsty()"); console.log("isThirsty()");
await waterMeService.isThirsty(); await waterMeService.isThirsty();