Files
tg-chat-bot/src/commands/when.ts
T
melod1n a736f786c2 feat(openai): add chat streaming and model commands
- add /openai (/chatgpt) chat command using OpenAI Responses API (streaming + incremental edits)
- add /openAIListModels, /openAIGetModel, /openAISetModel
- introduce base Command class and migrate non-chat commands to it
- wire OpenAI client + env vars (OPENAI_API_KEY, OPENAI_MODEL)
- bump deps (@google/genai, systeminformation, @types/node) and add openai
2026-02-03 13:39:01 +03:00

92 lines
2.9 KiB
TypeScript

import {Command} from "../base/command";
import {getRandomInt, getRangedRandomInt, logError, oldReplyToMessage} from "../util/utils";
import {Message} from "typescript-telegram-bot-api";
export class When extends Command {
command = ["when", "когда"];
argsMode = "required" as const;
title = "/when [value]";
description = "random date";
async execute(msg: Message) {
let text = "через ";
const type = getRandomInt(8);
switch (type) {
case 0:
text = "сейчас";
break;
case 1:
text = "никогда";
break;
case 2: //seconds
{
const seconds = getRangedRandomInt(1, 60);
text += `${seconds} `;
text += (
(seconds == 1 || seconds % 10 == 1) ? "секунду" :
((seconds > 1 && seconds < 5) || (seconds % 10 > 1 && seconds % 10 < 5)) ? "секунды" : "секунд"
);
break;
}
case 3: {
const minutes = getRangedRandomInt(1, 60);
text += `${minutes} `;
text += (
(minutes == 1 || minutes % 10 == 1) ? "минуту" :
((minutes > 1 && minutes < 5) || (minutes % 10 > 1 && minutes % 10 < 5)) ? "минуты" : "минут"
);
break;
}
case 4: {
const hours = getRangedRandomInt(1, 24);
text += `${hours} `;
text += (
(hours == 1 || hours % 10 == 1) ? "час" :
((hours > 1 && hours < 5) || (hours % 10 > 1 && hours % 10 < 5)) ? "часа" : "часов"
);
break;
}
case 5: {
const weeks = getRangedRandomInt(1, 4);
text += `${weeks} `;
text += (weeks == 1 ? "неделю" : "недель");
break;
}
case 6: {
const months = getRandomInt(12);
text += `${months} `;
text += (
(months == 1 || months % 10 == 1) ? "месяц" :
((months > 1 && months < 5) || (months % 10 > 1 && months % 10 < 5)) ? "месяца" : "месяцев"
);
break;
}
case 7: {
const years = getRangedRandomInt(1, 100);
text += `${years} `;
text += (
(years == 1 || years % 10 == 1) ? "год" :
((years > 1 && years < 5) || (years % 10 > 1 && years % 10 < 5)) ? "года" : "лет"
);
break;
}
}
await oldReplyToMessage(msg, text).catch(logError);
}
}