add greeting
add locales
This commit is contained in:
@@ -1,14 +1,47 @@
|
||||
import type { MessagesServiceInterface } from "entities/messages/messages.service";
|
||||
import type { BaseChannel, BaseMessage, BaseUser } from "lib/common";
|
||||
import type { I18nService } from "lib/i18n/i18n.service";
|
||||
|
||||
export class GreetingService<U = unknown> {
|
||||
messagesService: MessagesServiceInterface<U>;
|
||||
export class GreetingService<
|
||||
U extends BaseUser = BaseUser,
|
||||
M extends BaseMessage = BaseMessage,
|
||||
C extends BaseChannel = BaseChannel,
|
||||
> {
|
||||
messagesService: MessagesServiceInterface<U, M, C>;
|
||||
i18nService: I18nService;
|
||||
lang: "en" | "de";
|
||||
ns = "greeting";
|
||||
|
||||
constructor(messagesService: MessagesServiceInterface<U>) {
|
||||
constructor(
|
||||
messagesService: MessagesServiceInterface<U, M, C>,
|
||||
i18nService: I18nService,
|
||||
lang: "en" | "de",
|
||||
) {
|
||||
this.messagesService = messagesService;
|
||||
this.i18nService = i18nService;
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
async sendGreeting(user: U, userName: string) {
|
||||
const greetingMessage = `Hello, ${userName}! Welcome to the server!`;
|
||||
async sendDmGreeting(user: U, _userName: string) {
|
||||
const greetingMessage: string = await this.i18nService.t(
|
||||
"dmGreeting",
|
||||
this.lang,
|
||||
this.ns,
|
||||
);
|
||||
|
||||
await this.messagesService.sendToUser(user, greetingMessage);
|
||||
}
|
||||
|
||||
async sendGreeting(userName: string, channel: C) {
|
||||
const greetingMessage: string =
|
||||
(await this.i18nService.t("greeting1", this.lang, this.ns)) +
|
||||
(await this.i18nService.t("greeting2", this.lang, this.ns, {
|
||||
member: userName,
|
||||
})) +
|
||||
(await this.i18nService.t("greeting3", this.lang, this.ns)) +
|
||||
(await this.i18nService.t("greeting4", this.lang, this.ns)) +
|
||||
(await this.i18nService.t("emoji", this.lang, this.ns));
|
||||
|
||||
await this.messagesService.sendToChannel(channel, greetingMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
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";
|
||||
|
||||
@@ -13,6 +12,7 @@ export class WaterMeService {
|
||||
messagesService: MessagesServiceInterface;
|
||||
i18nService: I18nService;
|
||||
lang: "en" | "de";
|
||||
ns = "waterMe";
|
||||
|
||||
constructor(
|
||||
messagesService: MessagesServiceInterface,
|
||||
@@ -26,34 +26,30 @@ export class WaterMeService {
|
||||
}
|
||||
|
||||
async getReply() {
|
||||
// const key = (
|
||||
// this.waterLevel <= this.thirsty
|
||||
// ? "water-me.needMoreWater"
|
||||
// : this.waterLevel <= this.full
|
||||
// ? "water-me.enoughWater"
|
||||
// : "water-me.tooMuchWater"
|
||||
// ) as ParseKeys;
|
||||
|
||||
// return await this.i18nService.t(key, this.lang);
|
||||
|
||||
if (this.waterLevel <= this.thirsty)
|
||||
return this.i18nService.t("needMoreWater", this.lang, "waterMe");
|
||||
return this.i18nService.t("needMoreWater", this.lang, this.ns);
|
||||
if (this.waterLevel <= this.full)
|
||||
return this.i18nService.t("enoughWater", this.lang, "waterMe");
|
||||
return this.i18nService.t("tooMuchWater", this.lang, "waterMe");
|
||||
return this.i18nService.t("enoughWater", this.lang, this.ns);
|
||||
return this.i18nService.t("tooMuchWater", this.lang, this.ns);
|
||||
}
|
||||
|
||||
async notifyIfThirsty() {
|
||||
if (this.waterLevel <= this.thirsty) {
|
||||
await this.messagesService.sendToChannel(
|
||||
{ id: "channelId" },
|
||||
{ content: await this.i18nService.t("waterMe.thirsty", this.lang) },
|
||||
{
|
||||
content: await this.i18nService.t(
|
||||
"waterMe.thirsty",
|
||||
this.lang,
|
||||
this.ns,
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
waterMe() {
|
||||
const reply = this.getReply();
|
||||
async waterMe() {
|
||||
const reply = await this.getReply();
|
||||
|
||||
this.waterLevel++;
|
||||
this.logger.info(`Water level increased to ${this.waterLevel}`);
|
||||
@@ -64,11 +60,11 @@ export class WaterMeService {
|
||||
}
|
||||
|
||||
async handleCommand(channelId: string) {
|
||||
const result = this.waterMe(); // muss hier await weil promise rueckgabe?
|
||||
const result = await this.waterMe(); // muss hoer await wein promise rueckgabe?
|
||||
|
||||
this.messagesService.sendToChannel(
|
||||
{ id: channelId },
|
||||
{ content: await result.reply },
|
||||
{ content: result.reply },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user