Files
tg-chat-bot/src/commands/what-better.ts
T

26 lines
898 B
TypeScript

import {ChatCommand} from "../base/chat-command";
import {logError, oldSendMessage, randomValue} from "../util/utils";
import {betterAnswers} from "../db/database";
import {Message} from "typescript-telegram-bot-api";
export class WhatBetter extends ChatCommand {
command = ["what", "что"];
argsMode = "required" as const;
title = "/what better [a] or [b]";
description = "either a or b randomly (50% chance)";
private argsRe = /^(better|лучше)\s+([\s\S]+?)\s+(or|или)\s+([\s\S]+)$/i;
async execute(msg: Message, match?: RegExpExecArray) {
const args = (match?.[3] ?? "").trim();
const m = this.argsRe.exec(args);
if (!m) return;
const a = m[2].trim();
const b = m[4].trim();
const text = `${randomValue(betterAnswers)} ${randomValue([a, b])}`;
await oldSendMessage(msg, text).catch(logError);
}
}