UNPKG

grammy-guard

Version:
37 lines (36 loc) 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reply = exports.or = exports.and = exports.not = void 0; function not(predicate) { return (ctx) => Promise.resolve(predicate(ctx)).then((v) => !v); } exports.not = not; function and(...predicate) { return (ctx) => Promise.resolve(predicate.map((predicate) => predicate(ctx))).then((v) => v.every(Boolean)); } exports.and = and; function or(...predicate) { return (ctx) => Promise.resolve(predicate.map((predicate) => predicate(ctx))).then((v) => v.some(Boolean)); } exports.or = or; function reply(errorMessage, options) { const { replyToMessage, } = options ?? { replyToMessage: false, }; return async (ctx) => { const text = typeof errorMessage === "function" ? await errorMessage(ctx) : errorMessage; if (ctx.callbackQuery) { return await ctx.answerCallbackQuery({ text, }); } return await ctx.reply(text, { ...(replyToMessage && { reply_to_message_id: ctx.msg?.message_id, }), }); }; } exports.reply = reply;