2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-09-07 17:45:16 +00:00
Files
the-guard-bot/handlers/middlewares/commandButtons.js

34 lines
904 B
JavaScript
Raw Normal View History

2019-07-10 13:01:02 +02:00
'use strict';
const TelegrafContext = require('telegraf/core/context');
2020-03-10 22:10:48 +01:00
/** @type { import('../../typings/context').ContextExtensions } */
2019-07-10 13:01:02 +02:00
const contextCustomizations = require('../../bot/context');
2020-03-10 22:10:48 +01:00
/** @param { import('telegraf').ContextMessageUpdate } ctx */
2019-07-10 13:01:02 +02:00
module.exports = (ctx, next) => {
if (!ctx.callbackQuery) return next();
if (!ctx.callbackQuery.data.startsWith('/')) return next();
const cbUpdate = {
message: {
from: ctx.from,
chat: ctx.chat,
text: ctx.callbackQuery.data,
entities: [ { offset: 0, type: 'bot_command' } ],
}
};
2020-03-10 22:10:48 +01:00
/** @type { import('../../typings/context').ExtendedContext } */
2019-07-10 13:01:02 +02:00
const cbCtx = new TelegrafContext(cbUpdate, ctx.tg, ctx.options);
Object.assign(cbCtx, contextCustomizations);
cbCtx.botInfo = ctx.botInfo;
cbCtx.reply = (text, options = {}) => {
ctx.deleteMessage();
return ctx.reply(text, options);
};
return next(cbCtx);
};