gramstax 0.0.24 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/index.cjs +1 -1
- package/dist/src/index.d.cts +2 -5
- package/dist/src/index.d.ts +2 -5
- package/dist/src/index.js +1 -1
- package/package.json +1 -1
package/dist/src/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var G=Object.create;var v=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,X=Object.prototype.hasOwnProperty;var u=(p,t)=>v(p,"name",{value:t,configurable:!0});var Y=(p,t)=>{for(var e in t)v(p,e,{get:t[e],enumerable:!0})},R=(p,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of J(t))!X.call(p,s)&&s!==e&&v(p,s,{get:()=>t[s],enumerable:!(i=H(t,s))||i.enumerable});return p};var Z=(p,t,e)=>(e=p!=null?G(q(p)):{},R(t||!p||!p.__esModule?v(e,"default",{value:p,enumerable:!0}):e,p)),tt=p=>R(v({},"__esModule",{value:!0}),p);var et={};Y(et,{BaseGeneral:()=>I,CacheExternal:()=>M,Ctx:()=>x,Gramstax:()=>D,TemplateEngine:()=>f,TemplateManager:()=>T});module.exports=tt(et);var N=require("logging-pretty");var I=class{static{u(this,"BaseGeneral")}static log=new N.LoggingPretty;static logError(t,e){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${e}]: ${String(t)}`)}logError(t,e,i){this.constructor.log.error(`[${e||this.constructor.name}:${i}] ${String(t)}`)}};var K=require("keyv"),B=Z(require("@keyv/redis"),1);var M=class extends K.Keyv{constructor(e="memory",i,s,n){let o;e.startsWith("redis")&&(o=new B.default(e)),e==="memory"&&(o=new Map),n?.forceStore&&(o=n.forceStore);super({store:o,namespace:i,ttl:s});this.url=e}static{u(this,"CacheExternal")}};var E=require("timers/promises");var S=require("grammy");var x=class extends I{static{u(this,"Ctx")}static template;static data;data=this.constructor.data;get isPremium(){return this.ct.from?.is_premium??!1}get isBot(){return this.ct.from?.is_bot??!1}get userid(){return this.ct.from?.id}get username(){return this.ct.from?.username}get fullname(){return`${this.ct.from?.first_name||""}${this.ct.from?.last_name||""}`}get firstname(){return this.ct.from?.first_name}get lastname(){return this.ct.from?.last_name}get msgText(){return this.ct.message?.text}get msgTextIntent(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ")[0]:""}get msgTextPayloads(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ").slice(1):[]}get msgTextPayload(){return this.msgTextPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionIntent(){return this.msgCaption&&this.msgCaption.indexOf(" ")!=-1?this.msgCaption.split(" ")[0]:""}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataIntent(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":")[0]:""}get callbackDataPayloads(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":").slice(1):[]}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}get callbackDataParts(){return this.callbackDataPayload&&this.callbackDataPayload.indexOf("+")!=-1?this.callbackDataPayload.split("+"):[]}get languageCode(){return this.ct.from?.language_code}set languageCode(t){this.ct.from.language_code=t}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){super(),this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp,t?.data&&(this.temp.data=t.data)}async broadcast(t,e,i,s,n,o){let r=e.map(d=>this.templateManager.getMessage(this.data.name,n,d,s));for(let d=0;d<t.length;d++){let c=t[d],l=r[d];await this.ct.api.sendMessage(c,l,{parse_mode:"HTML",reply_markup:i,...o}),d+1==30&&await(0,E.setTimeout)(1200)}}async reply(t,e,i,s){let n=this.templateManager.getMessage(this.data.name,i,this.languageCode,e);return await this.ct.reply(n,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,e,i,s,n){let o=this.templateManager.getMedia(this.data.name,s,this.languageCode,i),a={parse_mode:"HTML",reply_markup:e,...n};if(t=="photo")return await this.ct.replyWithPhoto(o.src,{caption:o.caption,...a});if(t=="video")return await this.ct.replyWithVideo(o.src,{caption:o.caption,...a});if(t=="audio")return await this.ct.replyWithAudio(o.src,{caption:o.caption,...a});if(t=="document")return await this.ct.replyWithDocument(o.src,{caption:o.caption,...a});if(t=="animation")return await this.ct.replyWithAnimation(o.src,{caption:o.caption,...a});if(t=="voice")return await this.ct.replyWithVoice(o.src,a);if(t=="video_note")return await this.ct.replyWithVideoNote(o.src,a);if(t=="sticker")return await this.ct.replyWithSticker(o.src,a);if(t=="location")return await this.ct.replyWithLocation(o.latitude,o.longitude,a);if(t=="contact")return await this.ct.replyWithContact(o.phone,o.first_name,{vcard:o.vcard,...a})}async replyPhoto(t,e,i,s){return this.replyMedia("photo",t,e,i,s)}async replyVideo(t,e,i,s){return this.replyMedia("video",t,e,i,s)}async replyAudio(t,e,i,s){return this.replyMedia("audio",t,e,i,s)}async replyDocument(t,e,i,s){return this.replyMedia("document",t,e,i,s)}async replyAnimation(t,e,i,s){return this.replyMedia("animation",t,e,i,s)}async replyVoice(t,e,i,s){return this.replyMedia("voice",t,e,i,s)}async replyVideoNote(t,e,i,s){return this.replyMedia("video_note",t,e,i,s)}async replySticker(t,e,i,s){return this.replyMedia("sticker",t,e,i,s)}async replyLocation(t,e,i,s){return this.replyMedia("location",t,e,i,s)}async replyContact(t,e,i,s){return this.replyMedia("contact",t,e,i,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,e,i,s){try{let n=this.templateManager.getMessage(this.data.name,i,this.languageCode,e);return await this.ct.editMessageText(n,{parse_mode:"HTML",reply_markup:t,...s})}catch{await this.reply(t,e,i,s)}}async editMedia(t,e,i,s,n,o){try{let{src:a,caption:r}=this.templateManager.getMedia(this.data.name,s,this.languageCode,i);return t=="voice"?(await this.delete(),await this.replyVoice(e,i,s,n)):t=="video_note"?(await this.delete(),await this.replyVoice(e,i,s,n)):t=="sticker"?(await this.delete(),await this.replySticker(e,i,s,n)):t=="location"?(await this.delete(),await this.replyLocation(e,i,s,n)):t=="contact"?(await this.delete(),await this.replyContact(e,i,s,n)):await this.ct.editMessageMedia({media:a,caption:r,type:t,parse_mode:"HTML",...n},{reply_markup:e,...o})}catch{await this.reply(e,i,s,o)}}async editPhoto(t,e,i,s,n){return await this.editMedia("photo",t,e,i,s,n)}async editVideo(t,e,i,s,n){return await this.editMedia("video",t,e,i,s,n)}async editAudio(t,e,i,s,n){return await this.editMedia("audio",t,e,i,s,n)}async editDocument(t,e,i,s,n){return await this.editMedia("document",t,e,i,s,n)}async editAnimation(t,e,i,s,n){return await this.editMedia("animation",t,e,i,s,n)}async editVoice(t,e,i,s){return await this.editMedia("voice",t,e,i,s)}async editVideoNote(t,e,i,s){return await this.editMedia("video_note",t,e,i,s)}async editSticker(t,e,i,s){return await this.editMedia("sticker",t,e,i,s)}async editLocation(t,e,i,s){return await this.editMedia("location",t,e,i,s)}async editContact(t,e,i,s){return await this.editMedia("contact",t,e,i,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,e,i){try{let s={method:t,params:e,...i},n=await this.cacheSession.set(`${this.userid}`,s);return n&&(this.session=s),n}catch{return null}}async sessionGet(){try{let t=await this.cacheSession.get(`${this.userid}`);return t&&(this.session=t),t||null}catch{return null}}async sessionClear(){try{let t=await this.cacheSession.delete(`${this.userid}`);return t&&(this.session={}),t}catch{return null}}static buildData(t){return{name:"",callbackData:t?function(...e){let i=t(...e);return`${this.name}${i===void 0?"":`:${i}`}`}:function(){return this?.name}}}inlineKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.languageCode}:i`,r=this.cacheKeyboard.get(a);if(!r){let d=new S.InlineKeyboard,c=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"inline",e?.data),l=t(d,c);return this.cacheKeyboard.set(a,l),l}return r}let s=new S.InlineKeyboard,n=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"inline",e?.data);return t(s,n)}bottomKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.languageCode}:b`,r=this.cacheKeyboard.get(a);if(!r){let d=new S.Keyboard,c=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"bottom",e?.data),l=t(d,c);return l.resized(!0),this.cacheKeyboard.set(a,l),l}return r}let s=new S.Keyboard,n=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"bottom",e?.data),o=t(s,n);return o.resized(),o}validateSessionCallback(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallback(e)}validateSessionCallbackPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallbackPayload(e)}validateSessionText(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionText(e)}validateSessionTextPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextPayload(e)}validateSessionTextCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommand(e)}validateSessionTextCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommandPayload(e)}validateSessionTextFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextFree(e)}validateSessionPhotoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaption(e)}validateSessionPhotoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionPayload(e)}validateSessionPhotoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommand(e)}validateSessionPhotoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommandPayload(e)}validateSessionPhotoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoFree(e)}validateSessionVideoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaption(e)}validateSessionVideoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionPayload(e)}validateSessionVideoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommand(e)}validateSessionVideoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommandPayload(e)}validateSessionVideoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoFree(e)}validateSessionAudioCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaption(e)}validateSessionAudioCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionPayload(e)}validateSessionAudioCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommand(e)}validateSessionAudioCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommandPayload(e)}validateSessionAudioFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioFree(e)}validateSessionDocumentCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaption(e)}validateSessionDocumentCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionPayload(e)}validateSessionDocumentCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommand(e)}validateSessionDocumentCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommandPayload(e)}validateSessionDocumentFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentFree(e)}validateSessionAnimationCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaption(e)}validateSessionAnimationCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionPayload(e)}validateSessionAnimationCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommand(e)}validateSessionAnimationCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommandPayload(e)}validateSessionAnimationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationFree(e)}validateSessionVoiceCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaption(e)}validateSessionVoiceCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionPayload(e)}validateSessionVoiceCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommand(e)}validateSessionVoiceCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommandPayload(e)}validateSessionVoiceFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceFree(e)}validateSessionVideoNoteCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaption(e)}validateSessionVideoNoteCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionPayload(e)}validateSessionVideoNoteCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommand(e)}validateSessionVideoNoteCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommandPayload(e)}validateSessionVideoNoteFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteFree(e)}validateSessionStickerFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionStickerFree(e)}validateSessionLocationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionLocationFree(e)}validateSessionContactFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionContactFree(e)}sessionCallback(t,e){return this.sessionSet(this.methodSessionCallback(e),t)}sessionCallbackPayload(t,e){return this.sessionSet(this.methodSessionCallbackPayload(e),t)}sessionText(t,e){return this.sessionSet(this.methodSessionText(e),t)}sessionTextPayload(t,e){return this.sessionSet(this.methodSessionTextPayload(e),t)}sessionTextCommand(t,e){return this.sessionSet(this.methodSessionTextCommand(e),t)}sessionTextCommandPayload(t,e){return this.sessionSet(this.methodSessionTextCommandPayload(e),t)}sessionTextFree(t,e){return this.sessionSet(this.methodSessionTextFree(e),t)}sessionPhotoCaption(t,e){return this.sessionSet(this.methodSessionPhotoCaption(e),t)}sessionPhotoCaptionPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionPayload(e),t)}sessionPhotoCaptionCommand(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommand(e),t)}sessionPhotoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommandPayload(e),t)}sessionPhotoFree(t,e){return this.sessionSet(this.methodSessionPhotoFree(e),t)}sessionVideoCaption(t,e){return this.sessionSet(this.methodSessionVideoCaption(e),t)}sessionVideoCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionPayload(e),t)}sessionVideoCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommand(e),t)}sessionVideoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommandPayload(e),t)}sessionVideoFree(t,e){return this.sessionSet(this.methodSessionVideoFree(e),t)}sessionAudioCaption(t,e){return this.sessionSet(this.methodSessionAudioCaption(e),t)}sessionAudioCaptionPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionPayload(e),t)}sessionAudioCaptionCommand(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommand(e),t)}sessionAudioCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommandPayload(e),t)}sessionAudioFree(t,e){return this.sessionSet(this.methodSessionAudioFree(e),t)}sessionDocumentCaption(t,e){return this.sessionSet(this.methodSessionDocumentCaption(e),t)}sessionDocumentCaptionPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionPayload(e),t)}sessionDocumentCaptionCommand(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommand(e),t)}sessionDocumentCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommandPayload(e),t)}sessionDocumentFree(t,e){return this.sessionSet(this.methodSessionDocumentFree(e),t)}sessionAnimationCaption(t,e){return this.sessionSet(this.methodSessionAnimationCaption(e),t)}sessionAnimationCaptionPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionPayload(e),t)}sessionAnimationCaptionCommand(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommand(e),t)}sessionAnimationCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommandPayload(e),t)}sessionAnimationFree(t,e){return this.sessionSet(this.methodSessionAnimationFree(e),t)}sessionVoiceCaption(t,e){return this.sessionSet(this.methodSessionVoiceCaption(e),t)}sessionVoiceCaptionPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionPayload(e),t)}sessionVoiceCaptionCommand(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommand(e),t)}sessionVoiceCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommandPayload(e),t)}sessionVoiceFree(t,e){return this.sessionSet(this.methodSessionVoiceFree(e),t)}sessionVideoNoteCaption(t,e){return this.sessionSet(this.methodSessionVideoNoteCaption(e),t)}sessionVideoNoteCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionPayload(e),t)}sessionVideoNoteCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommand(e),t)}sessionVideoNoteCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommandPayload(e),t)}sessionVideoNoteFree(t,e){return this.sessionSet(this.methodSessionVideoNoteFree(e),t)}sessionStickerFree(t,e){return this.sessionSet(this.methodSessionStickerFree(e),t)}sessionLocationFree(t,e){return this.sessionSet(this.methodSessionLocationFree(e),t)}sessionContactFree(t,e){return this.sessionSet(this.methodSessionContactFree(e),t)}sessionToCallback(t,e){return this.sessionCallback({...this.session.params,...t},e)}sessionToCallbackPayload(t,e){return this.sessionCallbackPayload({...this.session.params,...t},e)}sessionToText(t,e){return this.sessionText({...this.session.params,...t},e)}sessionToTextPayload(t,e){return this.sessionTextPayload({...this.session.params,...t},e)}sessionToTextCommand(t,e){return this.sessionTextCommand({...this.session.params,...t},e)}sessionToTextCommandPayload(t,e){return this.sessionTextCommandPayload({...this.session.params,...t},e)}sessionToTextFree(t,e){return this.sessionTextFree({...this.session.params,...t},e)}sessionToPhotoCaption(t,e){return this.sessionPhotoCaption({...this.session.params,...t},e)}sessionToPhotoCaptionPayload(t,e){return this.sessionPhotoCaptionPayload({...this.session.params,...t},e)}sessionToPhotoCaptionCommand(t,e){return this.sessionPhotoCaptionCommand({...this.session.params,...t},e)}sessionToPhotoCaptionCommandPayload(t,e){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...t},e)}sessionToPhotoFree(t,e){return this.sessionPhotoFree({...this.session.params,...t},e)}sessionToVideoCaption(t,e){return this.sessionVideoCaption({...this.session.params,...t},e)}sessionToVideoCaptionPayload(t,e){return this.sessionVideoCaptionPayload({...this.session.params,...t},e)}sessionToVideoCaptionCommand(t,e){return this.sessionVideoCaptionCommand({...this.session.params,...t},e)}sessionToVideoCaptionCommandPayload(t,e){return this.sessionVideoCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoFree(t,e){return this.sessionVideoFree({...this.session.params,...t},e)}sessionToAudioCaption(t,e){return this.sessionAudioCaption({...this.session.params,...t},e)}sessionToAudioCaptionPayload(t,e){return this.sessionAudioCaptionPayload({...this.session.params,...t},e)}sessionToAudioCaptionCommand(t,e){return this.sessionAudioCaptionCommand({...this.session.params,...t},e)}sessionToAudioCaptionCommandPayload(t,e){return this.sessionAudioCaptionCommandPayload({...this.session.params,...t},e)}sessionToAudioFree(t,e){return this.sessionAudioFree({...this.session.params,...t},e)}sessionToDocumentCaption(t,e){return this.sessionDocumentCaption({...this.session.params,...t},e)}sessionToDocumentCaptionPayload(t,e){return this.sessionDocumentCaptionPayload({...this.session.params,...t},e)}sessionToDocumentCaptionCommand(t,e){return this.sessionDocumentCaptionCommand({...this.session.params,...t},e)}sessionToDocumentCaptionCommandPayload(t,e){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...t},e)}sessionToDocumentFree(t,e){return this.sessionDocumentFree({...this.session.params,...t},e)}sessionToAnimationCaption(t,e){return this.sessionAnimationCaption({...this.session.params,...t},e)}sessionToAnimationCaptionPayload(t,e){return this.sessionAnimationCaptionPayload({...this.session.params,...t},e)}sessionToAnimationCaptionCommand(t,e){return this.sessionAnimationCaptionCommand({...this.session.params,...t},e)}sessionToAnimationCaptionCommandPayload(t,e){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...t},e)}sessionToAnimationFree(t,e){return this.sessionAnimationFree({...this.session.params,...t},e)}sessionToVoiceCaption(t,e){return this.sessionVoiceCaption({...this.session.params,...t},e)}sessionToVoiceCaptionPayload(t,e){return this.sessionVoiceCaptionPayload({...this.session.params,...t},e)}sessionToVoiceCaptionCommand(t,e){return this.sessionVoiceCaptionCommand({...this.session.params,...t},e)}sessionToVoiceCaptionCommandPayload(t,e){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...t},e)}sessionToVoiceFree(t,e){return this.sessionVoiceFree({...this.session.params,...t},e)}sessionToVideoNoteCaption(t,e){return this.sessionVideoNoteCaption({...this.session.params,...t},e)}sessionToVideoNoteCaptionPayload(t,e){return this.sessionVideoNoteCaptionPayload({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommand(t,e){return this.sessionVideoNoteCaptionCommand({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommandPayload(t,e){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoNoteFree(t,e){return this.sessionVideoNoteFree({...this.session.params,...t},e)}sessionToStickerFree(t,e){return this.sessionStickerFree({...this.session.params,...t},e)}sessionToLocationFree(t,e){return this.sessionLocationFree({...this.session.params,...t},e)}sessionToContactFree(t,e){return this.sessionContactFree({...this.session.params,...t},e)}intent(t,e=!0){t||(t=e?this.data.callbackData():this.data.name);let i=e?":":" ";return t?.indexOf?.(i)!=-1?t?.split?.(i)?.[0]:t}methodSession(t,e){return`${t}-${e||this.data.name}`}methodSessionCallback(t){return this.methodSession("1",t)}methodSessionCallbackPayload(t){return this.methodSession("2",t)}methodSessionText(t){return this.methodSession("3",t)}methodSessionTextPayload(t){return this.methodSession("4",t)}methodSessionTextCommand(t){return this.methodSession("5",t)}methodSessionTextCommandPayload(t){return this.methodSession("6",t)}methodSessionTextFree(t){return this.methodSession("7",t)}methodSessionPhotoCaption(t){return this.methodSession("8",t)}methodSessionPhotoCaptionPayload(t){return this.methodSession("9",t)}methodSessionPhotoCaptionCommand(t){return this.methodSession("10",t)}methodSessionPhotoCaptionCommandPayload(t){return this.methodSession("11",t)}methodSessionPhotoFree(t){return this.methodSession("12",t)}methodSessionVideoCaption(t){return this.methodSession("13",t)}methodSessionVideoCaptionPayload(t){return this.methodSession("14",t)}methodSessionVideoCaptionCommand(t){return this.methodSession("15",t)}methodSessionVideoCaptionCommandPayload(t){return this.methodSession("16",t)}methodSessionVideoFree(t){return this.methodSession("17",t)}methodSessionAudioCaption(t){return this.methodSession("18",t)}methodSessionAudioCaptionPayload(t){return this.methodSession("19",t)}methodSessionAudioCaptionCommand(t){return this.methodSession("20",t)}methodSessionAudioCaptionCommandPayload(t){return this.methodSession("21",t)}methodSessionAudioFree(t){return this.methodSession("22",t)}methodSessionDocumentCaption(t){return this.methodSession("23",t)}methodSessionDocumentCaptionPayload(t){return this.methodSession("24",t)}methodSessionDocumentCaptionCommand(t){return this.methodSession("25",t)}methodSessionDocumentCaptionCommandPayload(t){return this.methodSession("26",t)}methodSessionDocumentFree(t){return this.methodSession("27",t)}methodSessionAnimationCaption(t){return this.methodSession("28",t)}methodSessionAnimationCaptionPayload(t){return this.methodSession("29",t)}methodSessionAnimationCaptionCommand(t){return this.methodSession("30",t)}methodSessionAnimationCaptionCommandPayload(t){return this.methodSession("31",t)}methodSessionAnimationFree(t){return this.methodSession("32",t)}methodSessionVoiceCaption(t){return this.methodSession("33",t)}methodSessionVoiceCaptionPayload(t){return this.methodSession("34",t)}methodSessionVoiceCaptionCommand(t){return this.methodSession("35",t)}methodSessionVoiceCaptionCommandPayload(t){return this.methodSession("36",t)}methodSessionVoiceFree(t){return this.methodSession("37",t)}methodSessionVideoNoteCaption(t){return this.methodSession("38",t)}methodSessionVideoNoteCaptionPayload(t){return this.methodSession("39",t)}methodSessionVideoNoteCaptionCommand(t){return this.methodSession("40",t)}methodSessionVideoNoteCaptionCommandPayload(t){return this.methodSession("41",t)}methodSessionVideoNoteFree(t){return this.methodSession("42",t)}methodSessionStickerFree(t){return this.methodSession("43",t)}methodSessionLocationFree(t){return this.methodSession("44",t)}methodSessionContactFree(t){return this.methodSession("45",t)}};var W=require("bun");var V=require("path"),F=require("fs");var P=class{static{u(this,"HelperPage")}static getPath(){return(0,V.join)(process.cwd(),"src","pages")}static _getPage(t,e,i=!0){let n=Object.values(t)[0];if(n===void 0)throw new Error(`File ${e} must have export (not default) class page`);return i===!0&&(n.template=void 0),n}static getPageSync(t,e=!0){t||(t=this.getPath());let i=require(t);return this._getPage(i,t,e)}static async getPage(t,e=!0){t||(t=this.getPath());let i=await import(`${t}?t=${Date.now()}`);return this._getPage(i,t,e)}static getPagesSync(t,e=!0){if(t||(t=this.getPath()),!(0,F.existsSync)(t))throw new Error(`Directory ${t} is not found, please make it manually`);return(0,F.readdirSync)(t).map(s=>{let n=(0,V.join)(t,s);return{path:n,page:this.getPageSync(n,e)}})}};var w=require("path");var j=require("logging-pretty");var f=class{static{u(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(e,i)=>`\${(data && data["${i}"]) ?? ""}`)}static _processBaseBlocks(t){let e=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,i={};for(let s of t.matchAll(e)){let n=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[n]=a}return i}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(e,i)=>{let s=i.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(t){return t.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(t){return t.replace(/<div>([\s\S]*?)<\/div>/gi,(e,i)=>i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(t){let e=/<media\s+([^>]+)>([\s\S]*?)<\/media>/gi,i={};for(let s of t.matchAll(e)){let n=s[1],o=s[2],a={},r=/(\w+)="([^"]*)"/g;for(let b of n.matchAll(r))a[b[1]]=b[2];if(!a.lang)continue;let d=a.lang,c=a.type,l=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),m={type:c};a.src&&(m.src=a.src),l&&c!=="video_note"&&c!=="sticker"&&(m.caption=l),c==="location"&&(a.latitude&&(m.latitude=a.latitude),a.longitude&&(m.longitude=a.longitude),l&&(m.caption=l)),c==="contact"&&(a.phone&&(m.phone=a.phone),a.first_name&&(m.first_name=a.first_name),a.last_name&&(m.last_name=a.last_name),a.vcard&&(m.vcard=a.vcard),l&&(m.caption=l)),i[d]=m}return i}static _processMessageBlocks(t){let e=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,i={};for(let[,s,n]of t.matchAll(e)){let o=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[s]=o}return i}static _processDescriptionBlocks(t){let e=/<description\b[^>]*\blang="([^"]*)"[^>]*\bscope="([^"]*)"[^>]*>([\s\S]*?)<\/description>/gi,i={};for(let[,s,n,o]of t.matchAll(e)){let a=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[s]||(i[s]={}),i[s][n]=a}return i}static _processKeyboardBlocks(t){let e=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\stype="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,i={};for(let[,s,n,o]of t.matchAll(e)){let a=n==="bottom"?"bottom":"inline",r=o.trim();i[s]||(i[s]={}),i[s][a]=r}return i}static _compileToFunction(t,e){let i;e?i=t.map(o=>`\`${o}\``).join(","):i=`\`${t}\``;let s=i;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),e){let n=`return [${s}]`;return new Function("data",n)}else{let n=`return ${s}`;return new Function("data",n)}}static compileMedia(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processMediaBlocks(n);i[s]={};for(let[a,r]of Object.entries(o))if(r.caption){let d=this._processVariables(this._processScriptBlocks(r.caption)),c=this._compileToFunction(d,!1);i[s][a]=l=>({...r,caption:c(l)})}else i[s][a]=()=>r}return i}static compileMessages(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processMessageBlocks(n);i[s]={};for(let[a,r]of Object.entries(o)){let d=this._processVariables(this._processScriptBlocks(r));i[s][a]=this._compileToFunction(d,!1)}}return i}static compileDescription(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processDescriptionBlocks(n);i[s]={};for(let[a,r]of Object.entries(o))for(let[d,c]of Object.entries(r))i[s][d]||(i[s][d]={}),i[s][d][a]=this._compileToFunction(c,!1)}return i}static compileKeyboards(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processKeyboardBlocks(n);i[s]={};for(let[a,r]of Object.entries(o)){i[s][a]={};for(let[d,c]of Object.entries(r)){let m=c.split(/(?<!\\),\s*/).map(b=>b.replace(/\\,/g,",").trim()).map(b=>this._processVariables(this._processScriptBlocks(b)));i[s][a][d]=this._compileToFunction(m,!0)}}}return i}};var $=require("fs/promises"),L=require("chokidar"),C=require("path"),y=require("fs");var T=class{static{u(this,"TemplateManager")}_map=new Map;_engine=f;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_forceLanguage;_isWatchEnabled;constructor(t){let{path:e,enableWatch:i=!1,forceLanguage:s}=t;this._path=e,this._forceLanguage=s,this._isWatchEnabled=i,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(!this._path||!Array.isArray(this._path))throw new Error("Path must be set as string array");for(let t=0;t<this._path.length;t++){let e=this._path[t];if(!(0,y.existsSync)(e))throw new Error(`Template base path is not exists: ${e}`);if(!(0,y.statSync)(e).isDirectory())throw new Error(`Template base path is not a directory: ${e}`)}return!0}catch(t){throw new Error(`Failed to validate Template base path: ${t}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let t=0;t<this._path.length;t++){let e=this._path[t],i=(0,L.watch)(e,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[t]=i,i.on("change",this._handleFileChange.bind(this)),i.on("add",this._handleFileAdd.bind(this)),i.on("unlink",this._handleFileDelete.bind(this)),i.on("error",this._handleWatchError.bind(this))}}async _handleFileChange(t){let e=(0,C.basename)(t);this._isValidFile(e)&&await this._loadFile(e,!1)}async _handleFileAdd(t){let e=(0,C.basename)(t);this._isValidFile(e)&&await this._loadFile(e,!1)}_handleFileDelete(t){let e=(0,C.basename)(t),i=this._getKey(e);this._map.has(i)&&this._map.delete(i)}_handleWatchError(t){}_loadAllFiles(){for(let t=0;t<this._path.length;t++){let e=this._path[t],s=(0,y.readdirSync)(e,"utf8").filter(n=>this._isValidFile(n));for(let n of s)this._loadFile(n,!0)}}async _loadFile(t,e=!0){for(let i=0;i<this._path.length;i++){let s=this._path[i],n=(0,C.join)(s,t),o=this._getExtension(t),a=this._getKey(t);if(o==".html"){let r=e?(0,y.readFileSync)(n,"utf8"):await(0,$.readFile)(n,"utf8");this._compile(a,r)}else if(o==".ts"){let r=await P.getPage(n,!1);r?.template!==void 0&&this._compile(a,r.template),r.template=void 0}else throw new Error(`File ${t} is not support`)}}_getExtension(t){return(0,C.extname)(t).toLowerCase()}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,e,i){let s=this._map.get(t),n=s||{},o=!1;(i===void 0||i?.media===!1||s?.media===void 0)&&(n.media=f.compileMedia(e),o=!0),(i===void 0||i?.message===!1||s?.message===void 0)&&(n.message=f.compileMessages(e),o=!0),(i===void 0||i?.keyboard===!1||s?.keyboard===void 0)&&(n.keyboard=f.compileKeyboards(e),o=!0),(i===void 0||i?.description===!1||s?.description===void 0)&&(n.description=f.compileDescription(e),o=!0),o&&this._map.set(t,n)}getMedia(t,e="default",i="en",s){let o=this._map.get(t)?.media?.[e]?.[this._forceLanguage||i];if(!o)return{};try{return o(s)}catch{return{}}}getMessage(t,e="default",i="en",s){let o=this._map.get(t)?.message?.[e]?.[this._forceLanguage||i];if(!o)return"";try{return o(s)}catch{return""}}getDescription(t,e="default",i="default",s="default",n){let a=this._map.get(t)?.description?.[e]?.[s]?.[this._forceLanguage||i];if(!a)return"";try{return a(n)}catch{return""}}getDescriptionLanguage(t,e="default",i="default"){let n=this._map.get(t)?.description?.[e]?.[i];return n?Object.keys(n):[]}getDescriptionScopes(t,e="default"){let s=this._map.get(t)?.description?.[e];return s?Object.keys(s):[]}getKeyboard(t,e="default",i="en",s="inline",n){let a=this._map.get(t)?.keyboard?.[e]?.[this._forceLanguage||i]?.[s];if(!a)return[];try{return a(n)}catch{return[]}}async write(t,e){if(this._getExtension(t)!=".html")return null;for(let i=0;i<this._path.length;i++){let s=(0,C.join)(this._path[i],t);if((0,y.existsSync)(s))return(0,y.writeFileSync)(s,e,"utf8"),await this._loadFile(t,!1),!0}return null}has(t){return this._map.has(t)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(t,e)=>typeof e=="function"?e.toString():e).length}}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};var k=require("grammy");var D=class{static{u(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;handlerBotUpdate;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");this.log=t.log===!0?new j.LoggingPretty:t.log?t.log:void 0,this.cacheSession=t.cacheSession||new M("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new T({path:[(0,w.join)(process.cwd(),"src","pages")]}),this.bot=this.createBot(t.token),this.bot.catch(this.onCatch),this.registerOnCallbackQueryData(),this.registerOnMessageText(),this.registerOnMessagePhoto(),this.registerOnMessageVideo(),this.registerOnMessageAudio(),this.registerOnMessageDocument(),this.registerOnMessageAnimation(),this.registerOnMessageVoice(),this.registerOnMessageVideoNote(),this.registerOnMessageSticker(),this.registerOnMessageLocation(),this.registerOnMessageContact(),this.handlerBotUpdate=this.bot.handleUpdate,this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),t.deploy.startsWith("polling")?this.runPolling():t.deploy.startsWith("webhook:")?this.runWebhook(t.deploy.split("webhook:")[1]):t.deploy.startsWith("serverless:")&&this.runServerless(t.deploy.split("serverless:")[1])}onCatch(t){this.log?.error?.(`[Bot.catch]: ${String(t)}`)}onStart(t,e,i){let{username:s}=t;this.log?.success?.(`Telegram bot polling started: ${s} ${e=="webhook"||e=="serverless"?`(${i})`:""}`)}createBot(t){return new k.Bot(t)}createCtx(t){return new x({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:u(async t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let e=(0,k.webhookCallback)(this.bot,"bun"),i="/telegram-webhook";this.handlerBotUpdate=e,(0,W.serve)({fetch(a){let{pathname:r}=new URL(a.url);if(r===i)return a.method==="POST"?e(a):new Response("OK",{status:200});if(r==="/"&&a.method==="GET"){let d=new Date().toISOString();return new Response(JSON.stringify({timestamp:d}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}});let s=await this.bot.api.getWebhookInfo(),n=t.endsWith("/")?t.slice(0,-1)+i:t+i;s.url!=n&&await this.bot.api.setWebhook(n);let o=await this.bot.api.getMe();this.onStart(o,"webhook",n)}async runServerless(t){this.handlerBotUpdate=(0,k.webhookCallback)(this.bot,t);let e=await this.bot.api.getMe();this.onStart(e,"serverless",t)}pageBuildData(t,e){t?.data===void 0&&(t.data=t.buildData()),t.data.name=(0,w.parse)(e).name}pageSorts(t,e){let i=t.data.name,s=t.prototype,n="Payload",o="Command",a="Caption",r="Free",d=e.dynamic,c=e.dynamicSpesific,l=u(h=>h.charAt(0).toUpperCase()+h.slice(1),"upFirst"),m=u(h=>h.replace(n,"").replace(o,"").replace(a,"").replace(r,""),"getPureFuncName"),b=u((h,g)=>s[`methodSession${l(h)}`](g),"methodSession");e.all[i]=t;for(let h=0;h<e.lenListFuncStaticSession;h++){let g=e.listFuncStaticSession[h],Q=e.static[g],U=e.staticIntent[g],O=e.staticSession[g],_={name:i,func:g},A=Q||U;if(A!==void 0){let z=g.includes(o)?`/${i}`:i;A[s.intent(z,g.startsWith("callback"))]=_}O!==void 0&&(O[b(g,i)]=_),g.toLowerCase().endsWith("free")&&c[m(g)].push(_)}s.free&&d.push(i)}async pageSyncDescription(t){let e=new Map,i=u((n,o,a,r)=>{e.has(o)||e.set(o,new Map);let d=e.get(o);d.has(a)||d.set(a,[]);let c=d.get(a);c.some(l=>l.command===n)||c.push({command:n,description:r})},"addCommand"),s=t.static.textCommand;for(let[,n]of Object.entries(s)){let o=n.name,a=this.templateManager.getDescriptionScopes(o);for(let r of a){let d=this.templateManager.getDescriptionLanguage(o,"default",r);for(let c of d){let l=this.templateManager.getDescription(o,"default",c,r);l&&i(o,r,c,l)}}}for(let[n,o]of e)for(let[a,r]of o){let d={type:n},c=a==="default"?void 0:a;try{let l=await this.bot.api.getMyCommands({scope:d,language_code:c}),m=JSON.stringify(l.map(h=>({command:h.command,description:h.description})).sort((h,g)=>h.command.localeCompare(g.command))),b=JSON.stringify(r.sort((h,g)=>h.command.localeCompare(g.command)));m!==b&&(await this.bot.api.setMyCommands(r,{scope:d,language_code:c}),this.log?.info?.(`Synced descriptions for scope: ${n},${c?` lang: ${c}`:""} (Total: ${r.length})`))}catch(l){this.log?.error?.(`Failed to sync descriptions for scope: ${n},${c?` lang: ${c}`:""}. ${String(l)}`)}}}pageLoads(){this.log?.info?.("Load pages..");let t={},e=t,i=t,s=[],n=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],o=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],a=[...n,...o,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],r=u((c,l)=>Object.fromEntries(c.map(m=>[m,{...l}])),"makeObject"),d={all:{},dynamic:[],dynamicSpesific:{text:s,photo:s,video:s,audio:s,document:s,animation:s,voice:s,videoNote:s,sticker:s,location:s,contact:s},static:r(n,t),staticIntent:r(o,e),staticSession:r(a,i),listFuncStatic:n,listFuncStaticIntent:o,listFuncStaticSession:a,lenListFuncStatic:n.length,lenListFuncStaticIntent:o.length,lenListFuncStaticSession:a.length};return P.getPagesSync(void 0,!0).forEach(({path:c,page:l})=>{this.pageBuildData(l,c),this.pageSorts(l,d)}),this.log?.info?.(`Finish load pages with total (${Object.keys(d.all).length})`),this.pageSyncDescription(d),d}async pageRoutes(t,e){let i,s;if(i===void 0){let o=t.callbackData,a=t.msgText,r=t.msgCaption,d=this.pages.static;for(let c=0;c<this.pages.lenListFuncStatic;c++){let l=this.pages.listFuncStatic[c];if(s=d[l][o||a||r],s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i===void 0){let o=await t.sessionGet();if(o){let a=o.method,r=this.pages.staticSession;for(let d=0;d<this.pages.lenListFuncStaticSession;d++){let c=this.pages.listFuncStaticSession[d];if(s=r[c][a],s)break}s!==void 0&&(i=this.pages.all[s.name])}}if(i===void 0){let o=t.callbackDataIntent,a=t.msgTextIntent,r=t.msgCaptionIntent,d=this.pages.staticIntent;for(let c=0;c<this.pages.lenListFuncStaticIntent;c++){let l=this.pages.listFuncStaticIntent[c];if(s=d[l][o||a||r],s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i!==void 0&&s!==void 0)return await new i(t)[s.func]?.();let n=this.pages.dynamicSpesific[e]||[];for(let o=0;o<n.length;o++){let a=n[o];if(a===void 0)continue;let r=this.pages.all[a.func];if(r===void 0)continue;let c=await new r(t)[a.name]?.();if(c!==null)return c}for(let o=0;o<this.pages.dynamic.length;o++){let a=this.pages.dynamic[o];if(a===void 0)continue;let r=this.pages.all[a];if(r===void 0)continue;let c=await new r(t).free?.();if(c!==null)return c}return null}async hookBeforeRoute(t,e){return!0}async hookErrorPage(t,e,i,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,e){let i=this.createCtx(t);try{if(await this.hookBeforeRoute(i,e)===!1)return;await this.pageRoutes(i,e)===null&&await this.hookErrorInputNotFoundPage(i)}catch(s){await this.hookErrorPage(i,e,s,!1)}}async onCallbackQueryData(t){let e=this.createCtx(t);try{if(await e.callbackQueryAnswer(),await this.hookBeforeRoute(e,"onCallbackQueryData")===!1)return;await this.pageRoutes(e,"callback")}catch(i){await this.hookErrorPage(e,"onCallbackQueryData",i,!0)}}async onMessageText(t){await this.onMessage(t,"onMessageText")}async onMessagePhoto(t){await this.onMessage(t,"onMessagePhoto")}async onMessageVideo(t){await this.onMessage(t,"onMessageVideo")}async onMessageAudio(t){await this.onMessage(t,"onMessageAudio")}async onMessageDocument(t){await this.onMessage(t,"onMessageDocument")}async onMessageAnimation(t){await this.onMessage(t,"onMessageAnimation")}async onMessageVoice(t){await this.onMessage(t,"onMessageVoice")}async onMessageVideoNote(t){await this.onMessage(t,"onMessageVideoNote")}async onMessageSticker(t){await this.onMessage(t,"onMessageSticker")}async onMessageLocation(t){await this.onMessage(t,"onMessageLocation")}async onMessageContact(t){await this.onMessage(t,"onMessageContact")}registerOnCallbackQueryData(){this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this))}registerOnMessageText(){this.bot.on("message:text",this.onMessageText.bind(this))}registerOnMessagePhoto(){this.bot.on("message:photo",this.onMessagePhoto.bind(this))}registerOnMessageVideo(){this.bot.on("message:video",this.onMessageVideo.bind(this))}registerOnMessageAudio(){this.bot.on("message:audio",this.onMessageAudio.bind(this))}registerOnMessageDocument(){this.bot.on("message:document",this.onMessageDocument.bind(this))}registerOnMessageAnimation(){this.bot.on("message:animation",this.onMessageAnimation.bind(this))}registerOnMessageVoice(){this.bot.on("message:voice",this.onMessageVoice.bind(this))}registerOnMessageVideoNote(){this.bot.on("message:video_note",this.onMessageVideoNote.bind(this))}registerOnMessageSticker(){this.bot.on("message:sticker",this.onMessageSticker.bind(this))}registerOnMessageLocation(){this.bot.on("message:location",this.onMessageLocation.bind(this))}registerOnMessageContact(){this.bot.on("message:contact",this.onMessageContact.bind(this))}};0&&(module.exports={BaseGeneral,CacheExternal,Ctx,Gramstax,TemplateEngine,TemplateManager});
|
|
1
|
+
"use strict";var G=Object.create;var v=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,X=Object.prototype.hasOwnProperty;var u=(p,t)=>v(p,"name",{value:t,configurable:!0});var Y=(p,t)=>{for(var e in t)v(p,e,{get:t[e],enumerable:!0})},R=(p,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of J(t))!X.call(p,s)&&s!==e&&v(p,s,{get:()=>t[s],enumerable:!(i=H(t,s))||i.enumerable});return p};var Z=(p,t,e)=>(e=p!=null?G(q(p)):{},R(t||!p||!p.__esModule?v(e,"default",{value:p,enumerable:!0}):e,p)),tt=p=>R(v({},"__esModule",{value:!0}),p);var et={};Y(et,{BaseGeneral:()=>M,CacheExternal:()=>I,Ctx:()=>x,Gramstax:()=>D,TemplateEngine:()=>f,TemplateManager:()=>k});module.exports=tt(et);var N=require("logging-pretty");var M=class{static{u(this,"BaseGeneral")}static log=new N.LoggingPretty;static logError(t,e){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${e}]: ${String(t)}`)}logError(t,e,i){this.constructor.log.error(`[${e||this.constructor.name}:${i}] ${String(t)}`)}};var K=require("keyv"),B=Z(require("@keyv/redis"),1);var I=class extends K.Keyv{constructor(e="memory",i,s,o){let n;e.startsWith("redis")&&(n=new B.default(e)),e==="memory"&&(n=new Map),o?.forceStore&&(n=o.forceStore);super({store:n,namespace:i,ttl:s});this.url=e}static{u(this,"CacheExternal")}};var E=require("timers/promises");var S=require("grammy");var x=class extends M{static{u(this,"Ctx")}static template;static data;data=this.constructor.data;get isPremium(){return this.ct.from?.is_premium??!1}get isBot(){return this.ct.from?.is_bot??!1}get userid(){return this.ct.from?.id}get username(){return this.ct.from?.username}get fullname(){return`${this.ct.from?.first_name||""}${this.ct.from?.last_name||""}`}get firstname(){return this.ct.from?.first_name}get lastname(){return this.ct.from?.last_name}get msgText(){return this.ct.message?.text}get msgTextIntent(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ")[0]:""}get msgTextPayloads(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ").slice(1):[]}get msgTextPayload(){return this.msgTextPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionIntent(){return this.msgCaption&&this.msgCaption.indexOf(" ")!=-1?this.msgCaption.split(" ")[0]:""}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataIntent(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":")[0]:""}get callbackDataPayloads(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":").slice(1):[]}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}get callbackDataParts(){return this.callbackDataPayload&&this.callbackDataPayload.indexOf("+")!=-1?this.callbackDataPayload.split("+"):[]}get languageCode(){return this.ct.from?.language_code}set languageCode(t){this.ct.from.language_code=t}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){super(),this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp,t?.data&&(this.temp.data=t.data)}async broadcast(t,e,i,s,o,n){let r=e.map(c=>this.templateManager.getMessage(this.data.name,o,c,s));for(let c=0;c<t.length;c++){let d=t[c],l=r[c];await this.ct.api.sendMessage(d,l,{parse_mode:"HTML",reply_markup:i,...n}),c+1==30&&await(0,E.setTimeout)(1200)}}async reply(t,e,i,s){let o=this.templateManager.getMessage(this.data.name,i,this.languageCode,e);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,e,i,s,o){let n=this.templateManager.getMedia(this.data.name,s,this.languageCode,i),a={parse_mode:"HTML",reply_markup:e,...o};if(t=="photo")return await this.ct.replyWithPhoto(n.src,{caption:n.caption,...a});if(t=="video")return await this.ct.replyWithVideo(n.src,{caption:n.caption,...a});if(t=="audio")return await this.ct.replyWithAudio(n.src,{caption:n.caption,...a});if(t=="document")return await this.ct.replyWithDocument(n.src,{caption:n.caption,...a});if(t=="animation")return await this.ct.replyWithAnimation(n.src,{caption:n.caption,...a});if(t=="voice")return await this.ct.replyWithVoice(n.src,a);if(t=="video_note")return await this.ct.replyWithVideoNote(n.src,a);if(t=="sticker")return await this.ct.replyWithSticker(n.src,a);if(t=="location")return await this.ct.replyWithLocation(n.latitude,n.longitude,a);if(t=="contact")return await this.ct.replyWithContact(n.phone,n.first_name,{vcard:n.vcard,...a})}async replyPhoto(t,e,i,s){return this.replyMedia("photo",t,e,i,s)}async replyVideo(t,e,i,s){return this.replyMedia("video",t,e,i,s)}async replyAudio(t,e,i,s){return this.replyMedia("audio",t,e,i,s)}async replyDocument(t,e,i,s){return this.replyMedia("document",t,e,i,s)}async replyAnimation(t,e,i,s){return this.replyMedia("animation",t,e,i,s)}async replyVoice(t,e,i,s){return this.replyMedia("voice",t,e,i,s)}async replyVideoNote(t,e,i,s){return this.replyMedia("video_note",t,e,i,s)}async replySticker(t,e,i,s){return this.replyMedia("sticker",t,e,i,s)}async replyLocation(t,e,i,s){return this.replyMedia("location",t,e,i,s)}async replyContact(t,e,i,s){return this.replyMedia("contact",t,e,i,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,e,i,s,o=!0){try{let n=this.templateManager.getMessage(this.data.name,i,this.languageCode,e);return await this.ct.editMessageText(n,{parse_mode:"HTML",reply_markup:t,...s})}catch(n){if(o)await this.reply(t,e,i,s);else throw n}}async editMedia(t,e,i,s,o,n,a=!0){try{let{src:r,caption:c}=this.templateManager.getMedia(this.data.name,s,this.languageCode,i);return t=="voice"?(await this.delete(),await this.replyVoice(e,i,s,o)):t=="video_note"?(await this.delete(),await this.replyVoice(e,i,s,o)):t=="sticker"?(await this.delete(),await this.replySticker(e,i,s,o)):t=="location"?(await this.delete(),await this.replyLocation(e,i,s,o)):t=="contact"?(await this.delete(),await this.replyContact(e,i,s,o)):await this.ct.editMessageMedia({media:r,caption:c,type:t,parse_mode:"HTML",...o},{reply_markup:e,...n})}catch(r){if(a===!0)await this.reply(e,i,s,n);else throw r}}async editPhoto(t,e,i,s,o){return await this.editMedia("photo",t,e,i,s,o)}async editVideo(t,e,i,s,o){return await this.editMedia("video",t,e,i,s,o)}async editAudio(t,e,i,s,o){return await this.editMedia("audio",t,e,i,s,o)}async editDocument(t,e,i,s,o){return await this.editMedia("document",t,e,i,s,o)}async editAnimation(t,e,i,s,o){return await this.editMedia("animation",t,e,i,s,o)}async editVoice(t,e,i,s){return await this.editMedia("voice",t,e,i,s)}async editVideoNote(t,e,i,s){return await this.editMedia("video_note",t,e,i,s)}async editSticker(t,e,i,s){return await this.editMedia("sticker",t,e,i,s)}async editLocation(t,e,i,s){return await this.editMedia("location",t,e,i,s)}async editContact(t,e,i,s){return await this.editMedia("contact",t,e,i,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,e,i){try{let s={method:t,params:e,...i},o=await this.cacheSession.set(`${this.userid}`,s);return o&&(this.session=s),o}catch{return null}}async sessionGet(){try{let t=await this.cacheSession.get(`${this.userid}`);return t&&(this.session=t),t||null}catch{return null}}async sessionClear(){try{let t=await this.cacheSession.delete(`${this.userid}`);return t&&(this.session={}),t}catch{return null}}static buildData(t){return{name:"",callbackData:t?function(...e){let i=t(...e);return`${this.name}${i===void 0?"":`:${i}`}`}:function(){return this?.name}}}inlineKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.languageCode}:i`,r=this.cacheKeyboard.get(a);if(!r){let c=new S.InlineKeyboard,d=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"inline",e?.data),l=t(c,d);return this.cacheKeyboard.set(a,l),l}return r}let s=new S.InlineKeyboard,o=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"inline",e?.data);return t(s,o)}bottomKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.languageCode}:b`,r=this.cacheKeyboard.get(a);if(!r){let c=new S.Keyboard,d=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"bottom",e?.data),l=t(c,d);return l.resized(!0),this.cacheKeyboard.set(a,l),l}return r}let s=new S.Keyboard,o=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"bottom",e?.data),n=t(s,o);return n.resized(),n}validateSessionCallback(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallback(e)}validateSessionCallbackPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallbackPayload(e)}validateSessionText(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionText(e)}validateSessionTextPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextPayload(e)}validateSessionTextCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommand(e)}validateSessionTextCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommandPayload(e)}validateSessionTextFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextFree(e)}validateSessionPhotoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaption(e)}validateSessionPhotoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionPayload(e)}validateSessionPhotoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommand(e)}validateSessionPhotoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommandPayload(e)}validateSessionPhotoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoFree(e)}validateSessionVideoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaption(e)}validateSessionVideoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionPayload(e)}validateSessionVideoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommand(e)}validateSessionVideoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommandPayload(e)}validateSessionVideoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoFree(e)}validateSessionAudioCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaption(e)}validateSessionAudioCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionPayload(e)}validateSessionAudioCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommand(e)}validateSessionAudioCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommandPayload(e)}validateSessionAudioFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioFree(e)}validateSessionDocumentCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaption(e)}validateSessionDocumentCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionPayload(e)}validateSessionDocumentCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommand(e)}validateSessionDocumentCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommandPayload(e)}validateSessionDocumentFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentFree(e)}validateSessionAnimationCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaption(e)}validateSessionAnimationCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionPayload(e)}validateSessionAnimationCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommand(e)}validateSessionAnimationCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommandPayload(e)}validateSessionAnimationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationFree(e)}validateSessionVoiceCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaption(e)}validateSessionVoiceCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionPayload(e)}validateSessionVoiceCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommand(e)}validateSessionVoiceCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommandPayload(e)}validateSessionVoiceFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceFree(e)}validateSessionVideoNoteCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaption(e)}validateSessionVideoNoteCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionPayload(e)}validateSessionVideoNoteCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommand(e)}validateSessionVideoNoteCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommandPayload(e)}validateSessionVideoNoteFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteFree(e)}validateSessionStickerFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionStickerFree(e)}validateSessionLocationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionLocationFree(e)}validateSessionContactFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionContactFree(e)}sessionCallback(t,e){return this.sessionSet(this.methodSessionCallback(e),t)}sessionCallbackPayload(t,e){return this.sessionSet(this.methodSessionCallbackPayload(e),t)}sessionText(t,e){return this.sessionSet(this.methodSessionText(e),t)}sessionTextPayload(t,e){return this.sessionSet(this.methodSessionTextPayload(e),t)}sessionTextCommand(t,e){return this.sessionSet(this.methodSessionTextCommand(e),t)}sessionTextCommandPayload(t,e){return this.sessionSet(this.methodSessionTextCommandPayload(e),t)}sessionTextFree(t,e){return this.sessionSet(this.methodSessionTextFree(e),t)}sessionPhotoCaption(t,e){return this.sessionSet(this.methodSessionPhotoCaption(e),t)}sessionPhotoCaptionPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionPayload(e),t)}sessionPhotoCaptionCommand(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommand(e),t)}sessionPhotoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommandPayload(e),t)}sessionPhotoFree(t,e){return this.sessionSet(this.methodSessionPhotoFree(e),t)}sessionVideoCaption(t,e){return this.sessionSet(this.methodSessionVideoCaption(e),t)}sessionVideoCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionPayload(e),t)}sessionVideoCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommand(e),t)}sessionVideoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommandPayload(e),t)}sessionVideoFree(t,e){return this.sessionSet(this.methodSessionVideoFree(e),t)}sessionAudioCaption(t,e){return this.sessionSet(this.methodSessionAudioCaption(e),t)}sessionAudioCaptionPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionPayload(e),t)}sessionAudioCaptionCommand(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommand(e),t)}sessionAudioCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommandPayload(e),t)}sessionAudioFree(t,e){return this.sessionSet(this.methodSessionAudioFree(e),t)}sessionDocumentCaption(t,e){return this.sessionSet(this.methodSessionDocumentCaption(e),t)}sessionDocumentCaptionPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionPayload(e),t)}sessionDocumentCaptionCommand(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommand(e),t)}sessionDocumentCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommandPayload(e),t)}sessionDocumentFree(t,e){return this.sessionSet(this.methodSessionDocumentFree(e),t)}sessionAnimationCaption(t,e){return this.sessionSet(this.methodSessionAnimationCaption(e),t)}sessionAnimationCaptionPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionPayload(e),t)}sessionAnimationCaptionCommand(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommand(e),t)}sessionAnimationCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommandPayload(e),t)}sessionAnimationFree(t,e){return this.sessionSet(this.methodSessionAnimationFree(e),t)}sessionVoiceCaption(t,e){return this.sessionSet(this.methodSessionVoiceCaption(e),t)}sessionVoiceCaptionPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionPayload(e),t)}sessionVoiceCaptionCommand(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommand(e),t)}sessionVoiceCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommandPayload(e),t)}sessionVoiceFree(t,e){return this.sessionSet(this.methodSessionVoiceFree(e),t)}sessionVideoNoteCaption(t,e){return this.sessionSet(this.methodSessionVideoNoteCaption(e),t)}sessionVideoNoteCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionPayload(e),t)}sessionVideoNoteCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommand(e),t)}sessionVideoNoteCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommandPayload(e),t)}sessionVideoNoteFree(t,e){return this.sessionSet(this.methodSessionVideoNoteFree(e),t)}sessionStickerFree(t,e){return this.sessionSet(this.methodSessionStickerFree(e),t)}sessionLocationFree(t,e){return this.sessionSet(this.methodSessionLocationFree(e),t)}sessionContactFree(t,e){return this.sessionSet(this.methodSessionContactFree(e),t)}sessionToCallback(t,e){return this.sessionCallback({...this.session.params,...t},e)}sessionToCallbackPayload(t,e){return this.sessionCallbackPayload({...this.session.params,...t},e)}sessionToText(t,e){return this.sessionText({...this.session.params,...t},e)}sessionToTextPayload(t,e){return this.sessionTextPayload({...this.session.params,...t},e)}sessionToTextCommand(t,e){return this.sessionTextCommand({...this.session.params,...t},e)}sessionToTextCommandPayload(t,e){return this.sessionTextCommandPayload({...this.session.params,...t},e)}sessionToTextFree(t,e){return this.sessionTextFree({...this.session.params,...t},e)}sessionToPhotoCaption(t,e){return this.sessionPhotoCaption({...this.session.params,...t},e)}sessionToPhotoCaptionPayload(t,e){return this.sessionPhotoCaptionPayload({...this.session.params,...t},e)}sessionToPhotoCaptionCommand(t,e){return this.sessionPhotoCaptionCommand({...this.session.params,...t},e)}sessionToPhotoCaptionCommandPayload(t,e){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...t},e)}sessionToPhotoFree(t,e){return this.sessionPhotoFree({...this.session.params,...t},e)}sessionToVideoCaption(t,e){return this.sessionVideoCaption({...this.session.params,...t},e)}sessionToVideoCaptionPayload(t,e){return this.sessionVideoCaptionPayload({...this.session.params,...t},e)}sessionToVideoCaptionCommand(t,e){return this.sessionVideoCaptionCommand({...this.session.params,...t},e)}sessionToVideoCaptionCommandPayload(t,e){return this.sessionVideoCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoFree(t,e){return this.sessionVideoFree({...this.session.params,...t},e)}sessionToAudioCaption(t,e){return this.sessionAudioCaption({...this.session.params,...t},e)}sessionToAudioCaptionPayload(t,e){return this.sessionAudioCaptionPayload({...this.session.params,...t},e)}sessionToAudioCaptionCommand(t,e){return this.sessionAudioCaptionCommand({...this.session.params,...t},e)}sessionToAudioCaptionCommandPayload(t,e){return this.sessionAudioCaptionCommandPayload({...this.session.params,...t},e)}sessionToAudioFree(t,e){return this.sessionAudioFree({...this.session.params,...t},e)}sessionToDocumentCaption(t,e){return this.sessionDocumentCaption({...this.session.params,...t},e)}sessionToDocumentCaptionPayload(t,e){return this.sessionDocumentCaptionPayload({...this.session.params,...t},e)}sessionToDocumentCaptionCommand(t,e){return this.sessionDocumentCaptionCommand({...this.session.params,...t},e)}sessionToDocumentCaptionCommandPayload(t,e){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...t},e)}sessionToDocumentFree(t,e){return this.sessionDocumentFree({...this.session.params,...t},e)}sessionToAnimationCaption(t,e){return this.sessionAnimationCaption({...this.session.params,...t},e)}sessionToAnimationCaptionPayload(t,e){return this.sessionAnimationCaptionPayload({...this.session.params,...t},e)}sessionToAnimationCaptionCommand(t,e){return this.sessionAnimationCaptionCommand({...this.session.params,...t},e)}sessionToAnimationCaptionCommandPayload(t,e){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...t},e)}sessionToAnimationFree(t,e){return this.sessionAnimationFree({...this.session.params,...t},e)}sessionToVoiceCaption(t,e){return this.sessionVoiceCaption({...this.session.params,...t},e)}sessionToVoiceCaptionPayload(t,e){return this.sessionVoiceCaptionPayload({...this.session.params,...t},e)}sessionToVoiceCaptionCommand(t,e){return this.sessionVoiceCaptionCommand({...this.session.params,...t},e)}sessionToVoiceCaptionCommandPayload(t,e){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...t},e)}sessionToVoiceFree(t,e){return this.sessionVoiceFree({...this.session.params,...t},e)}sessionToVideoNoteCaption(t,e){return this.sessionVideoNoteCaption({...this.session.params,...t},e)}sessionToVideoNoteCaptionPayload(t,e){return this.sessionVideoNoteCaptionPayload({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommand(t,e){return this.sessionVideoNoteCaptionCommand({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommandPayload(t,e){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoNoteFree(t,e){return this.sessionVideoNoteFree({...this.session.params,...t},e)}sessionToStickerFree(t,e){return this.sessionStickerFree({...this.session.params,...t},e)}sessionToLocationFree(t,e){return this.sessionLocationFree({...this.session.params,...t},e)}sessionToContactFree(t,e){return this.sessionContactFree({...this.session.params,...t},e)}intent(t,e=!0){t||(t=e?this.data.callbackData():this.data.name);let i=e?":":" ";return t?.indexOf?.(i)!=-1?t?.split?.(i)?.[0]:t}methodSession(t,e){return`${t}-${e||this.data.name}`}methodSessionCallback(t){return this.methodSession("1",t)}methodSessionCallbackPayload(t){return this.methodSession("2",t)}methodSessionText(t){return this.methodSession("3",t)}methodSessionTextPayload(t){return this.methodSession("4",t)}methodSessionTextCommand(t){return this.methodSession("5",t)}methodSessionTextCommandPayload(t){return this.methodSession("6",t)}methodSessionTextFree(t){return this.methodSession("7",t)}methodSessionPhotoCaption(t){return this.methodSession("8",t)}methodSessionPhotoCaptionPayload(t){return this.methodSession("9",t)}methodSessionPhotoCaptionCommand(t){return this.methodSession("10",t)}methodSessionPhotoCaptionCommandPayload(t){return this.methodSession("11",t)}methodSessionPhotoFree(t){return this.methodSession("12",t)}methodSessionVideoCaption(t){return this.methodSession("13",t)}methodSessionVideoCaptionPayload(t){return this.methodSession("14",t)}methodSessionVideoCaptionCommand(t){return this.methodSession("15",t)}methodSessionVideoCaptionCommandPayload(t){return this.methodSession("16",t)}methodSessionVideoFree(t){return this.methodSession("17",t)}methodSessionAudioCaption(t){return this.methodSession("18",t)}methodSessionAudioCaptionPayload(t){return this.methodSession("19",t)}methodSessionAudioCaptionCommand(t){return this.methodSession("20",t)}methodSessionAudioCaptionCommandPayload(t){return this.methodSession("21",t)}methodSessionAudioFree(t){return this.methodSession("22",t)}methodSessionDocumentCaption(t){return this.methodSession("23",t)}methodSessionDocumentCaptionPayload(t){return this.methodSession("24",t)}methodSessionDocumentCaptionCommand(t){return this.methodSession("25",t)}methodSessionDocumentCaptionCommandPayload(t){return this.methodSession("26",t)}methodSessionDocumentFree(t){return this.methodSession("27",t)}methodSessionAnimationCaption(t){return this.methodSession("28",t)}methodSessionAnimationCaptionPayload(t){return this.methodSession("29",t)}methodSessionAnimationCaptionCommand(t){return this.methodSession("30",t)}methodSessionAnimationCaptionCommandPayload(t){return this.methodSession("31",t)}methodSessionAnimationFree(t){return this.methodSession("32",t)}methodSessionVoiceCaption(t){return this.methodSession("33",t)}methodSessionVoiceCaptionPayload(t){return this.methodSession("34",t)}methodSessionVoiceCaptionCommand(t){return this.methodSession("35",t)}methodSessionVoiceCaptionCommandPayload(t){return this.methodSession("36",t)}methodSessionVoiceFree(t){return this.methodSession("37",t)}methodSessionVideoNoteCaption(t){return this.methodSession("38",t)}methodSessionVideoNoteCaptionPayload(t){return this.methodSession("39",t)}methodSessionVideoNoteCaptionCommand(t){return this.methodSession("40",t)}methodSessionVideoNoteCaptionCommandPayload(t){return this.methodSession("41",t)}methodSessionVideoNoteFree(t){return this.methodSession("42",t)}methodSessionStickerFree(t){return this.methodSession("43",t)}methodSessionLocationFree(t){return this.methodSession("44",t)}methodSessionContactFree(t){return this.methodSession("45",t)}};var W=require("bun");var _=require("path"),w=require("fs");var P=class{static{u(this,"HelperPage")}static getPath(){return(0,_.join)(process.cwd(),"src","pages")}static _getPage(t,e,i=!0){let o=Object.values(t)[0];if(o===void 0)throw new Error(`File ${e} must have export (not default) class page`);return i===!0&&(o.template=void 0),o}static getPageSync(t,e=!0){t||(t=this.getPath());let i=require(t);return this._getPage(i,t,e)}static async getPage(t,e=!0){t||(t=this.getPath());let i=await import(`${t}?t=${Date.now()}`);return this._getPage(i,t,e)}static getPagesSync(t,e=!0){if(t||(t=this.getPath()),!(0,w.existsSync)(t))throw new Error(`Directory ${t} is not found, please make it manually`);return(0,w.readdirSync)(t).map(s=>{let o=(0,_.join)(t,s);return{path:o,page:this.getPageSync(o,e)}})}};var F=require("path");var j=require("logging-pretty");var f=class{static{u(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(e,i)=>`\${(data && data["${i}"]) ?? ""}`)}static _processBaseBlocks(t){let e=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,i={};for(let s of t.matchAll(e)){let o=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[o]=a}return i}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(e,i)=>{let s=i.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(t){return t.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(t){return t.replace(/<div>([\s\S]*?)<\/div>/gi,(e,i)=>i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(t){let e=/<media(?:\s+([^>]*))?>([\s\S]*?)<\/media>/gi,i={};for(let s of t.matchAll(e)){let o=s[1],n=s[2],a={},r=/(\w+)="([^"]*)"/g;if(o)for(let b of o.matchAll(r))a[b[1]]=b[2];let c=a.lang||"default",d=a.type,l=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),m={type:d};a.src&&(m.src=a.src),l&&d!=="video_note"&&d!=="sticker"&&(m.caption=l),d==="location"&&(a.latitude&&(m.latitude=a.latitude),a.longitude&&(m.longitude=a.longitude),l&&(m.caption=l)),d==="contact"&&(a.phone&&(m.phone=a.phone),a.first_name&&(m.first_name=a.first_name),a.last_name&&(m.last_name=a.last_name),a.vcard&&(m.vcard=a.vcard),l&&(m.caption=l)),i[c]=m}return i}static _processMessageBlocks(t){let e=/<message(?:\s+([^>]*))?>([\s\S]*?)<\/message>/gi,i={};for(let[,s,o]of t.matchAll(e)){let n={},a=/(\w+)="([^"]*)"/g;if(s)for(let d of s.matchAll(a))n[d[1]]=d[2];let r=n.lang||"default",c=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[r]=c}return i}static _processDescriptionBlocks(t){let e=/<description(?:\s+([^>]*))?>([\s\S]*?)<\/description>/gi,i={};for(let[,s,o]of t.matchAll(e)){let n={},a=/(\w+)="([^"]*)"/g;if(s)for(let l of s.matchAll(a))n[l[1]]=l[2];let r=n.lang||"default",c=n.scope||"default",d=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[r]||(i[r]={}),i[r][c]=d}return i}static _processKeyboardBlocks(t){let e=/<keyboard(?:\s+([^>]*))?>([\s\S]*?)<\/keyboard>/gi,i={};for(let[,s,o]of t.matchAll(e)){let n={},a=/(\w+)="([^"]*)"/g;if(s)for(let l of s.matchAll(a))n[l[1]]=l[2];let r=n.lang||"default",c=n.type==="bottom"?"bottom":"inline",d=o.trim();i[r]||(i[r]={}),i[r][c]=d}return i}static _compileToFunction(t,e){let i;e?i=t.map(n=>`\`${n}\``).join(","):i=`\`${t}\``;let s=i;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),e){let o=`return [${s}]`;return new Function("data",o)}else{let o=`return ${s}`;return new Function("data",o)}}static compileMedia(t){let e=this._processBaseBlocks(t),i={};for(let[s,o]of Object.entries(e)){let n=this._processMediaBlocks(o);i[s]={};for(let[a,r]of Object.entries(n))if(r.caption){let c=this._processVariables(this._processScriptBlocks(r.caption)),d=this._compileToFunction(c,!1);i[s][a]=l=>({...r,caption:d(l)})}else i[s][a]=()=>r}return i}static compileMessages(t){let e=this._processBaseBlocks(t),i={};for(let[s,o]of Object.entries(e)){let n=this._processMessageBlocks(o);i[s]={};for(let[a,r]of Object.entries(n)){let c=this._processVariables(this._processScriptBlocks(r));i[s][a]=this._compileToFunction(c,!1)}}return i}static compileDescription(t){let e=this._processBaseBlocks(t),i={};for(let[s,o]of Object.entries(e)){let n=this._processDescriptionBlocks(o);i[s]={};for(let[a,r]of Object.entries(n))for(let[c,d]of Object.entries(r))i[s][c]||(i[s][c]={}),i[s][c][a]=this._compileToFunction(d,!1)}return i}static compileKeyboards(t){let e=this._processBaseBlocks(t),i={};for(let[s,o]of Object.entries(e)){let n=this._processKeyboardBlocks(o);i[s]={};for(let[a,r]of Object.entries(n)){i[s][a]={};for(let[c,d]of Object.entries(r)){let m=d.split(/(?<!\\),\s*/).map(b=>b.replace(/\\,/g,",").trim()).map(b=>this._processVariables(this._processScriptBlocks(b)));i[s][a][c]=this._compileToFunction(m,!0)}}}return i}};var $=require("fs/promises"),L=require("chokidar"),C=require("path"),y=require("fs");var k=class{static{u(this,"TemplateManager")}_map=new Map;_engine=f;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_isWatchEnabled;constructor(t){let{path:e,enableWatch:i=!1}=t;this._path=e,this._isWatchEnabled=i,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(!this._path||!Array.isArray(this._path))throw new Error("Path must be set as string array");for(let t=0;t<this._path.length;t++){let e=this._path[t];if(!(0,y.existsSync)(e))throw new Error(`Template base path is not exists: ${e}`);if(!(0,y.statSync)(e).isDirectory())throw new Error(`Template base path is not a directory: ${e}`)}return!0}catch(t){throw new Error(`Failed to validate Template base path: ${t}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let t=0;t<this._path.length;t++){let e=this._path[t],i=(0,L.watch)(e,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[t]=i,i.on("change",this._handleFileChange.bind(this)),i.on("add",this._handleFileAdd.bind(this)),i.on("unlink",this._handleFileDelete.bind(this)),i.on("error",this._handleWatchError.bind(this))}}async _handleFileChange(t){let e=(0,C.basename)(t);this._isValidFile(e)&&await this._loadFile(e,!1)}async _handleFileAdd(t){let e=(0,C.basename)(t);this._isValidFile(e)&&await this._loadFile(e,!1)}_handleFileDelete(t){let e=(0,C.basename)(t),i=this._getKey(e);this._map.has(i)&&this._map.delete(i)}_handleWatchError(t){}_loadAllFiles(){for(let t=0;t<this._path.length;t++){let e=this._path[t],s=(0,y.readdirSync)(e,"utf8").filter(o=>this._isValidFile(o));for(let o of s)this._loadFile(o,!0)}}async _loadFile(t,e=!0){for(let i=0;i<this._path.length;i++){let s=this._path[i],o=(0,C.join)(s,t),n=this._getExtension(t),a=this._getKey(t);if(n==".html"){let r=e?(0,y.readFileSync)(o,"utf8"):await(0,$.readFile)(o,"utf8");this._compile(a,r)}else if(n==".ts"){let r=await P.getPage(o,!1);r?.template!==void 0&&this._compile(a,r.template),r.template=void 0}else throw new Error(`File ${t} is not support`)}}_getExtension(t){return(0,C.extname)(t).toLowerCase()}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,e,i){let s=this._map.get(t),o=s||{},n=!1;(i===void 0||i?.media===!1||s?.media===void 0)&&(o.media=f.compileMedia(e),n=!0),(i===void 0||i?.message===!1||s?.message===void 0)&&(o.message=f.compileMessages(e),n=!0),(i===void 0||i?.keyboard===!1||s?.keyboard===void 0)&&(o.keyboard=f.compileKeyboards(e),n=!0),(i===void 0||i?.description===!1||s?.description===void 0)&&(o.description=f.compileDescription(e),n=!0),n&&this._map.set(t,o)}getMedia(t,e="default",i="default",s){let n=this._map.get(t)?.media?.[e],a=n?.[i]||n?.default;if(!a)return{};try{return a(s)}catch{return{}}}getMessage(t,e="default",i="default",s){let n=this._map.get(t)?.message?.[e],a=n?.[i]||n?.default;if(!a)return"";try{return a(s)}catch{return""}}getDescription(t,e="default",i="default",s="default",o){let a=this._map.get(t)?.description?.[e]?.[s],r=a?.[i]||a?.default;if(!r)return"";try{return r(o)}catch{return""}}getDescriptionLanguage(t,e="default",i="default"){let o=this._map.get(t)?.description?.[e]?.[i];return o?Object.keys(o):[]}getDescriptionScopes(t,e="default"){let s=this._map.get(t)?.description?.[e];return s?Object.keys(s):[]}getKeyboard(t,e="default",i="default",s="inline",o){let a=this._map.get(t)?.keyboard?.[e],r=a?.[i]?.[s]||a?.default?.[s];if(!r)return[];try{return r(o)}catch{return[]}}async write(t,e){if(this._getExtension(t)!=".html")return null;for(let i=0;i<this._path.length;i++){let s=(0,C.join)(this._path[i],t);if((0,y.existsSync)(s))return(0,y.writeFileSync)(s,e,"utf8"),await this._loadFile(t,!1),!0}return null}has(t){return this._map.has(t)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(t,e)=>typeof e=="function"?e.toString():e).length}}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};var T=require("grammy");var D=class{static{u(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;handlerBotUpdate;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");this.log=t.log===!0?new j.LoggingPretty:t.log?t.log:void 0,this.cacheSession=t.cacheSession||new I("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new k({path:[(0,F.join)(process.cwd(),"src","pages")]}),this.bot=this.createBot(t.token),this.bot.catch(this.onCatch),this.registerOnCallbackQueryData(),this.registerOnMessageText(),this.registerOnMessagePhoto(),this.registerOnMessageVideo(),this.registerOnMessageAudio(),this.registerOnMessageDocument(),this.registerOnMessageAnimation(),this.registerOnMessageVoice(),this.registerOnMessageVideoNote(),this.registerOnMessageSticker(),this.registerOnMessageLocation(),this.registerOnMessageContact(),this.handlerBotUpdate=this.bot.handleUpdate,this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),t.deploy.startsWith("polling")?this.runPolling():t.deploy.startsWith("webhook:")?this.runWebhook(t.deploy.split("webhook:")[1]):t.deploy.startsWith("serverless:")&&this.runServerless(t.deploy.split("serverless:")[1])}onCatch(t){this.log?.error?.(`[Bot.catch]: ${String(t)}`)}onStart(t,e,i){let{username:s}=t;this.log?.success?.(`Telegram bot polling started: ${s} ${e=="webhook"||e=="serverless"?`(${i})`:""}`)}createBot(t){return new T.Bot(t)}createCtx(t){return new x({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:u(async t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let e=(0,T.webhookCallback)(this.bot,"bun"),i="/telegram-webhook";this.handlerBotUpdate=e,(0,W.serve)({fetch(a){let{pathname:r}=new URL(a.url);if(r===i)return a.method==="POST"?e(a):new Response("OK",{status:200});if(r==="/"&&a.method==="GET"){let c=new Date().toISOString();return new Response(JSON.stringify({timestamp:c}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}});let s=await this.bot.api.getWebhookInfo(),o=t.endsWith("/")?t.slice(0,-1)+i:t+i;s.url!=o&&await this.bot.api.setWebhook(o);let n=await this.bot.api.getMe();this.onStart(n,"webhook",o)}async runServerless(t){this.handlerBotUpdate=(0,T.webhookCallback)(this.bot,t);let e=await this.bot.api.getMe();this.onStart(e,"serverless",t)}pageBuildData(t,e){t?.data===void 0&&(t.data=t.buildData()),t.data.name=(0,F.parse)(e).name}pageSorts(t,e){let i=t.data.name,s=t.prototype,o="Payload",n="Command",a="Caption",r="Free",c=e.dynamic,d=e.dynamicSpesific,l=u(h=>h.charAt(0).toUpperCase()+h.slice(1),"upFirst"),m=u(h=>h.replace(o,"").replace(n,"").replace(a,"").replace(r,""),"getPureFuncName"),b=u((h,g)=>s[`methodSession${l(h)}`](g),"methodSession");e.all[i]=t;for(let h=0;h<e.lenListFuncStaticSession;h++){let g=e.listFuncStaticSession[h],Q=e.static[g],U=e.staticIntent[g],O=e.staticSession[g],V={name:i,func:g},A=Q||U;if(A!==void 0){let z=g.includes(n)?`/${i}`:i;A[s.intent(z,g.startsWith("callback"))]=V}O!==void 0&&(O[b(g,i)]=V),g.toLowerCase().endsWith("free")&&d[m(g)].push(V)}s.free&&c.push(i)}async pageSyncDescription(t){let e=new Map,i=u((o,n,a,r)=>{e.has(n)||e.set(n,new Map);let c=e.get(n);c.has(a)||c.set(a,[]);let d=c.get(a);d.some(l=>l.command===o)||d.push({command:o,description:r})},"addCommand"),s=t.static.textCommand;for(let[,o]of Object.entries(s)){let n=o.name,a=this.templateManager.getDescriptionScopes(n);for(let r of a){let c=this.templateManager.getDescriptionLanguage(n,"default",r);for(let d of c){let l=this.templateManager.getDescription(n,"default",d,r);l&&i(n,r,d,l)}}}for(let[o,n]of e)for(let[a,r]of n){let c={type:o},d=a==="default"?void 0:a;try{let l=await this.bot.api.getMyCommands({scope:c,language_code:d}),m=JSON.stringify(l.map(h=>({command:h.command,description:h.description})).sort((h,g)=>h.command.localeCompare(g.command))),b=JSON.stringify(r.sort((h,g)=>h.command.localeCompare(g.command)));m!==b&&(await this.bot.api.setMyCommands(r,{scope:c,language_code:d}),this.log?.info?.(`Synced descriptions for scope: ${o},${d?` lang: ${d}`:""} (Total: ${r.length})`))}catch(l){this.log?.error?.(`Failed to sync descriptions for scope: ${o},${d?` lang: ${d}`:""}. ${String(l)}`)}}}pageLoads(){this.log?.info?.("Load pages..");let t={},e=t,i=t,s=[],o=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],n=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],a=[...o,...n,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],r=u((d,l)=>Object.fromEntries(d.map(m=>[m,{...l}])),"makeObject"),c={all:{},dynamic:[],dynamicSpesific:{text:s,photo:s,video:s,audio:s,document:s,animation:s,voice:s,videoNote:s,sticker:s,location:s,contact:s},static:r(o,t),staticIntent:r(n,e),staticSession:r(a,i),listFuncStatic:o,listFuncStaticIntent:n,listFuncStaticSession:a,lenListFuncStatic:o.length,lenListFuncStaticIntent:n.length,lenListFuncStaticSession:a.length};return P.getPagesSync(void 0,!0).forEach(({path:d,page:l})=>{this.pageBuildData(l,d),this.pageSorts(l,c)}),this.log?.info?.(`Finish load pages with total (${Object.keys(c.all).length})`),this.pageSyncDescription(c),c}async pageRoutes(t,e){let i,s;if(i===void 0){let n=t.callbackData,a=t.msgText,r=t.msgCaption,c=this.pages.static;for(let d=0;d<this.pages.lenListFuncStatic;d++){let l=this.pages.listFuncStatic[d];if(s=c[l][n||a||r],s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i===void 0){let n=await t.sessionGet();if(n){let a=n.method,r=this.pages.staticSession;for(let c=0;c<this.pages.lenListFuncStaticSession;c++){let d=this.pages.listFuncStaticSession[c];if(s=r[d][a],s)break}s!==void 0&&(i=this.pages.all[s.name])}}if(i===void 0){let n=t.callbackDataIntent,a=t.msgTextIntent,r=t.msgCaptionIntent,c=this.pages.staticIntent;for(let d=0;d<this.pages.lenListFuncStaticIntent;d++){let l=this.pages.listFuncStaticIntent[d];if(s=c[l][n||a||r],s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i!==void 0&&s!==void 0)return await new i(t)[s.func]?.();let o=this.pages.dynamicSpesific[e]||[];for(let n=0;n<o.length;n++){let a=o[n];if(a===void 0)continue;let r=this.pages.all[a.func];if(r===void 0)continue;let d=await new r(t)[a.name]?.();if(d!==null)return d}for(let n=0;n<this.pages.dynamic.length;n++){let a=this.pages.dynamic[n];if(a===void 0)continue;let r=this.pages.all[a];if(r===void 0)continue;let d=await new r(t).free?.();if(d!==null)return d}return null}async hookBeforeRoute(t,e){return!0}async hookErrorPage(t,e,i,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,e){let i=this.createCtx(t);try{if(await this.hookBeforeRoute(i,e)===!1)return;await this.pageRoutes(i,e)===null&&await this.hookErrorInputNotFoundPage(i)}catch(s){await this.hookErrorPage(i,e,s,!1)}}async onCallbackQueryData(t){let e=this.createCtx(t);try{if(await e.callbackQueryAnswer(),await this.hookBeforeRoute(e,"onCallbackQueryData")===!1)return;await this.pageRoutes(e,"callback")}catch(i){await this.hookErrorPage(e,"onCallbackQueryData",i,!0)}}async onMessageText(t){await this.onMessage(t,"onMessageText")}async onMessagePhoto(t){await this.onMessage(t,"onMessagePhoto")}async onMessageVideo(t){await this.onMessage(t,"onMessageVideo")}async onMessageAudio(t){await this.onMessage(t,"onMessageAudio")}async onMessageDocument(t){await this.onMessage(t,"onMessageDocument")}async onMessageAnimation(t){await this.onMessage(t,"onMessageAnimation")}async onMessageVoice(t){await this.onMessage(t,"onMessageVoice")}async onMessageVideoNote(t){await this.onMessage(t,"onMessageVideoNote")}async onMessageSticker(t){await this.onMessage(t,"onMessageSticker")}async onMessageLocation(t){await this.onMessage(t,"onMessageLocation")}async onMessageContact(t){await this.onMessage(t,"onMessageContact")}registerOnCallbackQueryData(){this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this))}registerOnMessageText(){this.bot.on("message:text",this.onMessageText.bind(this))}registerOnMessagePhoto(){this.bot.on("message:photo",this.onMessagePhoto.bind(this))}registerOnMessageVideo(){this.bot.on("message:video",this.onMessageVideo.bind(this))}registerOnMessageAudio(){this.bot.on("message:audio",this.onMessageAudio.bind(this))}registerOnMessageDocument(){this.bot.on("message:document",this.onMessageDocument.bind(this))}registerOnMessageAnimation(){this.bot.on("message:animation",this.onMessageAnimation.bind(this))}registerOnMessageVoice(){this.bot.on("message:voice",this.onMessageVoice.bind(this))}registerOnMessageVideoNote(){this.bot.on("message:video_note",this.onMessageVideoNote.bind(this))}registerOnMessageSticker(){this.bot.on("message:sticker",this.onMessageSticker.bind(this))}registerOnMessageLocation(){this.bot.on("message:location",this.onMessageLocation.bind(this))}registerOnMessageContact(){this.bot.on("message:contact",this.onMessageContact.bind(this))}};0&&(module.exports={BaseGeneral,CacheExternal,Ctx,Gramstax,TemplateEngine,TemplateManager});
|
package/dist/src/index.d.cts
CHANGED
|
@@ -98,8 +98,6 @@ type ITemplateOptions = {
|
|
|
98
98
|
path: string[];
|
|
99
99
|
/** Enable file watching for hot reloading (only work for persistent type) */
|
|
100
100
|
enableWatch?: boolean;
|
|
101
|
-
/** Force language params to this value */
|
|
102
|
-
forceLanguage?: string;
|
|
103
101
|
};
|
|
104
102
|
/** Template management system */
|
|
105
103
|
declare class TemplateManager {
|
|
@@ -108,7 +106,6 @@ declare class TemplateManager {
|
|
|
108
106
|
_watcher: FSWatcher[];
|
|
109
107
|
_supportedExtensions: Set<string>;
|
|
110
108
|
readonly _path: ITemplateOptions[`path`];
|
|
111
|
-
readonly _forceLanguage: ITemplateOptions[`forceLanguage`];
|
|
112
109
|
readonly _isWatchEnabled: ITemplateOptions[`enableWatch`];
|
|
113
110
|
constructor(options: ITemplateOptions);
|
|
114
111
|
/** Validate and ensure template directory exists. @returns Void */
|
|
@@ -287,12 +284,12 @@ declare class Ctx extends BaseGeneral {
|
|
|
287
284
|
replyLocation(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyLocation): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
|
|
288
285
|
replyContact(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyContact): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
|
|
289
286
|
replyAction(type: ITypeReplyAction): Promise<true>;
|
|
290
|
-
edit(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEdit): Promise<true | (grammy_types.Update.Edited & grammy_types.Message.CommonMessage & {
|
|
287
|
+
edit(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEdit, fallbackReply?: boolean): Promise<true | (grammy_types.Update.Edited & grammy_types.Message.CommonMessage & {
|
|
291
288
|
text: string;
|
|
292
289
|
} & Partial<{
|
|
293
290
|
entities: grammy_types.MessageEntity[];
|
|
294
291
|
}>) | undefined>;
|
|
295
|
-
editMedia<T extends IMediaBlock[`type`]>(type: T, keyboard?: IKb, data?: IData, baseId?: string, options1?: T extends `voice` ? IOptReplyVoice : T extends `video_note` ? IOptReplyVideoNote : T extends `sticker` ? IOptReplySticker : T extends `location` ? IOptReplyLocation : T extends `contact` ? IOptReplyContact : IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
|
|
292
|
+
editMedia<T extends IMediaBlock[`type`]>(type: T, keyboard?: IKb, data?: IData, baseId?: string, options1?: T extends `voice` ? IOptReplyVoice : T extends `video_note` ? IOptReplyVideoNote : T extends `sticker` ? IOptReplySticker : T extends `location` ? IOptReplyLocation : T extends `contact` ? IOptReplyContact : IOptEditMedia1, options2?: IOptEditMedia2, fallbackReply?: boolean): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
|
|
296
293
|
editPhoto(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
|
|
297
294
|
editVideo(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
|
|
298
295
|
editAudio(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -98,8 +98,6 @@ type ITemplateOptions = {
|
|
|
98
98
|
path: string[];
|
|
99
99
|
/** Enable file watching for hot reloading (only work for persistent type) */
|
|
100
100
|
enableWatch?: boolean;
|
|
101
|
-
/** Force language params to this value */
|
|
102
|
-
forceLanguage?: string;
|
|
103
101
|
};
|
|
104
102
|
/** Template management system */
|
|
105
103
|
declare class TemplateManager {
|
|
@@ -108,7 +106,6 @@ declare class TemplateManager {
|
|
|
108
106
|
_watcher: FSWatcher[];
|
|
109
107
|
_supportedExtensions: Set<string>;
|
|
110
108
|
readonly _path: ITemplateOptions[`path`];
|
|
111
|
-
readonly _forceLanguage: ITemplateOptions[`forceLanguage`];
|
|
112
109
|
readonly _isWatchEnabled: ITemplateOptions[`enableWatch`];
|
|
113
110
|
constructor(options: ITemplateOptions);
|
|
114
111
|
/** Validate and ensure template directory exists. @returns Void */
|
|
@@ -287,12 +284,12 @@ declare class Ctx extends BaseGeneral {
|
|
|
287
284
|
replyLocation(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyLocation): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
|
|
288
285
|
replyContact(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyContact): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
|
|
289
286
|
replyAction(type: ITypeReplyAction): Promise<true>;
|
|
290
|
-
edit(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEdit): Promise<true | (grammy_types.Update.Edited & grammy_types.Message.CommonMessage & {
|
|
287
|
+
edit(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEdit, fallbackReply?: boolean): Promise<true | (grammy_types.Update.Edited & grammy_types.Message.CommonMessage & {
|
|
291
288
|
text: string;
|
|
292
289
|
} & Partial<{
|
|
293
290
|
entities: grammy_types.MessageEntity[];
|
|
294
291
|
}>) | undefined>;
|
|
295
|
-
editMedia<T extends IMediaBlock[`type`]>(type: T, keyboard?: IKb, data?: IData, baseId?: string, options1?: T extends `voice` ? IOptReplyVoice : T extends `video_note` ? IOptReplyVideoNote : T extends `sticker` ? IOptReplySticker : T extends `location` ? IOptReplyLocation : T extends `contact` ? IOptReplyContact : IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
|
|
292
|
+
editMedia<T extends IMediaBlock[`type`]>(type: T, keyboard?: IKb, data?: IData, baseId?: string, options1?: T extends `voice` ? IOptReplyVoice : T extends `video_note` ? IOptReplyVideoNote : T extends `sticker` ? IOptReplySticker : T extends `location` ? IOptReplyLocation : T extends `contact` ? IOptReplyContact : IOptEditMedia1, options2?: IOptEditMedia2, fallbackReply?: boolean): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
|
|
296
293
|
editPhoto(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
|
|
297
294
|
editVideo(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
|
|
298
295
|
editAudio(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
|
package/dist/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var B=Object.defineProperty;var p=(g,t)=>B(g,"name",{value:t,configurable:!0}),k=(g=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(g,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):g)(function(g){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+g+'" is not supported')});import{LoggingPretty as E}from"logging-pretty";var C=class{static{p(this,"BaseGeneral")}static log=new E;static logError(t,e){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${e}]: ${String(t)}`)}logError(t,e,i){this.constructor.log.error(`[${e||this.constructor.name}:${i}] ${String(t)}`)}};import{Keyv as $}from"keyv";import L from"@keyv/redis";var S=class extends ${constructor(e="memory",i,s,n){let o;e.startsWith("redis")&&(o=new L(e)),e==="memory"&&(o=new Map),n?.forceStore&&(o=n.forceStore);super({store:o,namespace:i,ttl:s});this.url=e}static{p(this,"CacheExternal")}};import{setTimeout as W}from"timers/promises";import{InlineKeyboard as F,Keyboard as w}from"grammy";var P=class extends C{static{p(this,"Ctx")}static template;static data;data=this.constructor.data;get isPremium(){return this.ct.from?.is_premium??!1}get isBot(){return this.ct.from?.is_bot??!1}get userid(){return this.ct.from?.id}get username(){return this.ct.from?.username}get fullname(){return`${this.ct.from?.first_name||""}${this.ct.from?.last_name||""}`}get firstname(){return this.ct.from?.first_name}get lastname(){return this.ct.from?.last_name}get msgText(){return this.ct.message?.text}get msgTextIntent(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ")[0]:""}get msgTextPayloads(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ").slice(1):[]}get msgTextPayload(){return this.msgTextPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionIntent(){return this.msgCaption&&this.msgCaption.indexOf(" ")!=-1?this.msgCaption.split(" ")[0]:""}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataIntent(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":")[0]:""}get callbackDataPayloads(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":").slice(1):[]}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}get callbackDataParts(){return this.callbackDataPayload&&this.callbackDataPayload.indexOf("+")!=-1?this.callbackDataPayload.split("+"):[]}get languageCode(){return this.ct.from?.language_code}set languageCode(t){this.ct.from.language_code=t}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){super(),this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp,t?.data&&(this.temp.data=t.data)}async broadcast(t,e,i,s,n,o){let r=e.map(d=>this.templateManager.getMessage(this.data.name,n,d,s));for(let d=0;d<t.length;d++){let c=t[d],l=r[d];await this.ct.api.sendMessage(c,l,{parse_mode:"HTML",reply_markup:i,...o}),d+1==30&&await W(1200)}}async reply(t,e,i,s){let n=this.templateManager.getMessage(this.data.name,i,this.languageCode,e);return await this.ct.reply(n,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,e,i,s,n){let o=this.templateManager.getMedia(this.data.name,s,this.languageCode,i),a={parse_mode:"HTML",reply_markup:e,...n};if(t=="photo")return await this.ct.replyWithPhoto(o.src,{caption:o.caption,...a});if(t=="video")return await this.ct.replyWithVideo(o.src,{caption:o.caption,...a});if(t=="audio")return await this.ct.replyWithAudio(o.src,{caption:o.caption,...a});if(t=="document")return await this.ct.replyWithDocument(o.src,{caption:o.caption,...a});if(t=="animation")return await this.ct.replyWithAnimation(o.src,{caption:o.caption,...a});if(t=="voice")return await this.ct.replyWithVoice(o.src,a);if(t=="video_note")return await this.ct.replyWithVideoNote(o.src,a);if(t=="sticker")return await this.ct.replyWithSticker(o.src,a);if(t=="location")return await this.ct.replyWithLocation(o.latitude,o.longitude,a);if(t=="contact")return await this.ct.replyWithContact(o.phone,o.first_name,{vcard:o.vcard,...a})}async replyPhoto(t,e,i,s){return this.replyMedia("photo",t,e,i,s)}async replyVideo(t,e,i,s){return this.replyMedia("video",t,e,i,s)}async replyAudio(t,e,i,s){return this.replyMedia("audio",t,e,i,s)}async replyDocument(t,e,i,s){return this.replyMedia("document",t,e,i,s)}async replyAnimation(t,e,i,s){return this.replyMedia("animation",t,e,i,s)}async replyVoice(t,e,i,s){return this.replyMedia("voice",t,e,i,s)}async replyVideoNote(t,e,i,s){return this.replyMedia("video_note",t,e,i,s)}async replySticker(t,e,i,s){return this.replyMedia("sticker",t,e,i,s)}async replyLocation(t,e,i,s){return this.replyMedia("location",t,e,i,s)}async replyContact(t,e,i,s){return this.replyMedia("contact",t,e,i,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,e,i,s){try{let n=this.templateManager.getMessage(this.data.name,i,this.languageCode,e);return await this.ct.editMessageText(n,{parse_mode:"HTML",reply_markup:t,...s})}catch{await this.reply(t,e,i,s)}}async editMedia(t,e,i,s,n,o){try{let{src:a,caption:r}=this.templateManager.getMedia(this.data.name,s,this.languageCode,i);return t=="voice"?(await this.delete(),await this.replyVoice(e,i,s,n)):t=="video_note"?(await this.delete(),await this.replyVoice(e,i,s,n)):t=="sticker"?(await this.delete(),await this.replySticker(e,i,s,n)):t=="location"?(await this.delete(),await this.replyLocation(e,i,s,n)):t=="contact"?(await this.delete(),await this.replyContact(e,i,s,n)):await this.ct.editMessageMedia({media:a,caption:r,type:t,parse_mode:"HTML",...n},{reply_markup:e,...o})}catch{await this.reply(e,i,s,o)}}async editPhoto(t,e,i,s,n){return await this.editMedia("photo",t,e,i,s,n)}async editVideo(t,e,i,s,n){return await this.editMedia("video",t,e,i,s,n)}async editAudio(t,e,i,s,n){return await this.editMedia("audio",t,e,i,s,n)}async editDocument(t,e,i,s,n){return await this.editMedia("document",t,e,i,s,n)}async editAnimation(t,e,i,s,n){return await this.editMedia("animation",t,e,i,s,n)}async editVoice(t,e,i,s){return await this.editMedia("voice",t,e,i,s)}async editVideoNote(t,e,i,s){return await this.editMedia("video_note",t,e,i,s)}async editSticker(t,e,i,s){return await this.editMedia("sticker",t,e,i,s)}async editLocation(t,e,i,s){return await this.editMedia("location",t,e,i,s)}async editContact(t,e,i,s){return await this.editMedia("contact",t,e,i,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,e,i){try{let s={method:t,params:e,...i},n=await this.cacheSession.set(`${this.userid}`,s);return n&&(this.session=s),n}catch{return null}}async sessionGet(){try{let t=await this.cacheSession.get(`${this.userid}`);return t&&(this.session=t),t||null}catch{return null}}async sessionClear(){try{let t=await this.cacheSession.delete(`${this.userid}`);return t&&(this.session={}),t}catch{return null}}static buildData(t){return{name:"",callbackData:t?function(...e){let i=t(...e);return`${this.name}${i===void 0?"":`:${i}`}`}:function(){return this?.name}}}inlineKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.languageCode}:i`,r=this.cacheKeyboard.get(a);if(!r){let d=new F,c=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"inline",e?.data),l=t(d,c);return this.cacheKeyboard.set(a,l),l}return r}let s=new F,n=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"inline",e?.data);return t(s,n)}bottomKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.languageCode}:b`,r=this.cacheKeyboard.get(a);if(!r){let d=new w,c=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"bottom",e?.data),l=t(d,c);return l.resized(!0),this.cacheKeyboard.set(a,l),l}return r}let s=new w,n=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"bottom",e?.data),o=t(s,n);return o.resized(),o}validateSessionCallback(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallback(e)}validateSessionCallbackPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallbackPayload(e)}validateSessionText(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionText(e)}validateSessionTextPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextPayload(e)}validateSessionTextCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommand(e)}validateSessionTextCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommandPayload(e)}validateSessionTextFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextFree(e)}validateSessionPhotoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaption(e)}validateSessionPhotoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionPayload(e)}validateSessionPhotoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommand(e)}validateSessionPhotoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommandPayload(e)}validateSessionPhotoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoFree(e)}validateSessionVideoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaption(e)}validateSessionVideoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionPayload(e)}validateSessionVideoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommand(e)}validateSessionVideoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommandPayload(e)}validateSessionVideoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoFree(e)}validateSessionAudioCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaption(e)}validateSessionAudioCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionPayload(e)}validateSessionAudioCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommand(e)}validateSessionAudioCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommandPayload(e)}validateSessionAudioFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioFree(e)}validateSessionDocumentCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaption(e)}validateSessionDocumentCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionPayload(e)}validateSessionDocumentCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommand(e)}validateSessionDocumentCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommandPayload(e)}validateSessionDocumentFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentFree(e)}validateSessionAnimationCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaption(e)}validateSessionAnimationCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionPayload(e)}validateSessionAnimationCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommand(e)}validateSessionAnimationCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommandPayload(e)}validateSessionAnimationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationFree(e)}validateSessionVoiceCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaption(e)}validateSessionVoiceCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionPayload(e)}validateSessionVoiceCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommand(e)}validateSessionVoiceCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommandPayload(e)}validateSessionVoiceFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceFree(e)}validateSessionVideoNoteCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaption(e)}validateSessionVideoNoteCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionPayload(e)}validateSessionVideoNoteCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommand(e)}validateSessionVideoNoteCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommandPayload(e)}validateSessionVideoNoteFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteFree(e)}validateSessionStickerFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionStickerFree(e)}validateSessionLocationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionLocationFree(e)}validateSessionContactFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionContactFree(e)}sessionCallback(t,e){return this.sessionSet(this.methodSessionCallback(e),t)}sessionCallbackPayload(t,e){return this.sessionSet(this.methodSessionCallbackPayload(e),t)}sessionText(t,e){return this.sessionSet(this.methodSessionText(e),t)}sessionTextPayload(t,e){return this.sessionSet(this.methodSessionTextPayload(e),t)}sessionTextCommand(t,e){return this.sessionSet(this.methodSessionTextCommand(e),t)}sessionTextCommandPayload(t,e){return this.sessionSet(this.methodSessionTextCommandPayload(e),t)}sessionTextFree(t,e){return this.sessionSet(this.methodSessionTextFree(e),t)}sessionPhotoCaption(t,e){return this.sessionSet(this.methodSessionPhotoCaption(e),t)}sessionPhotoCaptionPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionPayload(e),t)}sessionPhotoCaptionCommand(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommand(e),t)}sessionPhotoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommandPayload(e),t)}sessionPhotoFree(t,e){return this.sessionSet(this.methodSessionPhotoFree(e),t)}sessionVideoCaption(t,e){return this.sessionSet(this.methodSessionVideoCaption(e),t)}sessionVideoCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionPayload(e),t)}sessionVideoCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommand(e),t)}sessionVideoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommandPayload(e),t)}sessionVideoFree(t,e){return this.sessionSet(this.methodSessionVideoFree(e),t)}sessionAudioCaption(t,e){return this.sessionSet(this.methodSessionAudioCaption(e),t)}sessionAudioCaptionPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionPayload(e),t)}sessionAudioCaptionCommand(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommand(e),t)}sessionAudioCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommandPayload(e),t)}sessionAudioFree(t,e){return this.sessionSet(this.methodSessionAudioFree(e),t)}sessionDocumentCaption(t,e){return this.sessionSet(this.methodSessionDocumentCaption(e),t)}sessionDocumentCaptionPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionPayload(e),t)}sessionDocumentCaptionCommand(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommand(e),t)}sessionDocumentCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommandPayload(e),t)}sessionDocumentFree(t,e){return this.sessionSet(this.methodSessionDocumentFree(e),t)}sessionAnimationCaption(t,e){return this.sessionSet(this.methodSessionAnimationCaption(e),t)}sessionAnimationCaptionPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionPayload(e),t)}sessionAnimationCaptionCommand(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommand(e),t)}sessionAnimationCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommandPayload(e),t)}sessionAnimationFree(t,e){return this.sessionSet(this.methodSessionAnimationFree(e),t)}sessionVoiceCaption(t,e){return this.sessionSet(this.methodSessionVoiceCaption(e),t)}sessionVoiceCaptionPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionPayload(e),t)}sessionVoiceCaptionCommand(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommand(e),t)}sessionVoiceCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommandPayload(e),t)}sessionVoiceFree(t,e){return this.sessionSet(this.methodSessionVoiceFree(e),t)}sessionVideoNoteCaption(t,e){return this.sessionSet(this.methodSessionVideoNoteCaption(e),t)}sessionVideoNoteCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionPayload(e),t)}sessionVideoNoteCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommand(e),t)}sessionVideoNoteCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommandPayload(e),t)}sessionVideoNoteFree(t,e){return this.sessionSet(this.methodSessionVideoNoteFree(e),t)}sessionStickerFree(t,e){return this.sessionSet(this.methodSessionStickerFree(e),t)}sessionLocationFree(t,e){return this.sessionSet(this.methodSessionLocationFree(e),t)}sessionContactFree(t,e){return this.sessionSet(this.methodSessionContactFree(e),t)}sessionToCallback(t,e){return this.sessionCallback({...this.session.params,...t},e)}sessionToCallbackPayload(t,e){return this.sessionCallbackPayload({...this.session.params,...t},e)}sessionToText(t,e){return this.sessionText({...this.session.params,...t},e)}sessionToTextPayload(t,e){return this.sessionTextPayload({...this.session.params,...t},e)}sessionToTextCommand(t,e){return this.sessionTextCommand({...this.session.params,...t},e)}sessionToTextCommandPayload(t,e){return this.sessionTextCommandPayload({...this.session.params,...t},e)}sessionToTextFree(t,e){return this.sessionTextFree({...this.session.params,...t},e)}sessionToPhotoCaption(t,e){return this.sessionPhotoCaption({...this.session.params,...t},e)}sessionToPhotoCaptionPayload(t,e){return this.sessionPhotoCaptionPayload({...this.session.params,...t},e)}sessionToPhotoCaptionCommand(t,e){return this.sessionPhotoCaptionCommand({...this.session.params,...t},e)}sessionToPhotoCaptionCommandPayload(t,e){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...t},e)}sessionToPhotoFree(t,e){return this.sessionPhotoFree({...this.session.params,...t},e)}sessionToVideoCaption(t,e){return this.sessionVideoCaption({...this.session.params,...t},e)}sessionToVideoCaptionPayload(t,e){return this.sessionVideoCaptionPayload({...this.session.params,...t},e)}sessionToVideoCaptionCommand(t,e){return this.sessionVideoCaptionCommand({...this.session.params,...t},e)}sessionToVideoCaptionCommandPayload(t,e){return this.sessionVideoCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoFree(t,e){return this.sessionVideoFree({...this.session.params,...t},e)}sessionToAudioCaption(t,e){return this.sessionAudioCaption({...this.session.params,...t},e)}sessionToAudioCaptionPayload(t,e){return this.sessionAudioCaptionPayload({...this.session.params,...t},e)}sessionToAudioCaptionCommand(t,e){return this.sessionAudioCaptionCommand({...this.session.params,...t},e)}sessionToAudioCaptionCommandPayload(t,e){return this.sessionAudioCaptionCommandPayload({...this.session.params,...t},e)}sessionToAudioFree(t,e){return this.sessionAudioFree({...this.session.params,...t},e)}sessionToDocumentCaption(t,e){return this.sessionDocumentCaption({...this.session.params,...t},e)}sessionToDocumentCaptionPayload(t,e){return this.sessionDocumentCaptionPayload({...this.session.params,...t},e)}sessionToDocumentCaptionCommand(t,e){return this.sessionDocumentCaptionCommand({...this.session.params,...t},e)}sessionToDocumentCaptionCommandPayload(t,e){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...t},e)}sessionToDocumentFree(t,e){return this.sessionDocumentFree({...this.session.params,...t},e)}sessionToAnimationCaption(t,e){return this.sessionAnimationCaption({...this.session.params,...t},e)}sessionToAnimationCaptionPayload(t,e){return this.sessionAnimationCaptionPayload({...this.session.params,...t},e)}sessionToAnimationCaptionCommand(t,e){return this.sessionAnimationCaptionCommand({...this.session.params,...t},e)}sessionToAnimationCaptionCommandPayload(t,e){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...t},e)}sessionToAnimationFree(t,e){return this.sessionAnimationFree({...this.session.params,...t},e)}sessionToVoiceCaption(t,e){return this.sessionVoiceCaption({...this.session.params,...t},e)}sessionToVoiceCaptionPayload(t,e){return this.sessionVoiceCaptionPayload({...this.session.params,...t},e)}sessionToVoiceCaptionCommand(t,e){return this.sessionVoiceCaptionCommand({...this.session.params,...t},e)}sessionToVoiceCaptionCommandPayload(t,e){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...t},e)}sessionToVoiceFree(t,e){return this.sessionVoiceFree({...this.session.params,...t},e)}sessionToVideoNoteCaption(t,e){return this.sessionVideoNoteCaption({...this.session.params,...t},e)}sessionToVideoNoteCaptionPayload(t,e){return this.sessionVideoNoteCaptionPayload({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommand(t,e){return this.sessionVideoNoteCaptionCommand({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommandPayload(t,e){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoNoteFree(t,e){return this.sessionVideoNoteFree({...this.session.params,...t},e)}sessionToStickerFree(t,e){return this.sessionStickerFree({...this.session.params,...t},e)}sessionToLocationFree(t,e){return this.sessionLocationFree({...this.session.params,...t},e)}sessionToContactFree(t,e){return this.sessionContactFree({...this.session.params,...t},e)}intent(t,e=!0){t||(t=e?this.data.callbackData():this.data.name);let i=e?":":" ";return t?.indexOf?.(i)!=-1?t?.split?.(i)?.[0]:t}methodSession(t,e){return`${t}-${e||this.data.name}`}methodSessionCallback(t){return this.methodSession("1",t)}methodSessionCallbackPayload(t){return this.methodSession("2",t)}methodSessionText(t){return this.methodSession("3",t)}methodSessionTextPayload(t){return this.methodSession("4",t)}methodSessionTextCommand(t){return this.methodSession("5",t)}methodSessionTextCommandPayload(t){return this.methodSession("6",t)}methodSessionTextFree(t){return this.methodSession("7",t)}methodSessionPhotoCaption(t){return this.methodSession("8",t)}methodSessionPhotoCaptionPayload(t){return this.methodSession("9",t)}methodSessionPhotoCaptionCommand(t){return this.methodSession("10",t)}methodSessionPhotoCaptionCommandPayload(t){return this.methodSession("11",t)}methodSessionPhotoFree(t){return this.methodSession("12",t)}methodSessionVideoCaption(t){return this.methodSession("13",t)}methodSessionVideoCaptionPayload(t){return this.methodSession("14",t)}methodSessionVideoCaptionCommand(t){return this.methodSession("15",t)}methodSessionVideoCaptionCommandPayload(t){return this.methodSession("16",t)}methodSessionVideoFree(t){return this.methodSession("17",t)}methodSessionAudioCaption(t){return this.methodSession("18",t)}methodSessionAudioCaptionPayload(t){return this.methodSession("19",t)}methodSessionAudioCaptionCommand(t){return this.methodSession("20",t)}methodSessionAudioCaptionCommandPayload(t){return this.methodSession("21",t)}methodSessionAudioFree(t){return this.methodSession("22",t)}methodSessionDocumentCaption(t){return this.methodSession("23",t)}methodSessionDocumentCaptionPayload(t){return this.methodSession("24",t)}methodSessionDocumentCaptionCommand(t){return this.methodSession("25",t)}methodSessionDocumentCaptionCommandPayload(t){return this.methodSession("26",t)}methodSessionDocumentFree(t){return this.methodSession("27",t)}methodSessionAnimationCaption(t){return this.methodSession("28",t)}methodSessionAnimationCaptionPayload(t){return this.methodSession("29",t)}methodSessionAnimationCaptionCommand(t){return this.methodSession("30",t)}methodSessionAnimationCaptionCommandPayload(t){return this.methodSession("31",t)}methodSessionAnimationFree(t){return this.methodSession("32",t)}methodSessionVoiceCaption(t){return this.methodSession("33",t)}methodSessionVoiceCaptionPayload(t){return this.methodSession("34",t)}methodSessionVoiceCaptionCommand(t){return this.methodSession("35",t)}methodSessionVoiceCaptionCommandPayload(t){return this.methodSession("36",t)}methodSessionVoiceFree(t){return this.methodSession("37",t)}methodSessionVideoNoteCaption(t){return this.methodSession("38",t)}methodSessionVideoNoteCaptionPayload(t){return this.methodSession("39",t)}methodSessionVideoNoteCaptionCommand(t){return this.methodSession("40",t)}methodSessionVideoNoteCaptionCommandPayload(t){return this.methodSession("41",t)}methodSessionVideoNoteFree(t){return this.methodSession("42",t)}methodSessionStickerFree(t){return this.methodSession("43",t)}methodSessionLocationFree(t){return this.methodSession("44",t)}methodSessionContactFree(t){return this.methodSession("45",t)}};import{serve as Y}from"bun";import{join as _}from"path";import{existsSync as j,readdirSync as Q}from"fs";var f=class{static{p(this,"HelperPage")}static getPath(){return _(process.cwd(),"src","pages")}static _getPage(t,e,i=!0){let n=Object.values(t)[0];if(n===void 0)throw new Error(`File ${e} must have export (not default) class page`);return i===!0&&(n.template=void 0),n}static getPageSync(t,e=!0){t||(t=this.getPath());let i=k(t);return this._getPage(i,t,e)}static async getPage(t,e=!0){t||(t=this.getPath());let i=await import(`${t}?t=${Date.now()}`);return this._getPage(i,t,e)}static getPagesSync(t,e=!0){if(t||(t=this.getPath()),!j(t))throw new Error(`Directory ${t} is not found, please make it manually`);return Q(t).map(s=>{let n=_(t,s);return{path:n,page:this.getPageSync(n,e)}})}};import{join as Z,parse as tt}from"path";import{LoggingPretty as et}from"logging-pretty";var b=class{static{p(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(e,i)=>`\${(data && data["${i}"]) ?? ""}`)}static _processBaseBlocks(t){let e=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,i={};for(let s of t.matchAll(e)){let n=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[n]=a}return i}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(e,i)=>{let s=i.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(t){return t.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(t){return t.replace(/<div>([\s\S]*?)<\/div>/gi,(e,i)=>i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(t){let e=/<media\s+([^>]+)>([\s\S]*?)<\/media>/gi,i={};for(let s of t.matchAll(e)){let n=s[1],o=s[2],a={},r=/(\w+)="([^"]*)"/g;for(let y of n.matchAll(r))a[y[1]]=y[2];if(!a.lang)continue;let d=a.lang,c=a.type,l=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),u={type:c};a.src&&(u.src=a.src),l&&c!=="video_note"&&c!=="sticker"&&(u.caption=l),c==="location"&&(a.latitude&&(u.latitude=a.latitude),a.longitude&&(u.longitude=a.longitude),l&&(u.caption=l)),c==="contact"&&(a.phone&&(u.phone=a.phone),a.first_name&&(u.first_name=a.first_name),a.last_name&&(u.last_name=a.last_name),a.vcard&&(u.vcard=a.vcard),l&&(u.caption=l)),i[d]=u}return i}static _processMessageBlocks(t){let e=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,i={};for(let[,s,n]of t.matchAll(e)){let o=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[s]=o}return i}static _processDescriptionBlocks(t){let e=/<description\b[^>]*\blang="([^"]*)"[^>]*\bscope="([^"]*)"[^>]*>([\s\S]*?)<\/description>/gi,i={};for(let[,s,n,o]of t.matchAll(e)){let a=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[s]||(i[s]={}),i[s][n]=a}return i}static _processKeyboardBlocks(t){let e=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\stype="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,i={};for(let[,s,n,o]of t.matchAll(e)){let a=n==="bottom"?"bottom":"inline",r=o.trim();i[s]||(i[s]={}),i[s][a]=r}return i}static _compileToFunction(t,e){let i;e?i=t.map(o=>`\`${o}\``).join(","):i=`\`${t}\``;let s=i;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),e){let n=`return [${s}]`;return new Function("data",n)}else{let n=`return ${s}`;return new Function("data",n)}}static compileMedia(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processMediaBlocks(n);i[s]={};for(let[a,r]of Object.entries(o))if(r.caption){let d=this._processVariables(this._processScriptBlocks(r.caption)),c=this._compileToFunction(d,!1);i[s][a]=l=>({...r,caption:c(l)})}else i[s][a]=()=>r}return i}static compileMessages(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processMessageBlocks(n);i[s]={};for(let[a,r]of Object.entries(o)){let d=this._processVariables(this._processScriptBlocks(r));i[s][a]=this._compileToFunction(d,!1)}}return i}static compileDescription(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processDescriptionBlocks(n);i[s]={};for(let[a,r]of Object.entries(o))for(let[d,c]of Object.entries(r))i[s][d]||(i[s][d]={}),i[s][d][a]=this._compileToFunction(c,!1)}return i}static compileKeyboards(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processKeyboardBlocks(n);i[s]={};for(let[a,r]of Object.entries(o)){i[s][a]={};for(let[d,c]of Object.entries(r)){let u=c.split(/(?<!\\),\s*/).map(y=>y.replace(/\\,/g,",").trim()).map(y=>this._processVariables(this._processScriptBlocks(y)));i[s][a][d]=this._compileToFunction(u,!0)}}}return i}};import{readFile as U}from"fs/promises";import{watch as z}from"chokidar";import{basename as M,join as V,extname as G}from"path";import{readdirSync as H,readFileSync as J,existsSync as D,statSync as q,writeFileSync as X}from"fs";var v=class{static{p(this,"TemplateManager")}_map=new Map;_engine=b;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_forceLanguage;_isWatchEnabled;constructor(t){let{path:e,enableWatch:i=!1,forceLanguage:s}=t;this._path=e,this._forceLanguage=s,this._isWatchEnabled=i,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(!this._path||!Array.isArray(this._path))throw new Error("Path must be set as string array");for(let t=0;t<this._path.length;t++){let e=this._path[t];if(!D(e))throw new Error(`Template base path is not exists: ${e}`);if(!q(e).isDirectory())throw new Error(`Template base path is not a directory: ${e}`)}return!0}catch(t){throw new Error(`Failed to validate Template base path: ${t}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let t=0;t<this._path.length;t++){let e=this._path[t],i=z(e,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[t]=i,i.on("change",this._handleFileChange.bind(this)),i.on("add",this._handleFileAdd.bind(this)),i.on("unlink",this._handleFileDelete.bind(this)),i.on("error",this._handleWatchError.bind(this))}}async _handleFileChange(t){let e=M(t);this._isValidFile(e)&&await this._loadFile(e,!1)}async _handleFileAdd(t){let e=M(t);this._isValidFile(e)&&await this._loadFile(e,!1)}_handleFileDelete(t){let e=M(t),i=this._getKey(e);this._map.has(i)&&this._map.delete(i)}_handleWatchError(t){}_loadAllFiles(){for(let t=0;t<this._path.length;t++){let e=this._path[t],s=H(e,"utf8").filter(n=>this._isValidFile(n));for(let n of s)this._loadFile(n,!0)}}async _loadFile(t,e=!0){for(let i=0;i<this._path.length;i++){let s=this._path[i],n=V(s,t),o=this._getExtension(t),a=this._getKey(t);if(o==".html"){let r=e?J(n,"utf8"):await U(n,"utf8");this._compile(a,r)}else if(o==".ts"){let r=await f.getPage(n,!1);r?.template!==void 0&&this._compile(a,r.template),r.template=void 0}else throw new Error(`File ${t} is not support`)}}_getExtension(t){return G(t).toLowerCase()}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,e,i){let s=this._map.get(t),n=s||{},o=!1;(i===void 0||i?.media===!1||s?.media===void 0)&&(n.media=b.compileMedia(e),o=!0),(i===void 0||i?.message===!1||s?.message===void 0)&&(n.message=b.compileMessages(e),o=!0),(i===void 0||i?.keyboard===!1||s?.keyboard===void 0)&&(n.keyboard=b.compileKeyboards(e),o=!0),(i===void 0||i?.description===!1||s?.description===void 0)&&(n.description=b.compileDescription(e),o=!0),o&&this._map.set(t,n)}getMedia(t,e="default",i="en",s){let o=this._map.get(t)?.media?.[e]?.[this._forceLanguage||i];if(!o)return{};try{return o(s)}catch{return{}}}getMessage(t,e="default",i="en",s){let o=this._map.get(t)?.message?.[e]?.[this._forceLanguage||i];if(!o)return"";try{return o(s)}catch{return""}}getDescription(t,e="default",i="default",s="default",n){let a=this._map.get(t)?.description?.[e]?.[s]?.[this._forceLanguage||i];if(!a)return"";try{return a(n)}catch{return""}}getDescriptionLanguage(t,e="default",i="default"){let n=this._map.get(t)?.description?.[e]?.[i];return n?Object.keys(n):[]}getDescriptionScopes(t,e="default"){let s=this._map.get(t)?.description?.[e];return s?Object.keys(s):[]}getKeyboard(t,e="default",i="en",s="inline",n){let a=this._map.get(t)?.keyboard?.[e]?.[this._forceLanguage||i]?.[s];if(!a)return[];try{return a(n)}catch{return[]}}async write(t,e){if(this._getExtension(t)!=".html")return null;for(let i=0;i<this._path.length;i++){let s=V(this._path[i],t);if(D(s))return X(s,e,"utf8"),await this._loadFile(t,!1),!0}return null}has(t){return this._map.has(t)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(t,e)=>typeof e=="function"?e.toString():e).length}}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};import{Bot as it,webhookCallback as O}from"grammy";var A=class{static{p(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;handlerBotUpdate;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");this.log=t.log===!0?new et:t.log?t.log:void 0,this.cacheSession=t.cacheSession||new S("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new v({path:[Z(process.cwd(),"src","pages")]}),this.bot=this.createBot(t.token),this.bot.catch(this.onCatch),this.registerOnCallbackQueryData(),this.registerOnMessageText(),this.registerOnMessagePhoto(),this.registerOnMessageVideo(),this.registerOnMessageAudio(),this.registerOnMessageDocument(),this.registerOnMessageAnimation(),this.registerOnMessageVoice(),this.registerOnMessageVideoNote(),this.registerOnMessageSticker(),this.registerOnMessageLocation(),this.registerOnMessageContact(),this.handlerBotUpdate=this.bot.handleUpdate,this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),t.deploy.startsWith("polling")?this.runPolling():t.deploy.startsWith("webhook:")?this.runWebhook(t.deploy.split("webhook:")[1]):t.deploy.startsWith("serverless:")&&this.runServerless(t.deploy.split("serverless:")[1])}onCatch(t){this.log?.error?.(`[Bot.catch]: ${String(t)}`)}onStart(t,e,i){let{username:s}=t;this.log?.success?.(`Telegram bot polling started: ${s} ${e=="webhook"||e=="serverless"?`(${i})`:""}`)}createBot(t){return new it(t)}createCtx(t){return new P({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:p(async t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let e=O(this.bot,"bun"),i="/telegram-webhook";this.handlerBotUpdate=e,Y({fetch(a){let{pathname:r}=new URL(a.url);if(r===i)return a.method==="POST"?e(a):new Response("OK",{status:200});if(r==="/"&&a.method==="GET"){let d=new Date().toISOString();return new Response(JSON.stringify({timestamp:d}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}});let s=await this.bot.api.getWebhookInfo(),n=t.endsWith("/")?t.slice(0,-1)+i:t+i;s.url!=n&&await this.bot.api.setWebhook(n);let o=await this.bot.api.getMe();this.onStart(o,"webhook",n)}async runServerless(t){this.handlerBotUpdate=O(this.bot,t);let e=await this.bot.api.getMe();this.onStart(e,"serverless",t)}pageBuildData(t,e){t?.data===void 0&&(t.data=t.buildData()),t.data.name=tt(e).name}pageSorts(t,e){let i=t.data.name,s=t.prototype,n="Payload",o="Command",a="Caption",r="Free",d=e.dynamic,c=e.dynamicSpesific,l=p(m=>m.charAt(0).toUpperCase()+m.slice(1),"upFirst"),u=p(m=>m.replace(n,"").replace(o,"").replace(a,"").replace(r,""),"getPureFuncName"),y=p((m,h)=>s[`methodSession${l(m)}`](h),"methodSession");e.all[i]=t;for(let m=0;m<e.lenListFuncStaticSession;m++){let h=e.listFuncStaticSession[m],R=e.static[h],N=e.staticIntent[h],x=e.staticSession[h],I={name:i,func:h},T=R||N;if(T!==void 0){let K=h.includes(o)?`/${i}`:i;T[s.intent(K,h.startsWith("callback"))]=I}x!==void 0&&(x[y(h,i)]=I),h.toLowerCase().endsWith("free")&&c[u(h)].push(I)}s.free&&d.push(i)}async pageSyncDescription(t){let e=new Map,i=p((n,o,a,r)=>{e.has(o)||e.set(o,new Map);let d=e.get(o);d.has(a)||d.set(a,[]);let c=d.get(a);c.some(l=>l.command===n)||c.push({command:n,description:r})},"addCommand"),s=t.static.textCommand;for(let[,n]of Object.entries(s)){let o=n.name,a=this.templateManager.getDescriptionScopes(o);for(let r of a){let d=this.templateManager.getDescriptionLanguage(o,"default",r);for(let c of d){let l=this.templateManager.getDescription(o,"default",c,r);l&&i(o,r,c,l)}}}for(let[n,o]of e)for(let[a,r]of o){let d={type:n},c=a==="default"?void 0:a;try{let l=await this.bot.api.getMyCommands({scope:d,language_code:c}),u=JSON.stringify(l.map(m=>({command:m.command,description:m.description})).sort((m,h)=>m.command.localeCompare(h.command))),y=JSON.stringify(r.sort((m,h)=>m.command.localeCompare(h.command)));u!==y&&(await this.bot.api.setMyCommands(r,{scope:d,language_code:c}),this.log?.info?.(`Synced descriptions for scope: ${n},${c?` lang: ${c}`:""} (Total: ${r.length})`))}catch(l){this.log?.error?.(`Failed to sync descriptions for scope: ${n},${c?` lang: ${c}`:""}. ${String(l)}`)}}}pageLoads(){this.log?.info?.("Load pages..");let t={},e=t,i=t,s=[],n=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],o=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],a=[...n,...o,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],r=p((c,l)=>Object.fromEntries(c.map(u=>[u,{...l}])),"makeObject"),d={all:{},dynamic:[],dynamicSpesific:{text:s,photo:s,video:s,audio:s,document:s,animation:s,voice:s,videoNote:s,sticker:s,location:s,contact:s},static:r(n,t),staticIntent:r(o,e),staticSession:r(a,i),listFuncStatic:n,listFuncStaticIntent:o,listFuncStaticSession:a,lenListFuncStatic:n.length,lenListFuncStaticIntent:o.length,lenListFuncStaticSession:a.length};return f.getPagesSync(void 0,!0).forEach(({path:c,page:l})=>{this.pageBuildData(l,c),this.pageSorts(l,d)}),this.log?.info?.(`Finish load pages with total (${Object.keys(d.all).length})`),this.pageSyncDescription(d),d}async pageRoutes(t,e){let i,s;if(i===void 0){let o=t.callbackData,a=t.msgText,r=t.msgCaption,d=this.pages.static;for(let c=0;c<this.pages.lenListFuncStatic;c++){let l=this.pages.listFuncStatic[c];if(s=d[l][o||a||r],s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i===void 0){let o=await t.sessionGet();if(o){let a=o.method,r=this.pages.staticSession;for(let d=0;d<this.pages.lenListFuncStaticSession;d++){let c=this.pages.listFuncStaticSession[d];if(s=r[c][a],s)break}s!==void 0&&(i=this.pages.all[s.name])}}if(i===void 0){let o=t.callbackDataIntent,a=t.msgTextIntent,r=t.msgCaptionIntent,d=this.pages.staticIntent;for(let c=0;c<this.pages.lenListFuncStaticIntent;c++){let l=this.pages.listFuncStaticIntent[c];if(s=d[l][o||a||r],s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i!==void 0&&s!==void 0)return await new i(t)[s.func]?.();let n=this.pages.dynamicSpesific[e]||[];for(let o=0;o<n.length;o++){let a=n[o];if(a===void 0)continue;let r=this.pages.all[a.func];if(r===void 0)continue;let c=await new r(t)[a.name]?.();if(c!==null)return c}for(let o=0;o<this.pages.dynamic.length;o++){let a=this.pages.dynamic[o];if(a===void 0)continue;let r=this.pages.all[a];if(r===void 0)continue;let c=await new r(t).free?.();if(c!==null)return c}return null}async hookBeforeRoute(t,e){return!0}async hookErrorPage(t,e,i,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,e){let i=this.createCtx(t);try{if(await this.hookBeforeRoute(i,e)===!1)return;await this.pageRoutes(i,e)===null&&await this.hookErrorInputNotFoundPage(i)}catch(s){await this.hookErrorPage(i,e,s,!1)}}async onCallbackQueryData(t){let e=this.createCtx(t);try{if(await e.callbackQueryAnswer(),await this.hookBeforeRoute(e,"onCallbackQueryData")===!1)return;await this.pageRoutes(e,"callback")}catch(i){await this.hookErrorPage(e,"onCallbackQueryData",i,!0)}}async onMessageText(t){await this.onMessage(t,"onMessageText")}async onMessagePhoto(t){await this.onMessage(t,"onMessagePhoto")}async onMessageVideo(t){await this.onMessage(t,"onMessageVideo")}async onMessageAudio(t){await this.onMessage(t,"onMessageAudio")}async onMessageDocument(t){await this.onMessage(t,"onMessageDocument")}async onMessageAnimation(t){await this.onMessage(t,"onMessageAnimation")}async onMessageVoice(t){await this.onMessage(t,"onMessageVoice")}async onMessageVideoNote(t){await this.onMessage(t,"onMessageVideoNote")}async onMessageSticker(t){await this.onMessage(t,"onMessageSticker")}async onMessageLocation(t){await this.onMessage(t,"onMessageLocation")}async onMessageContact(t){await this.onMessage(t,"onMessageContact")}registerOnCallbackQueryData(){this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this))}registerOnMessageText(){this.bot.on("message:text",this.onMessageText.bind(this))}registerOnMessagePhoto(){this.bot.on("message:photo",this.onMessagePhoto.bind(this))}registerOnMessageVideo(){this.bot.on("message:video",this.onMessageVideo.bind(this))}registerOnMessageAudio(){this.bot.on("message:audio",this.onMessageAudio.bind(this))}registerOnMessageDocument(){this.bot.on("message:document",this.onMessageDocument.bind(this))}registerOnMessageAnimation(){this.bot.on("message:animation",this.onMessageAnimation.bind(this))}registerOnMessageVoice(){this.bot.on("message:voice",this.onMessageVoice.bind(this))}registerOnMessageVideoNote(){this.bot.on("message:video_note",this.onMessageVideoNote.bind(this))}registerOnMessageSticker(){this.bot.on("message:sticker",this.onMessageSticker.bind(this))}registerOnMessageLocation(){this.bot.on("message:location",this.onMessageLocation.bind(this))}registerOnMessageContact(){this.bot.on("message:contact",this.onMessageContact.bind(this))}};export{C as BaseGeneral,S as CacheExternal,P as Ctx,A as Gramstax,b as TemplateEngine,v as TemplateManager};
|
|
1
|
+
var B=Object.defineProperty;var p=(g,t)=>B(g,"name",{value:t,configurable:!0}),T=(g=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(g,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):g)(function(g){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+g+'" is not supported')});import{LoggingPretty as E}from"logging-pretty";var C=class{static{p(this,"BaseGeneral")}static log=new E;static logError(t,e){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${e}]: ${String(t)}`)}logError(t,e,i){this.constructor.log.error(`[${e||this.constructor.name}:${i}] ${String(t)}`)}};import{Keyv as $}from"keyv";import L from"@keyv/redis";var S=class extends ${constructor(e="memory",i,s,o){let n;e.startsWith("redis")&&(n=new L(e)),e==="memory"&&(n=new Map),o?.forceStore&&(n=o.forceStore);super({store:n,namespace:i,ttl:s});this.url=e}static{p(this,"CacheExternal")}};import{setTimeout as W}from"timers/promises";import{InlineKeyboard as w,Keyboard as F}from"grammy";var P=class extends C{static{p(this,"Ctx")}static template;static data;data=this.constructor.data;get isPremium(){return this.ct.from?.is_premium??!1}get isBot(){return this.ct.from?.is_bot??!1}get userid(){return this.ct.from?.id}get username(){return this.ct.from?.username}get fullname(){return`${this.ct.from?.first_name||""}${this.ct.from?.last_name||""}`}get firstname(){return this.ct.from?.first_name}get lastname(){return this.ct.from?.last_name}get msgText(){return this.ct.message?.text}get msgTextIntent(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ")[0]:""}get msgTextPayloads(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ").slice(1):[]}get msgTextPayload(){return this.msgTextPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionIntent(){return this.msgCaption&&this.msgCaption.indexOf(" ")!=-1?this.msgCaption.split(" ")[0]:""}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataIntent(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":")[0]:""}get callbackDataPayloads(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":").slice(1):[]}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}get callbackDataParts(){return this.callbackDataPayload&&this.callbackDataPayload.indexOf("+")!=-1?this.callbackDataPayload.split("+"):[]}get languageCode(){return this.ct.from?.language_code}set languageCode(t){this.ct.from.language_code=t}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){super(),this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp,t?.data&&(this.temp.data=t.data)}async broadcast(t,e,i,s,o,n){let r=e.map(c=>this.templateManager.getMessage(this.data.name,o,c,s));for(let c=0;c<t.length;c++){let d=t[c],l=r[c];await this.ct.api.sendMessage(d,l,{parse_mode:"HTML",reply_markup:i,...n}),c+1==30&&await W(1200)}}async reply(t,e,i,s){let o=this.templateManager.getMessage(this.data.name,i,this.languageCode,e);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,e,i,s,o){let n=this.templateManager.getMedia(this.data.name,s,this.languageCode,i),a={parse_mode:"HTML",reply_markup:e,...o};if(t=="photo")return await this.ct.replyWithPhoto(n.src,{caption:n.caption,...a});if(t=="video")return await this.ct.replyWithVideo(n.src,{caption:n.caption,...a});if(t=="audio")return await this.ct.replyWithAudio(n.src,{caption:n.caption,...a});if(t=="document")return await this.ct.replyWithDocument(n.src,{caption:n.caption,...a});if(t=="animation")return await this.ct.replyWithAnimation(n.src,{caption:n.caption,...a});if(t=="voice")return await this.ct.replyWithVoice(n.src,a);if(t=="video_note")return await this.ct.replyWithVideoNote(n.src,a);if(t=="sticker")return await this.ct.replyWithSticker(n.src,a);if(t=="location")return await this.ct.replyWithLocation(n.latitude,n.longitude,a);if(t=="contact")return await this.ct.replyWithContact(n.phone,n.first_name,{vcard:n.vcard,...a})}async replyPhoto(t,e,i,s){return this.replyMedia("photo",t,e,i,s)}async replyVideo(t,e,i,s){return this.replyMedia("video",t,e,i,s)}async replyAudio(t,e,i,s){return this.replyMedia("audio",t,e,i,s)}async replyDocument(t,e,i,s){return this.replyMedia("document",t,e,i,s)}async replyAnimation(t,e,i,s){return this.replyMedia("animation",t,e,i,s)}async replyVoice(t,e,i,s){return this.replyMedia("voice",t,e,i,s)}async replyVideoNote(t,e,i,s){return this.replyMedia("video_note",t,e,i,s)}async replySticker(t,e,i,s){return this.replyMedia("sticker",t,e,i,s)}async replyLocation(t,e,i,s){return this.replyMedia("location",t,e,i,s)}async replyContact(t,e,i,s){return this.replyMedia("contact",t,e,i,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,e,i,s,o=!0){try{let n=this.templateManager.getMessage(this.data.name,i,this.languageCode,e);return await this.ct.editMessageText(n,{parse_mode:"HTML",reply_markup:t,...s})}catch(n){if(o)await this.reply(t,e,i,s);else throw n}}async editMedia(t,e,i,s,o,n,a=!0){try{let{src:r,caption:c}=this.templateManager.getMedia(this.data.name,s,this.languageCode,i);return t=="voice"?(await this.delete(),await this.replyVoice(e,i,s,o)):t=="video_note"?(await this.delete(),await this.replyVoice(e,i,s,o)):t=="sticker"?(await this.delete(),await this.replySticker(e,i,s,o)):t=="location"?(await this.delete(),await this.replyLocation(e,i,s,o)):t=="contact"?(await this.delete(),await this.replyContact(e,i,s,o)):await this.ct.editMessageMedia({media:r,caption:c,type:t,parse_mode:"HTML",...o},{reply_markup:e,...n})}catch(r){if(a===!0)await this.reply(e,i,s,n);else throw r}}async editPhoto(t,e,i,s,o){return await this.editMedia("photo",t,e,i,s,o)}async editVideo(t,e,i,s,o){return await this.editMedia("video",t,e,i,s,o)}async editAudio(t,e,i,s,o){return await this.editMedia("audio",t,e,i,s,o)}async editDocument(t,e,i,s,o){return await this.editMedia("document",t,e,i,s,o)}async editAnimation(t,e,i,s,o){return await this.editMedia("animation",t,e,i,s,o)}async editVoice(t,e,i,s){return await this.editMedia("voice",t,e,i,s)}async editVideoNote(t,e,i,s){return await this.editMedia("video_note",t,e,i,s)}async editSticker(t,e,i,s){return await this.editMedia("sticker",t,e,i,s)}async editLocation(t,e,i,s){return await this.editMedia("location",t,e,i,s)}async editContact(t,e,i,s){return await this.editMedia("contact",t,e,i,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,e,i){try{let s={method:t,params:e,...i},o=await this.cacheSession.set(`${this.userid}`,s);return o&&(this.session=s),o}catch{return null}}async sessionGet(){try{let t=await this.cacheSession.get(`${this.userid}`);return t&&(this.session=t),t||null}catch{return null}}async sessionClear(){try{let t=await this.cacheSession.delete(`${this.userid}`);return t&&(this.session={}),t}catch{return null}}static buildData(t){return{name:"",callbackData:t?function(...e){let i=t(...e);return`${this.name}${i===void 0?"":`:${i}`}`}:function(){return this?.name}}}inlineKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.languageCode}:i`,r=this.cacheKeyboard.get(a);if(!r){let c=new w,d=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"inline",e?.data),l=t(c,d);return this.cacheKeyboard.set(a,l),l}return r}let s=new w,o=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"inline",e?.data);return t(s,o)}bottomKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.languageCode}:b`,r=this.cacheKeyboard.get(a);if(!r){let c=new F,d=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"bottom",e?.data),l=t(c,d);return l.resized(!0),this.cacheKeyboard.set(a,l),l}return r}let s=new F,o=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"bottom",e?.data),n=t(s,o);return n.resized(),n}validateSessionCallback(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallback(e)}validateSessionCallbackPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallbackPayload(e)}validateSessionText(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionText(e)}validateSessionTextPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextPayload(e)}validateSessionTextCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommand(e)}validateSessionTextCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommandPayload(e)}validateSessionTextFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextFree(e)}validateSessionPhotoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaption(e)}validateSessionPhotoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionPayload(e)}validateSessionPhotoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommand(e)}validateSessionPhotoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommandPayload(e)}validateSessionPhotoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoFree(e)}validateSessionVideoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaption(e)}validateSessionVideoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionPayload(e)}validateSessionVideoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommand(e)}validateSessionVideoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommandPayload(e)}validateSessionVideoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoFree(e)}validateSessionAudioCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaption(e)}validateSessionAudioCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionPayload(e)}validateSessionAudioCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommand(e)}validateSessionAudioCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommandPayload(e)}validateSessionAudioFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioFree(e)}validateSessionDocumentCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaption(e)}validateSessionDocumentCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionPayload(e)}validateSessionDocumentCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommand(e)}validateSessionDocumentCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommandPayload(e)}validateSessionDocumentFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentFree(e)}validateSessionAnimationCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaption(e)}validateSessionAnimationCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionPayload(e)}validateSessionAnimationCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommand(e)}validateSessionAnimationCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommandPayload(e)}validateSessionAnimationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationFree(e)}validateSessionVoiceCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaption(e)}validateSessionVoiceCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionPayload(e)}validateSessionVoiceCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommand(e)}validateSessionVoiceCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommandPayload(e)}validateSessionVoiceFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceFree(e)}validateSessionVideoNoteCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaption(e)}validateSessionVideoNoteCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionPayload(e)}validateSessionVideoNoteCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommand(e)}validateSessionVideoNoteCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommandPayload(e)}validateSessionVideoNoteFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteFree(e)}validateSessionStickerFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionStickerFree(e)}validateSessionLocationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionLocationFree(e)}validateSessionContactFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionContactFree(e)}sessionCallback(t,e){return this.sessionSet(this.methodSessionCallback(e),t)}sessionCallbackPayload(t,e){return this.sessionSet(this.methodSessionCallbackPayload(e),t)}sessionText(t,e){return this.sessionSet(this.methodSessionText(e),t)}sessionTextPayload(t,e){return this.sessionSet(this.methodSessionTextPayload(e),t)}sessionTextCommand(t,e){return this.sessionSet(this.methodSessionTextCommand(e),t)}sessionTextCommandPayload(t,e){return this.sessionSet(this.methodSessionTextCommandPayload(e),t)}sessionTextFree(t,e){return this.sessionSet(this.methodSessionTextFree(e),t)}sessionPhotoCaption(t,e){return this.sessionSet(this.methodSessionPhotoCaption(e),t)}sessionPhotoCaptionPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionPayload(e),t)}sessionPhotoCaptionCommand(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommand(e),t)}sessionPhotoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommandPayload(e),t)}sessionPhotoFree(t,e){return this.sessionSet(this.methodSessionPhotoFree(e),t)}sessionVideoCaption(t,e){return this.sessionSet(this.methodSessionVideoCaption(e),t)}sessionVideoCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionPayload(e),t)}sessionVideoCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommand(e),t)}sessionVideoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommandPayload(e),t)}sessionVideoFree(t,e){return this.sessionSet(this.methodSessionVideoFree(e),t)}sessionAudioCaption(t,e){return this.sessionSet(this.methodSessionAudioCaption(e),t)}sessionAudioCaptionPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionPayload(e),t)}sessionAudioCaptionCommand(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommand(e),t)}sessionAudioCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommandPayload(e),t)}sessionAudioFree(t,e){return this.sessionSet(this.methodSessionAudioFree(e),t)}sessionDocumentCaption(t,e){return this.sessionSet(this.methodSessionDocumentCaption(e),t)}sessionDocumentCaptionPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionPayload(e),t)}sessionDocumentCaptionCommand(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommand(e),t)}sessionDocumentCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommandPayload(e),t)}sessionDocumentFree(t,e){return this.sessionSet(this.methodSessionDocumentFree(e),t)}sessionAnimationCaption(t,e){return this.sessionSet(this.methodSessionAnimationCaption(e),t)}sessionAnimationCaptionPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionPayload(e),t)}sessionAnimationCaptionCommand(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommand(e),t)}sessionAnimationCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommandPayload(e),t)}sessionAnimationFree(t,e){return this.sessionSet(this.methodSessionAnimationFree(e),t)}sessionVoiceCaption(t,e){return this.sessionSet(this.methodSessionVoiceCaption(e),t)}sessionVoiceCaptionPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionPayload(e),t)}sessionVoiceCaptionCommand(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommand(e),t)}sessionVoiceCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommandPayload(e),t)}sessionVoiceFree(t,e){return this.sessionSet(this.methodSessionVoiceFree(e),t)}sessionVideoNoteCaption(t,e){return this.sessionSet(this.methodSessionVideoNoteCaption(e),t)}sessionVideoNoteCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionPayload(e),t)}sessionVideoNoteCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommand(e),t)}sessionVideoNoteCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommandPayload(e),t)}sessionVideoNoteFree(t,e){return this.sessionSet(this.methodSessionVideoNoteFree(e),t)}sessionStickerFree(t,e){return this.sessionSet(this.methodSessionStickerFree(e),t)}sessionLocationFree(t,e){return this.sessionSet(this.methodSessionLocationFree(e),t)}sessionContactFree(t,e){return this.sessionSet(this.methodSessionContactFree(e),t)}sessionToCallback(t,e){return this.sessionCallback({...this.session.params,...t},e)}sessionToCallbackPayload(t,e){return this.sessionCallbackPayload({...this.session.params,...t},e)}sessionToText(t,e){return this.sessionText({...this.session.params,...t},e)}sessionToTextPayload(t,e){return this.sessionTextPayload({...this.session.params,...t},e)}sessionToTextCommand(t,e){return this.sessionTextCommand({...this.session.params,...t},e)}sessionToTextCommandPayload(t,e){return this.sessionTextCommandPayload({...this.session.params,...t},e)}sessionToTextFree(t,e){return this.sessionTextFree({...this.session.params,...t},e)}sessionToPhotoCaption(t,e){return this.sessionPhotoCaption({...this.session.params,...t},e)}sessionToPhotoCaptionPayload(t,e){return this.sessionPhotoCaptionPayload({...this.session.params,...t},e)}sessionToPhotoCaptionCommand(t,e){return this.sessionPhotoCaptionCommand({...this.session.params,...t},e)}sessionToPhotoCaptionCommandPayload(t,e){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...t},e)}sessionToPhotoFree(t,e){return this.sessionPhotoFree({...this.session.params,...t},e)}sessionToVideoCaption(t,e){return this.sessionVideoCaption({...this.session.params,...t},e)}sessionToVideoCaptionPayload(t,e){return this.sessionVideoCaptionPayload({...this.session.params,...t},e)}sessionToVideoCaptionCommand(t,e){return this.sessionVideoCaptionCommand({...this.session.params,...t},e)}sessionToVideoCaptionCommandPayload(t,e){return this.sessionVideoCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoFree(t,e){return this.sessionVideoFree({...this.session.params,...t},e)}sessionToAudioCaption(t,e){return this.sessionAudioCaption({...this.session.params,...t},e)}sessionToAudioCaptionPayload(t,e){return this.sessionAudioCaptionPayload({...this.session.params,...t},e)}sessionToAudioCaptionCommand(t,e){return this.sessionAudioCaptionCommand({...this.session.params,...t},e)}sessionToAudioCaptionCommandPayload(t,e){return this.sessionAudioCaptionCommandPayload({...this.session.params,...t},e)}sessionToAudioFree(t,e){return this.sessionAudioFree({...this.session.params,...t},e)}sessionToDocumentCaption(t,e){return this.sessionDocumentCaption({...this.session.params,...t},e)}sessionToDocumentCaptionPayload(t,e){return this.sessionDocumentCaptionPayload({...this.session.params,...t},e)}sessionToDocumentCaptionCommand(t,e){return this.sessionDocumentCaptionCommand({...this.session.params,...t},e)}sessionToDocumentCaptionCommandPayload(t,e){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...t},e)}sessionToDocumentFree(t,e){return this.sessionDocumentFree({...this.session.params,...t},e)}sessionToAnimationCaption(t,e){return this.sessionAnimationCaption({...this.session.params,...t},e)}sessionToAnimationCaptionPayload(t,e){return this.sessionAnimationCaptionPayload({...this.session.params,...t},e)}sessionToAnimationCaptionCommand(t,e){return this.sessionAnimationCaptionCommand({...this.session.params,...t},e)}sessionToAnimationCaptionCommandPayload(t,e){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...t},e)}sessionToAnimationFree(t,e){return this.sessionAnimationFree({...this.session.params,...t},e)}sessionToVoiceCaption(t,e){return this.sessionVoiceCaption({...this.session.params,...t},e)}sessionToVoiceCaptionPayload(t,e){return this.sessionVoiceCaptionPayload({...this.session.params,...t},e)}sessionToVoiceCaptionCommand(t,e){return this.sessionVoiceCaptionCommand({...this.session.params,...t},e)}sessionToVoiceCaptionCommandPayload(t,e){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...t},e)}sessionToVoiceFree(t,e){return this.sessionVoiceFree({...this.session.params,...t},e)}sessionToVideoNoteCaption(t,e){return this.sessionVideoNoteCaption({...this.session.params,...t},e)}sessionToVideoNoteCaptionPayload(t,e){return this.sessionVideoNoteCaptionPayload({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommand(t,e){return this.sessionVideoNoteCaptionCommand({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommandPayload(t,e){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoNoteFree(t,e){return this.sessionVideoNoteFree({...this.session.params,...t},e)}sessionToStickerFree(t,e){return this.sessionStickerFree({...this.session.params,...t},e)}sessionToLocationFree(t,e){return this.sessionLocationFree({...this.session.params,...t},e)}sessionToContactFree(t,e){return this.sessionContactFree({...this.session.params,...t},e)}intent(t,e=!0){t||(t=e?this.data.callbackData():this.data.name);let i=e?":":" ";return t?.indexOf?.(i)!=-1?t?.split?.(i)?.[0]:t}methodSession(t,e){return`${t}-${e||this.data.name}`}methodSessionCallback(t){return this.methodSession("1",t)}methodSessionCallbackPayload(t){return this.methodSession("2",t)}methodSessionText(t){return this.methodSession("3",t)}methodSessionTextPayload(t){return this.methodSession("4",t)}methodSessionTextCommand(t){return this.methodSession("5",t)}methodSessionTextCommandPayload(t){return this.methodSession("6",t)}methodSessionTextFree(t){return this.methodSession("7",t)}methodSessionPhotoCaption(t){return this.methodSession("8",t)}methodSessionPhotoCaptionPayload(t){return this.methodSession("9",t)}methodSessionPhotoCaptionCommand(t){return this.methodSession("10",t)}methodSessionPhotoCaptionCommandPayload(t){return this.methodSession("11",t)}methodSessionPhotoFree(t){return this.methodSession("12",t)}methodSessionVideoCaption(t){return this.methodSession("13",t)}methodSessionVideoCaptionPayload(t){return this.methodSession("14",t)}methodSessionVideoCaptionCommand(t){return this.methodSession("15",t)}methodSessionVideoCaptionCommandPayload(t){return this.methodSession("16",t)}methodSessionVideoFree(t){return this.methodSession("17",t)}methodSessionAudioCaption(t){return this.methodSession("18",t)}methodSessionAudioCaptionPayload(t){return this.methodSession("19",t)}methodSessionAudioCaptionCommand(t){return this.methodSession("20",t)}methodSessionAudioCaptionCommandPayload(t){return this.methodSession("21",t)}methodSessionAudioFree(t){return this.methodSession("22",t)}methodSessionDocumentCaption(t){return this.methodSession("23",t)}methodSessionDocumentCaptionPayload(t){return this.methodSession("24",t)}methodSessionDocumentCaptionCommand(t){return this.methodSession("25",t)}methodSessionDocumentCaptionCommandPayload(t){return this.methodSession("26",t)}methodSessionDocumentFree(t){return this.methodSession("27",t)}methodSessionAnimationCaption(t){return this.methodSession("28",t)}methodSessionAnimationCaptionPayload(t){return this.methodSession("29",t)}methodSessionAnimationCaptionCommand(t){return this.methodSession("30",t)}methodSessionAnimationCaptionCommandPayload(t){return this.methodSession("31",t)}methodSessionAnimationFree(t){return this.methodSession("32",t)}methodSessionVoiceCaption(t){return this.methodSession("33",t)}methodSessionVoiceCaptionPayload(t){return this.methodSession("34",t)}methodSessionVoiceCaptionCommand(t){return this.methodSession("35",t)}methodSessionVoiceCaptionCommandPayload(t){return this.methodSession("36",t)}methodSessionVoiceFree(t){return this.methodSession("37",t)}methodSessionVideoNoteCaption(t){return this.methodSession("38",t)}methodSessionVideoNoteCaptionPayload(t){return this.methodSession("39",t)}methodSessionVideoNoteCaptionCommand(t){return this.methodSession("40",t)}methodSessionVideoNoteCaptionCommandPayload(t){return this.methodSession("41",t)}methodSessionVideoNoteFree(t){return this.methodSession("42",t)}methodSessionStickerFree(t){return this.methodSession("43",t)}methodSessionLocationFree(t){return this.methodSession("44",t)}methodSessionContactFree(t){return this.methodSession("45",t)}};import{serve as Y}from"bun";import{join as V}from"path";import{existsSync as j,readdirSync as Q}from"fs";var f=class{static{p(this,"HelperPage")}static getPath(){return V(process.cwd(),"src","pages")}static _getPage(t,e,i=!0){let o=Object.values(t)[0];if(o===void 0)throw new Error(`File ${e} must have export (not default) class page`);return i===!0&&(o.template=void 0),o}static getPageSync(t,e=!0){t||(t=this.getPath());let i=T(t);return this._getPage(i,t,e)}static async getPage(t,e=!0){t||(t=this.getPath());let i=await import(`${t}?t=${Date.now()}`);return this._getPage(i,t,e)}static getPagesSync(t,e=!0){if(t||(t=this.getPath()),!j(t))throw new Error(`Directory ${t} is not found, please make it manually`);return Q(t).map(s=>{let o=V(t,s);return{path:o,page:this.getPageSync(o,e)}})}};import{join as Z,parse as tt}from"path";import{LoggingPretty as et}from"logging-pretty";var b=class{static{p(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(e,i)=>`\${(data && data["${i}"]) ?? ""}`)}static _processBaseBlocks(t){let e=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,i={};for(let s of t.matchAll(e)){let o=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[o]=a}return i}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(e,i)=>{let s=i.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(t){return t.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(t){return t.replace(/<div>([\s\S]*?)<\/div>/gi,(e,i)=>i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(t){let e=/<media(?:\s+([^>]*))?>([\s\S]*?)<\/media>/gi,i={};for(let s of t.matchAll(e)){let o=s[1],n=s[2],a={},r=/(\w+)="([^"]*)"/g;if(o)for(let y of o.matchAll(r))a[y[1]]=y[2];let c=a.lang||"default",d=a.type,l=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),u={type:d};a.src&&(u.src=a.src),l&&d!=="video_note"&&d!=="sticker"&&(u.caption=l),d==="location"&&(a.latitude&&(u.latitude=a.latitude),a.longitude&&(u.longitude=a.longitude),l&&(u.caption=l)),d==="contact"&&(a.phone&&(u.phone=a.phone),a.first_name&&(u.first_name=a.first_name),a.last_name&&(u.last_name=a.last_name),a.vcard&&(u.vcard=a.vcard),l&&(u.caption=l)),i[c]=u}return i}static _processMessageBlocks(t){let e=/<message(?:\s+([^>]*))?>([\s\S]*?)<\/message>/gi,i={};for(let[,s,o]of t.matchAll(e)){let n={},a=/(\w+)="([^"]*)"/g;if(s)for(let d of s.matchAll(a))n[d[1]]=d[2];let r=n.lang||"default",c=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[r]=c}return i}static _processDescriptionBlocks(t){let e=/<description(?:\s+([^>]*))?>([\s\S]*?)<\/description>/gi,i={};for(let[,s,o]of t.matchAll(e)){let n={},a=/(\w+)="([^"]*)"/g;if(s)for(let l of s.matchAll(a))n[l[1]]=l[2];let r=n.lang||"default",c=n.scope||"default",d=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[r]||(i[r]={}),i[r][c]=d}return i}static _processKeyboardBlocks(t){let e=/<keyboard(?:\s+([^>]*))?>([\s\S]*?)<\/keyboard>/gi,i={};for(let[,s,o]of t.matchAll(e)){let n={},a=/(\w+)="([^"]*)"/g;if(s)for(let l of s.matchAll(a))n[l[1]]=l[2];let r=n.lang||"default",c=n.type==="bottom"?"bottom":"inline",d=o.trim();i[r]||(i[r]={}),i[r][c]=d}return i}static _compileToFunction(t,e){let i;e?i=t.map(n=>`\`${n}\``).join(","):i=`\`${t}\``;let s=i;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),e){let o=`return [${s}]`;return new Function("data",o)}else{let o=`return ${s}`;return new Function("data",o)}}static compileMedia(t){let e=this._processBaseBlocks(t),i={};for(let[s,o]of Object.entries(e)){let n=this._processMediaBlocks(o);i[s]={};for(let[a,r]of Object.entries(n))if(r.caption){let c=this._processVariables(this._processScriptBlocks(r.caption)),d=this._compileToFunction(c,!1);i[s][a]=l=>({...r,caption:d(l)})}else i[s][a]=()=>r}return i}static compileMessages(t){let e=this._processBaseBlocks(t),i={};for(let[s,o]of Object.entries(e)){let n=this._processMessageBlocks(o);i[s]={};for(let[a,r]of Object.entries(n)){let c=this._processVariables(this._processScriptBlocks(r));i[s][a]=this._compileToFunction(c,!1)}}return i}static compileDescription(t){let e=this._processBaseBlocks(t),i={};for(let[s,o]of Object.entries(e)){let n=this._processDescriptionBlocks(o);i[s]={};for(let[a,r]of Object.entries(n))for(let[c,d]of Object.entries(r))i[s][c]||(i[s][c]={}),i[s][c][a]=this._compileToFunction(d,!1)}return i}static compileKeyboards(t){let e=this._processBaseBlocks(t),i={};for(let[s,o]of Object.entries(e)){let n=this._processKeyboardBlocks(o);i[s]={};for(let[a,r]of Object.entries(n)){i[s][a]={};for(let[c,d]of Object.entries(r)){let u=d.split(/(?<!\\),\s*/).map(y=>y.replace(/\\,/g,",").trim()).map(y=>this._processVariables(this._processScriptBlocks(y)));i[s][a][c]=this._compileToFunction(u,!0)}}}return i}};import{readFile as U}from"fs/promises";import{watch as z}from"chokidar";import{basename as I,join as _,extname as G}from"path";import{readdirSync as H,readFileSync as J,existsSync as D,statSync as q,writeFileSync as X}from"fs";var v=class{static{p(this,"TemplateManager")}_map=new Map;_engine=b;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_isWatchEnabled;constructor(t){let{path:e,enableWatch:i=!1}=t;this._path=e,this._isWatchEnabled=i,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(!this._path||!Array.isArray(this._path))throw new Error("Path must be set as string array");for(let t=0;t<this._path.length;t++){let e=this._path[t];if(!D(e))throw new Error(`Template base path is not exists: ${e}`);if(!q(e).isDirectory())throw new Error(`Template base path is not a directory: ${e}`)}return!0}catch(t){throw new Error(`Failed to validate Template base path: ${t}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let t=0;t<this._path.length;t++){let e=this._path[t],i=z(e,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[t]=i,i.on("change",this._handleFileChange.bind(this)),i.on("add",this._handleFileAdd.bind(this)),i.on("unlink",this._handleFileDelete.bind(this)),i.on("error",this._handleWatchError.bind(this))}}async _handleFileChange(t){let e=I(t);this._isValidFile(e)&&await this._loadFile(e,!1)}async _handleFileAdd(t){let e=I(t);this._isValidFile(e)&&await this._loadFile(e,!1)}_handleFileDelete(t){let e=I(t),i=this._getKey(e);this._map.has(i)&&this._map.delete(i)}_handleWatchError(t){}_loadAllFiles(){for(let t=0;t<this._path.length;t++){let e=this._path[t],s=H(e,"utf8").filter(o=>this._isValidFile(o));for(let o of s)this._loadFile(o,!0)}}async _loadFile(t,e=!0){for(let i=0;i<this._path.length;i++){let s=this._path[i],o=_(s,t),n=this._getExtension(t),a=this._getKey(t);if(n==".html"){let r=e?J(o,"utf8"):await U(o,"utf8");this._compile(a,r)}else if(n==".ts"){let r=await f.getPage(o,!1);r?.template!==void 0&&this._compile(a,r.template),r.template=void 0}else throw new Error(`File ${t} is not support`)}}_getExtension(t){return G(t).toLowerCase()}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,e,i){let s=this._map.get(t),o=s||{},n=!1;(i===void 0||i?.media===!1||s?.media===void 0)&&(o.media=b.compileMedia(e),n=!0),(i===void 0||i?.message===!1||s?.message===void 0)&&(o.message=b.compileMessages(e),n=!0),(i===void 0||i?.keyboard===!1||s?.keyboard===void 0)&&(o.keyboard=b.compileKeyboards(e),n=!0),(i===void 0||i?.description===!1||s?.description===void 0)&&(o.description=b.compileDescription(e),n=!0),n&&this._map.set(t,o)}getMedia(t,e="default",i="default",s){let n=this._map.get(t)?.media?.[e],a=n?.[i]||n?.default;if(!a)return{};try{return a(s)}catch{return{}}}getMessage(t,e="default",i="default",s){let n=this._map.get(t)?.message?.[e],a=n?.[i]||n?.default;if(!a)return"";try{return a(s)}catch{return""}}getDescription(t,e="default",i="default",s="default",o){let a=this._map.get(t)?.description?.[e]?.[s],r=a?.[i]||a?.default;if(!r)return"";try{return r(o)}catch{return""}}getDescriptionLanguage(t,e="default",i="default"){let o=this._map.get(t)?.description?.[e]?.[i];return o?Object.keys(o):[]}getDescriptionScopes(t,e="default"){let s=this._map.get(t)?.description?.[e];return s?Object.keys(s):[]}getKeyboard(t,e="default",i="default",s="inline",o){let a=this._map.get(t)?.keyboard?.[e],r=a?.[i]?.[s]||a?.default?.[s];if(!r)return[];try{return r(o)}catch{return[]}}async write(t,e){if(this._getExtension(t)!=".html")return null;for(let i=0;i<this._path.length;i++){let s=_(this._path[i],t);if(D(s))return X(s,e,"utf8"),await this._loadFile(t,!1),!0}return null}has(t){return this._map.has(t)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(t,e)=>typeof e=="function"?e.toString():e).length}}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};import{Bot as it,webhookCallback as O}from"grammy";var A=class{static{p(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;handlerBotUpdate;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");this.log=t.log===!0?new et:t.log?t.log:void 0,this.cacheSession=t.cacheSession||new S("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new v({path:[Z(process.cwd(),"src","pages")]}),this.bot=this.createBot(t.token),this.bot.catch(this.onCatch),this.registerOnCallbackQueryData(),this.registerOnMessageText(),this.registerOnMessagePhoto(),this.registerOnMessageVideo(),this.registerOnMessageAudio(),this.registerOnMessageDocument(),this.registerOnMessageAnimation(),this.registerOnMessageVoice(),this.registerOnMessageVideoNote(),this.registerOnMessageSticker(),this.registerOnMessageLocation(),this.registerOnMessageContact(),this.handlerBotUpdate=this.bot.handleUpdate,this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),t.deploy.startsWith("polling")?this.runPolling():t.deploy.startsWith("webhook:")?this.runWebhook(t.deploy.split("webhook:")[1]):t.deploy.startsWith("serverless:")&&this.runServerless(t.deploy.split("serverless:")[1])}onCatch(t){this.log?.error?.(`[Bot.catch]: ${String(t)}`)}onStart(t,e,i){let{username:s}=t;this.log?.success?.(`Telegram bot polling started: ${s} ${e=="webhook"||e=="serverless"?`(${i})`:""}`)}createBot(t){return new it(t)}createCtx(t){return new P({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:p(async t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let e=O(this.bot,"bun"),i="/telegram-webhook";this.handlerBotUpdate=e,Y({fetch(a){let{pathname:r}=new URL(a.url);if(r===i)return a.method==="POST"?e(a):new Response("OK",{status:200});if(r==="/"&&a.method==="GET"){let c=new Date().toISOString();return new Response(JSON.stringify({timestamp:c}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}});let s=await this.bot.api.getWebhookInfo(),o=t.endsWith("/")?t.slice(0,-1)+i:t+i;s.url!=o&&await this.bot.api.setWebhook(o);let n=await this.bot.api.getMe();this.onStart(n,"webhook",o)}async runServerless(t){this.handlerBotUpdate=O(this.bot,t);let e=await this.bot.api.getMe();this.onStart(e,"serverless",t)}pageBuildData(t,e){t?.data===void 0&&(t.data=t.buildData()),t.data.name=tt(e).name}pageSorts(t,e){let i=t.data.name,s=t.prototype,o="Payload",n="Command",a="Caption",r="Free",c=e.dynamic,d=e.dynamicSpesific,l=p(m=>m.charAt(0).toUpperCase()+m.slice(1),"upFirst"),u=p(m=>m.replace(o,"").replace(n,"").replace(a,"").replace(r,""),"getPureFuncName"),y=p((m,h)=>s[`methodSession${l(m)}`](h),"methodSession");e.all[i]=t;for(let m=0;m<e.lenListFuncStaticSession;m++){let h=e.listFuncStaticSession[m],R=e.static[h],N=e.staticIntent[h],x=e.staticSession[h],M={name:i,func:h},k=R||N;if(k!==void 0){let K=h.includes(n)?`/${i}`:i;k[s.intent(K,h.startsWith("callback"))]=M}x!==void 0&&(x[y(h,i)]=M),h.toLowerCase().endsWith("free")&&d[u(h)].push(M)}s.free&&c.push(i)}async pageSyncDescription(t){let e=new Map,i=p((o,n,a,r)=>{e.has(n)||e.set(n,new Map);let c=e.get(n);c.has(a)||c.set(a,[]);let d=c.get(a);d.some(l=>l.command===o)||d.push({command:o,description:r})},"addCommand"),s=t.static.textCommand;for(let[,o]of Object.entries(s)){let n=o.name,a=this.templateManager.getDescriptionScopes(n);for(let r of a){let c=this.templateManager.getDescriptionLanguage(n,"default",r);for(let d of c){let l=this.templateManager.getDescription(n,"default",d,r);l&&i(n,r,d,l)}}}for(let[o,n]of e)for(let[a,r]of n){let c={type:o},d=a==="default"?void 0:a;try{let l=await this.bot.api.getMyCommands({scope:c,language_code:d}),u=JSON.stringify(l.map(m=>({command:m.command,description:m.description})).sort((m,h)=>m.command.localeCompare(h.command))),y=JSON.stringify(r.sort((m,h)=>m.command.localeCompare(h.command)));u!==y&&(await this.bot.api.setMyCommands(r,{scope:c,language_code:d}),this.log?.info?.(`Synced descriptions for scope: ${o},${d?` lang: ${d}`:""} (Total: ${r.length})`))}catch(l){this.log?.error?.(`Failed to sync descriptions for scope: ${o},${d?` lang: ${d}`:""}. ${String(l)}`)}}}pageLoads(){this.log?.info?.("Load pages..");let t={},e=t,i=t,s=[],o=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],n=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],a=[...o,...n,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],r=p((d,l)=>Object.fromEntries(d.map(u=>[u,{...l}])),"makeObject"),c={all:{},dynamic:[],dynamicSpesific:{text:s,photo:s,video:s,audio:s,document:s,animation:s,voice:s,videoNote:s,sticker:s,location:s,contact:s},static:r(o,t),staticIntent:r(n,e),staticSession:r(a,i),listFuncStatic:o,listFuncStaticIntent:n,listFuncStaticSession:a,lenListFuncStatic:o.length,lenListFuncStaticIntent:n.length,lenListFuncStaticSession:a.length};return f.getPagesSync(void 0,!0).forEach(({path:d,page:l})=>{this.pageBuildData(l,d),this.pageSorts(l,c)}),this.log?.info?.(`Finish load pages with total (${Object.keys(c.all).length})`),this.pageSyncDescription(c),c}async pageRoutes(t,e){let i,s;if(i===void 0){let n=t.callbackData,a=t.msgText,r=t.msgCaption,c=this.pages.static;for(let d=0;d<this.pages.lenListFuncStatic;d++){let l=this.pages.listFuncStatic[d];if(s=c[l][n||a||r],s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i===void 0){let n=await t.sessionGet();if(n){let a=n.method,r=this.pages.staticSession;for(let c=0;c<this.pages.lenListFuncStaticSession;c++){let d=this.pages.listFuncStaticSession[c];if(s=r[d][a],s)break}s!==void 0&&(i=this.pages.all[s.name])}}if(i===void 0){let n=t.callbackDataIntent,a=t.msgTextIntent,r=t.msgCaptionIntent,c=this.pages.staticIntent;for(let d=0;d<this.pages.lenListFuncStaticIntent;d++){let l=this.pages.listFuncStaticIntent[d];if(s=c[l][n||a||r],s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i!==void 0&&s!==void 0)return await new i(t)[s.func]?.();let o=this.pages.dynamicSpesific[e]||[];for(let n=0;n<o.length;n++){let a=o[n];if(a===void 0)continue;let r=this.pages.all[a.func];if(r===void 0)continue;let d=await new r(t)[a.name]?.();if(d!==null)return d}for(let n=0;n<this.pages.dynamic.length;n++){let a=this.pages.dynamic[n];if(a===void 0)continue;let r=this.pages.all[a];if(r===void 0)continue;let d=await new r(t).free?.();if(d!==null)return d}return null}async hookBeforeRoute(t,e){return!0}async hookErrorPage(t,e,i,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,e){let i=this.createCtx(t);try{if(await this.hookBeforeRoute(i,e)===!1)return;await this.pageRoutes(i,e)===null&&await this.hookErrorInputNotFoundPage(i)}catch(s){await this.hookErrorPage(i,e,s,!1)}}async onCallbackQueryData(t){let e=this.createCtx(t);try{if(await e.callbackQueryAnswer(),await this.hookBeforeRoute(e,"onCallbackQueryData")===!1)return;await this.pageRoutes(e,"callback")}catch(i){await this.hookErrorPage(e,"onCallbackQueryData",i,!0)}}async onMessageText(t){await this.onMessage(t,"onMessageText")}async onMessagePhoto(t){await this.onMessage(t,"onMessagePhoto")}async onMessageVideo(t){await this.onMessage(t,"onMessageVideo")}async onMessageAudio(t){await this.onMessage(t,"onMessageAudio")}async onMessageDocument(t){await this.onMessage(t,"onMessageDocument")}async onMessageAnimation(t){await this.onMessage(t,"onMessageAnimation")}async onMessageVoice(t){await this.onMessage(t,"onMessageVoice")}async onMessageVideoNote(t){await this.onMessage(t,"onMessageVideoNote")}async onMessageSticker(t){await this.onMessage(t,"onMessageSticker")}async onMessageLocation(t){await this.onMessage(t,"onMessageLocation")}async onMessageContact(t){await this.onMessage(t,"onMessageContact")}registerOnCallbackQueryData(){this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this))}registerOnMessageText(){this.bot.on("message:text",this.onMessageText.bind(this))}registerOnMessagePhoto(){this.bot.on("message:photo",this.onMessagePhoto.bind(this))}registerOnMessageVideo(){this.bot.on("message:video",this.onMessageVideo.bind(this))}registerOnMessageAudio(){this.bot.on("message:audio",this.onMessageAudio.bind(this))}registerOnMessageDocument(){this.bot.on("message:document",this.onMessageDocument.bind(this))}registerOnMessageAnimation(){this.bot.on("message:animation",this.onMessageAnimation.bind(this))}registerOnMessageVoice(){this.bot.on("message:voice",this.onMessageVoice.bind(this))}registerOnMessageVideoNote(){this.bot.on("message:video_note",this.onMessageVideoNote.bind(this))}registerOnMessageSticker(){this.bot.on("message:sticker",this.onMessageSticker.bind(this))}registerOnMessageLocation(){this.bot.on("message:location",this.onMessageLocation.bind(this))}registerOnMessageContact(){this.bot.on("message:contact",this.onMessageContact.bind(this))}};export{C as BaseGeneral,S as CacheExternal,P as Ctx,A as Gramstax,b as TemplateEngine,v as TemplateManager};
|