Files
bot/core/src/features/water-me/water-me.service.ts
enricobuehler 0a460800b6 refactor water me service
remove "text-based-feature"
improve messages service interface
implement more features for fluxer
2026-02-18 18:38:09 +01:00

68 lines
1.6 KiB
TypeScript

import type { MessagesServiceInterface } from "entities/messages/messages.service";
import { createLogger } from "lib/logger";
import { getRandomInt } from "lib/utils";
export class WaterMeService {
waterLevel: number;
private logger = createLogger("WaterMeService");
private thirsty = 3 as const;
private enough = 10 as const;
messagesService: MessagesServiceInterface;
constructor(messagesService: MessagesServiceInterface) {
this.waterLevel = 0;
this.messagesService = messagesService;
}
getReply() {
const thirstyReplies = [
"... wow das wars schon??? ich brauche noch mehr wasser :(",
"dankeeeee!!!! ich waer fast verdurstet :(((",
"*roelpssssss*",
];
const fullReplies = [
"langsam reicht es :o",
"poah, das hat gut getan",
"das ist krass :3",
];
const tooMuchReplies = [
"ES REICHT!!!!",
"bitte hoer auf, ich platze gleich :(",
];
if (this.waterLevel <= this.thirsty) {
return thirstyReplies[getRandomInt(0, thirstyReplies.length - 1)];
}
if (this.waterLevel > this.thirsty && this.waterLevel <= this.enough) {
return fullReplies[getRandomInt(0, fullReplies.length - 1)];
}
if (this.waterLevel > this.enough) {
return tooMuchReplies[getRandomInt(0, tooMuchReplies.length - 1)];
}
}
async notifyIfThirsty() {
if (this.waterLevel <= this.thirsty) {
await this.messagesService.sendToChannel(
{ id: "channelId" },
{ content: "ich brauche wasser :(" },
);
}
}
waterMe() {
const reply = this.getReply();
this.waterLevel++;
this.logger.info(`Water level increased to ${this.waterLevel}`);
return {
reply,
};
}
}