begin rewriting first services to be domain agnostic
more rewrites
This commit is contained in:
64
core/src/features/water-me/water-me.service.ts
Normal file
64
core/src/features/water-me/water-me.service.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { TextBasedFeature } from "features/text-based-feature/text-based-feature";
|
||||
import type { TextBasedFeatureInput } from "features/text-based-feature/text-based-feature.schema";
|
||||
import { createLogger } from "lib/logger";
|
||||
import { getRandomInt } from "lib/utils";
|
||||
|
||||
export class WaterMeService extends TextBasedFeature {
|
||||
waterLevel: number;
|
||||
|
||||
private logger = createLogger("WaterMeService");
|
||||
|
||||
private thirsty = 3 as const;
|
||||
private enough = 10 as const;
|
||||
|
||||
constructor(input: TextBasedFeatureInput) {
|
||||
super(input);
|
||||
this.waterLevel = 0;
|
||||
}
|
||||
|
||||
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.sendMessage({ content: "ich brauche wasser :(" });
|
||||
}
|
||||
}
|
||||
|
||||
waterMe() {
|
||||
const reply = this.getReply();
|
||||
|
||||
this.waterLevel++;
|
||||
this.logger.info(`Water level increased to ${this.waterLevel}`);
|
||||
|
||||
return {
|
||||
reply,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user