i18n waterMe

This commit is contained in:
mo
2026-02-21 00:20:12 +01:00
parent d2e88f15ea
commit 453577f1b2
13 changed files with 144 additions and 78 deletions

View File

@@ -1,6 +1,7 @@
import type { MessagesServiceInterface } from "entities/messages/messages.service";
import type { ParseKeys } from "i18next";
import type { I18nService } from "lib/i18n/i18n.service";
import { createLogger } from "lib/logger";
import { getRandomInt } from "lib/utils";
export class WaterMeService {
waterLevel: number;
@@ -8,48 +9,45 @@ export class WaterMeService {
private logger = createLogger("WaterMeService");
private thirsty = 3 as const;
private enough = 10 as const;
private full = 10 as const;
messagesService: MessagesServiceInterface;
i18nService: I18nService;
lang: "en" | "de";
constructor(messagesService: MessagesServiceInterface) {
constructor(
messagesService: MessagesServiceInterface,
i18nService: I18nService,
lang: "en" | "de",
) {
this.waterLevel = 0;
this.messagesService = messagesService;
this.i18nService = i18nService;
this.lang = lang;
}
getReply() {
const thirstyReplies = [
"... wow das wars schon??? ich brauche noch mehr wasser :(",
"dankeeeee!!!! ich waer fast verdurstet :(((",
"*roelpssssss*",
];
async getReply() {
// const key = (
// this.waterLevel <= this.thirsty
// ? "water-me.needMoreWater"
// : this.waterLevel <= this.full
// ? "water-me.enoughWater"
// : "water-me.tooMuchWater"
// ) as ParseKeys;
const fullReplies = [
"langsam reicht es :o",
"poah, das hat gut getan",
"das ist krass :3",
];
// return await this.i18nService.t(key, this.lang);
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)];
}
if (this.waterLevel <= this.thirsty)
return this.i18nService.t("needMoreWater", this.lang, "waterMe");
if (this.waterLevel <= this.full)
return this.i18nService.t("enoughWater", this.lang, "waterMe");
return this.i18nService.t("tooMuchWater", this.lang, "waterMe");
}
async notifyIfThirsty() {
if (this.waterLevel <= this.thirsty) {
await this.messagesService.sendToChannel(
{ id: "channelId" },
{ content: "ich brauche wasser :(" },
{ content: await this.i18nService.t("waterMe.thirsty", this.lang) },
);
}
}
@@ -66,11 +64,11 @@ export class WaterMeService {
}
async handleCommand(channelId: string) {
const result = this.waterMe();
const result = this.waterMe(); // muss hier await weil promise rueckgabe?
this.messagesService.sendToChannel(
{ id: channelId },
{ content: result.reply },
{ content: await result.reply },
);
}
}