gramstax 0.3.19 → 0.3.21

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.
@@ -1,11 +1,11 @@
1
- "use strict";var gt=Object.create;var V=Object.defineProperty;var ut=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var ft=Object.getPrototypeOf,Ct=Object.prototype.hasOwnProperty;var p=(g,t)=>V(g,"name",{value:t,configurable:!0});var St=(g,t)=>{for(var e in t)V(g,e,{get:t[e],enumerable:!0})},Y=(g,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of yt(t))!Ct.call(g,s)&&s!==e&&V(g,s,{get:()=>t[s],enumerable:!(n=ut(t,s))||n.enumerable});return g};var Z=(g,t,e)=>(e=g!=null?gt(ft(g)):{},Y(t||!g||!g.__esModule?V(e,"default",{value:g,enumerable:!0}):e,g)),Pt=g=>Y(V({},"__esModule",{value:!0}),g);var xt={};St(xt,{CacheExternal:()=>A,ComponentKeyboard:()=>U,Ctx:()=>O,DataKeyboard:()=>Q,Gramstax:()=>G,LoggingUtils:()=>E,TemplateEngine:()=>k,TemplateManager:()=>$,WorkerThreadExport:()=>J,WorkerThreadGatewayClient:()=>K,WorkerThreadGatewayServer:()=>N,WorkerThreadInit:()=>H,WorkerThreadLaunch:()=>B,WorkerThreadPool:()=>z,WorkerThreadRpc:()=>T,log:()=>kt});module.exports=Pt(xt);var bt=p(()=>typeof document>"u"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"?document.currentScript.src:new URL("main.js",document.baseURI).href,"getImportMetaUrl"),S=bt();var tt=require("logging-pretty");var E=class extends tt.LoggingPretty{static{p(this,"LoggingUtils")}constructor(t){super(t)}errorMake(t,e,n){this.error(`[${e?`${e}:${n}`:n}] ${String(t)}`)}},kt=new E;var et=require("keyv"),st=Z(require("@keyv/redis"),1);var A=class extends et.Keyv{constructor(e="memory",n,s,o){let a;e.startsWith("redis")&&(a=new st.default(e)),e==="memory"&&(a=new Map),o?.forceStore&&(a=o.forceStore);super({store:a,namespace:n,ttl:s});this.url=e}static{p(this,"CacheExternal")}};var nt=require("timers/promises"),F=require("grammy");var O=class{static{p(this,"Ctx")}static template;static data;data=this.constructor.data;get userIsPremium(){return this.ct.from?.is_premium??!1}get userIsBot(){return this.ct.from?.is_bot??!1}get userId(){return this.ct.from?.id}get userName(){return this.ct.from?.username}get userFullName(){return`${this.ct.from?.first_name} ${this.ct.from?.last_name||""}`}get userFirstName(){return this.ct.from?.first_name}get userLastName(){return this.ct.from?.last_name}get userLanguage(){return this.ct.from?.language_code}set userLanguage(t){this.ct.from.language_code=t}get msgText(){return this.ct.message?.text}get msgTextPayloads(){return this.getPayloads(this.msgText,"space",this.data?._positionPayloadText||this.temp?.data?._positionPayloadText)}get msgTextPayload(){return this.msgTextPayloads[0]}get msgTextCommandPayloads(){return this.getPayloads(this.msgText,"space")}get msgTextCommandPayload(){return this.msgTextCommandPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionPayloads(){return this.getPayloads(this.msgCaption,"space")}get msgCaptionPayload(){return this.msgCaptionPayloads[0]}get msgCaptionCommandPayloads(){return this.getPayloads(this.msgCaption,"space")}get msgCaptionCommandPayload(){return this.msgCaptionCommandPayloads[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 callbackDataPayloads(){return this.getPayloads(this.callbackData,"colon")}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}get callbackDataParts(){return this.callbackDataPayload&&this.callbackDataPayload.indexOf("+")!=-1?this.callbackDataPayload.split("+"):[]}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp}async broadcast(t,e,n,s,o,a,i=!1){try{this.temp.isAnswer=!0;let r=30,c=e.map(l=>this.templateManager.getMessage(this.data.name,o,l,s));for(let l=0;l<t.length;l++){let d=t[l],h=c[l];await this.ct.api.sendMessage(d,h,{parse_mode:"HTML",reply_markup:n,...a}),l+1==r&&await(0,nt.setTimeout)(1200)}}catch(r){if(i)throw r}}async reply(t,e,n,s){this.temp.isAnswer=!0;let o=this.templateManager.getMessage(this.data.name,n,this.userLanguage,e);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,e,n,s,o){this.temp.isAnswer=!0;let a=this.templateManager.getMedia(this.data.name,s,this.userLanguage,n),i={parse_mode:"HTML",reply_markup:e,...o};if(t=="photo")return await this.ct.replyWithPhoto(a.src,{caption:a.caption,...i});if(t=="video")return await this.ct.replyWithVideo(a.src,{caption:a.caption,...i});if(t=="audio")return await this.ct.replyWithAudio(a.src,{caption:a.caption,...i});if(t=="document")return await this.ct.replyWithDocument(a.src,{caption:a.caption,...i});if(t=="animation")return await this.ct.replyWithAnimation(a.src,{caption:a.caption,...i});if(t=="voice")return await this.ct.replyWithVoice(a.src,i);if(t=="video_note")return await this.ct.replyWithVideoNote(a.src,i);if(t=="sticker")return await this.ct.replyWithSticker(a.src,i);if(t=="location")return await this.ct.replyWithLocation(parseInt(a.latitude),parseInt(a.longitude),i);if(t=="contact")return await this.ct.replyWithContact(a.phone,a.first_name,{vcard:a.vcard,...i})}async replyPhoto(t,e,n,s){return this.replyMedia("photo",t,e,n,s)}async replyVideo(t,e,n,s){return this.replyMedia("video",t,e,n,s)}async replyAudio(t,e,n,s){return this.replyMedia("audio",t,e,n,s)}async replyDocument(t,e,n,s){return this.replyMedia("document",t,e,n,s)}async replyAnimation(t,e,n,s){return this.replyMedia("animation",t,e,n,s)}async replyVoice(t,e,n,s){return this.replyMedia("voice",t,e,n,s)}async replyVideoNote(t,e,n,s){return this.replyMedia("video_note",t,e,n,s)}async replySticker(t,e,n,s){return this.replyMedia("sticker",t,e,n,s)}async replyLocation(t,e,n,s){return this.replyMedia("location",t,e,n,s)}async replyContact(t,e,n,s){return this.replyMedia("contact",t,e,n,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,e,n,s,o=!0){try{this.temp.isAnswer=!0;let a=this.templateManager.getMessage(this.data.name,n,this.userLanguage,e);return await this.ct.editMessageText(a,{parse_mode:"HTML",reply_markup:t,...s})}catch(a){if(o)await this.reply(t,e,n,s);else throw a}}async editMedia(t,e,n,s,o,a,i=!0){try{this.temp.isAnswer=!0;let{src:r,caption:c}=this.templateManager.getMedia(this.data.name,s,this.userLanguage,n);return t=="voice"?(await this.delete(),await this.replyVoice(e,n,s,o)):t=="video_note"?(await this.delete(),await this.replyVoice(e,n,s,o)):t=="sticker"?(await this.delete(),await this.replySticker(e,n,s,o)):t=="location"?(await this.delete(),await this.replyLocation(e,n,s,o)):t=="contact"?(await this.delete(),await this.replyContact(e,n,s,o)):await this.ct.editMessageMedia({media:r,caption:c,type:t,parse_mode:"HTML",...o},{reply_markup:e,...a})}catch(r){if(i===!0)await this.reply(e,n,s,a);else throw r}}async editPhoto(t,e,n,s,o){return await this.editMedia("photo",t,e,n,s,o)}async editVideo(t,e,n,s,o){return await this.editMedia("video",t,e,n,s,o)}async editAudio(t,e,n,s,o){return await this.editMedia("audio",t,e,n,s,o)}async editDocument(t,e,n,s,o){return await this.editMedia("document",t,e,n,s,o)}async editAnimation(t,e,n,s,o){return await this.editMedia("animation",t,e,n,s,o)}async editVoice(t,e,n,s){return await this.editMedia("voice",t,e,n,s)}async editVideoNote(t,e,n,s){return await this.editMedia("video_note",t,e,n,s)}async editSticker(t,e,n,s){return await this.editMedia("sticker",t,e,n,s)}async editLocation(t,e,n,s){return await this.editMedia("location",t,e,n,s)}async editContact(t,e,n,s){return await this.editMedia("contact",t,e,n,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return this.temp.isAnswer=!0,await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,e,n){try{let s={method:t,params:e,...n},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){let n=typeof t=="function"?{callbackData:t}:t||{},s=n.callbackData;return{name:"",text:n.text,textCommand:n.textCommand,callbackData:s?function(...a){let i=s(...a);return`${this._callbackData}${i==""||i===void 0?"":`:${i}`}`}:function(){return this?._callbackData},_callbackData:"",_positionPayloadText:n.text?n.text.split(this.prototype.getSeperatorTag("space")).length:void 0}}ikb(...t){return this.inlineKeyboard(...t)}bkb(...t){return this.bottomKeyboard(...t)}inlineKeyboard(t,e){let n=this.data.name;if(e?.cache===!0){let i=`${n}:${this.userLanguage}:i`,r=this.cacheKeyboard.get(i);if(!r){let c=new F.InlineKeyboard,l=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"inline",e?.data),d=t(c,l);return this.cacheKeyboard.set(i,d),d}return r}let s=new F.InlineKeyboard,o=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"inline",e?.data);return t(s,o)}bottomKeyboard(t,e){let n=this.data.name;if(e?.cache===!0){let i=`${n}:${this.userLanguage}:b`,r=this.cacheKeyboard.get(i);if(!r){let c=new F.Keyboard,l=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"bottom",e?.data),d=t(c,l);return d.resized(!0),this.cacheKeyboard.set(i,d),d}return r}let s=new F.Keyboard,o=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"bottom",e?.data),a=t(s,o);return a.resized(),a}getSeperatorTag(t="space"){return t=="space"?" ":":"}havePayloads(t="",e){return t.includes(this.getSeperatorTag(e))}getPayloads(t="",e,n=1){if(!t)return[];let s=this.getSeperatorTag(e);return t.split(s).slice(n)}getIntent(t="",e,n=1){if(!t)return"";let s=this.getSeperatorTag(e),o=t.split(s);return n==1?o[0]:o.slice(0,n).join(s)}validateSessionCallback(t,e){return(t??this.session.method)===this.methodSessionCallback(e)}validateSessionCallbackPayload(t,e){return(t??this.session.method)===this.methodSessionCallbackPayload(e)}validateSessionText(t,e){return(t??this.session.method)===this.methodSessionText(e)}validateSessionTextPayload(t,e){return(t??this.session.method)===this.methodSessionTextPayload(e)}validateSessionTextCommand(t,e){return(t??this.session.method)===this.methodSessionTextCommand(e)}validateSessionTextCommandPayload(t,e){return(t??this.session.method)===this.methodSessionTextCommandPayload(e)}validateSessionTextFree(t,e){return(t??this.session.method)===this.methodSessionTextFree(e)}validateSessionPhotoCaption(t,e){return(t??this.session.method)===this.methodSessionPhotoCaption(e)}validateSessionPhotoCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionPhotoCaptionPayload(e)}validateSessionPhotoCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionPhotoCaptionCommand(e)}validateSessionPhotoCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionPhotoCaptionCommandPayload(e)}validateSessionPhotoFree(t,e){return(t??this.session.method)===this.methodSessionPhotoFree(e)}validateSessionVideoCaption(t,e){return(t??this.session.method)===this.methodSessionVideoCaption(e)}validateSessionVideoCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionVideoCaptionPayload(e)}validateSessionVideoCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionVideoCaptionCommand(e)}validateSessionVideoCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionVideoCaptionCommandPayload(e)}validateSessionVideoFree(t,e){return(t??this.session.method)===this.methodSessionVideoFree(e)}validateSessionAudioCaption(t,e){return(t??this.session.method)===this.methodSessionAudioCaption(e)}validateSessionAudioCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionAudioCaptionPayload(e)}validateSessionAudioCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionAudioCaptionCommand(e)}validateSessionAudioCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionAudioCaptionCommandPayload(e)}validateSessionAudioFree(t,e){return(t??this.session.method)===this.methodSessionAudioFree(e)}validateSessionDocumentCaption(t,e){return(t??this.session.method)===this.methodSessionDocumentCaption(e)}validateSessionDocumentCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionDocumentCaptionPayload(e)}validateSessionDocumentCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionDocumentCaptionCommand(e)}validateSessionDocumentCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionDocumentCaptionCommandPayload(e)}validateSessionDocumentFree(t,e){return(t??this.session.method)===this.methodSessionDocumentFree(e)}validateSessionAnimationCaption(t,e){return(t??this.session.method)===this.methodSessionAnimationCaption(e)}validateSessionAnimationCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionAnimationCaptionPayload(e)}validateSessionAnimationCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionAnimationCaptionCommand(e)}validateSessionAnimationCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionAnimationCaptionCommandPayload(e)}validateSessionAnimationFree(t,e){return(t??this.session.method)===this.methodSessionAnimationFree(e)}validateSessionVoiceCaption(t,e){return(t??this.session.method)===this.methodSessionVoiceCaption(e)}validateSessionVoiceCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionVoiceCaptionPayload(e)}validateSessionVoiceCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionVoiceCaptionCommand(e)}validateSessionVoiceCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionVoiceCaptionCommandPayload(e)}validateSessionVoiceFree(t,e){return(t??this.session.method)===this.methodSessionVoiceFree(e)}validateSessionVideoNoteCaption(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaption(e)}validateSessionVideoNoteCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaptionPayload(e)}validateSessionVideoNoteCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaptionCommand(e)}validateSessionVideoNoteCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaptionCommandPayload(e)}validateSessionVideoNoteFree(t,e){return(t??this.session.method)===this.methodSessionVideoNoteFree(e)}validateSessionStickerFree(t,e){return(t??this.session.method)===this.methodSessionStickerFree(e)}validateSessionLocationFree(t,e){return(t??this.session.method)===this.methodSessionLocationFree(e)}validateSessionContactFree(t,e){return(t??this.session.method)===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)}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 I=require("path"),at=require("fs"),rt=require("url");var L=require("path"),R=require("fs"),it=require("module");var b=class{static{p(this,"PageManager")}static _getFile(t,e,n=0){let o=Object.values(t)[n];if(o===void 0)throw new Error(`File ${e} must have export (not default) class page`);return o}static getFilePath(){return(0,L.join)(process.cwd(),"src","pages")}static getFileSync(t,e=0){t||(t=this.getFilePath());let s=(0,it.createRequire)(t)(t);return this._getFile(s,t,e)}static async getFile(t,e=0){t||(t=this.getFilePath());let n=await import(`${t}?t=${Date.now()}`);return this._getFile(n,t,e)}static getFileManySync(t,e=0){if(t||(t=this.getFilePath()),!(0,R.existsSync)(t))throw new Error(`Directory ${t} is not found, please make it manually`);return(0,R.readdirSync)(t).map(s=>{let o=(0,L.join)(t,s);return{path:o,page:this.getFileSync(o,e)}})}static clearCacheRequire(t){if(t||(t=this.getFilePath()),!(0,R.existsSync)(t))throw new Error(`Directory ${t} is not found, please make it manually`);return(0,R.readdirSync)(t).forEach(n=>{let s=(0,L.join)(t,n);delete require.cache[require.resolve(s)]}),!0}};var ct=require("logging-pretty");var P=require("path"),f=require("fs"),ot=require("chokidar");var k=class{static{p(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(e,n)=>`\${(data && data["${n}"]) ?? ""}`)}static _processBaseBlocks(t){let e=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,n={};for(let s of t.matchAll(e)){let o=s[2]??"default",i=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[o]=i}return n}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(e,n)=>{let s=n.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,n)=>n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processSwitchBlocks(t){let e=/<switch\b(?:\s+value="([^"]+)")?>([\s\S]*?)<\/switch>/gi;return t.replace(e,(n,s,o)=>{if(!s)return"";let a="",i=/<case\b(?:\s+is="([^"]+)")?>([\s\S]*?)<\/case>/gi,r=/<default>([\s\S]*?)<\/default>/gi,c;for(;(c=i.exec(o))!==null;){let d=(c[1]||"").split(",").map(m=>m.trim()),h=(c[2]||"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim().replace(/`/g,"\\`");d.forEach(m=>{a+=`case "${m}": `}),a+=`return \`${h}\`; `}let l=r.exec(o);if(l){let d=(l[1]||"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim().replace(/`/g,"\\`");a+=`default: return \`${d}\`; `}else a+="default: return ''; ";return`\${(() => { switch((data && data["${s}"])) { ${a} } })()}`})}static _processExec(t){return t.replace(/{~\s*([\s\S]*?)\s*~}/g,(e,n)=>`\${(() => { try { return ${n} } catch(e) { try { with(data || {}) { return ${n} } } catch(ee) { return '' } } })()}`)}static _processMapBlocks(t){let e=/<map(?:\s+([^>]*))?>([\s\S]*?)<\/map>/gi;return t.replace(e,(n,s,o)=>{let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let h of s.matchAll(i))a[h[1]]=h[2];let r=a.src;if(!r)return"";let c=a.join??"\\n",l=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").replace(/`/g,"\\`");l=l.replace(/\{\{([\w.]+)\}\}/g,(h,m)=>m==="e"||m.startsWith("e.")?`\${${m}}`:m==="i"?"${i}":h);let d=c.replace(/"/g,'\\"');return`\${(data && data["${r}"] || []).map((e, i) => \`${l}\`).join("${d}")}`})}static _processMediaBlocks(t){let e=/<media(?:\s+([^>]*))?>([\s\S]*?)<\/media>/gi,n={};for(let s of t.matchAll(e)){let o=s[1],a=s[2],i={},r=/(\w+)="([^"]*)"/g;if(o)for(let m of o.matchAll(r))i[m[1]]=m[2];let c=i.lang||"default",l=i.type,d=a.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),h={type:l};i.src&&(h.src=i.src),d&&l!=="video_note"&&l!=="sticker"&&(h.caption=d),l==="location"&&(i.latitude&&(h.latitude=i.latitude),i.longitude&&(h.longitude=i.longitude),d&&(h.caption=d)),l==="contact"&&(i.phone&&(h.phone=i.phone),i.first_name&&(h.first_name=i.first_name),i.last_name&&(h.last_name=i.last_name),i.vcard&&(h.vcard=i.vcard),d&&(h.caption=d)),n[c]=h}return n}static _processMessageBlocks(t){let e=/<message(?:\s+([^>]*))?>([\s\S]*?)<\/message>/gi,n={};for(let[,s,o]of t.matchAll(e)){let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let l of s.matchAll(i))a[l[1]]=l[2];let r=a.lang||"default",c=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[r]=c}return n}static _processDescriptionBlocks(t){let e=/<description(?:\s+([^>]*))?>([\s\S]*?)<\/description>/gi,n={};for(let[,s,o]of t.matchAll(e)){let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let d of s.matchAll(i))a[d[1]]=d[2];let r=a.lang||"default",c=a.scope||"default",l=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[r]||(n[r]={}),n[r][c]=l}return n}static _processKeyboardBlocks(t){let e=/<keyboard(?:\s+([^>]*))?>([\s\S]*?)<\/keyboard>/gi,n={};for(let[,s,o]of t.matchAll(e)){let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let d of s.matchAll(i))a[d[1]]=d[2];let r=a.lang||"default",c=a.type==="bottom"?"bottom":"inline",l=o.trim();n[r]||(n[r]={}),n[r][c]=l}return n}static _compileToFunction(t,e){let n;e?n=t.map(a=>`\`${a}\``).join(","):n=`\`${t}\``;let s=n;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,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processMediaBlocks(a);s[o]={};for(let[r,c]of Object.entries(i)){let l={};for(let[d,h]of Object.entries(c)){if(d==="type"||typeof h!="string")continue;let m=this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(h)))));l[d]=this._compileToFunction(m,!1)}s[o][r]=d=>{let h={...c};for(let[m,y]of Object.entries(l))h[m]=y(d);return h}}}return s}static compileMessages(t,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processMessageBlocks(a);s[o]={};for(let[r,c]of Object.entries(i)){let l=this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(c)))));s[o][r]=this._compileToFunction(l,!1)}}return s}static compileDescription(t,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processDescriptionBlocks(a);s[o]={};for(let[r,c]of Object.entries(i))for(let[l,d]of Object.entries(c)){s[o][l]||(s[o][l]={});let h=this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(d)))));s[o][l][r]=this._compileToFunction(h,!1)}}return s}static compileKeyboards(t,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processKeyboardBlocks(a);s[o]={};for(let[r,c]of Object.entries(i)){s[o][r]={};for(let[l,d]of Object.entries(c)){let m=d.split(/(?<!\\),\s*/).map(y=>y.replace(/\\,/g,",").trim()).map(y=>this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(y))))));s[o][r][l]=this._compileToFunction(m,!0)}}}return s}static _extractBlock(t,e,n="default",s="all",o){let a=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,i=t,r=!1;for(let c of t.matchAll(a))if((c[2]??"default")===n){i=c[3]??"",r=!0;break}if(!r){let c=/<base\b/.test(t);if(!(n==="default"&&!c))return""}if(e){if(e==="all")return i;let c=Array.isArray(e)?e:[e],l=[];for(let h of c){let m=new RegExp(`([ \\t]*)<${h}(?:\\s+([^>]*))?>([\\s\\S]*?)<\\/${h}>`,"gi");for(let y of i.matchAll(m)){let C=y[2];if(o){let u=/lang="([^"]*)"/i,w=C?.match(u);if(((w?w[1]:void 0)||"default")!==o)continue}l.push({start:y.index,content:y[0],innerContent:y[3]??""})}}l.sort((h,m)=>h.start-m.start);let d=p(h=>{let m=h.split(`
2
- `);if(m.length<=1)return h.trim();let y=m.filter(u=>u.trim().length>0);if(y.length===0)return"";let C=y.reduce((u,w)=>{let v=w.match(/^([ \t]*)/),x=v?v[1].length:0;return x<u?x:u},1/0);return m.map(u=>u.length>=C?u.slice(C):u.trimStart()).join(`
3
- `).trim()},"processResult");return s==="all"?l.map(m=>d(m.content)).join(`
4
- `):l.map(m=>d(m.innerContent)).join(`
5
- `)}return i}static _processImportBlocks(t){let e=/([ \t]*)<import(?:\s+([^>]*))?\/?>/gi,n=[];return{processed:t.replace(e,(o,a,i)=>{let r={},c=/(\w+)="([^"]*)"/g;if(i)for(let m of i.matchAll(c))r[m[1]]=m[2];let l=r.src;if(!l)return"";let d;r.block&&(r.block==="all"?d="all":r.block.includes(",")?d=r.block.split(",").map(m=>m.trim()).filter(m=>m):d=r.block);let h={src:l,blocks:d,base:r.base||"default",lang:r.lang,section:r.section||"all",indent:a||""};return n.push(h),`${a}__IMPORT_${n.length-1}__`}),imports:n}}static processImportBlocks(t,e,n=0,s){if(n>10)return"";let{processed:o,imports:a}=this._processImportBlocks(t),i=o;for(let r=0;r<a.length;r++){let c=a[r],l=`${c.src}|${c.base}|${c.lang||""}|${c.section}|${Array.isArray(c.blocks)?c.blocks.join(","):c.blocks||""}`,d;if(s&&s.has(l))d=s.get(l);else{let m=e(c.src);d=m?this._extractBlock(m,c.blocks,c.base,c.section,c.lang):"",d&&d.includes("<import")&&(d=this.processImportBlocks(d,e,n+1,s)),s&&s.set(l,d)}let h=d.split(`
1
+ "use strict";var gt=Object.create;var V=Object.defineProperty;var ut=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var ft=Object.getPrototypeOf,Ct=Object.prototype.hasOwnProperty;var p=(g,t)=>V(g,"name",{value:t,configurable:!0});var St=(g,t)=>{for(var e in t)V(g,e,{get:t[e],enumerable:!0})},Y=(g,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of yt(t))!Ct.call(g,s)&&s!==e&&V(g,s,{get:()=>t[s],enumerable:!(n=ut(t,s))||n.enumerable});return g};var Z=(g,t,e)=>(e=g!=null?gt(ft(g)):{},Y(t||!g||!g.__esModule?V(e,"default",{value:g,enumerable:!0}):e,g)),Pt=g=>Y(V({},"__esModule",{value:!0}),g);var xt={};St(xt,{CacheExternal:()=>A,ComponentKeyboard:()=>U,Ctx:()=>O,DataKeyboard:()=>Q,Gramstax:()=>q,LoggingUtils:()=>E,TemplateEngine:()=>k,TemplateManager:()=>B,WorkerThreadExport:()=>J,WorkerThreadGatewayClient:()=>K,WorkerThreadGatewayServer:()=>N,WorkerThreadInit:()=>H,WorkerThreadLaunch:()=>W,WorkerThreadPool:()=>z,WorkerThreadRpc:()=>w,log:()=>kt});module.exports=Pt(xt);var bt=p(()=>typeof document>"u"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"?document.currentScript.src:new URL("main.js",document.baseURI).href,"getImportMetaUrl"),S=bt();var tt=require("logging-pretty");var E=class extends tt.LoggingPretty{static{p(this,"LoggingUtils")}constructor(t){super(t)}errorMake(t,e,n){this.error(`[${e?`${e}:${n}`:n}] ${String(t)}`)}},kt=new E;var et=require("keyv"),st=Z(require("@keyv/redis"),1);var A=class extends et.Keyv{constructor(e="memory",n,s,o){let a;e.startsWith("redis")&&(a=new st.default(e)),e==="memory"&&(a=new Map),o?.forceStore&&(a=o.forceStore);super({store:a,namespace:n,ttl:s});this.url=e}static{p(this,"CacheExternal")}};var nt=require("timers/promises"),F=require("grammy");var O=class{static{p(this,"Ctx")}static template;static data;data=this.constructor.data;get userIsPremium(){return this.ct.from?.is_premium??!1}get userIsBot(){return this.ct.from?.is_bot??!1}get userId(){return this.ct.from?.id}get userName(){return this.ct.from?.username}get userFullName(){return`${this.ct.from?.first_name} ${this.ct.from?.last_name||""}`}get userFirstName(){return this.ct.from?.first_name}get userLastName(){return this.ct.from?.last_name}get userLanguage(){return this.ct.from?.language_code}set userLanguage(t){this.ct.from.language_code=t}get msgText(){return this.ct.message?.text}get msgTextPayloads(){return this.getPayloads(this.msgText,"space",this.data?._positionPayloadText||this.temp?.data?._positionPayloadText)}get msgTextPayload(){return this.msgTextPayloads[0]}get msgTextCommandPayloads(){return this.getPayloads(this.msgText,"space")}get msgTextCommandPayload(){return this.msgTextCommandPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionPayloads(){return this.getPayloads(this.msgCaption,"space")}get msgCaptionPayload(){return this.msgCaptionPayloads[0]}get msgCaptionCommandPayloads(){return this.getPayloads(this.msgCaption,"space")}get msgCaptionCommandPayload(){return this.msgCaptionCommandPayloads[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 callbackDataPayloads(){return this.getPayloads(this.callbackData,"colon")}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp}async broadcast(t,e,n,s,o,a,i=!1){try{this.temp.isAnswer=!0;let r=30,c=e.map(h=>this.templateManager.getMessage(this.data.name,o,h,s));for(let h=0;h<t.length;h++){let d=t[h],l=c[h];await this.ct.api.sendMessage(d,l,{parse_mode:"HTML",reply_markup:n,...a}),h+1==r&&await(0,nt.setTimeout)(1200)}}catch(r){if(i)throw r}}async reply(t,e,n,s){this.temp.isAnswer=!0;let o=this.templateManager.getMessage(this.data.name,n,this.userLanguage,e);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,e,n,s,o){this.temp.isAnswer=!0;let a=this.templateManager.getMedia(this.data.name,s,this.userLanguage,n),i={parse_mode:"HTML",reply_markup:e,...o};if(t=="photo")return await this.ct.replyWithPhoto(a.src,{caption:a.caption,...i});if(t=="video")return await this.ct.replyWithVideo(a.src,{caption:a.caption,...i});if(t=="audio")return await this.ct.replyWithAudio(a.src,{caption:a.caption,...i});if(t=="document")return await this.ct.replyWithDocument(a.src,{caption:a.caption,...i});if(t=="animation")return await this.ct.replyWithAnimation(a.src,{caption:a.caption,...i});if(t=="voice")return await this.ct.replyWithVoice(a.src,i);if(t=="video_note")return await this.ct.replyWithVideoNote(a.src,i);if(t=="sticker")return await this.ct.replyWithSticker(a.src,i);if(t=="location")return await this.ct.replyWithLocation(parseInt(a.latitude),parseInt(a.longitude),i);if(t=="contact")return await this.ct.replyWithContact(a.phone,a.first_name,{vcard:a.vcard,...i})}async replyPhoto(t,e,n,s){return this.replyMedia("photo",t,e,n,s)}async replyVideo(t,e,n,s){return this.replyMedia("video",t,e,n,s)}async replyAudio(t,e,n,s){return this.replyMedia("audio",t,e,n,s)}async replyDocument(t,e,n,s){return this.replyMedia("document",t,e,n,s)}async replyAnimation(t,e,n,s){return this.replyMedia("animation",t,e,n,s)}async replyVoice(t,e,n,s){return this.replyMedia("voice",t,e,n,s)}async replyVideoNote(t,e,n,s){return this.replyMedia("video_note",t,e,n,s)}async replySticker(t,e,n,s){return this.replyMedia("sticker",t,e,n,s)}async replyLocation(t,e,n,s){return this.replyMedia("location",t,e,n,s)}async replyContact(t,e,n,s){return this.replyMedia("contact",t,e,n,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,e,n,s,o=!0){try{this.temp.isAnswer=!0;let a=this.templateManager.getMessage(this.data.name,n,this.userLanguage,e);return await this.ct.editMessageText(a,{parse_mode:"HTML",reply_markup:t,...s})}catch(a){if(o)await this.reply(t,e,n,s);else throw a}}async editMedia(t,e,n,s,o,a,i=!0){try{this.temp.isAnswer=!0;let{src:r,caption:c}=this.templateManager.getMedia(this.data.name,s,this.userLanguage,n);return t=="voice"?(await this.delete(),await this.replyVoice(e,n,s,o)):t=="video_note"?(await this.delete(),await this.replyVoice(e,n,s,o)):t=="sticker"?(await this.delete(),await this.replySticker(e,n,s,o)):t=="location"?(await this.delete(),await this.replyLocation(e,n,s,o)):t=="contact"?(await this.delete(),await this.replyContact(e,n,s,o)):await this.ct.editMessageMedia({media:r,caption:c,type:t,parse_mode:"HTML",...o},{reply_markup:e,...a})}catch(r){if(i===!0)await this.reply(e,n,s,a);else throw r}}async editPhoto(t,e,n,s,o){return await this.editMedia("photo",t,e,n,s,o)}async editVideo(t,e,n,s,o){return await this.editMedia("video",t,e,n,s,o)}async editAudio(t,e,n,s,o){return await this.editMedia("audio",t,e,n,s,o)}async editDocument(t,e,n,s,o){return await this.editMedia("document",t,e,n,s,o)}async editAnimation(t,e,n,s,o){return await this.editMedia("animation",t,e,n,s,o)}async editVoice(t,e,n,s){return await this.editMedia("voice",t,e,n,s)}async editVideoNote(t,e,n,s){return await this.editMedia("video_note",t,e,n,s)}async editSticker(t,e,n,s){return await this.editMedia("sticker",t,e,n,s)}async editLocation(t,e,n,s){return await this.editMedia("location",t,e,n,s)}async editContact(t,e,n,s){return await this.editMedia("contact",t,e,n,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return this.temp.isAnswer=!0,await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,e,n){try{let s={method:t,params:e,...n},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){let n=typeof t=="function"?{callbackData:t}:t||{},s=n.callbackData;return{name:"",text:n.text,textCommand:n.textCommand,callbackData:s?function(...a){let i=s(...a);return`${this._callbackData}${i==""||i===void 0?"":`:${i}`}`}:function(){return this?._callbackData},_callbackData:"",_positionPayloadText:n.text?n.text.split(this.prototype.getSeperatorTag("space")).length:void 0}}ikb(...t){return this.inlineKeyboard(...t)}bkb(...t){return this.bottomKeyboard(...t)}inlineKeyboard(t,e){let n=this.data.name;if(e?.cache===!0){let i=`${n}:${this.userLanguage}:i`,r=this.cacheKeyboard.get(i);if(!r){let c=new F.InlineKeyboard,h=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"inline",e?.data),d=t(c,h);return this.cacheKeyboard.set(i,d),d}return r}let s=new F.InlineKeyboard,o=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"inline",e?.data);return t(s,o)}bottomKeyboard(t,e){let n=this.data.name;if(e?.cache===!0){let i=`${n}:${this.userLanguage}:b`,r=this.cacheKeyboard.get(i);if(!r){let c=new F.Keyboard,h=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"bottom",e?.data),d=t(c,h);return d.resized(!0),this.cacheKeyboard.set(i,d),d}return r}let s=new F.Keyboard,o=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"bottom",e?.data),a=t(s,o);return a.resized(),a}getSeperatorTag(t="space"){return t=="space"?" ":":"}havePayloads(t="",e){return t.includes(this.getSeperatorTag(e))}getPayloads(t="",e,n=1){if(!t)return[];let s=this.getSeperatorTag(e);return t.split(s).slice(n)}getIntent(t="",e,n=1){if(!t)return"";let s=this.getSeperatorTag(e),o=t.split(s);return n==1?o[0]:o.slice(0,n).join(s)}validateSessionCallback(t,e){return(t??this.session.method)===this.methodSessionCallback(e)}validateSessionCallbackPayload(t,e){return(t??this.session.method)===this.methodSessionCallbackPayload(e)}validateSessionText(t,e){return(t??this.session.method)===this.methodSessionText(e)}validateSessionTextPayload(t,e){return(t??this.session.method)===this.methodSessionTextPayload(e)}validateSessionTextCommand(t,e){return(t??this.session.method)===this.methodSessionTextCommand(e)}validateSessionTextCommandPayload(t,e){return(t??this.session.method)===this.methodSessionTextCommandPayload(e)}validateSessionTextFree(t,e){return(t??this.session.method)===this.methodSessionTextFree(e)}validateSessionPhotoCaption(t,e){return(t??this.session.method)===this.methodSessionPhotoCaption(e)}validateSessionPhotoCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionPhotoCaptionPayload(e)}validateSessionPhotoCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionPhotoCaptionCommand(e)}validateSessionPhotoCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionPhotoCaptionCommandPayload(e)}validateSessionPhotoFree(t,e){return(t??this.session.method)===this.methodSessionPhotoFree(e)}validateSessionVideoCaption(t,e){return(t??this.session.method)===this.methodSessionVideoCaption(e)}validateSessionVideoCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionVideoCaptionPayload(e)}validateSessionVideoCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionVideoCaptionCommand(e)}validateSessionVideoCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionVideoCaptionCommandPayload(e)}validateSessionVideoFree(t,e){return(t??this.session.method)===this.methodSessionVideoFree(e)}validateSessionAudioCaption(t,e){return(t??this.session.method)===this.methodSessionAudioCaption(e)}validateSessionAudioCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionAudioCaptionPayload(e)}validateSessionAudioCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionAudioCaptionCommand(e)}validateSessionAudioCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionAudioCaptionCommandPayload(e)}validateSessionAudioFree(t,e){return(t??this.session.method)===this.methodSessionAudioFree(e)}validateSessionDocumentCaption(t,e){return(t??this.session.method)===this.methodSessionDocumentCaption(e)}validateSessionDocumentCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionDocumentCaptionPayload(e)}validateSessionDocumentCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionDocumentCaptionCommand(e)}validateSessionDocumentCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionDocumentCaptionCommandPayload(e)}validateSessionDocumentFree(t,e){return(t??this.session.method)===this.methodSessionDocumentFree(e)}validateSessionAnimationCaption(t,e){return(t??this.session.method)===this.methodSessionAnimationCaption(e)}validateSessionAnimationCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionAnimationCaptionPayload(e)}validateSessionAnimationCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionAnimationCaptionCommand(e)}validateSessionAnimationCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionAnimationCaptionCommandPayload(e)}validateSessionAnimationFree(t,e){return(t??this.session.method)===this.methodSessionAnimationFree(e)}validateSessionVoiceCaption(t,e){return(t??this.session.method)===this.methodSessionVoiceCaption(e)}validateSessionVoiceCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionVoiceCaptionPayload(e)}validateSessionVoiceCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionVoiceCaptionCommand(e)}validateSessionVoiceCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionVoiceCaptionCommandPayload(e)}validateSessionVoiceFree(t,e){return(t??this.session.method)===this.methodSessionVoiceFree(e)}validateSessionVideoNoteCaption(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaption(e)}validateSessionVideoNoteCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaptionPayload(e)}validateSessionVideoNoteCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaptionCommand(e)}validateSessionVideoNoteCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaptionCommandPayload(e)}validateSessionVideoNoteFree(t,e){return(t??this.session.method)===this.methodSessionVideoNoteFree(e)}validateSessionStickerFree(t,e){return(t??this.session.method)===this.methodSessionStickerFree(e)}validateSessionLocationFree(t,e){return(t??this.session.method)===this.methodSessionLocationFree(e)}validateSessionContactFree(t,e){return(t??this.session.method)===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)}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 I=require("path"),at=require("fs"),rt=require("url");var L=require("path"),R=require("fs"),it=require("module");var b=class{static{p(this,"PageManager")}static _getFile(t,e,n=0){let o=Object.values(t)[n];if(o===void 0)throw new Error(`File ${e} must have export (not default) class page`);return o}static getFilePath(){return(0,L.join)(process.cwd(),"src","pages")}static getFileSync(t,e=0){t||(t=this.getFilePath());let s=(0,it.createRequire)(t)(t);return this._getFile(s,t,e)}static async getFile(t,e=0){t||(t=this.getFilePath());let n=await import(`${t}?t=${Date.now()}`);return this._getFile(n,t,e)}static getFileManySync(t,e=0){if(t||(t=this.getFilePath()),!(0,R.existsSync)(t))throw new Error(`Directory ${t} is not found, please make it manually`);return(0,R.readdirSync)(t).map(s=>{let o=(0,L.join)(t,s);return{path:o,page:this.getFileSync(o,e)}})}static clearCacheRequire(t){if(t||(t=this.getFilePath()),!(0,R.existsSync)(t))throw new Error(`Directory ${t} is not found, please make it manually`);return(0,R.readdirSync)(t).forEach(n=>{let s=(0,L.join)(t,n);delete require.cache[require.resolve(s)]}),!0}};var ct=require("logging-pretty");var P=require("path"),f=require("fs"),ot=require("chokidar");var k=class{static{p(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(e,n)=>`\${(data && data["${n}"]) ?? ""}`)}static _processBaseBlocks(t){let e=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,n={};for(let s of t.matchAll(e)){let o=s[2]??"default",i=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[o]=i}return n}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(e,n)=>{let s=n.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,n)=>n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processSwitchBlocks(t){let e=/<switch\b(?:\s+value="([^"]+)")?>([\s\S]*?)<\/switch>/gi;return t.replace(e,(n,s,o)=>{if(!s)return"";let a="",i=/<case\b(?:\s+is="([^"]+)")?>([\s\S]*?)<\/case>/gi,r=/<default>([\s\S]*?)<\/default>/gi,c;for(;(c=i.exec(o))!==null;){let d=(c[1]||"").split(",").map(m=>m.trim()),l=(c[2]||"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim().replace(/`/g,"\\`");d.forEach(m=>{a+=`case "${m}": `}),a+=`return \`${l}\`; `}let h=r.exec(o);if(h){let d=(h[1]||"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim().replace(/`/g,"\\`");a+=`default: return \`${d}\`; `}else a+="default: return ''; ";return`\${(() => { switch((data && data["${s}"])) { ${a} } })()}`})}static _processExec(t){return t.replace(/{~\s*([\s\S]*?)\s*~}/g,(e,n)=>`\${(() => { try { return ${n} } catch(e) { try { with(data || {}) { return ${n} } } catch(ee) { return '' } } })()}`)}static _processMapBlocks(t){let e=/<map(?:\s+([^>]*))?>([\s\S]*?)<\/map>/gi;return t.replace(e,(n,s,o)=>{let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let l of s.matchAll(i))a[l[1]]=l[2];let r=a.src;if(!r)return"";let c=a.join??"\\n",h=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").replace(/`/g,"\\`");h=h.replace(/\{\{([\w.]+)\}\}/g,(l,m)=>m==="e"||m.startsWith("e.")?`\${${m}}`:m==="i"?"${i}":l);let d=c.replace(/"/g,'\\"');return`\${(data && data["${r}"] || []).map((e, i) => \`${h}\`).join("${d}")}`})}static _processMediaBlocks(t){let e=/<media(?:\s+([^>]*))?>([\s\S]*?)<\/media>/gi,n={};for(let s of t.matchAll(e)){let o=s[1],a=s[2],i={},r=/(\w+)="([^"]*)"/g;if(o)for(let m of o.matchAll(r))i[m[1]]=m[2];let c=i.lang||"default",h=i.type,d=a.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),l={type:h};i.src&&(l.src=i.src),d&&h!=="video_note"&&h!=="sticker"&&(l.caption=d),h==="location"&&(i.latitude&&(l.latitude=i.latitude),i.longitude&&(l.longitude=i.longitude),d&&(l.caption=d)),h==="contact"&&(i.phone&&(l.phone=i.phone),i.first_name&&(l.first_name=i.first_name),i.last_name&&(l.last_name=i.last_name),i.vcard&&(l.vcard=i.vcard),d&&(l.caption=d)),n[c]=l}return n}static _processMessageBlocks(t){let e=/<message(?:\s+([^>]*))?>([\s\S]*?)<\/message>/gi,n={};for(let[,s,o]of t.matchAll(e)){let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let h of s.matchAll(i))a[h[1]]=h[2];let r=a.lang||"default",c=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[r]=c}return n}static _processDescriptionBlocks(t){let e=/<description(?:\s+([^>]*))?>([\s\S]*?)<\/description>/gi,n={};for(let[,s,o]of t.matchAll(e)){let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let d of s.matchAll(i))a[d[1]]=d[2];let r=a.lang||"default",c=a.scope||"default",h=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[r]||(n[r]={}),n[r][c]=h}return n}static _processKeyboardBlocks(t){let e=/<keyboard(?:\s+([^>]*))?>([\s\S]*?)<\/keyboard>/gi,n={};for(let[,s,o]of t.matchAll(e)){let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let d of s.matchAll(i))a[d[1]]=d[2];let r=a.lang||"default",c=a.type==="bottom"?"bottom":"inline",h=o.trim();n[r]||(n[r]={}),n[r][c]=h}return n}static _compileToFunction(t,e){let n;e?n=t.map(a=>`\`${a}\``).join(","):n=`\`${t}\``;let s=n;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,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processMediaBlocks(a);s[o]={};for(let[r,c]of Object.entries(i)){let h={};for(let[d,l]of Object.entries(c)){if(d==="type"||typeof l!="string")continue;let m=this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(l)))));h[d]=this._compileToFunction(m,!1)}s[o][r]=d=>{let l={...c};for(let[m,y]of Object.entries(h))l[m]=y(d);return l}}}return s}static compileMessages(t,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processMessageBlocks(a);s[o]={};for(let[r,c]of Object.entries(i)){let h=this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(c)))));s[o][r]=this._compileToFunction(h,!1)}}return s}static compileDescription(t,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processDescriptionBlocks(a);s[o]={};for(let[r,c]of Object.entries(i))for(let[h,d]of Object.entries(c)){s[o][h]||(s[o][h]={});let l=this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(d)))));s[o][h][r]=this._compileToFunction(l,!1)}}return s}static compileKeyboards(t,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processKeyboardBlocks(a);s[o]={};for(let[r,c]of Object.entries(i)){s[o][r]={};for(let[h,d]of Object.entries(c)){let m=d.split(/(?<!\\),\s*/).map(y=>y.replace(/\\,/g,",").trim()).map(y=>this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(y))))));s[o][r][h]=this._compileToFunction(m,!0)}}}return s}static _extractBlock(t,e,n="default",s="all",o){let a=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,i=t,r=!1;for(let c of t.matchAll(a))if((c[2]??"default")===n){i=c[3]??"",r=!0;break}if(!r){let c=/<base\b/.test(t);if(!(n==="default"&&!c))return""}if(e){if(e==="all")return i;let c=Array.isArray(e)?e:[e],h=[];for(let l of c){let m=new RegExp(`([ \\t]*)<${l}(?:\\s+([^>]*))?>([\\s\\S]*?)<\\/${l}>`,"gi");for(let y of i.matchAll(m)){let C=y[2];if(o){let u=/lang="([^"]*)"/i,v=C?.match(u);if(((v?v[1]:void 0)||"default")!==o)continue}h.push({start:y.index,content:y[0],innerContent:y[3]??""})}}h.sort((l,m)=>l.start-m.start);let d=p(l=>{let m=l.split(`
2
+ `);if(m.length<=1)return l.trim();let y=m.filter(u=>u.trim().length>0);if(y.length===0)return"";let C=y.reduce((u,v)=>{let T=v.match(/^([ \t]*)/),x=T?T[1].length:0;return x<u?x:u},1/0);return m.map(u=>u.length>=C?u.slice(C):u.trimStart()).join(`
3
+ `).trim()},"processResult");return s==="all"?h.map(m=>d(m.content)).join(`
4
+ `):h.map(m=>d(m.innerContent)).join(`
5
+ `)}return i}static _processImportBlocks(t){let e=/([ \t]*)<import(?:\s+([^>]*))?\/?>/gi,n=[];return{processed:t.replace(e,(o,a,i)=>{let r={},c=/(\w+)="([^"]*)"/g;if(i)for(let m of i.matchAll(c))r[m[1]]=m[2];let h=r.src;if(!h)return"";let d;r.block&&(r.block==="all"?d="all":r.block.includes(",")?d=r.block.split(",").map(m=>m.trim()).filter(m=>m):d=r.block);let l={src:h,blocks:d,base:r.base||"default",lang:r.lang,section:r.section||"all",indent:a||""};return n.push(l),`${a}__IMPORT_${n.length-1}__`}),imports:n}}static processImportBlocks(t,e,n=0,s){if(n>10)return"";let{processed:o,imports:a}=this._processImportBlocks(t),i=o;for(let r=0;r<a.length;r++){let c=a[r],h=`${c.src}|${c.base}|${c.lang||""}|${c.section}|${Array.isArray(c.blocks)?c.blocks.join(","):c.blocks||""}`,d;if(s&&s.has(h))d=s.get(h);else{let m=e(c.src);d=m?this._extractBlock(m,c.blocks,c.base,c.section,c.lang):"",d&&d.includes("<import")&&(d=this.processImportBlocks(d,e,n+1,s)),s&&s.set(h,d)}let l=d.split(`
6
6
  `).map((m,y)=>y===0?m:c.indent+m).join(`
7
- `);i=i.replace(`__IMPORT_${r}__`,h)}return i}};var $=class{static{p(this,"TemplateManager")}_map=new Map;_engine=k;_watcher=[];_pageManager=b;_supportedExtensions=new Set([".html",".ts",".js"]);_path;_isWatchEnabled;constructor(t){let{path:e,enableWatch:n=!1}=t;this._path=e,this._isWatchEnabled=n,this._validatePath(),this._initializeWatcher(t.watchOptions),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,f.existsSync)(e))throw new Error(`Template base path is not exists: ${e}`);if(!(0,f.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: ${String(t)}`)}}_initializeWatcher(t){if(this._isWatchEnabled){if(this._watcher.length>0)throw new Error("Watcher already enabled");for(let e=0;e<this._path.length;e++){let n=this._path[e],s=(0,ot.watch)(n,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},...t});this._watcher[e]=s,s.on("change",this._handleFileChange.bind(this)),s.on("add",this._handleFileAdd.bind(this)),s.on("unlink",this._handleFileDelete.bind(this)),s.on("error",this._handleWatchError.bind(this))}}}_handleFileChange(t){let e=(0,P.basename)(t);this._isValidFile(e)&&this._loadFile(e)}_handleFileAdd(t){let e=(0,P.basename)(t);this._isValidFile(e)&&this._loadFile(e)}_handleFileDelete(t){let e=(0,P.basename)(t),n=this._getKey(e);this._map.has(n)&&this._map.delete(n)}_handleWatchError(t){}_loadAllFiles(){let t=new Map,e=[];for(let s=0;s<this._path.length;s++){let o=this._path[s],i=(0,f.readdirSync)(o,"utf8").filter(r=>this._isValidFile(r));for(let r of i){let c=(0,P.join)(o,r),l=this._getExtension(r),d=this._getKey(r);if(l===".html")t.set(d,(0,f.readFileSync)(c,"utf8"));else if(l===".ts"||l===".js"){let h=b.getFileSync(c);h?.template!==void 0&&(t.set(d,h.template),e.push(h))}}}let n=new Map;for(let[s,o]of t.entries())this._compile(s,o,void 0,n,t);t.clear(),n.clear();for(let s of e)s.template=void 0}_loadFile(t){for(let e=0;e<this._path.length;e++){let n=this._path[e],s=(0,P.join)(n,t),o=this._getExtension(t),a=this._getKey(t);if(o==".html"){let i=(0,f.readFileSync)(s,"utf8");this._compile(a,i)}else if(o==".ts"||o==".js"){let i=b.getFileSync(s);i?.template!==void 0&&(this._compile(a,i.template),i.template=void 0)}else throw new Error(`File ${t} is not support`)}}_getExtension(t){return(0,P.extname)(t).toLowerCase()}_readTemplateFile(t){for(let e of this._path){let n=(0,P.extname)(t).toLowerCase();if(n){let i=(0,P.join)(e,t);if((0,f.existsSync)(i)&&(0,f.statSync)(i).isFile()){if(n===".html")return(0,f.readFileSync)(i,"utf8");if(n===".ts"||n===".js")try{return b.getFileSync(i)?.template??null}catch{return null}}continue}let s=(0,P.join)(e,`${t}.ts`),o=(0,P.join)(e,`${t}.js`);if((0,f.existsSync)(s)&&(0,f.statSync)(s).isFile())try{return b.getFileSync(s)?.template??null}catch{}else if((0,f.existsSync)(o)&&(0,f.statSync)(o).isFile())try{return b.getFileSync(s)?.template??null}catch{}let a=(0,P.join)(e,`${t}.html`);if((0,f.existsSync)(a)&&(0,f.statSync)(a).isFile())return(0,f.readFileSync)(a,"utf8")}return null}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,e,n,s,o){let a=this._map.get(t),i=a||{},r=!1,c=k.processImportBlocks(e,d=>o&&o.has(d)?o.get(d):this._readTemplateFile(d),0,s),l=k._processBaseBlocks(c);(n===void 0||n?.media===!1||a?.media===void 0)&&(i.media=k.compileMedia(c,l),r=!0),(n===void 0||n?.message===!1||a?.message===void 0)&&(i.message=k.compileMessages(c,l),r=!0),(n===void 0||n?.keyboard===!1||a?.keyboard===void 0)&&(i.keyboard=k.compileKeyboards(c,l),r=!0),(n===void 0||n?.description===!1||a?.description===void 0)&&(i.description=k.compileDescription(c,l),r=!0),r&&this._map.set(t,i)}getMedia(t,e="default",n="default",s){let a=this._map.get(t)?.media?.[e],i=a?.[n]||a?.default;try{if(!i)throw new Error("Media function not found, please check your template");return i(s)}catch{return{}}}getMessage(t,e="default",n="default",s){try{let a=this._map.get(t)?.message?.[e],i=a?.[n]||a?.default;if(!i)throw"";return i(s)}catch{return""}}getDescription(t,e="default",n="default",s="default",o){try{let i=this._map.get(t)?.description?.[e]?.[s],r=i?.[n]||i?.default;if(!r)throw"";return r(o)}catch{return""}}getDescriptionLanguage(t,e="default",n="default"){try{let o=this._map.get(t)?.description?.[e]?.[n];return o?Object.keys(o):[]}catch{return[]}}getDescriptionScopes(t,e="default"){try{let s=this._map.get(t)?.description?.[e];return s?Object.keys(s):[]}catch{return[]}}getKeyboard(t,e="default",n="default",s="inline",o){try{let i=this._map.get(t)?.keyboard?.[e],r=i?.[n]?.[s]||i?.default?.[s];if(!r)throw[];return r(o)}catch{return[]}}async write(t,e){if(this._getExtension(t)!=".html")return null;for(let n=0;n<this._path.length;n++){let s=(0,P.join)(this._path[n],t);if((0,f.existsSync)(s))return(0,f.writeFileSync)(s,e,"utf8"),this._loadFile(t),!0}return null}has(t){return this._map.has(t)}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};var W=require("grammy");var Tt=(()=>{try{return __filename}catch{return(0,rt.fileURLToPath)(S)}})(),wt=(0,I.dirname)(Tt),vt=JSON.parse((0,at.readFileSync)((0,I.join)(wt,"../../package.json"),"utf-8")).version,G=class{static{p(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;optionsPage={shortCallbackData:!1};log;bot;handlerBotUpdate;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");if(typeof t.optionsPage?.shortCallbackData=="boolean"&&(this.optionsPage.shortCallbackData=t.optionsPage.shortCallbackData),this.log=t.log===!0?new ct.LoggingPretty:t.log?t.log:void 0,this.log?.info?.(`Gramstax v${vt}`),this.cacheSession=t.cacheSession||new A("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new $({path:[(0,I.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()),this.hookBeforeStart(),t.deploy.startsWith("polling"))this.runPolling();else if(t.deploy.startsWith("webhook:"))this.runWebhook(t.deploy.split("webhook:")[1]);else if(t.deploy.startsWith("serverless:"))this.runServerless(t.deploy.split("serverless:")[1]);else if(!t.deploy.startsWith("test"))throw new Error("Params deploy is not valid, expected: polling, webhook:<public-url>, serverless:<your-adapter>")}onCatch(t){this.log?.error?.(`[Bot.catch]: ${JSON.stringify(t,null,2)}`)}hookBeforeStart(){}hookAfterStart(){}async onStart(t,e,n){await this.executeSyncBlocksDescription(this.pages);let{username:s}=t;this.log?.success?.(`Telegram bot polling started: ${s} ${e=="webhook"||e=="serverless"?`(${n})`:""}`),this.hookAfterStart()}createBot(t){return new W.Bot(t)}createCtx(t){return new O({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{isAnswer:!1,session:{},data:{}}})}runPolling(){this.bot.start({onStart:p(t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let{serve:e}=await import("bun"),n=(0,W.webhookCallback)(this.bot,"bun");this.handlerBotUpdate=n;let s=new URL(t).pathname;e({fetch(i){let{pathname:r}=new URL(i.url);if(i.method=="POST"&&r==s)return n(i);if(i.method=="GET"&&r=="/"){let c=new Date().toISOString();return new Response(JSON.stringify({status:"OK",timestamp:c}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}}),(await this.bot.api.getWebhookInfo()).url!=t&&await this.bot.api.setWebhook(t);let a=await this.bot.api.getMe();await this.onStart(a,"webhook",t)}async runServerless(t){this.handlerBotUpdate=(0,W.webhookCallback)(this.bot,t);let e=await this.bot.api.getMe();await this.onStart(e,"serverless",t)}pageBuildData(t,e){t?.data===void 0&&(t.data=t.buildData()),t.data.name=(0,I.parse)(e).name,t.data._callbackData.length==0&&(t.data._callbackData=t.data.name)}pageSorts(t,e,n){let s=t.data.name,o=t.prototype,a="Payload",i="Command",r="Caption",c="Free",l=e.routeDynamic,d=e.routeDynamicSpesific,h=p(C=>C.charAt(0).toUpperCase()+C.slice(1),"upFirst"),m=p(C=>C.replace(a,"").replace(i,"").replace(r,"").replace(c,""),"getPureRouteName"),y=p((C,u)=>o[`methodSession${h(C)}`]?.(u),"methodSession");e.all[s]=t;for(let C=0;C<e.lenListRouteStaticSession;C++){let u=e.listRouteStaticSession[C];if(typeof o[u]!="function")continue;let w=e.routeStatic[u],v=e.routeStaticIntent[u],x=e.routeStaticSession[u],q={name:s,routeName:u},X=w||v;if(X!==void 0){let ht=u.includes(i),mt=u.includes("callback"),pt=u.startsWith("text"),_;if(ht){let M=t.data.textCommand||t.data.name;_=M?`/${M}`:void 0}else if(mt){let M=t.data._callbackData||t.data.name;this.optionsPage.shortCallbackData===!0&&(M=String(n),t.data._callbackData=M),_=M}else pt?_=t.data.text||t.data.name:_=t.data.name;_&&(X[_]=q)}x!==void 0&&(x[y(u,s)]=q),u.toLowerCase().endsWith("free")&&d[m(u)].push(q)}o.free&&l.push(s)}async executeSyncBlocksDescription(t){let e=new Map,n=t.routeStatic.textCommand;for(let[,s]of Object.entries(n)){let o=s.name,a=this.templateManager.getDescriptionScopes(o);for(let i of a){e.has(i)||e.set(i,new Set);let r=this.templateManager.getDescriptionLanguage(o,"default",i);for(let c of r)e.get(i).add(c)}}for(let[s,o]of e)for(let a of o){let i=[];for(let[,l]of Object.entries(n)){let d=l.name,h=this.templateManager.getDescription(d,"default",a,s);h&&i.push({command:d,description:h})}if(i.length===0)continue;let r={type:s},c=a==="default"?void 0:a;try{let l=await this.bot.api.getMyCommands({scope:r,language_code:c}),d=JSON.stringify(l.map(m=>({command:m.command,description:m.description})).sort((m,y)=>m.command.localeCompare(y.command))),h=JSON.stringify(i.sort((m,y)=>m.command.localeCompare(y.command)));d!==h&&(await this.bot.api.setMyCommands(i,{scope:r,language_code:c}),this.log?.info?.(`Synced descriptions for scope: ${s},${c?` lang: ${c},`:""} total (${i.length})`))}catch(l){this.log?.error?.(`Failed to sync descriptions for scope: ${s},${c?` lang: ${c},`:""} error: ${String(l)}`)}}}pageLoads(){this.log?.info?.("Load pages..");let t=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],e=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],n=[...t,...e,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],s=p((i,r)=>Object.fromEntries(i.map(c=>[c,r()])),"makeObject"),o=p(()=>[],"initDynamicSpesific"),a={all:{},routeDynamic:[],routeDynamicSpesific:{text:o(),photo:o(),video:o(),audio:o(),document:o(),animation:o(),voice:o(),videoNote:o(),sticker:o(),location:o(),contact:o()},routeStatic:s(t,()=>({})),routeStaticIntent:s(e,()=>({})),routeStaticSession:s(n,()=>({})),listRouteStatic:t,listRouteStaticIntent:e,listRouteStaticSession:n,lenListRouteStatic:t.length,lenListRouteStaticIntent:e.length,lenListRouteStaticSession:n.length};return b.getFileManySync(void 0).forEach(({path:i,page:r},c)=>{this.pageBuildData(r,i),this.pageSorts(r,a,c),r.template=void 0}),this.log?.info?.(`Finish load pages with total (${Object.keys(a.all).length})`),a}async pageRoutes(t,e){let n,s;if(n===void 0){let a=await t.sessionGet();if(a){let i=a.method,r=this.pages.routeStaticSession,c=t.callbackData,l=t.msgText,d=t.msgCaption,h=c||l||d,m=e==="callback",y=m?"colon":"space",C=h&&t.havePayloads(h,y)?t.getIntent(h,y,1):void 0,u=!m&&h?t.getIntent(h,"space",2):void 0;for(let w=0;w<this.pages.lenListRouteStaticSession;w++){let v=this.pages.listRouteStaticSession[w];if(v.startsWith(e)){if(h){if(this.pages.routeStatic[v]?.[h])continue;let x=this.pages.routeStaticIntent[v];if(x&&(C&&x[C]||u&&x[u]))continue}s=r[v][i]}if(s)break}s!==void 0&&(n=this.pages.all[s.name])}}if(n===void 0){let a=t.callbackData,i=t.msgText,r=t.msgCaption,c=this.pages.routeStatic;for(let l=0;l<this.pages.lenListRouteStatic;l++){let d=this.pages.listRouteStatic[l];if(d.startsWith(e)&&(s=c[d][a||i||r]),s)break}s!==void 0&&(n=this.pages.all[s.name])}if(n===void 0){let a=this.pages.routeStaticIntent,i=e==="callback",r=i?"colon":"space",c=i?t.callbackData:t.msgText||t.msgCaption,l=t.havePayloads(c,r);if(c&&l)for(let d=0;d<this.pages.lenListRouteStaticIntent;d++){let h=this.pages.listRouteStaticIntent[d];if(!h.startsWith(e))continue;let m=a[h];if(s=m[t.getIntent(c,r,1)],!s&&!i&&(s=m[t.getIntent(c,"space",2)]),s)break}s!==void 0&&(n=this.pages.all[s.name])}if(n!==void 0&&s!==void 0){if(!n.prototype[s.routeName])return;let i=await new n(t)[s.routeName]?.();return t.temp.isAnswer===!0?i:null}let o=this.pages.routeDynamicSpesific[e]||[];for(let a=0;a<o.length;a++){let i=o[a];if(i===void 0)continue;let r=this.pages.all[i.name];r!==void 0&&typeof r.prototype[i.routeName]=="function"&&await new r(t)[i.routeName]()}for(let a=0;a<this.pages.routeDynamic.length;a++){let i=this.pages.routeDynamic[a];if(i===void 0)continue;let r=this.pages.all[i];r!==void 0&&typeof r.prototype.free=="function"&&await new r(t).free()}if(t.temp.isAnswer===!1)return null}async hookBeforeRoute(t,e){return!!(t||e)}async hookErrorPage(t,e,n,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,e){let n=this.createCtx(t);try{if(await this.hookBeforeRoute(n,e)===!1)return;await this.pageRoutes(n,e)===null&&await this.hookErrorInputNotFoundPage(n)}catch(s){await this.hookErrorPage(n,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(n){await this.hookErrorPage(e,"onCallbackQueryData",n,!0)}}async onMessageText(t){await this.onMessage(t,"text")}async onMessagePhoto(t){await this.onMessage(t,"photo")}async onMessageVideo(t){await this.onMessage(t,"video")}async onMessageAudio(t){await this.onMessage(t,"audio")}async onMessageDocument(t){await this.onMessage(t,"document")}async onMessageAnimation(t){await this.onMessage(t,"animation")}async onMessageVoice(t){await this.onMessage(t,"voice")}async onMessageVideoNote(t){await this.onMessage(t,"videoNote")}async onMessageSticker(t){await this.onMessage(t,"sticker")}async onMessageLocation(t){await this.onMessage(t,"location")}async onMessageContact(t){await this.onMessage(t,"contact")}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))}};var U=class{static{p(this,"ComponentKeyboard")}static data;static _process(t,e){if(e.type||(e.type="inline"),e.lang){let n=t[e.lang];return`
7
+ `);i=i.replace(`__IMPORT_${r}__`,l)}return i}};var B=class{static{p(this,"TemplateManager")}_map=new Map;_engine=k;_watcher=[];_pageManager=b;_supportedExtensions=new Set([".html",".ts",".js"]);_path;_isWatchEnabled;constructor(t){let{path:e,enableWatch:n=!1}=t;this._path=e,this._isWatchEnabled=n,this._validatePath(),this._initializeWatcher(t.watchOptions),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,f.existsSync)(e))throw new Error(`Template base path is not exists: ${e}`);if(!(0,f.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: ${String(t)}`)}}_initializeWatcher(t){if(this._isWatchEnabled){if(this._watcher.length>0)throw new Error("Watcher already enabled");for(let e=0;e<this._path.length;e++){let n=this._path[e],s=(0,ot.watch)(n,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},...t});this._watcher[e]=s,s.on("change",this._handleFileChange.bind(this)),s.on("add",this._handleFileAdd.bind(this)),s.on("unlink",this._handleFileDelete.bind(this)),s.on("error",this._handleWatchError.bind(this))}}}_handleFileChange(t){let e=(0,P.basename)(t);this._isValidFile(e)&&this._loadFile(e)}_handleFileAdd(t){let e=(0,P.basename)(t);this._isValidFile(e)&&this._loadFile(e)}_handleFileDelete(t){let e=(0,P.basename)(t),n=this._getKey(e);this._map.has(n)&&this._map.delete(n)}_handleWatchError(t){}_loadAllFiles(){let t=new Map,e=[];for(let s=0;s<this._path.length;s++){let o=this._path[s],i=(0,f.readdirSync)(o,"utf8").filter(r=>this._isValidFile(r));for(let r of i){let c=(0,P.join)(o,r),h=this._getExtension(r),d=this._getKey(r);if(h===".html")t.set(d,(0,f.readFileSync)(c,"utf8"));else if(h===".ts"||h===".js"){let l=b.getFileSync(c);l?.template!==void 0&&(t.set(d,l.template),e.push(l))}}}let n=new Map;for(let[s,o]of t.entries())this._compile(s,o,void 0,n,t);t.clear(),n.clear();for(let s of e)s.template=void 0}_loadFile(t){for(let e=0;e<this._path.length;e++){let n=this._path[e],s=(0,P.join)(n,t),o=this._getExtension(t),a=this._getKey(t);if(o==".html"){let i=(0,f.readFileSync)(s,"utf8");this._compile(a,i)}else if(o==".ts"||o==".js"){let i=b.getFileSync(s);i?.template!==void 0&&(this._compile(a,i.template),i.template=void 0)}else throw new Error(`File ${t} is not support`)}}_getExtension(t){return(0,P.extname)(t).toLowerCase()}_readTemplateFile(t){for(let e of this._path){let n=(0,P.extname)(t).toLowerCase();if(n){let i=(0,P.join)(e,t);if((0,f.existsSync)(i)&&(0,f.statSync)(i).isFile()){if(n===".html")return(0,f.readFileSync)(i,"utf8");if(n===".ts"||n===".js")try{return b.getFileSync(i)?.template??null}catch{return null}}continue}let s=(0,P.join)(e,`${t}.ts`),o=(0,P.join)(e,`${t}.js`);if((0,f.existsSync)(s)&&(0,f.statSync)(s).isFile())try{return b.getFileSync(s)?.template??null}catch{}else if((0,f.existsSync)(o)&&(0,f.statSync)(o).isFile())try{return b.getFileSync(s)?.template??null}catch{}let a=(0,P.join)(e,`${t}.html`);if((0,f.existsSync)(a)&&(0,f.statSync)(a).isFile())return(0,f.readFileSync)(a,"utf8")}return null}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,e,n,s,o){let a=this._map.get(t),i=a||{},r=!1,c=k.processImportBlocks(e,d=>o&&o.has(d)?o.get(d):this._readTemplateFile(d),0,s),h=k._processBaseBlocks(c);(n===void 0||n?.media===!1||a?.media===void 0)&&(i.media=k.compileMedia(c,h),r=!0),(n===void 0||n?.message===!1||a?.message===void 0)&&(i.message=k.compileMessages(c,h),r=!0),(n===void 0||n?.keyboard===!1||a?.keyboard===void 0)&&(i.keyboard=k.compileKeyboards(c,h),r=!0),(n===void 0||n?.description===!1||a?.description===void 0)&&(i.description=k.compileDescription(c,h),r=!0),r&&this._map.set(t,i)}getMedia(t,e="default",n="default",s){let a=this._map.get(t)?.media?.[e],i=a?.[n]||a?.default;try{if(!i)throw new Error("Media function not found, please check your template");return i(s)}catch{return{}}}getMessage(t,e="default",n="default",s){try{let a=this._map.get(t)?.message?.[e],i=a?.[n]||a?.default;if(!i)throw"";return i(s)}catch{return""}}getDescription(t,e="default",n="default",s="default",o){try{let i=this._map.get(t)?.description?.[e]?.[s],r=i?.[n]||i?.default;if(!r)throw"";return r(o)}catch{return""}}getDescriptionLanguage(t,e="default",n="default"){try{let o=this._map.get(t)?.description?.[e]?.[n];return o?Object.keys(o):[]}catch{return[]}}getDescriptionScopes(t,e="default"){try{let s=this._map.get(t)?.description?.[e];return s?Object.keys(s):[]}catch{return[]}}getKeyboard(t,e="default",n="default",s="inline",o){try{let i=this._map.get(t)?.keyboard?.[e],r=i?.[n]?.[s]||i?.default?.[s];if(!r)throw[];return r(o)}catch{return[]}}async write(t,e){if(this._getExtension(t)!=".html")return null;for(let n=0;n<this._path.length;n++){let s=(0,P.join)(this._path[n],t);if((0,f.existsSync)(s))return(0,f.writeFileSync)(s,e,"utf8"),this._loadFile(t),!0}return null}has(t){return this._map.has(t)}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};var $=require("grammy");var wt=(()=>{try{return __filename}catch{return(0,rt.fileURLToPath)(S)}})(),vt=(0,I.dirname)(wt),Tt=JSON.parse((0,at.readFileSync)((0,I.join)(vt,"../../package.json"),"utf-8")).version,q=class{static{p(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;optionsPage={shortCallbackData:!1};log;bot;handlerBotUpdate;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");if(typeof t.optionsPage?.shortCallbackData=="boolean"&&(this.optionsPage.shortCallbackData=t.optionsPage.shortCallbackData),this.log=t.log===!0?new ct.LoggingPretty:t.log?t.log:void 0,this.log?.info?.(`Gramstax v${Tt}`),this.cacheSession=t.cacheSession||new A("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new B({path:[(0,I.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()),this.hookBeforeStart(),t.deploy.startsWith("polling"))this.runPolling();else if(t.deploy.startsWith("webhook:"))this.runWebhook(t.deploy.split("webhook:")[1]);else if(t.deploy.startsWith("serverless:"))this.runServerless(t.deploy.split("serverless:")[1]);else if(!t.deploy.startsWith("test"))throw new Error("Params deploy is not valid, expected: polling, webhook:<public-url>, serverless:<your-adapter>")}onCatch(t){this.log?.error?.(`[Bot.catch]: ${JSON.stringify(t,null,2)}`)}hookBeforeStart(){}hookAfterStart(){}async onStart(t,e,n){await this.executeSyncBlocksDescription(this.pages);let{username:s}=t;this.log?.success?.(`Telegram bot polling started: ${s} ${e=="webhook"||e=="serverless"?`(${n})`:""}`),this.hookAfterStart()}createBot(t){return new $.Bot(t)}createCtx(t){return new O({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{isAnswer:!1,session:{},data:{}}})}runPolling(){this.bot.start({onStart:p(t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let{serve:e}=await import("bun"),n=(0,$.webhookCallback)(this.bot,"bun");this.handlerBotUpdate=n;let s=new URL(t).pathname;e({fetch(i){let{pathname:r}=new URL(i.url);if(i.method=="POST"&&r==s)return n(i);if(i.method=="GET"&&r=="/"){let c=new Date().toISOString();return new Response(JSON.stringify({status:"OK",timestamp:c}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}}),(await this.bot.api.getWebhookInfo()).url!=t&&await this.bot.api.setWebhook(t);let a=await this.bot.api.getMe();await this.onStart(a,"webhook",t)}async runServerless(t){this.handlerBotUpdate=(0,$.webhookCallback)(this.bot,t);let e=await this.bot.api.getMe();await this.onStart(e,"serverless",t)}pageBuildData(t,e){t?.data===void 0&&(t.data=t.buildData()),t.data.name=(0,I.parse)(e).name,t.data._callbackData.length==0&&(t.data._callbackData=t.data.name)}pageSorts(t,e,n){let s=t.data.name,o=t.prototype,a="Payload",i="Command",r="Caption",c="Free",h=e.routeDynamic,d=e.routeDynamicSpesific,l=p(C=>C.charAt(0).toUpperCase()+C.slice(1),"upFirst"),m=p(C=>C.replace(a,"").replace(i,"").replace(r,"").replace(c,""),"getPureRouteName"),y=p((C,u)=>o[`methodSession${l(C)}`]?.(u),"methodSession");e.all[s]=t;for(let C=0;C<e.lenListRouteStaticSession;C++){let u=e.listRouteStaticSession[C];if(typeof o[u]!="function")continue;let v=e.routeStatic[u],T=e.routeStaticIntent[u],x=e.routeStaticSession[u],G={name:s,routeName:u},X=v||T;if(X!==void 0){let lt=u.includes(i),mt=u.includes("callback"),pt=u.startsWith("text"),_;if(lt){let M=t.data.textCommand||t.data.name;_=M?`/${M}`:void 0}else if(mt){let M=t.data._callbackData||t.data.name;this.optionsPage.shortCallbackData===!0&&(M=String(n),t.data._callbackData=M),_=M}else pt?_=t.data.text||t.data.name:_=t.data.name;_&&(X[_]=G)}x!==void 0&&(x[y(u,s)]=G),u.toLowerCase().endsWith("free")&&d[m(u)].push(G)}o.free&&h.push(s)}async executeSyncBlocksDescription(t){let e=new Map,n=t.routeStatic.textCommand;for(let[,s]of Object.entries(n)){let o=s.name,a=this.templateManager.getDescriptionScopes(o);for(let i of a){e.has(i)||e.set(i,new Set);let r=this.templateManager.getDescriptionLanguage(o,"default",i);for(let c of r)e.get(i).add(c)}}for(let[s,o]of e)for(let a of o){let i=[];for(let[,h]of Object.entries(n)){let d=h.name,l=this.templateManager.getDescription(d,"default",a,s);l&&i.push({command:d,description:l})}if(i.length===0)continue;let r={type:s},c=a==="default"?void 0:a;try{let h=await this.bot.api.getMyCommands({scope:r,language_code:c}),d=JSON.stringify(h.map(m=>({command:m.command,description:m.description})).sort((m,y)=>m.command.localeCompare(y.command))),l=JSON.stringify(i.sort((m,y)=>m.command.localeCompare(y.command)));d!==l&&(await this.bot.api.setMyCommands(i,{scope:r,language_code:c}),this.log?.info?.(`Synced descriptions for scope: ${s},${c?` lang: ${c},`:""} total (${i.length})`))}catch(h){this.log?.error?.(`Failed to sync descriptions for scope: ${s},${c?` lang: ${c},`:""} error: ${String(h)}`)}}}pageLoads(){this.log?.info?.("Load pages..");let t=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],e=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],n=[...t,...e,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],s=p((i,r)=>Object.fromEntries(i.map(c=>[c,r()])),"makeObject"),o=p(()=>[],"initDynamicSpesific"),a={all:{},routeDynamic:[],routeDynamicSpesific:{text:o(),photo:o(),video:o(),audio:o(),document:o(),animation:o(),voice:o(),videoNote:o(),sticker:o(),location:o(),contact:o()},routeStatic:s(t,()=>({})),routeStaticIntent:s(e,()=>({})),routeStaticSession:s(n,()=>({})),listRouteStatic:t,listRouteStaticIntent:e,listRouteStaticSession:n,lenListRouteStatic:t.length,lenListRouteStaticIntent:e.length,lenListRouteStaticSession:n.length};return b.getFileManySync(void 0).forEach(({path:i,page:r},c)=>{this.pageBuildData(r,i),this.pageSorts(r,a,c),r.template=void 0}),this.log?.info?.(`Finish load pages with total (${Object.keys(a.all).length})`),a}async pageRoutes(t,e){let n,s;if(n===void 0){let a=await t.sessionGet();if(a){let i=a.method,r=this.pages.routeStaticSession,c=t.callbackData,h=t.msgText,d=t.msgCaption,l=c||h||d,m=e==="callback",y=m?"colon":"space",C=l&&t.havePayloads(l,y)?t.getIntent(l,y,1):void 0,u=!m&&l?t.getIntent(l,"space",2):void 0;for(let v=0;v<this.pages.lenListRouteStaticSession;v++){let T=this.pages.listRouteStaticSession[v];if(T.startsWith(e)){if(l){if(this.pages.routeStatic[T]?.[l])continue;let x=this.pages.routeStaticIntent[T];if(x&&(C&&x[C]||u&&x[u]))continue}s=r[T][i]}if(s)break}s!==void 0&&(n=this.pages.all[s.name])}}if(n===void 0){let a=t.callbackData,i=t.msgText,r=t.msgCaption,c=this.pages.routeStatic;for(let h=0;h<this.pages.lenListRouteStatic;h++){let d=this.pages.listRouteStatic[h];if(d.startsWith(e)&&(s=c[d][a||i||r]),s)break}s!==void 0&&(n=this.pages.all[s.name])}if(n===void 0){let a=this.pages.routeStaticIntent,i=e==="callback",r=i?"colon":"space",c=i?t.callbackData:t.msgText||t.msgCaption,h=t.havePayloads(c,r);if(c&&h)for(let d=0;d<this.pages.lenListRouteStaticIntent;d++){let l=this.pages.listRouteStaticIntent[d];if(!l.startsWith(e))continue;let m=a[l];if(s=m[t.getIntent(c,r,1)],!s&&!i&&(s=m[t.getIntent(c,"space",2)]),s)break}s!==void 0&&(n=this.pages.all[s.name])}if(n!==void 0&&s!==void 0){if(!n.prototype[s.routeName])return;let i=await new n(t)[s.routeName]?.();return t.temp.isAnswer===!0?i:null}let o=this.pages.routeDynamicSpesific[e]||[];for(let a=0;a<o.length;a++){let i=o[a];if(i===void 0)continue;let r=this.pages.all[i.name];r!==void 0&&typeof r.prototype[i.routeName]=="function"&&await new r(t)[i.routeName]()}for(let a=0;a<this.pages.routeDynamic.length;a++){let i=this.pages.routeDynamic[a];if(i===void 0)continue;let r=this.pages.all[i];r!==void 0&&typeof r.prototype.free=="function"&&await new r(t).free()}if(t.temp.isAnswer===!1)return null}async hookBeforeRoute(t,e){return!!(t||e)}async hookErrorPage(t,e,n,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,e){let n=this.createCtx(t);try{if(await this.hookBeforeRoute(n,e)===!1)return;await this.pageRoutes(n,e)===null&&await this.hookErrorInputNotFoundPage(n)}catch(s){await this.hookErrorPage(n,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(n){await this.hookErrorPage(e,"onCallbackQueryData",n,!0)}}async onMessageText(t){await this.onMessage(t,"text")}async onMessagePhoto(t){await this.onMessage(t,"photo")}async onMessageVideo(t){await this.onMessage(t,"video")}async onMessageAudio(t){await this.onMessage(t,"audio")}async onMessageDocument(t){await this.onMessage(t,"document")}async onMessageAnimation(t){await this.onMessage(t,"animation")}async onMessageVoice(t){await this.onMessage(t,"voice")}async onMessageVideoNote(t){await this.onMessage(t,"videoNote")}async onMessageSticker(t){await this.onMessage(t,"sticker")}async onMessageLocation(t){await this.onMessage(t,"location")}async onMessageContact(t){await this.onMessage(t,"contact")}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))}};var U=class{static{p(this,"ComponentKeyboard")}static data;static _process(t,e){if(e.type||(e.type="inline"),e.lang){let n=t[e.lang];return`
8
8
  <keyboard type="${e.type}" lang="${e.lang}">${e.reverse?this.data._reverse(n):n}</keyboard>
9
9
  `}return Object.keys(t).map(n=>{let s=t[n];return`
10
10
  <keyboard type="${e.type}" lang="${n}">${e.reverse?this.data._reverse(s):s}</keyboard>
11
- `}).join(" ")}static _build(t,e,n){if(!this.data)throw new Error("Data not found");let s=this.data[t];if(!s)throw new Error(`Function ${t} not found`);return this._process(s.call(this.data,e),{type:n,lang:e})}};var Q=class{static{p(this,"DataKeyboard")}static _reverse(t){return t.split(/(?<!\\), */).reverse().join(", ")}static _reverseObj(t){return Object.keys(t).reduce((e,n)=>(e[n]=this._reverse(t[n]),e),{})}static _build(t,e,n){if(t){let s=n[t||""];return e?this._reverse(s):s}return e?this._reverseObj(n):n}};var j=require("worker_threads");var T=class{constructor(t,e){this.send=t;this.register=e}static{p(this,"WorkerThreadRpc")}map=new Map;async make(t){let e=this.map,n=this.send,{id:s,method:o,params:a,result:i,error:r}=t;if(o!==void 0)try{let c=this.register[o];if(typeof c!="function")throw new Error(`Method ${o} not found or not function`);let l=await c.apply(this.register,a);n({id:s,result:l})}catch(c){n({id:s,error:c instanceof Error?{message:c.message,stack:c.stack,name:c.name}:c})}else if(i!==void 0){let c=e.get(s);c&&(c.resolve(i),e.delete(s))}else if(r!==void 0){let c=e.get(s);c&&(c.reject(r),e.delete(s))}}makeId(){return Math.random()}makeRequest(t,e,n=!0,s){let o=this.makeId(),a={id:o,method:t,params:e,...s};return n?new Promise((i,r)=>{this.map.set(o,{resolve:i,reject:r}),this.send(a)}):this.send(a)}};var B=class{constructor(t,e){this.path=t;this.argv=e;this.init(),this.rpc=new T(this.send.bind(this),this)}static{p(this,"WorkerThreadLaunch")}static isMainThread=j.isMainThread;_readyResolve;_readyPromise=new Promise(t=>this._readyResolve=t);pid=process.pid;thread={};threadId={};rpc={};ready(){return this._readyPromise}mtdReady(){this._readyResolve?.()}init(){this.thread=new j.Worker(this.path,{argv:this.argv.length==0&&this.argv[0]===void 0?void 0:this.argv}),this.threadId=this.thread.threadId,this.thread.on("message",t=>this.handleOnMessage(t)),this.thread.on("exit",()=>this.kill()),process.once("SIGINT",()=>this.kill()),process.once("SIGTERM",()=>this.kill())}async handleOnMessage(t){this.rpc.make(t)}kill(){this.thread.terminate()}send(t){this.thread.postMessage(t)}async request(t,e,n=!0,s){return this.rpc.makeRequest(t,e,n,s)}};var J=class g{static{p(this,"WorkerThreadExport")}static gateway(t){let e=new Proxy({},{get(s,o){if(!(typeof o!="string"||o==="then"))return async(a,...i)=>{let r=a.gatewayClients.get(t);return r||(r=await a.createGatewayClient(t)),r.request(o,i)}}}),n=p(function(s){return new Proxy({},{get(o,a){if(!(typeof a!="string"||a==="then"))return async(...i)=>{let r=s.gatewayClients.get(t);return r||(r=await s.createGatewayClient(t)),r.request(a,i)}}})},"ctor");return Object.setPrototypeOf(n,e),n}static init(t){let{WTInit:e,WTLaunch:n=B,path:s,wrap:o}=t,a=`for-${s}`;if(process.argv[2]===a)return new e,{gateway:p(d=>g.gateway(d),"gateway")};let i,r=new Proxy({},{get(d,h){if(h!=="then")return h==="sendRequest"||h==="request"||h==="kill"||h==="send"?(...m)=>{if(!i)throw new Error(`Thread at ${s} not launched yet.`);return i[h](...m)}:(...m)=>{if(!i)throw new Error(`Thread at ${s} not launched yet.`);return i.request(h,m)}}}),l={...o?o(r):{},launchWorker:p(async(d=[])=>(i=new n(s,[a,...d]),await i.ready(),i),"launchWorker"),gateway:p(d=>g.gateway(d),"gateway")};return new Proxy(l,{get(d,h){if(h!=="then")return h==="gateway"?d.gateway:h==="launchWorker"?d.launchWorker:h in d?d[h]:typeof h=="string"?(...m)=>{if(!i)throw new Error(`Thread at ${s} not launched yet.`);return i.request(h,m)}:d[h]}})}};var dt=require("net-ipc");var K=class{static{p(this,"WorkerThreadGatewayClient")}client=new dt.Client;rpc;constructor(){this.rpc=new T(t=>this.client.send(t),{}),this.client.on("message",t=>{this.rpc.make(t)})}async connect(t){this.client.options.path=t;let e=new Promise(n=>{this.client.once("ready",()=>n(this))});return await this.client.connect(),e}async request(t,e,n=!0,s){return this.rpc.makeRequest(t,e,n,s)}};var lt=require("net-ipc");var N=class{static{p(this,"WorkerThreadGatewayServer")}server=new lt.Server;rpc=new Map;methods={};constructor(){this.server.on("connect",t=>{let e=new T(n=>t.send(n),this.methods);this.rpc.set(t.id,e)}),this.server.on("disconnect",t=>{this.rpc.delete(t.id)}),this.server.on("message",(t,e)=>{let n=this.rpc.get(e.id);n&&n.make(t)}),this.server.on("error",t=>{console.error(t)})}async start(t,e={}){this.methods=e,this.server.options.path=t;let n=new Promise(s=>{this.server.once("ready",()=>s(this))});return await this.server.start(),n}};var D=require("worker_threads");var H=class{static{p(this,"WorkerThreadInit")}argv=process.argv;id=D.threadId;pid=process.pid;rpc={};parentPort=D.parentPort;gatewayServer;gatewayClients=new Map;gatewayClientLatest;get gatewayClient(){return this.gatewayClientLatest}static isMainThread=D.isMainThread;constructor(){this.init(),this.rpc=new T(this.send.bind(this),this),this.send({method:"mtdReady"})}init(){this.parentPort?.on("message",t=>this.handleOnMessage(t))}handleOnMessage(t){this.rpc.make(t)}send(t){this.parentPort?.postMessage(t)}request(t,e,n=!0,s){return this.rpc.makeRequest(t,e,n,s)}async createGatewayServer(t,e={}){return this.gatewayServer=new N,await this.gatewayServer.start(t,e),!0}async createGatewayClient(t){let e=new K;return await e.connect(t),this.gatewayClients.set(t,e),this.gatewayClientLatest=e,e}};var z=class{static{p(this,"WorkerThreadPool")}thread=new Map;threadCount=0;constructor(t){this.addMany(t)}add(t){this.thread.set(t.threadId,t),this.threadCount+=1}addMany(t){t.forEach(e=>this.add(e))}getInstance(t){return this.thread.get(t)}kill(t){let e=this.thread.get(t);return e?.kill(),this.thread.delete(t),this.threadCount-=1,e?.threadId}killAll(){this.thread.values().forEach(({threadId:t})=>this.kill(t))}async broadcastRequest(t,e){return await Promise.all(Object.values(this.thread).map(n=>n.request(t,e,!0)))}async request(t,e,n,s=!0,o){return await this.thread.get(t)?.request(e,n,s,o)}};0&&(module.exports={CacheExternal,ComponentKeyboard,Ctx,DataKeyboard,Gramstax,LoggingUtils,TemplateEngine,TemplateManager,WorkerThreadExport,WorkerThreadGatewayClient,WorkerThreadGatewayServer,WorkerThreadInit,WorkerThreadLaunch,WorkerThreadPool,WorkerThreadRpc,log});
11
+ `}).join(" ")}static _build(t,e,n){if(!this.data)throw new Error("Data not found");let s=this.data[t];if(!s)throw new Error(`Function ${t} not found`);return this._process(s.call(this.data,e),{type:n,lang:e})}};var Q=class{static{p(this,"DataKeyboard")}static _reverse(t){return t.split(/(?<!\\), */).reverse().join(", ")}static _reverseObj(t){return Object.keys(t).reduce((e,n)=>(e[n]=this._reverse(t[n]),e),{})}static _build(t,e,n){if(t){let s=n[t||""];return e?this._reverse(s):s}return e?this._reverseObj(n):n}};var j=require("worker_threads");var w=class{constructor(t,e){this.send=t;this.register=e}static{p(this,"WorkerThreadRpc")}map=new Map;async make(t){let e=this.map,n=this.send,{id:s,method:o,params:a,result:i,error:r}=t;if(o!==void 0)try{let c=this.register[o];if(typeof c!="function")throw new Error(`Method ${o} not found or not function`);let h=await c.apply(this.register,a);n({id:s,result:h})}catch(c){n({id:s,error:c instanceof Error?{message:c.message,stack:c.stack,name:c.name}:c})}else if(i!==void 0){let c=e.get(s);c&&(c.resolve(i),e.delete(s))}else if(r!==void 0){let c=e.get(s);c&&(c.reject(r),e.delete(s))}}makeId(){return Math.random()}makeRequest(t,e,n=!0,s){let o=this.makeId(),a={id:o,method:t,params:e,...s};return n?new Promise((i,r)=>{this.map.set(o,{resolve:i,reject:r}),this.send(a)}):this.send(a)}};var W=class{constructor(t,e){this.path=t;this.argv=e;this.init(),this.rpc=new w(this.send.bind(this),this)}static{p(this,"WorkerThreadLaunch")}static isMainThread=j.isMainThread;_readyResolve;_readyPromise=new Promise(t=>this._readyResolve=t);pid=process.pid;thread={};threadId={};rpc={};ready(){return this._readyPromise}mtdReady(){this._readyResolve?.()}init(){this.thread=new j.Worker(this.path,{argv:this.argv.length==0&&this.argv[0]===void 0?void 0:this.argv}),this.threadId=this.thread.threadId,this.thread.on("message",t=>this.handleOnMessage(t)),this.thread.on("exit",()=>this.kill()),process.once("SIGINT",()=>this.kill()),process.once("SIGTERM",()=>this.kill())}async handleOnMessage(t){this.rpc.make(t)}kill(){this.thread.terminate()}send(t){this.thread.postMessage(t)}async request(t,e,n=!0,s){return this.rpc.makeRequest(t,e,n,s)}};var J=class g{static{p(this,"WorkerThreadExport")}static launchGatewayClient(t){let e=new Proxy({},{get(s,o){if(!(typeof o!="string"||o==="then"))return async(a,...i)=>{let r=a.gatewayClients.get(t);return r||(r=await a.createGatewayClient(t)),r.request(o,i)}}}),n=p(function(s){return new Proxy({},{get(o,a){if(!(typeof a!="string"||a==="then"))return async(...i)=>{let r=s.gatewayClients.get(t);return r||(r=await s.createGatewayClient(t)),r.request(a,i)}}})},"ctor");return Object.setPrototypeOf(n,e),n}static init(t){let{WTInit:e,WTLaunch:n=W,path:s,wrap:o}=t,a=`for-${s}`;if(process.argv[2]===a)return new e,{launchGatewayClient:p(d=>g.launchGatewayClient(d||e.gatewayServerPath),"launchGatewayClient")};let i,r=new Proxy({},{get(d,l){if(l!=="then")return l==="sendRequest"||l==="request"||l==="kill"||l==="send"?(...m)=>{if(!i)throw new Error(`Thread at ${s} not launched yet.`);return i[l](...m)}:(...m)=>{if(!i)throw new Error(`Thread at ${s} not launched yet.`);return i.request(l,m)}}}),h={...o?o(r):{},launchWorker:p(async(d=[])=>(i=new n(s,[a,...d]),await i.ready(),i),"launchWorker"),launchGatewayClient:p(d=>g.launchGatewayClient(d||e.gatewayServerPath),"launchGatewayClient")};return new Proxy(h,{get(d,l){if(l!=="then")return l==="launchGatewayClient"?d.launchGatewayClient:l==="launchWorker"?d.launchWorker:l in d?d[l]:typeof l=="string"?(...m)=>{if(!i)throw new Error(`Thread at ${s} not launched yet.`);return i.request(l,m)}:d[l]}})}};var dt=require("net-ipc");var K=class{static{p(this,"WorkerThreadGatewayClient")}client=new dt.Client;rpc;constructor(){this.rpc=new w(t=>this.client.send(t),{}),this.client.on("message",t=>{this.rpc.make(t)})}async connect(t){this.client.options.path=t;let e=new Promise(n=>{this.client.once("ready",()=>n(this))});return await this.client.connect(),e}async request(t,e,n=!0,s){return this.rpc.makeRequest(t,e,n,s)}};var ht=require("net-ipc");var N=class{static{p(this,"WorkerThreadGatewayServer")}server=new ht.Server;rpc=new Map;methods={};constructor(){this.server.on("connect",t=>{let e=new w(n=>t.send(n),this.methods);this.rpc.set(t.id,e)}),this.server.on("disconnect",t=>{this.rpc.delete(t.id)}),this.server.on("message",(t,e)=>{let n=this.rpc.get(e.id);n&&n.make(t)}),this.server.on("error",t=>{console.error(t)})}async start(t,e={}){this.methods=e,this.server.options.path=t;let n=new Promise(s=>{this.server.once("ready",()=>s(this))});return await this.server.start(),n}};var D=require("worker_threads");var H=class{static{p(this,"WorkerThreadInit")}argv=process.argv;id=D.threadId;pid=process.pid;rpc={};parentPort=D.parentPort;gatewayServer;gatewayClients=new Map;gatewayClientLatest;static gatewayServerPath;gatewayServerPath=this.constructor.gatewayServerPath;get gatewayClient(){return this.gatewayClientLatest}static isMainThread=D.isMainThread;constructor(){this.init(),this.rpc=new w(this.send.bind(this),this),this.send({method:"mtdReady"})}init(){this.parentPort?.on("message",t=>this.handleOnMessage(t))}handleOnMessage(t){this.rpc.make(t)}send(t){this.parentPort?.postMessage(t)}request(t,e,n=!0,s){return this.rpc.makeRequest(t,e,n,s)}async createGatewayServer(t,e){return t||(t=this),e||(e=this.constructor.gatewayServerPath),this.gatewayServer=new N,await this.gatewayServer.start(e,t),this.constructor.gatewayServerPath=e,!0}async createGatewayClient(t){let e=new K;return await e.connect(t),this.gatewayClients.set(t,e),this.gatewayClientLatest=e,e}};var z=class{static{p(this,"WorkerThreadPool")}thread=new Map;threadCount=0;constructor(t){this.addMany(t)}add(t){this.thread.set(t.threadId,t),this.threadCount+=1}addMany(t){t.forEach(e=>this.add(e))}getInstance(t){return this.thread.get(t)}kill(t){let e=this.thread.get(t);return e?.kill(),this.thread.delete(t),this.threadCount-=1,e?.threadId}killAll(){this.thread.values().forEach(({threadId:t})=>this.kill(t))}async broadcastRequest(t,e){return await Promise.all(Object.values(this.thread).map(n=>n.request(t,e,!0)))}async request(t,e,n,s=!0,o){return await this.thread.get(t)?.request(e,n,s,o)}};0&&(module.exports={CacheExternal,ComponentKeyboard,Ctx,DataKeyboard,Gramstax,LoggingUtils,TemplateEngine,TemplateManager,WorkerThreadExport,WorkerThreadGatewayClient,WorkerThreadGatewayServer,WorkerThreadInit,WorkerThreadLaunch,WorkerThreadPool,WorkerThreadRpc,log});
@@ -224,7 +224,7 @@ declare class TemplateManager {
224
224
 
225
225
  type IInlineKb = InlineKeyboard
226
226
  type IBottomKb = Keyboard
227
- type IKb = IBottomKb | IInlineKb
227
+ type IInBoKb = IBottomKb | IInlineKb
228
228
  type ICt = Context
229
229
  type IOptReply = Parameters<Context[`reply`]>[1]
230
230
  type IOptReplyPhoto = Parameters<Context[`replyWithPhoto`]>[1]
@@ -290,7 +290,6 @@ declare class Ctx {
290
290
  get callbackData(): string;
291
291
  get callbackDataPayloads(): string[];
292
292
  get callbackDataPayload(): string;
293
- get callbackDataParts(): string[];
294
293
  set session(v: ITemp[`session`]);
295
294
  get session(): ITemp[`session`];
296
295
  ct: ICt;
@@ -305,19 +304,19 @@ declare class Ctx {
305
304
  templateManager: TemplateManager;
306
305
  temp: ITemp;
307
306
  });
308
- broadcast(ids: number[], languageCode: string[], keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReply, throwError?: boolean): Promise<void>;
309
- reply(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReply): Promise<_grammyjs_types.Message.TextMessage>;
310
- replyMedia<T extends IMediaBlock[`type`]>(type: T, keyboard?: IKb, data?: IData, baseId?: string, options?: T extends `photo` ? IOptReplyPhoto : T extends `video` ? IOptReplyVideo : T extends `audio` ? IOptReplyAudio : T extends `document` ? IOptReplyDocument : T extends `animation` ? IOptReplyAnimation : T extends `voice` ? IOptReplyVoice : T extends `video_note` ? IOptReplyVideoNote : T extends `sticker` ? IOptReplySticker : T extends `location` ? IOptReplyLocation : T extends `contact` ? IOptReplyContact : undefined): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
311
- replyPhoto(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyPhoto): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
312
- replyVideo(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyVideo): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
313
- replyAudio(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyAudio): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
314
- replyDocument(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyDocument): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
315
- replyAnimation(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyAnimation): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
316
- replyVoice(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyVoice): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
317
- replyVideoNote(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyVideoNote): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
318
- replySticker(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplySticker): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
319
- replyLocation(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyLocation): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
320
- replyContact(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyContact): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
307
+ broadcast(ids: number[], languageCode: string[], keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReply, throwError?: boolean): Promise<void>;
308
+ reply(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReply): Promise<_grammyjs_types.Message.TextMessage>;
309
+ replyMedia<T extends IMediaBlock[`type`]>(type: T, keyboard?: IInBoKb, data?: IData, baseId?: string, options?: T extends `photo` ? IOptReplyPhoto : T extends `video` ? IOptReplyVideo : T extends `audio` ? IOptReplyAudio : T extends `document` ? IOptReplyDocument : T extends `animation` ? IOptReplyAnimation : T extends `voice` ? IOptReplyVoice : T extends `video_note` ? IOptReplyVideoNote : T extends `sticker` ? IOptReplySticker : T extends `location` ? IOptReplyLocation : T extends `contact` ? IOptReplyContact : undefined): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
310
+ replyPhoto(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyPhoto): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
311
+ replyVideo(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyVideo): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
312
+ replyAudio(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyAudio): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
313
+ replyDocument(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyDocument): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
314
+ replyAnimation(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyAnimation): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
315
+ replyVoice(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyVoice): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
316
+ replyVideoNote(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyVideoNote): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
317
+ replySticker(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplySticker): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
318
+ replyLocation(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyLocation): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
319
+ replyContact(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyContact): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
321
320
  replyAction(type: ITypeReplyAction): Promise<true>;
322
321
  edit(keyboardInline?: IInlineKb, data?: IData, baseId?: string, options?: IOptEdit, fallbackReply?: boolean): Promise<true | (_grammyjs_types.Update.Edited & _grammyjs_types.Message.CommonMessage & {
323
322
  text: string;
@@ -357,12 +356,12 @@ declare class Ctx {
357
356
  static buildData(): IPageData<[]>;
358
357
  ikb(...args: Parameters<typeof this.inlineKeyboard>): InlineKeyboard;
359
358
  bkb(...args: Parameters<typeof this.bottomKeyboard>): Keyboard;
360
- inlineKeyboard(callback: (kb: IInlineKb, arr: string[]) => IInlineKb, params?: {
359
+ inlineKeyboard(callback: (k: IInlineKb, a: string[]) => IInlineKb, params?: {
361
360
  baseId?: string;
362
361
  data?: IData;
363
362
  cache?: boolean;
364
363
  }): IInlineKb;
365
- bottomKeyboard(callback: (kb: IBottomKb, arr: string[]) => IBottomKb, params?: {
364
+ bottomKeyboard(callback: (k: IBottomKb, a: string[]) => IBottomKb, params?: {
366
365
  baseId?: string;
367
366
  data?: IData;
368
367
  cache?: boolean;
@@ -1121,6 +1120,8 @@ declare class WorkerThreadInit {
1121
1120
  gatewayServer?: WorkerThreadGatewayServer;
1122
1121
  gatewayClients: Map<string, WorkerThreadGatewayClient>;
1123
1122
  gatewayClientLatest?: WorkerThreadGatewayClient;
1123
+ static gatewayServerPath?: string;
1124
+ gatewayServerPath: any;
1124
1125
  get gatewayClient(): WorkerThreadGatewayClient | undefined;
1125
1126
  static isMainThread: boolean;
1126
1127
  constructor();
@@ -1128,8 +1129,8 @@ declare class WorkerThreadInit {
1128
1129
  handleOnMessage(data: any): void;
1129
1130
  send(payload: any): void;
1130
1131
  request(method: string, params: any, _wait?: boolean, _others?: any): Promise<any>;
1131
- createGatewayServer(path: string, methods?: any): Promise<boolean>;
1132
- createGatewayClient(path: string): Promise<WorkerThreadGatewayClient>;
1132
+ createGatewayServer(methods?: any, path?: string): Promise<boolean>;
1133
+ createGatewayClient(serverPath: string): Promise<WorkerThreadGatewayClient>;
1133
1134
  }
1134
1135
 
1135
1136
  type WorkerThreadExportOpt<TWorker extends WorkerThreadInit, TMain extends WorkerThreadLaunch, TWrap> = {
@@ -1145,12 +1146,12 @@ type WorkerThreadAsyncMethods<T> = {
1145
1146
  [K in keyof T as K extends keyof WorkerThreadInit ? never : K extends string ? (T[K] extends (...args: any[]) => any ? K : never) : never]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<Awaited<R>> : never;
1146
1147
  };
1147
1148
  declare class WorkerThreadExport {
1148
- static gateway<TWorker extends WorkerThreadInit>(path: string): WorkerThreadGatewayProxy<TWorker> & {
1149
+ static launchGatewayClient<TWorker extends WorkerThreadInit>(path: string): WorkerThreadGatewayProxy<TWorker> & {
1149
1150
  new (owner: WorkerThreadInit): WorkerThreadAsyncMethods<TWorker>;
1150
1151
  };
1151
1152
  static init<TWorker extends WorkerThreadInit, TMain extends WorkerThreadLaunch, TWrap = Record<any, any>>(options: WorkerThreadExportOpt<TWorker, TMain, TWrap>): TWrap & WorkerThreadAsyncMethods<TWorker> & {
1152
1153
  launchWorker: (argv?: any[]) => Promise<TMain>;
1153
- gateway: (path: string) => WorkerThreadGatewayProxy<TWorker> & {
1154
+ launchGatewayClient: (serverPath?: string) => WorkerThreadGatewayProxy<TWorker> & {
1154
1155
  new (owner: WorkerThreadInit): WorkerThreadAsyncMethods<TWorker>;
1155
1156
  };
1156
1157
  };
@@ -224,7 +224,7 @@ declare class TemplateManager {
224
224
 
225
225
  type IInlineKb = InlineKeyboard
226
226
  type IBottomKb = Keyboard
227
- type IKb = IBottomKb | IInlineKb
227
+ type IInBoKb = IBottomKb | IInlineKb
228
228
  type ICt = Context
229
229
  type IOptReply = Parameters<Context[`reply`]>[1]
230
230
  type IOptReplyPhoto = Parameters<Context[`replyWithPhoto`]>[1]
@@ -290,7 +290,6 @@ declare class Ctx {
290
290
  get callbackData(): string;
291
291
  get callbackDataPayloads(): string[];
292
292
  get callbackDataPayload(): string;
293
- get callbackDataParts(): string[];
294
293
  set session(v: ITemp[`session`]);
295
294
  get session(): ITemp[`session`];
296
295
  ct: ICt;
@@ -305,19 +304,19 @@ declare class Ctx {
305
304
  templateManager: TemplateManager;
306
305
  temp: ITemp;
307
306
  });
308
- broadcast(ids: number[], languageCode: string[], keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReply, throwError?: boolean): Promise<void>;
309
- reply(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReply): Promise<_grammyjs_types.Message.TextMessage>;
310
- replyMedia<T extends IMediaBlock[`type`]>(type: T, keyboard?: IKb, data?: IData, baseId?: string, options?: T extends `photo` ? IOptReplyPhoto : T extends `video` ? IOptReplyVideo : T extends `audio` ? IOptReplyAudio : T extends `document` ? IOptReplyDocument : T extends `animation` ? IOptReplyAnimation : T extends `voice` ? IOptReplyVoice : T extends `video_note` ? IOptReplyVideoNote : T extends `sticker` ? IOptReplySticker : T extends `location` ? IOptReplyLocation : T extends `contact` ? IOptReplyContact : undefined): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
311
- replyPhoto(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyPhoto): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
312
- replyVideo(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyVideo): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
313
- replyAudio(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyAudio): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
314
- replyDocument(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyDocument): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
315
- replyAnimation(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyAnimation): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
316
- replyVoice(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyVoice): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
317
- replyVideoNote(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyVideoNote): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
318
- replySticker(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplySticker): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
319
- replyLocation(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyLocation): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
320
- replyContact(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyContact): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
307
+ broadcast(ids: number[], languageCode: string[], keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReply, throwError?: boolean): Promise<void>;
308
+ reply(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReply): Promise<_grammyjs_types.Message.TextMessage>;
309
+ replyMedia<T extends IMediaBlock[`type`]>(type: T, keyboard?: IInBoKb, data?: IData, baseId?: string, options?: T extends `photo` ? IOptReplyPhoto : T extends `video` ? IOptReplyVideo : T extends `audio` ? IOptReplyAudio : T extends `document` ? IOptReplyDocument : T extends `animation` ? IOptReplyAnimation : T extends `voice` ? IOptReplyVoice : T extends `video_note` ? IOptReplyVideoNote : T extends `sticker` ? IOptReplySticker : T extends `location` ? IOptReplyLocation : T extends `contact` ? IOptReplyContact : undefined): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
310
+ replyPhoto(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyPhoto): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
311
+ replyVideo(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyVideo): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
312
+ replyAudio(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyAudio): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
313
+ replyDocument(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyDocument): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
314
+ replyAnimation(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyAnimation): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
315
+ replyVoice(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyVoice): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
316
+ replyVideoNote(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyVideoNote): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
317
+ replySticker(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplySticker): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
318
+ replyLocation(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyLocation): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
319
+ replyContact(keyboard?: IInBoKb, data?: IData, baseId?: string, options?: IOptReplyContact): Promise<_grammyjs_types.Message.LocationMessage | _grammyjs_types.Message.ContactMessage | _grammyjs_types.Message.PhotoMessage | _grammyjs_types.Message.VideoMessage | _grammyjs_types.Message.AudioMessage | _grammyjs_types.Message.DocumentMessage | _grammyjs_types.Message.VoiceMessage | _grammyjs_types.Message.VideoNoteMessage | _grammyjs_types.Message.StickerMessage | undefined>;
321
320
  replyAction(type: ITypeReplyAction): Promise<true>;
322
321
  edit(keyboardInline?: IInlineKb, data?: IData, baseId?: string, options?: IOptEdit, fallbackReply?: boolean): Promise<true | (_grammyjs_types.Update.Edited & _grammyjs_types.Message.CommonMessage & {
323
322
  text: string;
@@ -357,12 +356,12 @@ declare class Ctx {
357
356
  static buildData(): IPageData<[]>;
358
357
  ikb(...args: Parameters<typeof this.inlineKeyboard>): InlineKeyboard;
359
358
  bkb(...args: Parameters<typeof this.bottomKeyboard>): Keyboard;
360
- inlineKeyboard(callback: (kb: IInlineKb, arr: string[]) => IInlineKb, params?: {
359
+ inlineKeyboard(callback: (k: IInlineKb, a: string[]) => IInlineKb, params?: {
361
360
  baseId?: string;
362
361
  data?: IData;
363
362
  cache?: boolean;
364
363
  }): IInlineKb;
365
- bottomKeyboard(callback: (kb: IBottomKb, arr: string[]) => IBottomKb, params?: {
364
+ bottomKeyboard(callback: (k: IBottomKb, a: string[]) => IBottomKb, params?: {
366
365
  baseId?: string;
367
366
  data?: IData;
368
367
  cache?: boolean;
@@ -1121,6 +1120,8 @@ declare class WorkerThreadInit {
1121
1120
  gatewayServer?: WorkerThreadGatewayServer;
1122
1121
  gatewayClients: Map<string, WorkerThreadGatewayClient>;
1123
1122
  gatewayClientLatest?: WorkerThreadGatewayClient;
1123
+ static gatewayServerPath?: string;
1124
+ gatewayServerPath: any;
1124
1125
  get gatewayClient(): WorkerThreadGatewayClient | undefined;
1125
1126
  static isMainThread: boolean;
1126
1127
  constructor();
@@ -1128,8 +1129,8 @@ declare class WorkerThreadInit {
1128
1129
  handleOnMessage(data: any): void;
1129
1130
  send(payload: any): void;
1130
1131
  request(method: string, params: any, _wait?: boolean, _others?: any): Promise<any>;
1131
- createGatewayServer(path: string, methods?: any): Promise<boolean>;
1132
- createGatewayClient(path: string): Promise<WorkerThreadGatewayClient>;
1132
+ createGatewayServer(methods?: any, path?: string): Promise<boolean>;
1133
+ createGatewayClient(serverPath: string): Promise<WorkerThreadGatewayClient>;
1133
1134
  }
1134
1135
 
1135
1136
  type WorkerThreadExportOpt<TWorker extends WorkerThreadInit, TMain extends WorkerThreadLaunch, TWrap> = {
@@ -1145,12 +1146,12 @@ type WorkerThreadAsyncMethods<T> = {
1145
1146
  [K in keyof T as K extends keyof WorkerThreadInit ? never : K extends string ? (T[K] extends (...args: any[]) => any ? K : never) : never]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<Awaited<R>> : never;
1146
1147
  };
1147
1148
  declare class WorkerThreadExport {
1148
- static gateway<TWorker extends WorkerThreadInit>(path: string): WorkerThreadGatewayProxy<TWorker> & {
1149
+ static launchGatewayClient<TWorker extends WorkerThreadInit>(path: string): WorkerThreadGatewayProxy<TWorker> & {
1149
1150
  new (owner: WorkerThreadInit): WorkerThreadAsyncMethods<TWorker>;
1150
1151
  };
1151
1152
  static init<TWorker extends WorkerThreadInit, TMain extends WorkerThreadLaunch, TWrap = Record<any, any>>(options: WorkerThreadExportOpt<TWorker, TMain, TWrap>): TWrap & WorkerThreadAsyncMethods<TWorker> & {
1152
1153
  launchWorker: (argv?: any[]) => Promise<TMain>;
1153
- gateway: (path: string) => WorkerThreadGatewayProxy<TWorker> & {
1154
+ launchGatewayClient: (serverPath?: string) => WorkerThreadGatewayProxy<TWorker> & {
1154
1155
  new (owner: WorkerThreadInit): WorkerThreadAsyncMethods<TWorker>;
1155
1156
  };
1156
1157
  };
package/dist/src/index.js CHANGED
@@ -1,11 +1,11 @@
1
- var at=Object.defineProperty;var p=(u,t)=>at(u,"name",{value:t,configurable:!0}),K=(u=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(u,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):u)(function(u){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+u+'" is not supported')});import Ot from"path";import{fileURLToPath as rt}from"url";var ct=p(()=>rt(import.meta.url),"getFilename");var C=ct();import{LoggingPretty as dt}from"logging-pretty";var N=class extends dt{static{p(this,"LoggingUtils")}constructor(t){super(t)}errorMake(t,e,n){this.error(`[${e?`${e}:${n}`:n}] ${String(t)}`)}},Nt=new N;import{Keyv as lt}from"keyv";import ht from"@keyv/redis";var R=class extends lt{constructor(e="memory",n,s,o){let a;e.startsWith("redis")&&(a=new ht(e)),e==="memory"&&(a=new Map),o?.forceStore&&(a=o.forceStore);super({store:a,namespace:n,ttl:s});this.url=e}static{p(this,"CacheExternal")}};import{setTimeout as mt}from"timers/promises";import{InlineKeyboard as q,Keyboard as G}from"grammy";var D=class{static{p(this,"Ctx")}static template;static data;data=this.constructor.data;get userIsPremium(){return this.ct.from?.is_premium??!1}get userIsBot(){return this.ct.from?.is_bot??!1}get userId(){return this.ct.from?.id}get userName(){return this.ct.from?.username}get userFullName(){return`${this.ct.from?.first_name} ${this.ct.from?.last_name||""}`}get userFirstName(){return this.ct.from?.first_name}get userLastName(){return this.ct.from?.last_name}get userLanguage(){return this.ct.from?.language_code}set userLanguage(t){this.ct.from.language_code=t}get msgText(){return this.ct.message?.text}get msgTextPayloads(){return this.getPayloads(this.msgText,"space",this.data?._positionPayloadText||this.temp?.data?._positionPayloadText)}get msgTextPayload(){return this.msgTextPayloads[0]}get msgTextCommandPayloads(){return this.getPayloads(this.msgText,"space")}get msgTextCommandPayload(){return this.msgTextCommandPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionPayloads(){return this.getPayloads(this.msgCaption,"space")}get msgCaptionPayload(){return this.msgCaptionPayloads[0]}get msgCaptionCommandPayloads(){return this.getPayloads(this.msgCaption,"space")}get msgCaptionCommandPayload(){return this.msgCaptionCommandPayloads[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 callbackDataPayloads(){return this.getPayloads(this.callbackData,"colon")}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}get callbackDataParts(){return this.callbackDataPayload&&this.callbackDataPayload.indexOf("+")!=-1?this.callbackDataPayload.split("+"):[]}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp}async broadcast(t,e,n,s,o,a,i=!1){try{this.temp.isAnswer=!0;let r=30,c=e.map(l=>this.templateManager.getMessage(this.data.name,o,l,s));for(let l=0;l<t.length;l++){let d=t[l],h=c[l];await this.ct.api.sendMessage(d,h,{parse_mode:"HTML",reply_markup:n,...a}),l+1==r&&await mt(1200)}}catch(r){if(i)throw r}}async reply(t,e,n,s){this.temp.isAnswer=!0;let o=this.templateManager.getMessage(this.data.name,n,this.userLanguage,e);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,e,n,s,o){this.temp.isAnswer=!0;let a=this.templateManager.getMedia(this.data.name,s,this.userLanguage,n),i={parse_mode:"HTML",reply_markup:e,...o};if(t=="photo")return await this.ct.replyWithPhoto(a.src,{caption:a.caption,...i});if(t=="video")return await this.ct.replyWithVideo(a.src,{caption:a.caption,...i});if(t=="audio")return await this.ct.replyWithAudio(a.src,{caption:a.caption,...i});if(t=="document")return await this.ct.replyWithDocument(a.src,{caption:a.caption,...i});if(t=="animation")return await this.ct.replyWithAnimation(a.src,{caption:a.caption,...i});if(t=="voice")return await this.ct.replyWithVoice(a.src,i);if(t=="video_note")return await this.ct.replyWithVideoNote(a.src,i);if(t=="sticker")return await this.ct.replyWithSticker(a.src,i);if(t=="location")return await this.ct.replyWithLocation(parseInt(a.latitude),parseInt(a.longitude),i);if(t=="contact")return await this.ct.replyWithContact(a.phone,a.first_name,{vcard:a.vcard,...i})}async replyPhoto(t,e,n,s){return this.replyMedia("photo",t,e,n,s)}async replyVideo(t,e,n,s){return this.replyMedia("video",t,e,n,s)}async replyAudio(t,e,n,s){return this.replyMedia("audio",t,e,n,s)}async replyDocument(t,e,n,s){return this.replyMedia("document",t,e,n,s)}async replyAnimation(t,e,n,s){return this.replyMedia("animation",t,e,n,s)}async replyVoice(t,e,n,s){return this.replyMedia("voice",t,e,n,s)}async replyVideoNote(t,e,n,s){return this.replyMedia("video_note",t,e,n,s)}async replySticker(t,e,n,s){return this.replyMedia("sticker",t,e,n,s)}async replyLocation(t,e,n,s){return this.replyMedia("location",t,e,n,s)}async replyContact(t,e,n,s){return this.replyMedia("contact",t,e,n,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,e,n,s,o=!0){try{this.temp.isAnswer=!0;let a=this.templateManager.getMessage(this.data.name,n,this.userLanguage,e);return await this.ct.editMessageText(a,{parse_mode:"HTML",reply_markup:t,...s})}catch(a){if(o)await this.reply(t,e,n,s);else throw a}}async editMedia(t,e,n,s,o,a,i=!0){try{this.temp.isAnswer=!0;let{src:r,caption:c}=this.templateManager.getMedia(this.data.name,s,this.userLanguage,n);return t=="voice"?(await this.delete(),await this.replyVoice(e,n,s,o)):t=="video_note"?(await this.delete(),await this.replyVoice(e,n,s,o)):t=="sticker"?(await this.delete(),await this.replySticker(e,n,s,o)):t=="location"?(await this.delete(),await this.replyLocation(e,n,s,o)):t=="contact"?(await this.delete(),await this.replyContact(e,n,s,o)):await this.ct.editMessageMedia({media:r,caption:c,type:t,parse_mode:"HTML",...o},{reply_markup:e,...a})}catch(r){if(i===!0)await this.reply(e,n,s,a);else throw r}}async editPhoto(t,e,n,s,o){return await this.editMedia("photo",t,e,n,s,o)}async editVideo(t,e,n,s,o){return await this.editMedia("video",t,e,n,s,o)}async editAudio(t,e,n,s,o){return await this.editMedia("audio",t,e,n,s,o)}async editDocument(t,e,n,s,o){return await this.editMedia("document",t,e,n,s,o)}async editAnimation(t,e,n,s,o){return await this.editMedia("animation",t,e,n,s,o)}async editVoice(t,e,n,s){return await this.editMedia("voice",t,e,n,s)}async editVideoNote(t,e,n,s){return await this.editMedia("video_note",t,e,n,s)}async editSticker(t,e,n,s){return await this.editMedia("sticker",t,e,n,s)}async editLocation(t,e,n,s){return await this.editMedia("location",t,e,n,s)}async editContact(t,e,n,s){return await this.editMedia("contact",t,e,n,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return this.temp.isAnswer=!0,await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,e,n){try{let s={method:t,params:e,...n},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){let n=typeof t=="function"?{callbackData:t}:t||{},s=n.callbackData;return{name:"",text:n.text,textCommand:n.textCommand,callbackData:s?function(...a){let i=s(...a);return`${this._callbackData}${i==""||i===void 0?"":`:${i}`}`}:function(){return this?._callbackData},_callbackData:"",_positionPayloadText:n.text?n.text.split(this.prototype.getSeperatorTag("space")).length:void 0}}ikb(...t){return this.inlineKeyboard(...t)}bkb(...t){return this.bottomKeyboard(...t)}inlineKeyboard(t,e){let n=this.data.name;if(e?.cache===!0){let i=`${n}:${this.userLanguage}:i`,r=this.cacheKeyboard.get(i);if(!r){let c=new q,l=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"inline",e?.data),d=t(c,l);return this.cacheKeyboard.set(i,d),d}return r}let s=new q,o=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"inline",e?.data);return t(s,o)}bottomKeyboard(t,e){let n=this.data.name;if(e?.cache===!0){let i=`${n}:${this.userLanguage}:b`,r=this.cacheKeyboard.get(i);if(!r){let c=new G,l=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"bottom",e?.data),d=t(c,l);return d.resized(!0),this.cacheKeyboard.set(i,d),d}return r}let s=new G,o=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"bottom",e?.data),a=t(s,o);return a.resized(),a}getSeperatorTag(t="space"){return t=="space"?" ":":"}havePayloads(t="",e){return t.includes(this.getSeperatorTag(e))}getPayloads(t="",e,n=1){if(!t)return[];let s=this.getSeperatorTag(e);return t.split(s).slice(n)}getIntent(t="",e,n=1){if(!t)return"";let s=this.getSeperatorTag(e),o=t.split(s);return n==1?o[0]:o.slice(0,n).join(s)}validateSessionCallback(t,e){return(t??this.session.method)===this.methodSessionCallback(e)}validateSessionCallbackPayload(t,e){return(t??this.session.method)===this.methodSessionCallbackPayload(e)}validateSessionText(t,e){return(t??this.session.method)===this.methodSessionText(e)}validateSessionTextPayload(t,e){return(t??this.session.method)===this.methodSessionTextPayload(e)}validateSessionTextCommand(t,e){return(t??this.session.method)===this.methodSessionTextCommand(e)}validateSessionTextCommandPayload(t,e){return(t??this.session.method)===this.methodSessionTextCommandPayload(e)}validateSessionTextFree(t,e){return(t??this.session.method)===this.methodSessionTextFree(e)}validateSessionPhotoCaption(t,e){return(t??this.session.method)===this.methodSessionPhotoCaption(e)}validateSessionPhotoCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionPhotoCaptionPayload(e)}validateSessionPhotoCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionPhotoCaptionCommand(e)}validateSessionPhotoCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionPhotoCaptionCommandPayload(e)}validateSessionPhotoFree(t,e){return(t??this.session.method)===this.methodSessionPhotoFree(e)}validateSessionVideoCaption(t,e){return(t??this.session.method)===this.methodSessionVideoCaption(e)}validateSessionVideoCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionVideoCaptionPayload(e)}validateSessionVideoCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionVideoCaptionCommand(e)}validateSessionVideoCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionVideoCaptionCommandPayload(e)}validateSessionVideoFree(t,e){return(t??this.session.method)===this.methodSessionVideoFree(e)}validateSessionAudioCaption(t,e){return(t??this.session.method)===this.methodSessionAudioCaption(e)}validateSessionAudioCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionAudioCaptionPayload(e)}validateSessionAudioCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionAudioCaptionCommand(e)}validateSessionAudioCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionAudioCaptionCommandPayload(e)}validateSessionAudioFree(t,e){return(t??this.session.method)===this.methodSessionAudioFree(e)}validateSessionDocumentCaption(t,e){return(t??this.session.method)===this.methodSessionDocumentCaption(e)}validateSessionDocumentCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionDocumentCaptionPayload(e)}validateSessionDocumentCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionDocumentCaptionCommand(e)}validateSessionDocumentCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionDocumentCaptionCommandPayload(e)}validateSessionDocumentFree(t,e){return(t??this.session.method)===this.methodSessionDocumentFree(e)}validateSessionAnimationCaption(t,e){return(t??this.session.method)===this.methodSessionAnimationCaption(e)}validateSessionAnimationCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionAnimationCaptionPayload(e)}validateSessionAnimationCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionAnimationCaptionCommand(e)}validateSessionAnimationCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionAnimationCaptionCommandPayload(e)}validateSessionAnimationFree(t,e){return(t??this.session.method)===this.methodSessionAnimationFree(e)}validateSessionVoiceCaption(t,e){return(t??this.session.method)===this.methodSessionVoiceCaption(e)}validateSessionVoiceCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionVoiceCaptionPayload(e)}validateSessionVoiceCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionVoiceCaptionCommand(e)}validateSessionVoiceCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionVoiceCaptionCommandPayload(e)}validateSessionVoiceFree(t,e){return(t??this.session.method)===this.methodSessionVoiceFree(e)}validateSessionVideoNoteCaption(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaption(e)}validateSessionVideoNoteCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaptionPayload(e)}validateSessionVideoNoteCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaptionCommand(e)}validateSessionVideoNoteCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaptionCommandPayload(e)}validateSessionVideoNoteFree(t,e){return(t??this.session.method)===this.methodSessionVideoNoteFree(e)}validateSessionStickerFree(t,e){return(t??this.session.method)===this.methodSessionStickerFree(e)}validateSessionLocationFree(t,e){return(t??this.session.method)===this.methodSessionLocationFree(e)}validateSessionContactFree(t,e){return(t??this.session.method)===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)}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{join as X,dirname as ft,parse as Ct}from"path";import{readFileSync as St}from"fs";import{fileURLToPath as Pt}from"url";import{join as E}from"path";import{existsSync as Q,readdirSync as U}from"fs";import{createRequire as pt}from"module";var P=class{static{p(this,"PageManager")}static _getFile(t,e,n=0){let o=Object.values(t)[n];if(o===void 0)throw new Error(`File ${e} must have export (not default) class page`);return o}static getFilePath(){return E(process.cwd(),"src","pages")}static getFileSync(t,e=0){t||(t=this.getFilePath());let s=pt(t)(t);return this._getFile(s,t,e)}static async getFile(t,e=0){t||(t=this.getFilePath());let n=await import(`${t}?t=${Date.now()}`);return this._getFile(n,t,e)}static getFileManySync(t,e=0){if(t||(t=this.getFilePath()),!Q(t))throw new Error(`Directory ${t} is not found, please make it manually`);return U(t).map(s=>{let o=E(t,s);return{path:o,page:this.getFileSync(o,e)}})}static clearCacheRequire(t){if(t||(t=this.getFilePath()),!Q(t))throw new Error(`Directory ${t} is not found, please make it manually`);return U(t).forEach(n=>{let s=E(t,n);delete K.cache[K.resolve(s)]}),!0}};import{LoggingPretty as bt}from"logging-pretty";import{basename as L,join as x,extname as J}from"path";import{readdirSync as gt,readFileSync as V,existsSync as M,statSync as F,writeFileSync as ut}from"fs";import{watch as yt}from"chokidar";var v=class{static{p(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(e,n)=>`\${(data && data["${n}"]) ?? ""}`)}static _processBaseBlocks(t){let e=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,n={};for(let s of t.matchAll(e)){let o=s[2]??"default",i=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[o]=i}return n}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(e,n)=>{let s=n.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,n)=>n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processSwitchBlocks(t){let e=/<switch\b(?:\s+value="([^"]+)")?>([\s\S]*?)<\/switch>/gi;return t.replace(e,(n,s,o)=>{if(!s)return"";let a="",i=/<case\b(?:\s+is="([^"]+)")?>([\s\S]*?)<\/case>/gi,r=/<default>([\s\S]*?)<\/default>/gi,c;for(;(c=i.exec(o))!==null;){let d=(c[1]||"").split(",").map(m=>m.trim()),h=(c[2]||"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim().replace(/`/g,"\\`");d.forEach(m=>{a+=`case "${m}": `}),a+=`return \`${h}\`; `}let l=r.exec(o);if(l){let d=(l[1]||"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim().replace(/`/g,"\\`");a+=`default: return \`${d}\`; `}else a+="default: return ''; ";return`\${(() => { switch((data && data["${s}"])) { ${a} } })()}`})}static _processExec(t){return t.replace(/{~\s*([\s\S]*?)\s*~}/g,(e,n)=>`\${(() => { try { return ${n} } catch(e) { try { with(data || {}) { return ${n} } } catch(ee) { return '' } } })()}`)}static _processMapBlocks(t){let e=/<map(?:\s+([^>]*))?>([\s\S]*?)<\/map>/gi;return t.replace(e,(n,s,o)=>{let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let h of s.matchAll(i))a[h[1]]=h[2];let r=a.src;if(!r)return"";let c=a.join??"\\n",l=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").replace(/`/g,"\\`");l=l.replace(/\{\{([\w.]+)\}\}/g,(h,m)=>m==="e"||m.startsWith("e.")?`\${${m}}`:m==="i"?"${i}":h);let d=c.replace(/"/g,'\\"');return`\${(data && data["${r}"] || []).map((e, i) => \`${l}\`).join("${d}")}`})}static _processMediaBlocks(t){let e=/<media(?:\s+([^>]*))?>([\s\S]*?)<\/media>/gi,n={};for(let s of t.matchAll(e)){let o=s[1],a=s[2],i={},r=/(\w+)="([^"]*)"/g;if(o)for(let m of o.matchAll(r))i[m[1]]=m[2];let c=i.lang||"default",l=i.type,d=a.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),h={type:l};i.src&&(h.src=i.src),d&&l!=="video_note"&&l!=="sticker"&&(h.caption=d),l==="location"&&(i.latitude&&(h.latitude=i.latitude),i.longitude&&(h.longitude=i.longitude),d&&(h.caption=d)),l==="contact"&&(i.phone&&(h.phone=i.phone),i.first_name&&(h.first_name=i.first_name),i.last_name&&(h.last_name=i.last_name),i.vcard&&(h.vcard=i.vcard),d&&(h.caption=d)),n[c]=h}return n}static _processMessageBlocks(t){let e=/<message(?:\s+([^>]*))?>([\s\S]*?)<\/message>/gi,n={};for(let[,s,o]of t.matchAll(e)){let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let l of s.matchAll(i))a[l[1]]=l[2];let r=a.lang||"default",c=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[r]=c}return n}static _processDescriptionBlocks(t){let e=/<description(?:\s+([^>]*))?>([\s\S]*?)<\/description>/gi,n={};for(let[,s,o]of t.matchAll(e)){let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let d of s.matchAll(i))a[d[1]]=d[2];let r=a.lang||"default",c=a.scope||"default",l=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[r]||(n[r]={}),n[r][c]=l}return n}static _processKeyboardBlocks(t){let e=/<keyboard(?:\s+([^>]*))?>([\s\S]*?)<\/keyboard>/gi,n={};for(let[,s,o]of t.matchAll(e)){let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let d of s.matchAll(i))a[d[1]]=d[2];let r=a.lang||"default",c=a.type==="bottom"?"bottom":"inline",l=o.trim();n[r]||(n[r]={}),n[r][c]=l}return n}static _compileToFunction(t,e){let n;e?n=t.map(a=>`\`${a}\``).join(","):n=`\`${t}\``;let s=n;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,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processMediaBlocks(a);s[o]={};for(let[r,c]of Object.entries(i)){let l={};for(let[d,h]of Object.entries(c)){if(d==="type"||typeof h!="string")continue;let m=this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(h)))));l[d]=this._compileToFunction(m,!1)}s[o][r]=d=>{let h={...c};for(let[m,y]of Object.entries(l))h[m]=y(d);return h}}}return s}static compileMessages(t,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processMessageBlocks(a);s[o]={};for(let[r,c]of Object.entries(i)){let l=this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(c)))));s[o][r]=this._compileToFunction(l,!1)}}return s}static compileDescription(t,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processDescriptionBlocks(a);s[o]={};for(let[r,c]of Object.entries(i))for(let[l,d]of Object.entries(c)){s[o][l]||(s[o][l]={});let h=this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(d)))));s[o][l][r]=this._compileToFunction(h,!1)}}return s}static compileKeyboards(t,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processKeyboardBlocks(a);s[o]={};for(let[r,c]of Object.entries(i)){s[o][r]={};for(let[l,d]of Object.entries(c)){let m=d.split(/(?<!\\),\s*/).map(y=>y.replace(/\\,/g,",").trim()).map(y=>this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(y))))));s[o][r][l]=this._compileToFunction(m,!0)}}}return s}static _extractBlock(t,e,n="default",s="all",o){let a=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,i=t,r=!1;for(let c of t.matchAll(a))if((c[2]??"default")===n){i=c[3]??"",r=!0;break}if(!r){let c=/<base\b/.test(t);if(!(n==="default"&&!c))return""}if(e){if(e==="all")return i;let c=Array.isArray(e)?e:[e],l=[];for(let h of c){let m=new RegExp(`([ \\t]*)<${h}(?:\\s+([^>]*))?>([\\s\\S]*?)<\\/${h}>`,"gi");for(let y of i.matchAll(m)){let f=y[2];if(o){let g=/lang="([^"]*)"/i,b=f?.match(g);if(((b?b[1]:void 0)||"default")!==o)continue}l.push({start:y.index,content:y[0],innerContent:y[3]??""})}}l.sort((h,m)=>h.start-m.start);let d=p(h=>{let m=h.split(`
2
- `);if(m.length<=1)return h.trim();let y=m.filter(g=>g.trim().length>0);if(y.length===0)return"";let f=y.reduce((g,b)=>{let k=b.match(/^([ \t]*)/),T=k?k[1].length:0;return T<g?T:g},1/0);return m.map(g=>g.length>=f?g.slice(f):g.trimStart()).join(`
3
- `).trim()},"processResult");return s==="all"?l.map(m=>d(m.content)).join(`
4
- `):l.map(m=>d(m.innerContent)).join(`
5
- `)}return i}static _processImportBlocks(t){let e=/([ \t]*)<import(?:\s+([^>]*))?\/?>/gi,n=[];return{processed:t.replace(e,(o,a,i)=>{let r={},c=/(\w+)="([^"]*)"/g;if(i)for(let m of i.matchAll(c))r[m[1]]=m[2];let l=r.src;if(!l)return"";let d;r.block&&(r.block==="all"?d="all":r.block.includes(",")?d=r.block.split(",").map(m=>m.trim()).filter(m=>m):d=r.block);let h={src:l,blocks:d,base:r.base||"default",lang:r.lang,section:r.section||"all",indent:a||""};return n.push(h),`${a}__IMPORT_${n.length-1}__`}),imports:n}}static processImportBlocks(t,e,n=0,s){if(n>10)return"";let{processed:o,imports:a}=this._processImportBlocks(t),i=o;for(let r=0;r<a.length;r++){let c=a[r],l=`${c.src}|${c.base}|${c.lang||""}|${c.section}|${Array.isArray(c.blocks)?c.blocks.join(","):c.blocks||""}`,d;if(s&&s.has(l))d=s.get(l);else{let m=e(c.src);d=m?this._extractBlock(m,c.blocks,c.base,c.section,c.lang):"",d&&d.includes("<import")&&(d=this.processImportBlocks(d,e,n+1,s)),s&&s.set(l,d)}let h=d.split(`
1
+ var at=Object.defineProperty;var p=(u,t)=>at(u,"name",{value:t,configurable:!0}),K=(u=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(u,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):u)(function(u){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+u+'" is not supported')});import Ot from"path";import{fileURLToPath as rt}from"url";var ct=p(()=>rt(import.meta.url),"getFilename");var C=ct();import{LoggingPretty as dt}from"logging-pretty";var N=class extends dt{static{p(this,"LoggingUtils")}constructor(t){super(t)}errorMake(t,e,n){this.error(`[${e?`${e}:${n}`:n}] ${String(t)}`)}},Nt=new N;import{Keyv as ht}from"keyv";import lt from"@keyv/redis";var R=class extends ht{constructor(e="memory",n,s,o){let a;e.startsWith("redis")&&(a=new lt(e)),e==="memory"&&(a=new Map),o?.forceStore&&(a=o.forceStore);super({store:a,namespace:n,ttl:s});this.url=e}static{p(this,"CacheExternal")}};import{setTimeout as mt}from"timers/promises";import{InlineKeyboard as G,Keyboard as q}from"grammy";var D=class{static{p(this,"Ctx")}static template;static data;data=this.constructor.data;get userIsPremium(){return this.ct.from?.is_premium??!1}get userIsBot(){return this.ct.from?.is_bot??!1}get userId(){return this.ct.from?.id}get userName(){return this.ct.from?.username}get userFullName(){return`${this.ct.from?.first_name} ${this.ct.from?.last_name||""}`}get userFirstName(){return this.ct.from?.first_name}get userLastName(){return this.ct.from?.last_name}get userLanguage(){return this.ct.from?.language_code}set userLanguage(t){this.ct.from.language_code=t}get msgText(){return this.ct.message?.text}get msgTextPayloads(){return this.getPayloads(this.msgText,"space",this.data?._positionPayloadText||this.temp?.data?._positionPayloadText)}get msgTextPayload(){return this.msgTextPayloads[0]}get msgTextCommandPayloads(){return this.getPayloads(this.msgText,"space")}get msgTextCommandPayload(){return this.msgTextCommandPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionPayloads(){return this.getPayloads(this.msgCaption,"space")}get msgCaptionPayload(){return this.msgCaptionPayloads[0]}get msgCaptionCommandPayloads(){return this.getPayloads(this.msgCaption,"space")}get msgCaptionCommandPayload(){return this.msgCaptionCommandPayloads[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 callbackDataPayloads(){return this.getPayloads(this.callbackData,"colon")}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp}async broadcast(t,e,n,s,o,a,i=!1){try{this.temp.isAnswer=!0;let r=30,c=e.map(h=>this.templateManager.getMessage(this.data.name,o,h,s));for(let h=0;h<t.length;h++){let d=t[h],l=c[h];await this.ct.api.sendMessage(d,l,{parse_mode:"HTML",reply_markup:n,...a}),h+1==r&&await mt(1200)}}catch(r){if(i)throw r}}async reply(t,e,n,s){this.temp.isAnswer=!0;let o=this.templateManager.getMessage(this.data.name,n,this.userLanguage,e);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,e,n,s,o){this.temp.isAnswer=!0;let a=this.templateManager.getMedia(this.data.name,s,this.userLanguage,n),i={parse_mode:"HTML",reply_markup:e,...o};if(t=="photo")return await this.ct.replyWithPhoto(a.src,{caption:a.caption,...i});if(t=="video")return await this.ct.replyWithVideo(a.src,{caption:a.caption,...i});if(t=="audio")return await this.ct.replyWithAudio(a.src,{caption:a.caption,...i});if(t=="document")return await this.ct.replyWithDocument(a.src,{caption:a.caption,...i});if(t=="animation")return await this.ct.replyWithAnimation(a.src,{caption:a.caption,...i});if(t=="voice")return await this.ct.replyWithVoice(a.src,i);if(t=="video_note")return await this.ct.replyWithVideoNote(a.src,i);if(t=="sticker")return await this.ct.replyWithSticker(a.src,i);if(t=="location")return await this.ct.replyWithLocation(parseInt(a.latitude),parseInt(a.longitude),i);if(t=="contact")return await this.ct.replyWithContact(a.phone,a.first_name,{vcard:a.vcard,...i})}async replyPhoto(t,e,n,s){return this.replyMedia("photo",t,e,n,s)}async replyVideo(t,e,n,s){return this.replyMedia("video",t,e,n,s)}async replyAudio(t,e,n,s){return this.replyMedia("audio",t,e,n,s)}async replyDocument(t,e,n,s){return this.replyMedia("document",t,e,n,s)}async replyAnimation(t,e,n,s){return this.replyMedia("animation",t,e,n,s)}async replyVoice(t,e,n,s){return this.replyMedia("voice",t,e,n,s)}async replyVideoNote(t,e,n,s){return this.replyMedia("video_note",t,e,n,s)}async replySticker(t,e,n,s){return this.replyMedia("sticker",t,e,n,s)}async replyLocation(t,e,n,s){return this.replyMedia("location",t,e,n,s)}async replyContact(t,e,n,s){return this.replyMedia("contact",t,e,n,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,e,n,s,o=!0){try{this.temp.isAnswer=!0;let a=this.templateManager.getMessage(this.data.name,n,this.userLanguage,e);return await this.ct.editMessageText(a,{parse_mode:"HTML",reply_markup:t,...s})}catch(a){if(o)await this.reply(t,e,n,s);else throw a}}async editMedia(t,e,n,s,o,a,i=!0){try{this.temp.isAnswer=!0;let{src:r,caption:c}=this.templateManager.getMedia(this.data.name,s,this.userLanguage,n);return t=="voice"?(await this.delete(),await this.replyVoice(e,n,s,o)):t=="video_note"?(await this.delete(),await this.replyVoice(e,n,s,o)):t=="sticker"?(await this.delete(),await this.replySticker(e,n,s,o)):t=="location"?(await this.delete(),await this.replyLocation(e,n,s,o)):t=="contact"?(await this.delete(),await this.replyContact(e,n,s,o)):await this.ct.editMessageMedia({media:r,caption:c,type:t,parse_mode:"HTML",...o},{reply_markup:e,...a})}catch(r){if(i===!0)await this.reply(e,n,s,a);else throw r}}async editPhoto(t,e,n,s,o){return await this.editMedia("photo",t,e,n,s,o)}async editVideo(t,e,n,s,o){return await this.editMedia("video",t,e,n,s,o)}async editAudio(t,e,n,s,o){return await this.editMedia("audio",t,e,n,s,o)}async editDocument(t,e,n,s,o){return await this.editMedia("document",t,e,n,s,o)}async editAnimation(t,e,n,s,o){return await this.editMedia("animation",t,e,n,s,o)}async editVoice(t,e,n,s){return await this.editMedia("voice",t,e,n,s)}async editVideoNote(t,e,n,s){return await this.editMedia("video_note",t,e,n,s)}async editSticker(t,e,n,s){return await this.editMedia("sticker",t,e,n,s)}async editLocation(t,e,n,s){return await this.editMedia("location",t,e,n,s)}async editContact(t,e,n,s){return await this.editMedia("contact",t,e,n,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return this.temp.isAnswer=!0,await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,e,n){try{let s={method:t,params:e,...n},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){let n=typeof t=="function"?{callbackData:t}:t||{},s=n.callbackData;return{name:"",text:n.text,textCommand:n.textCommand,callbackData:s?function(...a){let i=s(...a);return`${this._callbackData}${i==""||i===void 0?"":`:${i}`}`}:function(){return this?._callbackData},_callbackData:"",_positionPayloadText:n.text?n.text.split(this.prototype.getSeperatorTag("space")).length:void 0}}ikb(...t){return this.inlineKeyboard(...t)}bkb(...t){return this.bottomKeyboard(...t)}inlineKeyboard(t,e){let n=this.data.name;if(e?.cache===!0){let i=`${n}:${this.userLanguage}:i`,r=this.cacheKeyboard.get(i);if(!r){let c=new G,h=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"inline",e?.data),d=t(c,h);return this.cacheKeyboard.set(i,d),d}return r}let s=new G,o=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"inline",e?.data);return t(s,o)}bottomKeyboard(t,e){let n=this.data.name;if(e?.cache===!0){let i=`${n}:${this.userLanguage}:b`,r=this.cacheKeyboard.get(i);if(!r){let c=new q,h=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"bottom",e?.data),d=t(c,h);return d.resized(!0),this.cacheKeyboard.set(i,d),d}return r}let s=new q,o=this.templateManager.getKeyboard(n,e?.baseId,this.userLanguage,"bottom",e?.data),a=t(s,o);return a.resized(),a}getSeperatorTag(t="space"){return t=="space"?" ":":"}havePayloads(t="",e){return t.includes(this.getSeperatorTag(e))}getPayloads(t="",e,n=1){if(!t)return[];let s=this.getSeperatorTag(e);return t.split(s).slice(n)}getIntent(t="",e,n=1){if(!t)return"";let s=this.getSeperatorTag(e),o=t.split(s);return n==1?o[0]:o.slice(0,n).join(s)}validateSessionCallback(t,e){return(t??this.session.method)===this.methodSessionCallback(e)}validateSessionCallbackPayload(t,e){return(t??this.session.method)===this.methodSessionCallbackPayload(e)}validateSessionText(t,e){return(t??this.session.method)===this.methodSessionText(e)}validateSessionTextPayload(t,e){return(t??this.session.method)===this.methodSessionTextPayload(e)}validateSessionTextCommand(t,e){return(t??this.session.method)===this.methodSessionTextCommand(e)}validateSessionTextCommandPayload(t,e){return(t??this.session.method)===this.methodSessionTextCommandPayload(e)}validateSessionTextFree(t,e){return(t??this.session.method)===this.methodSessionTextFree(e)}validateSessionPhotoCaption(t,e){return(t??this.session.method)===this.methodSessionPhotoCaption(e)}validateSessionPhotoCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionPhotoCaptionPayload(e)}validateSessionPhotoCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionPhotoCaptionCommand(e)}validateSessionPhotoCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionPhotoCaptionCommandPayload(e)}validateSessionPhotoFree(t,e){return(t??this.session.method)===this.methodSessionPhotoFree(e)}validateSessionVideoCaption(t,e){return(t??this.session.method)===this.methodSessionVideoCaption(e)}validateSessionVideoCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionVideoCaptionPayload(e)}validateSessionVideoCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionVideoCaptionCommand(e)}validateSessionVideoCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionVideoCaptionCommandPayload(e)}validateSessionVideoFree(t,e){return(t??this.session.method)===this.methodSessionVideoFree(e)}validateSessionAudioCaption(t,e){return(t??this.session.method)===this.methodSessionAudioCaption(e)}validateSessionAudioCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionAudioCaptionPayload(e)}validateSessionAudioCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionAudioCaptionCommand(e)}validateSessionAudioCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionAudioCaptionCommandPayload(e)}validateSessionAudioFree(t,e){return(t??this.session.method)===this.methodSessionAudioFree(e)}validateSessionDocumentCaption(t,e){return(t??this.session.method)===this.methodSessionDocumentCaption(e)}validateSessionDocumentCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionDocumentCaptionPayload(e)}validateSessionDocumentCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionDocumentCaptionCommand(e)}validateSessionDocumentCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionDocumentCaptionCommandPayload(e)}validateSessionDocumentFree(t,e){return(t??this.session.method)===this.methodSessionDocumentFree(e)}validateSessionAnimationCaption(t,e){return(t??this.session.method)===this.methodSessionAnimationCaption(e)}validateSessionAnimationCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionAnimationCaptionPayload(e)}validateSessionAnimationCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionAnimationCaptionCommand(e)}validateSessionAnimationCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionAnimationCaptionCommandPayload(e)}validateSessionAnimationFree(t,e){return(t??this.session.method)===this.methodSessionAnimationFree(e)}validateSessionVoiceCaption(t,e){return(t??this.session.method)===this.methodSessionVoiceCaption(e)}validateSessionVoiceCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionVoiceCaptionPayload(e)}validateSessionVoiceCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionVoiceCaptionCommand(e)}validateSessionVoiceCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionVoiceCaptionCommandPayload(e)}validateSessionVoiceFree(t,e){return(t??this.session.method)===this.methodSessionVoiceFree(e)}validateSessionVideoNoteCaption(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaption(e)}validateSessionVideoNoteCaptionPayload(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaptionPayload(e)}validateSessionVideoNoteCaptionCommand(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaptionCommand(e)}validateSessionVideoNoteCaptionCommandPayload(t,e){return(t??this.session.method)===this.methodSessionVideoNoteCaptionCommandPayload(e)}validateSessionVideoNoteFree(t,e){return(t??this.session.method)===this.methodSessionVideoNoteFree(e)}validateSessionStickerFree(t,e){return(t??this.session.method)===this.methodSessionStickerFree(e)}validateSessionLocationFree(t,e){return(t??this.session.method)===this.methodSessionLocationFree(e)}validateSessionContactFree(t,e){return(t??this.session.method)===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)}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{join as X,dirname as ft,parse as Ct}from"path";import{readFileSync as St}from"fs";import{fileURLToPath as Pt}from"url";import{join as E}from"path";import{existsSync as Q,readdirSync as U}from"fs";import{createRequire as pt}from"module";var P=class{static{p(this,"PageManager")}static _getFile(t,e,n=0){let o=Object.values(t)[n];if(o===void 0)throw new Error(`File ${e} must have export (not default) class page`);return o}static getFilePath(){return E(process.cwd(),"src","pages")}static getFileSync(t,e=0){t||(t=this.getFilePath());let s=pt(t)(t);return this._getFile(s,t,e)}static async getFile(t,e=0){t||(t=this.getFilePath());let n=await import(`${t}?t=${Date.now()}`);return this._getFile(n,t,e)}static getFileManySync(t,e=0){if(t||(t=this.getFilePath()),!Q(t))throw new Error(`Directory ${t} is not found, please make it manually`);return U(t).map(s=>{let o=E(t,s);return{path:o,page:this.getFileSync(o,e)}})}static clearCacheRequire(t){if(t||(t=this.getFilePath()),!Q(t))throw new Error(`Directory ${t} is not found, please make it manually`);return U(t).forEach(n=>{let s=E(t,n);delete K.cache[K.resolve(s)]}),!0}};import{LoggingPretty as bt}from"logging-pretty";import{basename as L,join as x,extname as J}from"path";import{readdirSync as gt,readFileSync as V,existsSync as M,statSync as F,writeFileSync as ut}from"fs";import{watch as yt}from"chokidar";var T=class{static{p(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(e,n)=>`\${(data && data["${n}"]) ?? ""}`)}static _processBaseBlocks(t){let e=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,n={};for(let s of t.matchAll(e)){let o=s[2]??"default",i=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[o]=i}return n}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(e,n)=>{let s=n.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,n)=>n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processSwitchBlocks(t){let e=/<switch\b(?:\s+value="([^"]+)")?>([\s\S]*?)<\/switch>/gi;return t.replace(e,(n,s,o)=>{if(!s)return"";let a="",i=/<case\b(?:\s+is="([^"]+)")?>([\s\S]*?)<\/case>/gi,r=/<default>([\s\S]*?)<\/default>/gi,c;for(;(c=i.exec(o))!==null;){let d=(c[1]||"").split(",").map(m=>m.trim()),l=(c[2]||"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim().replace(/`/g,"\\`");d.forEach(m=>{a+=`case "${m}": `}),a+=`return \`${l}\`; `}let h=r.exec(o);if(h){let d=(h[1]||"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim().replace(/`/g,"\\`");a+=`default: return \`${d}\`; `}else a+="default: return ''; ";return`\${(() => { switch((data && data["${s}"])) { ${a} } })()}`})}static _processExec(t){return t.replace(/{~\s*([\s\S]*?)\s*~}/g,(e,n)=>`\${(() => { try { return ${n} } catch(e) { try { with(data || {}) { return ${n} } } catch(ee) { return '' } } })()}`)}static _processMapBlocks(t){let e=/<map(?:\s+([^>]*))?>([\s\S]*?)<\/map>/gi;return t.replace(e,(n,s,o)=>{let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let l of s.matchAll(i))a[l[1]]=l[2];let r=a.src;if(!r)return"";let c=a.join??"\\n",h=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").replace(/`/g,"\\`");h=h.replace(/\{\{([\w.]+)\}\}/g,(l,m)=>m==="e"||m.startsWith("e.")?`\${${m}}`:m==="i"?"${i}":l);let d=c.replace(/"/g,'\\"');return`\${(data && data["${r}"] || []).map((e, i) => \`${h}\`).join("${d}")}`})}static _processMediaBlocks(t){let e=/<media(?:\s+([^>]*))?>([\s\S]*?)<\/media>/gi,n={};for(let s of t.matchAll(e)){let o=s[1],a=s[2],i={},r=/(\w+)="([^"]*)"/g;if(o)for(let m of o.matchAll(r))i[m[1]]=m[2];let c=i.lang||"default",h=i.type,d=a.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),l={type:h};i.src&&(l.src=i.src),d&&h!=="video_note"&&h!=="sticker"&&(l.caption=d),h==="location"&&(i.latitude&&(l.latitude=i.latitude),i.longitude&&(l.longitude=i.longitude),d&&(l.caption=d)),h==="contact"&&(i.phone&&(l.phone=i.phone),i.first_name&&(l.first_name=i.first_name),i.last_name&&(l.last_name=i.last_name),i.vcard&&(l.vcard=i.vcard),d&&(l.caption=d)),n[c]=l}return n}static _processMessageBlocks(t){let e=/<message(?:\s+([^>]*))?>([\s\S]*?)<\/message>/gi,n={};for(let[,s,o]of t.matchAll(e)){let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let h of s.matchAll(i))a[h[1]]=h[2];let r=a.lang||"default",c=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[r]=c}return n}static _processDescriptionBlocks(t){let e=/<description(?:\s+([^>]*))?>([\s\S]*?)<\/description>/gi,n={};for(let[,s,o]of t.matchAll(e)){let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let d of s.matchAll(i))a[d[1]]=d[2];let r=a.lang||"default",c=a.scope||"default",h=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[r]||(n[r]={}),n[r][c]=h}return n}static _processKeyboardBlocks(t){let e=/<keyboard(?:\s+([^>]*))?>([\s\S]*?)<\/keyboard>/gi,n={};for(let[,s,o]of t.matchAll(e)){let a={},i=/(\w+)="([^"]*)"/g;if(s)for(let d of s.matchAll(i))a[d[1]]=d[2];let r=a.lang||"default",c=a.type==="bottom"?"bottom":"inline",h=o.trim();n[r]||(n[r]={}),n[r][c]=h}return n}static _compileToFunction(t,e){let n;e?n=t.map(a=>`\`${a}\``).join(","):n=`\`${t}\``;let s=n;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,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processMediaBlocks(a);s[o]={};for(let[r,c]of Object.entries(i)){let h={};for(let[d,l]of Object.entries(c)){if(d==="type"||typeof l!="string")continue;let m=this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(l)))));h[d]=this._compileToFunction(m,!1)}s[o][r]=d=>{let l={...c};for(let[m,y]of Object.entries(h))l[m]=y(d);return l}}}return s}static compileMessages(t,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processMessageBlocks(a);s[o]={};for(let[r,c]of Object.entries(i)){let h=this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(c)))));s[o][r]=this._compileToFunction(h,!1)}}return s}static compileDescription(t,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processDescriptionBlocks(a);s[o]={};for(let[r,c]of Object.entries(i))for(let[h,d]of Object.entries(c)){s[o][h]||(s[o][h]={});let l=this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(d)))));s[o][h][r]=this._compileToFunction(l,!1)}}return s}static compileKeyboards(t,e){let n=e||this._processBaseBlocks(t),s={};for(let[o,a]of Object.entries(n)){let i=this._processKeyboardBlocks(a);s[o]={};for(let[r,c]of Object.entries(i)){s[o][r]={};for(let[h,d]of Object.entries(c)){let m=d.split(/(?<!\\),\s*/).map(y=>y.replace(/\\,/g,",").trim()).map(y=>this._processVariables(this._processExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(y))))));s[o][r][h]=this._compileToFunction(m,!0)}}}return s}static _extractBlock(t,e,n="default",s="all",o){let a=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,i=t,r=!1;for(let c of t.matchAll(a))if((c[2]??"default")===n){i=c[3]??"",r=!0;break}if(!r){let c=/<base\b/.test(t);if(!(n==="default"&&!c))return""}if(e){if(e==="all")return i;let c=Array.isArray(e)?e:[e],h=[];for(let l of c){let m=new RegExp(`([ \\t]*)<${l}(?:\\s+([^>]*))?>([\\s\\S]*?)<\\/${l}>`,"gi");for(let y of i.matchAll(m)){let f=y[2];if(o){let g=/lang="([^"]*)"/i,b=f?.match(g);if(((b?b[1]:void 0)||"default")!==o)continue}h.push({start:y.index,content:y[0],innerContent:y[3]??""})}}h.sort((l,m)=>l.start-m.start);let d=p(l=>{let m=l.split(`
2
+ `);if(m.length<=1)return l.trim();let y=m.filter(g=>g.trim().length>0);if(y.length===0)return"";let f=y.reduce((g,b)=>{let k=b.match(/^([ \t]*)/),v=k?k[1].length:0;return v<g?v:g},1/0);return m.map(g=>g.length>=f?g.slice(f):g.trimStart()).join(`
3
+ `).trim()},"processResult");return s==="all"?h.map(m=>d(m.content)).join(`
4
+ `):h.map(m=>d(m.innerContent)).join(`
5
+ `)}return i}static _processImportBlocks(t){let e=/([ \t]*)<import(?:\s+([^>]*))?\/?>/gi,n=[];return{processed:t.replace(e,(o,a,i)=>{let r={},c=/(\w+)="([^"]*)"/g;if(i)for(let m of i.matchAll(c))r[m[1]]=m[2];let h=r.src;if(!h)return"";let d;r.block&&(r.block==="all"?d="all":r.block.includes(",")?d=r.block.split(",").map(m=>m.trim()).filter(m=>m):d=r.block);let l={src:h,blocks:d,base:r.base||"default",lang:r.lang,section:r.section||"all",indent:a||""};return n.push(l),`${a}__IMPORT_${n.length-1}__`}),imports:n}}static processImportBlocks(t,e,n=0,s){if(n>10)return"";let{processed:o,imports:a}=this._processImportBlocks(t),i=o;for(let r=0;r<a.length;r++){let c=a[r],h=`${c.src}|${c.base}|${c.lang||""}|${c.section}|${Array.isArray(c.blocks)?c.blocks.join(","):c.blocks||""}`,d;if(s&&s.has(h))d=s.get(h);else{let m=e(c.src);d=m?this._extractBlock(m,c.blocks,c.base,c.section,c.lang):"",d&&d.includes("<import")&&(d=this.processImportBlocks(d,e,n+1,s)),s&&s.set(h,d)}let l=d.split(`
6
6
  `).map((m,y)=>y===0?m:c.indent+m).join(`
7
- `);i=i.replace(`__IMPORT_${r}__`,h)}return i}};var A=class{static{p(this,"TemplateManager")}_map=new Map;_engine=v;_watcher=[];_pageManager=P;_supportedExtensions=new Set([".html",".ts",".js"]);_path;_isWatchEnabled;constructor(t){let{path:e,enableWatch:n=!1}=t;this._path=e,this._isWatchEnabled=n,this._validatePath(),this._initializeWatcher(t.watchOptions),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(!M(e))throw new Error(`Template base path is not exists: ${e}`);if(!F(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: ${String(t)}`)}}_initializeWatcher(t){if(this._isWatchEnabled){if(this._watcher.length>0)throw new Error("Watcher already enabled");for(let e=0;e<this._path.length;e++){let n=this._path[e],s=yt(n,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},...t});this._watcher[e]=s,s.on("change",this._handleFileChange.bind(this)),s.on("add",this._handleFileAdd.bind(this)),s.on("unlink",this._handleFileDelete.bind(this)),s.on("error",this._handleWatchError.bind(this))}}}_handleFileChange(t){let e=L(t);this._isValidFile(e)&&this._loadFile(e)}_handleFileAdd(t){let e=L(t);this._isValidFile(e)&&this._loadFile(e)}_handleFileDelete(t){let e=L(t),n=this._getKey(e);this._map.has(n)&&this._map.delete(n)}_handleWatchError(t){}_loadAllFiles(){let t=new Map,e=[];for(let s=0;s<this._path.length;s++){let o=this._path[s],i=gt(o,"utf8").filter(r=>this._isValidFile(r));for(let r of i){let c=x(o,r),l=this._getExtension(r),d=this._getKey(r);if(l===".html")t.set(d,V(c,"utf8"));else if(l===".ts"||l===".js"){let h=P.getFileSync(c);h?.template!==void 0&&(t.set(d,h.template),e.push(h))}}}let n=new Map;for(let[s,o]of t.entries())this._compile(s,o,void 0,n,t);t.clear(),n.clear();for(let s of e)s.template=void 0}_loadFile(t){for(let e=0;e<this._path.length;e++){let n=this._path[e],s=x(n,t),o=this._getExtension(t),a=this._getKey(t);if(o==".html"){let i=V(s,"utf8");this._compile(a,i)}else if(o==".ts"||o==".js"){let i=P.getFileSync(s);i?.template!==void 0&&(this._compile(a,i.template),i.template=void 0)}else throw new Error(`File ${t} is not support`)}}_getExtension(t){return J(t).toLowerCase()}_readTemplateFile(t){for(let e of this._path){let n=J(t).toLowerCase();if(n){let i=x(e,t);if(M(i)&&F(i).isFile()){if(n===".html")return V(i,"utf8");if(n===".ts"||n===".js")try{return P.getFileSync(i)?.template??null}catch{return null}}continue}let s=x(e,`${t}.ts`),o=x(e,`${t}.js`);if(M(s)&&F(s).isFile())try{return P.getFileSync(s)?.template??null}catch{}else if(M(o)&&F(o).isFile())try{return P.getFileSync(s)?.template??null}catch{}let a=x(e,`${t}.html`);if(M(a)&&F(a).isFile())return V(a,"utf8")}return null}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,e,n,s,o){let a=this._map.get(t),i=a||{},r=!1,c=v.processImportBlocks(e,d=>o&&o.has(d)?o.get(d):this._readTemplateFile(d),0,s),l=v._processBaseBlocks(c);(n===void 0||n?.media===!1||a?.media===void 0)&&(i.media=v.compileMedia(c,l),r=!0),(n===void 0||n?.message===!1||a?.message===void 0)&&(i.message=v.compileMessages(c,l),r=!0),(n===void 0||n?.keyboard===!1||a?.keyboard===void 0)&&(i.keyboard=v.compileKeyboards(c,l),r=!0),(n===void 0||n?.description===!1||a?.description===void 0)&&(i.description=v.compileDescription(c,l),r=!0),r&&this._map.set(t,i)}getMedia(t,e="default",n="default",s){let a=this._map.get(t)?.media?.[e],i=a?.[n]||a?.default;try{if(!i)throw new Error("Media function not found, please check your template");return i(s)}catch{return{}}}getMessage(t,e="default",n="default",s){try{let a=this._map.get(t)?.message?.[e],i=a?.[n]||a?.default;if(!i)throw"";return i(s)}catch{return""}}getDescription(t,e="default",n="default",s="default",o){try{let i=this._map.get(t)?.description?.[e]?.[s],r=i?.[n]||i?.default;if(!r)throw"";return r(o)}catch{return""}}getDescriptionLanguage(t,e="default",n="default"){try{let o=this._map.get(t)?.description?.[e]?.[n];return o?Object.keys(o):[]}catch{return[]}}getDescriptionScopes(t,e="default"){try{let s=this._map.get(t)?.description?.[e];return s?Object.keys(s):[]}catch{return[]}}getKeyboard(t,e="default",n="default",s="inline",o){try{let i=this._map.get(t)?.keyboard?.[e],r=i?.[n]?.[s]||i?.default?.[s];if(!r)throw[];return r(o)}catch{return[]}}async write(t,e){if(this._getExtension(t)!=".html")return null;for(let n=0;n<this._path.length;n++){let s=x(this._path[n],t);if(M(s))return ut(s,e,"utf8"),this._loadFile(t),!0}return null}has(t){return this._map.has(t)}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};import{Bot as kt,webhookCallback as H}from"grammy";var Tt=(()=>{try{return C}catch{return Pt(import.meta.url)}})(),vt=ft(Tt),wt=JSON.parse(St(X(vt,"../../package.json"),"utf-8")).version,z=class{static{p(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;optionsPage={shortCallbackData:!1};log;bot;handlerBotUpdate;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");if(typeof t.optionsPage?.shortCallbackData=="boolean"&&(this.optionsPage.shortCallbackData=t.optionsPage.shortCallbackData),this.log=t.log===!0?new bt:t.log?t.log:void 0,this.log?.info?.(`Gramstax v${wt}`),this.cacheSession=t.cacheSession||new R("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new A({path:[X(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()),this.hookBeforeStart(),t.deploy.startsWith("polling"))this.runPolling();else if(t.deploy.startsWith("webhook:"))this.runWebhook(t.deploy.split("webhook:")[1]);else if(t.deploy.startsWith("serverless:"))this.runServerless(t.deploy.split("serverless:")[1]);else if(!t.deploy.startsWith("test"))throw new Error("Params deploy is not valid, expected: polling, webhook:<public-url>, serverless:<your-adapter>")}onCatch(t){this.log?.error?.(`[Bot.catch]: ${JSON.stringify(t,null,2)}`)}hookBeforeStart(){}hookAfterStart(){}async onStart(t,e,n){await this.executeSyncBlocksDescription(this.pages);let{username:s}=t;this.log?.success?.(`Telegram bot polling started: ${s} ${e=="webhook"||e=="serverless"?`(${n})`:""}`),this.hookAfterStart()}createBot(t){return new kt(t)}createCtx(t){return new D({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{isAnswer:!1,session:{},data:{}}})}runPolling(){this.bot.start({onStart:p(t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let{serve:e}=await import("bun"),n=H(this.bot,"bun");this.handlerBotUpdate=n;let s=new URL(t).pathname;e({fetch(i){let{pathname:r}=new URL(i.url);if(i.method=="POST"&&r==s)return n(i);if(i.method=="GET"&&r=="/"){let c=new Date().toISOString();return new Response(JSON.stringify({status:"OK",timestamp:c}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}}),(await this.bot.api.getWebhookInfo()).url!=t&&await this.bot.api.setWebhook(t);let a=await this.bot.api.getMe();await this.onStart(a,"webhook",t)}async runServerless(t){this.handlerBotUpdate=H(this.bot,t);let e=await this.bot.api.getMe();await this.onStart(e,"serverless",t)}pageBuildData(t,e){t?.data===void 0&&(t.data=t.buildData()),t.data.name=Ct(e).name,t.data._callbackData.length==0&&(t.data._callbackData=t.data.name)}pageSorts(t,e,n){let s=t.data.name,o=t.prototype,a="Payload",i="Command",r="Caption",c="Free",l=e.routeDynamic,d=e.routeDynamicSpesific,h=p(f=>f.charAt(0).toUpperCase()+f.slice(1),"upFirst"),m=p(f=>f.replace(a,"").replace(i,"").replace(r,"").replace(c,""),"getPureRouteName"),y=p((f,g)=>o[`methodSession${h(f)}`]?.(g),"methodSession");e.all[s]=t;for(let f=0;f<e.lenListRouteStaticSession;f++){let g=e.listRouteStaticSession[f];if(typeof o[g]!="function")continue;let b=e.routeStatic[g],k=e.routeStaticIntent[g],T=e.routeStaticSession[g],B={name:s,routeName:g},j=b||k;if(j!==void 0){let nt=g.includes(i),it=g.includes("callback"),ot=g.startsWith("text"),I;if(nt){let _=t.data.textCommand||t.data.name;I=_?`/${_}`:void 0}else if(it){let _=t.data._callbackData||t.data.name;this.optionsPage.shortCallbackData===!0&&(_=String(n),t.data._callbackData=_),I=_}else ot?I=t.data.text||t.data.name:I=t.data.name;I&&(j[I]=B)}T!==void 0&&(T[y(g,s)]=B),g.toLowerCase().endsWith("free")&&d[m(g)].push(B)}o.free&&l.push(s)}async executeSyncBlocksDescription(t){let e=new Map,n=t.routeStatic.textCommand;for(let[,s]of Object.entries(n)){let o=s.name,a=this.templateManager.getDescriptionScopes(o);for(let i of a){e.has(i)||e.set(i,new Set);let r=this.templateManager.getDescriptionLanguage(o,"default",i);for(let c of r)e.get(i).add(c)}}for(let[s,o]of e)for(let a of o){let i=[];for(let[,l]of Object.entries(n)){let d=l.name,h=this.templateManager.getDescription(d,"default",a,s);h&&i.push({command:d,description:h})}if(i.length===0)continue;let r={type:s},c=a==="default"?void 0:a;try{let l=await this.bot.api.getMyCommands({scope:r,language_code:c}),d=JSON.stringify(l.map(m=>({command:m.command,description:m.description})).sort((m,y)=>m.command.localeCompare(y.command))),h=JSON.stringify(i.sort((m,y)=>m.command.localeCompare(y.command)));d!==h&&(await this.bot.api.setMyCommands(i,{scope:r,language_code:c}),this.log?.info?.(`Synced descriptions for scope: ${s},${c?` lang: ${c},`:""} total (${i.length})`))}catch(l){this.log?.error?.(`Failed to sync descriptions for scope: ${s},${c?` lang: ${c},`:""} error: ${String(l)}`)}}}pageLoads(){this.log?.info?.("Load pages..");let t=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],e=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],n=[...t,...e,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],s=p((i,r)=>Object.fromEntries(i.map(c=>[c,r()])),"makeObject"),o=p(()=>[],"initDynamicSpesific"),a={all:{},routeDynamic:[],routeDynamicSpesific:{text:o(),photo:o(),video:o(),audio:o(),document:o(),animation:o(),voice:o(),videoNote:o(),sticker:o(),location:o(),contact:o()},routeStatic:s(t,()=>({})),routeStaticIntent:s(e,()=>({})),routeStaticSession:s(n,()=>({})),listRouteStatic:t,listRouteStaticIntent:e,listRouteStaticSession:n,lenListRouteStatic:t.length,lenListRouteStaticIntent:e.length,lenListRouteStaticSession:n.length};return P.getFileManySync(void 0).forEach(({path:i,page:r},c)=>{this.pageBuildData(r,i),this.pageSorts(r,a,c),r.template=void 0}),this.log?.info?.(`Finish load pages with total (${Object.keys(a.all).length})`),a}async pageRoutes(t,e){let n,s;if(n===void 0){let a=await t.sessionGet();if(a){let i=a.method,r=this.pages.routeStaticSession,c=t.callbackData,l=t.msgText,d=t.msgCaption,h=c||l||d,m=e==="callback",y=m?"colon":"space",f=h&&t.havePayloads(h,y)?t.getIntent(h,y,1):void 0,g=!m&&h?t.getIntent(h,"space",2):void 0;for(let b=0;b<this.pages.lenListRouteStaticSession;b++){let k=this.pages.listRouteStaticSession[b];if(k.startsWith(e)){if(h){if(this.pages.routeStatic[k]?.[h])continue;let T=this.pages.routeStaticIntent[k];if(T&&(f&&T[f]||g&&T[g]))continue}s=r[k][i]}if(s)break}s!==void 0&&(n=this.pages.all[s.name])}}if(n===void 0){let a=t.callbackData,i=t.msgText,r=t.msgCaption,c=this.pages.routeStatic;for(let l=0;l<this.pages.lenListRouteStatic;l++){let d=this.pages.listRouteStatic[l];if(d.startsWith(e)&&(s=c[d][a||i||r]),s)break}s!==void 0&&(n=this.pages.all[s.name])}if(n===void 0){let a=this.pages.routeStaticIntent,i=e==="callback",r=i?"colon":"space",c=i?t.callbackData:t.msgText||t.msgCaption,l=t.havePayloads(c,r);if(c&&l)for(let d=0;d<this.pages.lenListRouteStaticIntent;d++){let h=this.pages.listRouteStaticIntent[d];if(!h.startsWith(e))continue;let m=a[h];if(s=m[t.getIntent(c,r,1)],!s&&!i&&(s=m[t.getIntent(c,"space",2)]),s)break}s!==void 0&&(n=this.pages.all[s.name])}if(n!==void 0&&s!==void 0){if(!n.prototype[s.routeName])return;let i=await new n(t)[s.routeName]?.();return t.temp.isAnswer===!0?i:null}let o=this.pages.routeDynamicSpesific[e]||[];for(let a=0;a<o.length;a++){let i=o[a];if(i===void 0)continue;let r=this.pages.all[i.name];r!==void 0&&typeof r.prototype[i.routeName]=="function"&&await new r(t)[i.routeName]()}for(let a=0;a<this.pages.routeDynamic.length;a++){let i=this.pages.routeDynamic[a];if(i===void 0)continue;let r=this.pages.all[i];r!==void 0&&typeof r.prototype.free=="function"&&await new r(t).free()}if(t.temp.isAnswer===!1)return null}async hookBeforeRoute(t,e){return!!(t||e)}async hookErrorPage(t,e,n,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,e){let n=this.createCtx(t);try{if(await this.hookBeforeRoute(n,e)===!1)return;await this.pageRoutes(n,e)===null&&await this.hookErrorInputNotFoundPage(n)}catch(s){await this.hookErrorPage(n,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(n){await this.hookErrorPage(e,"onCallbackQueryData",n,!0)}}async onMessageText(t){await this.onMessage(t,"text")}async onMessagePhoto(t){await this.onMessage(t,"photo")}async onMessageVideo(t){await this.onMessage(t,"video")}async onMessageAudio(t){await this.onMessage(t,"audio")}async onMessageDocument(t){await this.onMessage(t,"document")}async onMessageAnimation(t){await this.onMessage(t,"animation")}async onMessageVoice(t){await this.onMessage(t,"voice")}async onMessageVideoNote(t){await this.onMessage(t,"videoNote")}async onMessageSticker(t){await this.onMessage(t,"sticker")}async onMessageLocation(t){await this.onMessage(t,"location")}async onMessageContact(t){await this.onMessage(t,"contact")}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))}};var Y=class{static{p(this,"ComponentKeyboard")}static data;static _process(t,e){if(e.type||(e.type="inline"),e.lang){let n=t[e.lang];return`
7
+ `);i=i.replace(`__IMPORT_${r}__`,l)}return i}};var A=class{static{p(this,"TemplateManager")}_map=new Map;_engine=T;_watcher=[];_pageManager=P;_supportedExtensions=new Set([".html",".ts",".js"]);_path;_isWatchEnabled;constructor(t){let{path:e,enableWatch:n=!1}=t;this._path=e,this._isWatchEnabled=n,this._validatePath(),this._initializeWatcher(t.watchOptions),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(!M(e))throw new Error(`Template base path is not exists: ${e}`);if(!F(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: ${String(t)}`)}}_initializeWatcher(t){if(this._isWatchEnabled){if(this._watcher.length>0)throw new Error("Watcher already enabled");for(let e=0;e<this._path.length;e++){let n=this._path[e],s=yt(n,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},...t});this._watcher[e]=s,s.on("change",this._handleFileChange.bind(this)),s.on("add",this._handleFileAdd.bind(this)),s.on("unlink",this._handleFileDelete.bind(this)),s.on("error",this._handleWatchError.bind(this))}}}_handleFileChange(t){let e=L(t);this._isValidFile(e)&&this._loadFile(e)}_handleFileAdd(t){let e=L(t);this._isValidFile(e)&&this._loadFile(e)}_handleFileDelete(t){let e=L(t),n=this._getKey(e);this._map.has(n)&&this._map.delete(n)}_handleWatchError(t){}_loadAllFiles(){let t=new Map,e=[];for(let s=0;s<this._path.length;s++){let o=this._path[s],i=gt(o,"utf8").filter(r=>this._isValidFile(r));for(let r of i){let c=x(o,r),h=this._getExtension(r),d=this._getKey(r);if(h===".html")t.set(d,V(c,"utf8"));else if(h===".ts"||h===".js"){let l=P.getFileSync(c);l?.template!==void 0&&(t.set(d,l.template),e.push(l))}}}let n=new Map;for(let[s,o]of t.entries())this._compile(s,o,void 0,n,t);t.clear(),n.clear();for(let s of e)s.template=void 0}_loadFile(t){for(let e=0;e<this._path.length;e++){let n=this._path[e],s=x(n,t),o=this._getExtension(t),a=this._getKey(t);if(o==".html"){let i=V(s,"utf8");this._compile(a,i)}else if(o==".ts"||o==".js"){let i=P.getFileSync(s);i?.template!==void 0&&(this._compile(a,i.template),i.template=void 0)}else throw new Error(`File ${t} is not support`)}}_getExtension(t){return J(t).toLowerCase()}_readTemplateFile(t){for(let e of this._path){let n=J(t).toLowerCase();if(n){let i=x(e,t);if(M(i)&&F(i).isFile()){if(n===".html")return V(i,"utf8");if(n===".ts"||n===".js")try{return P.getFileSync(i)?.template??null}catch{return null}}continue}let s=x(e,`${t}.ts`),o=x(e,`${t}.js`);if(M(s)&&F(s).isFile())try{return P.getFileSync(s)?.template??null}catch{}else if(M(o)&&F(o).isFile())try{return P.getFileSync(s)?.template??null}catch{}let a=x(e,`${t}.html`);if(M(a)&&F(a).isFile())return V(a,"utf8")}return null}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,e,n,s,o){let a=this._map.get(t),i=a||{},r=!1,c=T.processImportBlocks(e,d=>o&&o.has(d)?o.get(d):this._readTemplateFile(d),0,s),h=T._processBaseBlocks(c);(n===void 0||n?.media===!1||a?.media===void 0)&&(i.media=T.compileMedia(c,h),r=!0),(n===void 0||n?.message===!1||a?.message===void 0)&&(i.message=T.compileMessages(c,h),r=!0),(n===void 0||n?.keyboard===!1||a?.keyboard===void 0)&&(i.keyboard=T.compileKeyboards(c,h),r=!0),(n===void 0||n?.description===!1||a?.description===void 0)&&(i.description=T.compileDescription(c,h),r=!0),r&&this._map.set(t,i)}getMedia(t,e="default",n="default",s){let a=this._map.get(t)?.media?.[e],i=a?.[n]||a?.default;try{if(!i)throw new Error("Media function not found, please check your template");return i(s)}catch{return{}}}getMessage(t,e="default",n="default",s){try{let a=this._map.get(t)?.message?.[e],i=a?.[n]||a?.default;if(!i)throw"";return i(s)}catch{return""}}getDescription(t,e="default",n="default",s="default",o){try{let i=this._map.get(t)?.description?.[e]?.[s],r=i?.[n]||i?.default;if(!r)throw"";return r(o)}catch{return""}}getDescriptionLanguage(t,e="default",n="default"){try{let o=this._map.get(t)?.description?.[e]?.[n];return o?Object.keys(o):[]}catch{return[]}}getDescriptionScopes(t,e="default"){try{let s=this._map.get(t)?.description?.[e];return s?Object.keys(s):[]}catch{return[]}}getKeyboard(t,e="default",n="default",s="inline",o){try{let i=this._map.get(t)?.keyboard?.[e],r=i?.[n]?.[s]||i?.default?.[s];if(!r)throw[];return r(o)}catch{return[]}}async write(t,e){if(this._getExtension(t)!=".html")return null;for(let n=0;n<this._path.length;n++){let s=x(this._path[n],t);if(M(s))return ut(s,e,"utf8"),this._loadFile(t),!0}return null}has(t){return this._map.has(t)}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};import{Bot as kt,webhookCallback as H}from"grammy";var vt=(()=>{try{return C}catch{return Pt(import.meta.url)}})(),Tt=ft(vt),wt=JSON.parse(St(X(Tt,"../../package.json"),"utf-8")).version,z=class{static{p(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;optionsPage={shortCallbackData:!1};log;bot;handlerBotUpdate;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");if(typeof t.optionsPage?.shortCallbackData=="boolean"&&(this.optionsPage.shortCallbackData=t.optionsPage.shortCallbackData),this.log=t.log===!0?new bt:t.log?t.log:void 0,this.log?.info?.(`Gramstax v${wt}`),this.cacheSession=t.cacheSession||new R("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new A({path:[X(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()),this.hookBeforeStart(),t.deploy.startsWith("polling"))this.runPolling();else if(t.deploy.startsWith("webhook:"))this.runWebhook(t.deploy.split("webhook:")[1]);else if(t.deploy.startsWith("serverless:"))this.runServerless(t.deploy.split("serverless:")[1]);else if(!t.deploy.startsWith("test"))throw new Error("Params deploy is not valid, expected: polling, webhook:<public-url>, serverless:<your-adapter>")}onCatch(t){this.log?.error?.(`[Bot.catch]: ${JSON.stringify(t,null,2)}`)}hookBeforeStart(){}hookAfterStart(){}async onStart(t,e,n){await this.executeSyncBlocksDescription(this.pages);let{username:s}=t;this.log?.success?.(`Telegram bot polling started: ${s} ${e=="webhook"||e=="serverless"?`(${n})`:""}`),this.hookAfterStart()}createBot(t){return new kt(t)}createCtx(t){return new D({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{isAnswer:!1,session:{},data:{}}})}runPolling(){this.bot.start({onStart:p(t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let{serve:e}=await import("bun"),n=H(this.bot,"bun");this.handlerBotUpdate=n;let s=new URL(t).pathname;e({fetch(i){let{pathname:r}=new URL(i.url);if(i.method=="POST"&&r==s)return n(i);if(i.method=="GET"&&r=="/"){let c=new Date().toISOString();return new Response(JSON.stringify({status:"OK",timestamp:c}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}}),(await this.bot.api.getWebhookInfo()).url!=t&&await this.bot.api.setWebhook(t);let a=await this.bot.api.getMe();await this.onStart(a,"webhook",t)}async runServerless(t){this.handlerBotUpdate=H(this.bot,t);let e=await this.bot.api.getMe();await this.onStart(e,"serverless",t)}pageBuildData(t,e){t?.data===void 0&&(t.data=t.buildData()),t.data.name=Ct(e).name,t.data._callbackData.length==0&&(t.data._callbackData=t.data.name)}pageSorts(t,e,n){let s=t.data.name,o=t.prototype,a="Payload",i="Command",r="Caption",c="Free",h=e.routeDynamic,d=e.routeDynamicSpesific,l=p(f=>f.charAt(0).toUpperCase()+f.slice(1),"upFirst"),m=p(f=>f.replace(a,"").replace(i,"").replace(r,"").replace(c,""),"getPureRouteName"),y=p((f,g)=>o[`methodSession${l(f)}`]?.(g),"methodSession");e.all[s]=t;for(let f=0;f<e.lenListRouteStaticSession;f++){let g=e.listRouteStaticSession[f];if(typeof o[g]!="function")continue;let b=e.routeStatic[g],k=e.routeStaticIntent[g],v=e.routeStaticSession[g],$={name:s,routeName:g},j=b||k;if(j!==void 0){let nt=g.includes(i),it=g.includes("callback"),ot=g.startsWith("text"),I;if(nt){let _=t.data.textCommand||t.data.name;I=_?`/${_}`:void 0}else if(it){let _=t.data._callbackData||t.data.name;this.optionsPage.shortCallbackData===!0&&(_=String(n),t.data._callbackData=_),I=_}else ot?I=t.data.text||t.data.name:I=t.data.name;I&&(j[I]=$)}v!==void 0&&(v[y(g,s)]=$),g.toLowerCase().endsWith("free")&&d[m(g)].push($)}o.free&&h.push(s)}async executeSyncBlocksDescription(t){let e=new Map,n=t.routeStatic.textCommand;for(let[,s]of Object.entries(n)){let o=s.name,a=this.templateManager.getDescriptionScopes(o);for(let i of a){e.has(i)||e.set(i,new Set);let r=this.templateManager.getDescriptionLanguage(o,"default",i);for(let c of r)e.get(i).add(c)}}for(let[s,o]of e)for(let a of o){let i=[];for(let[,h]of Object.entries(n)){let d=h.name,l=this.templateManager.getDescription(d,"default",a,s);l&&i.push({command:d,description:l})}if(i.length===0)continue;let r={type:s},c=a==="default"?void 0:a;try{let h=await this.bot.api.getMyCommands({scope:r,language_code:c}),d=JSON.stringify(h.map(m=>({command:m.command,description:m.description})).sort((m,y)=>m.command.localeCompare(y.command))),l=JSON.stringify(i.sort((m,y)=>m.command.localeCompare(y.command)));d!==l&&(await this.bot.api.setMyCommands(i,{scope:r,language_code:c}),this.log?.info?.(`Synced descriptions for scope: ${s},${c?` lang: ${c},`:""} total (${i.length})`))}catch(h){this.log?.error?.(`Failed to sync descriptions for scope: ${s},${c?` lang: ${c},`:""} error: ${String(h)}`)}}}pageLoads(){this.log?.info?.("Load pages..");let t=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],e=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],n=[...t,...e,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],s=p((i,r)=>Object.fromEntries(i.map(c=>[c,r()])),"makeObject"),o=p(()=>[],"initDynamicSpesific"),a={all:{},routeDynamic:[],routeDynamicSpesific:{text:o(),photo:o(),video:o(),audio:o(),document:o(),animation:o(),voice:o(),videoNote:o(),sticker:o(),location:o(),contact:o()},routeStatic:s(t,()=>({})),routeStaticIntent:s(e,()=>({})),routeStaticSession:s(n,()=>({})),listRouteStatic:t,listRouteStaticIntent:e,listRouteStaticSession:n,lenListRouteStatic:t.length,lenListRouteStaticIntent:e.length,lenListRouteStaticSession:n.length};return P.getFileManySync(void 0).forEach(({path:i,page:r},c)=>{this.pageBuildData(r,i),this.pageSorts(r,a,c),r.template=void 0}),this.log?.info?.(`Finish load pages with total (${Object.keys(a.all).length})`),a}async pageRoutes(t,e){let n,s;if(n===void 0){let a=await t.sessionGet();if(a){let i=a.method,r=this.pages.routeStaticSession,c=t.callbackData,h=t.msgText,d=t.msgCaption,l=c||h||d,m=e==="callback",y=m?"colon":"space",f=l&&t.havePayloads(l,y)?t.getIntent(l,y,1):void 0,g=!m&&l?t.getIntent(l,"space",2):void 0;for(let b=0;b<this.pages.lenListRouteStaticSession;b++){let k=this.pages.listRouteStaticSession[b];if(k.startsWith(e)){if(l){if(this.pages.routeStatic[k]?.[l])continue;let v=this.pages.routeStaticIntent[k];if(v&&(f&&v[f]||g&&v[g]))continue}s=r[k][i]}if(s)break}s!==void 0&&(n=this.pages.all[s.name])}}if(n===void 0){let a=t.callbackData,i=t.msgText,r=t.msgCaption,c=this.pages.routeStatic;for(let h=0;h<this.pages.lenListRouteStatic;h++){let d=this.pages.listRouteStatic[h];if(d.startsWith(e)&&(s=c[d][a||i||r]),s)break}s!==void 0&&(n=this.pages.all[s.name])}if(n===void 0){let a=this.pages.routeStaticIntent,i=e==="callback",r=i?"colon":"space",c=i?t.callbackData:t.msgText||t.msgCaption,h=t.havePayloads(c,r);if(c&&h)for(let d=0;d<this.pages.lenListRouteStaticIntent;d++){let l=this.pages.listRouteStaticIntent[d];if(!l.startsWith(e))continue;let m=a[l];if(s=m[t.getIntent(c,r,1)],!s&&!i&&(s=m[t.getIntent(c,"space",2)]),s)break}s!==void 0&&(n=this.pages.all[s.name])}if(n!==void 0&&s!==void 0){if(!n.prototype[s.routeName])return;let i=await new n(t)[s.routeName]?.();return t.temp.isAnswer===!0?i:null}let o=this.pages.routeDynamicSpesific[e]||[];for(let a=0;a<o.length;a++){let i=o[a];if(i===void 0)continue;let r=this.pages.all[i.name];r!==void 0&&typeof r.prototype[i.routeName]=="function"&&await new r(t)[i.routeName]()}for(let a=0;a<this.pages.routeDynamic.length;a++){let i=this.pages.routeDynamic[a];if(i===void 0)continue;let r=this.pages.all[i];r!==void 0&&typeof r.prototype.free=="function"&&await new r(t).free()}if(t.temp.isAnswer===!1)return null}async hookBeforeRoute(t,e){return!!(t||e)}async hookErrorPage(t,e,n,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,e){let n=this.createCtx(t);try{if(await this.hookBeforeRoute(n,e)===!1)return;await this.pageRoutes(n,e)===null&&await this.hookErrorInputNotFoundPage(n)}catch(s){await this.hookErrorPage(n,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(n){await this.hookErrorPage(e,"onCallbackQueryData",n,!0)}}async onMessageText(t){await this.onMessage(t,"text")}async onMessagePhoto(t){await this.onMessage(t,"photo")}async onMessageVideo(t){await this.onMessage(t,"video")}async onMessageAudio(t){await this.onMessage(t,"audio")}async onMessageDocument(t){await this.onMessage(t,"document")}async onMessageAnimation(t){await this.onMessage(t,"animation")}async onMessageVoice(t){await this.onMessage(t,"voice")}async onMessageVideoNote(t){await this.onMessage(t,"videoNote")}async onMessageSticker(t){await this.onMessage(t,"sticker")}async onMessageLocation(t){await this.onMessage(t,"location")}async onMessageContact(t){await this.onMessage(t,"contact")}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))}};var Y=class{static{p(this,"ComponentKeyboard")}static data;static _process(t,e){if(e.type||(e.type="inline"),e.lang){let n=t[e.lang];return`
8
8
  <keyboard type="${e.type}" lang="${e.lang}">${e.reverse?this.data._reverse(n):n}</keyboard>
9
9
  `}return Object.keys(t).map(n=>{let s=t[n];return`
10
10
  <keyboard type="${e.type}" lang="${n}">${e.reverse?this.data._reverse(s):s}</keyboard>
11
- `}).join(" ")}static _build(t,e,n){if(!this.data)throw new Error("Data not found");let s=this.data[t];if(!s)throw new Error(`Function ${t} not found`);return this._process(s.call(this.data,e),{type:n,lang:e})}};var Z=class{static{p(this,"DataKeyboard")}static _reverse(t){return t.split(/(?<!\\), */).reverse().join(", ")}static _reverseObj(t){return Object.keys(t).reduce((e,n)=>(e[n]=this._reverse(t[n]),e),{})}static _build(t,e,n){if(t){let s=n[t||""];return e?this._reverse(s):s}return e?this._reverseObj(n):n}};import{isMainThread as xt,Worker as It}from"worker_threads";var w=class{constructor(t,e){this.send=t;this.register=e}static{p(this,"WorkerThreadRpc")}map=new Map;async make(t){let e=this.map,n=this.send,{id:s,method:o,params:a,result:i,error:r}=t;if(o!==void 0)try{let c=this.register[o];if(typeof c!="function")throw new Error(`Method ${o} not found or not function`);let l=await c.apply(this.register,a);n({id:s,result:l})}catch(c){n({id:s,error:c instanceof Error?{message:c.message,stack:c.stack,name:c.name}:c})}else if(i!==void 0){let c=e.get(s);c&&(c.resolve(i),e.delete(s))}else if(r!==void 0){let c=e.get(s);c&&(c.reject(r),e.delete(s))}}makeId(){return Math.random()}makeRequest(t,e,n=!0,s){let o=this.makeId(),a={id:o,method:t,params:e,...s};return n?new Promise((i,r)=>{this.map.set(o,{resolve:i,reject:r}),this.send(a)}):this.send(a)}};var O=class{constructor(t,e){this.path=t;this.argv=e;this.init(),this.rpc=new w(this.send.bind(this),this)}static{p(this,"WorkerThreadLaunch")}static isMainThread=xt;_readyResolve;_readyPromise=new Promise(t=>this._readyResolve=t);pid=process.pid;thread={};threadId={};rpc={};ready(){return this._readyPromise}mtdReady(){this._readyResolve?.()}init(){this.thread=new It(this.path,{argv:this.argv.length==0&&this.argv[0]===void 0?void 0:this.argv}),this.threadId=this.thread.threadId,this.thread.on("message",t=>this.handleOnMessage(t)),this.thread.on("exit",()=>this.kill()),process.once("SIGINT",()=>this.kill()),process.once("SIGTERM",()=>this.kill())}async handleOnMessage(t){this.rpc.make(t)}kill(){this.thread.terminate()}send(t){this.thread.postMessage(t)}async request(t,e,n=!0,s){return this.rpc.makeRequest(t,e,n,s)}};var tt=class u{static{p(this,"WorkerThreadExport")}static gateway(t){let e=new Proxy({},{get(s,o){if(!(typeof o!="string"||o==="then"))return async(a,...i)=>{let r=a.gatewayClients.get(t);return r||(r=await a.createGatewayClient(t)),r.request(o,i)}}}),n=p(function(s){return new Proxy({},{get(o,a){if(!(typeof a!="string"||a==="then"))return async(...i)=>{let r=s.gatewayClients.get(t);return r||(r=await s.createGatewayClient(t)),r.request(a,i)}}})},"ctor");return Object.setPrototypeOf(n,e),n}static init(t){let{WTInit:e,WTLaunch:n=O,path:s,wrap:o}=t,a=`for-${s}`;if(process.argv[2]===a)return new e,{gateway:p(d=>u.gateway(d),"gateway")};let i,r=new Proxy({},{get(d,h){if(h!=="then")return h==="sendRequest"||h==="request"||h==="kill"||h==="send"?(...m)=>{if(!i)throw new Error(`Thread at ${s} not launched yet.`);return i[h](...m)}:(...m)=>{if(!i)throw new Error(`Thread at ${s} not launched yet.`);return i.request(h,m)}}}),l={...o?o(r):{},launchWorker:p(async(d=[])=>(i=new n(s,[a,...d]),await i.ready(),i),"launchWorker"),gateway:p(d=>u.gateway(d),"gateway")};return new Proxy(l,{get(d,h){if(h!=="then")return h==="gateway"?d.gateway:h==="launchWorker"?d.launchWorker:h in d?d[h]:typeof h=="string"?(...m)=>{if(!i)throw new Error(`Thread at ${s} not launched yet.`);return i.request(h,m)}:d[h]}})}};import{Client as _t}from"net-ipc";var W=class{static{p(this,"WorkerThreadGatewayClient")}client=new _t;rpc;constructor(){this.rpc=new w(t=>this.client.send(t),{}),this.client.on("message",t=>{this.rpc.make(t)})}async connect(t){this.client.options.path=t;let e=new Promise(n=>{this.client.once("ready",()=>n(this))});return await this.client.connect(),e}async request(t,e,n=!0,s){return this.rpc.makeRequest(t,e,n,s)}};import{Server as Mt}from"net-ipc";var $=class{static{p(this,"WorkerThreadGatewayServer")}server=new Mt;rpc=new Map;methods={};constructor(){this.server.on("connect",t=>{let e=new w(n=>t.send(n),this.methods);this.rpc.set(t.id,e)}),this.server.on("disconnect",t=>{this.rpc.delete(t.id)}),this.server.on("message",(t,e)=>{let n=this.rpc.get(e.id);n&&n.make(t)}),this.server.on("error",t=>{console.error(t)})}async start(t,e={}){this.methods=e,this.server.options.path=t;let n=new Promise(s=>{this.server.once("ready",()=>s(this))});return await this.server.start(),n}};import{parentPort as Ft,threadId as Rt,isMainThread as Dt}from"worker_threads";var et=class{static{p(this,"WorkerThreadInit")}argv=process.argv;id=Rt;pid=process.pid;rpc={};parentPort=Ft;gatewayServer;gatewayClients=new Map;gatewayClientLatest;get gatewayClient(){return this.gatewayClientLatest}static isMainThread=Dt;constructor(){this.init(),this.rpc=new w(this.send.bind(this),this),this.send({method:"mtdReady"})}init(){this.parentPort?.on("message",t=>this.handleOnMessage(t))}handleOnMessage(t){this.rpc.make(t)}send(t){this.parentPort?.postMessage(t)}request(t,e,n=!0,s){return this.rpc.makeRequest(t,e,n,s)}async createGatewayServer(t,e={}){return this.gatewayServer=new $,await this.gatewayServer.start(t,e),!0}async createGatewayClient(t){let e=new W;return await e.connect(t),this.gatewayClients.set(t,e),this.gatewayClientLatest=e,e}};var st=class{static{p(this,"WorkerThreadPool")}thread=new Map;threadCount=0;constructor(t){this.addMany(t)}add(t){this.thread.set(t.threadId,t),this.threadCount+=1}addMany(t){t.forEach(e=>this.add(e))}getInstance(t){return this.thread.get(t)}kill(t){let e=this.thread.get(t);return e?.kill(),this.thread.delete(t),this.threadCount-=1,e?.threadId}killAll(){this.thread.values().forEach(({threadId:t})=>this.kill(t))}async broadcastRequest(t,e){return await Promise.all(Object.values(this.thread).map(n=>n.request(t,e,!0)))}async request(t,e,n,s=!0,o){return await this.thread.get(t)?.request(e,n,s,o)}};export{R as CacheExternal,Y as ComponentKeyboard,D as Ctx,Z as DataKeyboard,z as Gramstax,N as LoggingUtils,v as TemplateEngine,A as TemplateManager,tt as WorkerThreadExport,W as WorkerThreadGatewayClient,$ as WorkerThreadGatewayServer,et as WorkerThreadInit,O as WorkerThreadLaunch,st as WorkerThreadPool,w as WorkerThreadRpc,Nt as log};
11
+ `}).join(" ")}static _build(t,e,n){if(!this.data)throw new Error("Data not found");let s=this.data[t];if(!s)throw new Error(`Function ${t} not found`);return this._process(s.call(this.data,e),{type:n,lang:e})}};var Z=class{static{p(this,"DataKeyboard")}static _reverse(t){return t.split(/(?<!\\), */).reverse().join(", ")}static _reverseObj(t){return Object.keys(t).reduce((e,n)=>(e[n]=this._reverse(t[n]),e),{})}static _build(t,e,n){if(t){let s=n[t||""];return e?this._reverse(s):s}return e?this._reverseObj(n):n}};import{isMainThread as xt,Worker as It}from"worker_threads";var w=class{constructor(t,e){this.send=t;this.register=e}static{p(this,"WorkerThreadRpc")}map=new Map;async make(t){let e=this.map,n=this.send,{id:s,method:o,params:a,result:i,error:r}=t;if(o!==void 0)try{let c=this.register[o];if(typeof c!="function")throw new Error(`Method ${o} not found or not function`);let h=await c.apply(this.register,a);n({id:s,result:h})}catch(c){n({id:s,error:c instanceof Error?{message:c.message,stack:c.stack,name:c.name}:c})}else if(i!==void 0){let c=e.get(s);c&&(c.resolve(i),e.delete(s))}else if(r!==void 0){let c=e.get(s);c&&(c.reject(r),e.delete(s))}}makeId(){return Math.random()}makeRequest(t,e,n=!0,s){let o=this.makeId(),a={id:o,method:t,params:e,...s};return n?new Promise((i,r)=>{this.map.set(o,{resolve:i,reject:r}),this.send(a)}):this.send(a)}};var O=class{constructor(t,e){this.path=t;this.argv=e;this.init(),this.rpc=new w(this.send.bind(this),this)}static{p(this,"WorkerThreadLaunch")}static isMainThread=xt;_readyResolve;_readyPromise=new Promise(t=>this._readyResolve=t);pid=process.pid;thread={};threadId={};rpc={};ready(){return this._readyPromise}mtdReady(){this._readyResolve?.()}init(){this.thread=new It(this.path,{argv:this.argv.length==0&&this.argv[0]===void 0?void 0:this.argv}),this.threadId=this.thread.threadId,this.thread.on("message",t=>this.handleOnMessage(t)),this.thread.on("exit",()=>this.kill()),process.once("SIGINT",()=>this.kill()),process.once("SIGTERM",()=>this.kill())}async handleOnMessage(t){this.rpc.make(t)}kill(){this.thread.terminate()}send(t){this.thread.postMessage(t)}async request(t,e,n=!0,s){return this.rpc.makeRequest(t,e,n,s)}};var tt=class u{static{p(this,"WorkerThreadExport")}static launchGatewayClient(t){let e=new Proxy({},{get(s,o){if(!(typeof o!="string"||o==="then"))return async(a,...i)=>{let r=a.gatewayClients.get(t);return r||(r=await a.createGatewayClient(t)),r.request(o,i)}}}),n=p(function(s){return new Proxy({},{get(o,a){if(!(typeof a!="string"||a==="then"))return async(...i)=>{let r=s.gatewayClients.get(t);return r||(r=await s.createGatewayClient(t)),r.request(a,i)}}})},"ctor");return Object.setPrototypeOf(n,e),n}static init(t){let{WTInit:e,WTLaunch:n=O,path:s,wrap:o}=t,a=`for-${s}`;if(process.argv[2]===a)return new e,{launchGatewayClient:p(d=>u.launchGatewayClient(d||e.gatewayServerPath),"launchGatewayClient")};let i,r=new Proxy({},{get(d,l){if(l!=="then")return l==="sendRequest"||l==="request"||l==="kill"||l==="send"?(...m)=>{if(!i)throw new Error(`Thread at ${s} not launched yet.`);return i[l](...m)}:(...m)=>{if(!i)throw new Error(`Thread at ${s} not launched yet.`);return i.request(l,m)}}}),h={...o?o(r):{},launchWorker:p(async(d=[])=>(i=new n(s,[a,...d]),await i.ready(),i),"launchWorker"),launchGatewayClient:p(d=>u.launchGatewayClient(d||e.gatewayServerPath),"launchGatewayClient")};return new Proxy(h,{get(d,l){if(l!=="then")return l==="launchGatewayClient"?d.launchGatewayClient:l==="launchWorker"?d.launchWorker:l in d?d[l]:typeof l=="string"?(...m)=>{if(!i)throw new Error(`Thread at ${s} not launched yet.`);return i.request(l,m)}:d[l]}})}};import{Client as _t}from"net-ipc";var B=class{static{p(this,"WorkerThreadGatewayClient")}client=new _t;rpc;constructor(){this.rpc=new w(t=>this.client.send(t),{}),this.client.on("message",t=>{this.rpc.make(t)})}async connect(t){this.client.options.path=t;let e=new Promise(n=>{this.client.once("ready",()=>n(this))});return await this.client.connect(),e}async request(t,e,n=!0,s){return this.rpc.makeRequest(t,e,n,s)}};import{Server as Mt}from"net-ipc";var W=class{static{p(this,"WorkerThreadGatewayServer")}server=new Mt;rpc=new Map;methods={};constructor(){this.server.on("connect",t=>{let e=new w(n=>t.send(n),this.methods);this.rpc.set(t.id,e)}),this.server.on("disconnect",t=>{this.rpc.delete(t.id)}),this.server.on("message",(t,e)=>{let n=this.rpc.get(e.id);n&&n.make(t)}),this.server.on("error",t=>{console.error(t)})}async start(t,e={}){this.methods=e,this.server.options.path=t;let n=new Promise(s=>{this.server.once("ready",()=>s(this))});return await this.server.start(),n}};import{parentPort as Ft,threadId as Rt,isMainThread as Dt}from"worker_threads";var et=class{static{p(this,"WorkerThreadInit")}argv=process.argv;id=Rt;pid=process.pid;rpc={};parentPort=Ft;gatewayServer;gatewayClients=new Map;gatewayClientLatest;static gatewayServerPath;gatewayServerPath=this.constructor.gatewayServerPath;get gatewayClient(){return this.gatewayClientLatest}static isMainThread=Dt;constructor(){this.init(),this.rpc=new w(this.send.bind(this),this),this.send({method:"mtdReady"})}init(){this.parentPort?.on("message",t=>this.handleOnMessage(t))}handleOnMessage(t){this.rpc.make(t)}send(t){this.parentPort?.postMessage(t)}request(t,e,n=!0,s){return this.rpc.makeRequest(t,e,n,s)}async createGatewayServer(t,e){return t||(t=this),e||(e=this.constructor.gatewayServerPath),this.gatewayServer=new W,await this.gatewayServer.start(e,t),this.constructor.gatewayServerPath=e,!0}async createGatewayClient(t){let e=new B;return await e.connect(t),this.gatewayClients.set(t,e),this.gatewayClientLatest=e,e}};var st=class{static{p(this,"WorkerThreadPool")}thread=new Map;threadCount=0;constructor(t){this.addMany(t)}add(t){this.thread.set(t.threadId,t),this.threadCount+=1}addMany(t){t.forEach(e=>this.add(e))}getInstance(t){return this.thread.get(t)}kill(t){let e=this.thread.get(t);return e?.kill(),this.thread.delete(t),this.threadCount-=1,e?.threadId}killAll(){this.thread.values().forEach(({threadId:t})=>this.kill(t))}async broadcastRequest(t,e){return await Promise.all(Object.values(this.thread).map(n=>n.request(t,e,!0)))}async request(t,e,n,s=!0,o){return await this.thread.get(t)?.request(e,n,s,o)}};export{R as CacheExternal,Y as ComponentKeyboard,D as Ctx,Z as DataKeyboard,z as Gramstax,N as LoggingUtils,T as TemplateEngine,A as TemplateManager,tt as WorkerThreadExport,B as WorkerThreadGatewayClient,W as WorkerThreadGatewayServer,et as WorkerThreadInit,O as WorkerThreadLaunch,st as WorkerThreadPool,w as WorkerThreadRpc,Nt as log};
package/package.json CHANGED
@@ -1,21 +1,13 @@
1
1
  {
2
2
  "name": "gramstax",
3
- "version": "0.3.19",
3
+ "version": "0.3.21",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": false
8
8
  },
9
- "description": "A powerful Telegram bot framework with page-based routing and template system",
10
- "keywords": [
11
- "telegram",
12
- "bot",
13
- "grammy",
14
- "telegram-bot",
15
- "bot-framework",
16
- "bot-framework",
17
- "gramstax"
18
- ],
9
+ "description": "",
10
+ "keywords": [],
19
11
  "scripts": {
20
12
  "nx-release-publish": "npm publish --access public"
21
13
  },
@@ -28,7 +20,7 @@
28
20
  },
29
21
  "homepage": "https://github.com/gramstax/gramstax",
30
22
  "author": "gramstax",
31
- "license": "MIT",
23
+ "license": "PROPRIETARY",
32
24
  "type": "module",
33
25
  "main": "./dist/src/index.js",
34
26
  "module": "./dist/src/index.mjs",