gramstax 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/index.cjs +1 -1
- package/dist/src/index.d.cts +0 -2
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +1 -1
- package/package.json +1 -1
package/dist/src/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ye=Object.create;var V=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var Te=Object.getPrototypeOf,be=Object.prototype.hasOwnProperty;var p=(u,e)=>V(u,"name",{value:e,configurable:!0});var Se=(u,e)=>{for(var t in e)V(u,t,{get:e[t],enumerable:!0})},ie=(u,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ce(e))!be.call(u,s)&&s!==t&&V(u,s,{get:()=>e[s],enumerable:!(n=fe(e,s))||n.enumerable});return u};var oe=(u,e,t)=>(t=u!=null?ye(Te(u)):{},ie(e||!u||!u.__esModule?V(t,"default",{value:u,enumerable:!0}):t,u)),ke=u=>ie(V({},"__esModule",{value:!0}),u);var _e={};Se(_e,{BlockKeyboard:()=>X,CacheExternal:()=>W,Ctx:()=>K,Gramstax:()=>J,LabelKeyboard:()=>Y,LoggingUtil:()=>Q,MockTelegramServer:()=>se,PageManager:()=>x,TemplateEngine:()=>M,TemplateManager:()=>$,WebhookQueue:()=>E,WorkerThreadExport:()=>Z,WorkerThreadGatewayClient:()=>j,WorkerThreadGatewayServer:()=>q,WorkerThreadInit:()=>ee,WorkerThreadLaunch:()=>N,WorkerThreadPool:()=>te,WorkerThreadRpc:()=>P,log:()=>z});module.exports=ke(_e);var we=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"),f=we();var ae=require("logging-pretty");var Q=class extends ae.LoggingPretty{static{p(this,"LoggingUtil")}timers=new Map;constructor(e){super(e)}errorMake(e,t,n){this.error(`[${t?`${t}:${n}`:n}] ${this._formatErrorObj(e)}`)}_formatErrorObj(e){return JSON.stringify(e instanceof Error?{message:e.message,stack:e.stack,name:e.name}:e,null,2)}time(e){this.timers.set(e,process.hrtime.bigint())}timeEnd(e,t){let n=this.timers.get(e);if(n===void 0){this.debug(`${e}: Timer was never started`);return}let s=(Number(process.hrtime.bigint()-n)/1e6).toFixed(3);this.timers.delete(e),t?this.debug(`${t} (took ${s}ms)`):this.debug(`${e} (took ${s}ms)`)}timeCheck(e){let t=this.timers.get(e);if(t!==void 0)return(Number(process.hrtime.bigint()-t)/1e6).toFixed(3)}timeLog(e,t){let n=this.timeCheck(e);if(n===void 0){this.debug(`${e}: Timer was never started`);return}t?this.debug(`${t} (${n}ms)`):this.debug(`${e} (${n}ms)`)}timeClear(){this.timers.clear()}timeActive(){return Array.from(this.timers.keys())}},z=new Q;var re=require("keyv"),ce=oe(require("@keyv/redis"),1);var W=class extends re.Keyv{constructor(t="memory",n,s,i){let o;t.startsWith("redis")&&(o=new ce.default(t)),t==="memory"&&(o=new Map),i?.forceStore&&(o=i.forceStore);super({store:o,namespace:s,ttl:n});this.url=t}static{p(this,"CacheExternal")}refreshLruCache(t){let n=this.store,s=this.opts.namespace?this.opts.namespace?.length+1:null,i=n.keys().toArray();for(let o=0;o<i.length;o++){let a=i[o];if(o==t)return;this.get(s?a.slice(s):a)}}};var H=require("timers/promises"),O=require("grammy");var K=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(e){this.ct.from.language_code=e}get msgText(){return this.ct.message?.text}get msgTextArgs(){return this.getArgs(this.msgText,"space",this.data?._positionArgText||this.temp?.data?._positionArgText)}get msgTextArg(){return this.msgTextArgs[0]}get msgTextCommandArgs(){return this.getArgs(this.msgText,"space")}get msgTextCommandArg(){return this.msgTextCommandArgs[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionArgs(){return this.getArgs(this.msgCaption,"space")}get msgCaptionArg(){return this.msgCaptionArgs[0]}get msgCaptionCommandArgs(){return this.getArgs(this.msgCaption,"space")}get msgCaptionCommandArg(){return this.msgCaptionCommandArgs[0]}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get msgDocument(){return this.ct.message?.document}get msgAnimation(){return this.ct.message?.animation}get msgVoice(){return this.ct.message?.voice}get msgVideoNote(){return this.ct.message?.video_note}get msgSticker(){return this.ct.message?.sticker}get msgLocation(){return this.ct.message?.location}get msgContact(){return this.ct.message?.contact}get msgWebAppData(){return this.ct.message?.web_app_data}get msgGift(){return this.ct.message?.gift}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataArgs(){return this.getArgs(this.callbackData,"colon")}get callbackDataArg(){return this.callbackDataArgs?.[0]}get session(){return this.temp.session}set session(e){this.temp.session=e}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(e){this.ct=e.ct,this.cacheSession=e.cacheSession,this.cacheKeyboard=e.cacheKeyboard,this.templateManager=e.templateManager,this.temp=e.temp}async broadcast(e,t,n,s,i,o,a=!1){try{this.temp.isAnswer=!0;let r=30,c=t.map(l=>this.templateManager.getMessage(this.data.name,i,l,s));for(let l=0;l<e.length;l++){let d=e[l],h=c[l];await this.ct.api.sendMessage(d,h,{parse_mode:"HTML",reply_markup:n,...o}),l+1==r&&await(0,H.setTimeout)(1200)}}catch(r){if(a)throw r}}async broadcastMedia(e,t,n,s,i,o,a=!1){try{this.temp.isAnswer=!0;let r=30,c=t.map(l=>this.templateManager.getMedia(this.data.name,i,l,s));for(let l=0;l<e.length;l++){let d=e[l],h=c[l];if(!h)continue;let m={parse_mode:"HTML",reply_markup:n,...o};h.type=="photo"&&await this.ct.api.sendPhoto(d,h.src,{caption:h.caption,...m}),h.type=="video"&&await this.ct.api.sendVideo(d,h.src,{caption:h.caption,...m}),h.type=="audio"&&await this.ct.api.sendAudio(d,h.src,{caption:h.caption,...m}),h.type=="document"&&await this.ct.api.sendDocument(d,h.src,{caption:h.caption,...m}),h.type=="animation"&&await this.ct.api.sendAnimation(d,h.src,{caption:h.caption,...m}),h.type=="voice"&&await this.ct.api.sendVoice(d,h.src,m),h.type=="video_note"&&await this.ct.api.sendVideoNote(d,h.src,m),h.type=="sticker"&&await this.ct.api.sendSticker(d,h.src,m),h.type=="location"&&await this.ct.api.sendLocation(d,parseInt(h.latitude),parseInt(h.longitude),m),h.type=="contact"&&await this.ct.api.sendContact(d,h.phone,h.first_name,{vcard:h.vcard,...m}),l+1==r&&await(0,H.setTimeout)(1200)}}catch(r){if(a)throw r}}async reply(e,t,n,s){this.temp.isAnswer=!0;let i=this.templateManager.getMessage(this.data.name,n,this.userLanguage,t);return await this.ct.reply(i,{parse_mode:"HTML",reply_markup:e,...s})}async replyMedia(e,t,n,s,i){this.temp.isAnswer=!0;let o=this.templateManager.getMedia(this.data.name,s,this.userLanguage,n),a={parse_mode:"HTML",reply_markup:t,...i};if(e=="photo")return await this.ct.replyWithPhoto(o.src,{caption:o.caption,...a});if(e=="video")return await this.ct.replyWithVideo(o.src,{caption:o.caption,...a});if(e=="audio")return await this.ct.replyWithAudio(o.src,{caption:o.caption,...a});if(e=="document")return await this.ct.replyWithDocument(o.src,{caption:o.caption,...a});if(e=="animation")return await this.ct.replyWithAnimation(o.src,{caption:o.caption,...a});if(e=="voice")return await this.ct.replyWithVoice(o.src,a);if(e=="video_note")return await this.ct.replyWithVideoNote(o.src,a);if(e=="sticker")return await this.ct.replyWithSticker(o.src,a);if(e=="location")return await this.ct.replyWithLocation(parseInt(o.latitude),parseInt(o.longitude),a);if(e=="contact")return await this.ct.replyWithContact(o.phone,o.first_name,{vcard:o.vcard,...a})}async replyPhoto(e,t,n,s){return this.replyMedia("photo",e,t,n,s)}async replyVideo(e,t,n,s){return this.replyMedia("video",e,t,n,s)}async replyAudio(e,t,n,s){return this.replyMedia("audio",e,t,n,s)}async replyDocument(e,t,n,s){return this.replyMedia("document",e,t,n,s)}async replyAnimation(e,t,n,s){return this.replyMedia("animation",e,t,n,s)}async replyVoice(e,t,n,s){return this.replyMedia("voice",e,t,n,s)}async replyVideoNote(e,t,n,s){return this.replyMedia("video_note",e,t,n,s)}async replySticker(e,t,n,s){return this.replyMedia("sticker",e,t,n,s)}async replyLocation(e,t,n,s){return this.replyMedia("location",e,t,n,s)}async replyContact(e,t,n,s){return this.replyMedia("contact",e,t,n,s)}async replyAction(e){return await this.ct.replyWithChatAction(e)}async edit(e,t,n,s,i=!0){try{this.temp.isAnswer=!0;let o=this.templateManager.getMessage(this.data.name,n,this.userLanguage,t);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:e,...s})}catch(o){if(i)await this.reply(e,t,n,s);else throw o}}async editMedia(e,t,n,s,i,o,a=!0){try{this.temp.isAnswer=!0;let{src:r,caption:c}=this.templateManager.getMedia(this.data.name,s,this.userLanguage,n);return e=="voice"?(await this.delete(),await this.replyVoice(t,n,s,i)):e=="video_note"?(await this.delete(),await this.replyVoice(t,n,s,i)):e=="sticker"?(await this.delete(),await this.replySticker(t,n,s,i)):e=="location"?(await this.delete(),await this.replyLocation(t,n,s,i)):e=="contact"?(await this.delete(),await this.replyContact(t,n,s,i)):await this.ct.editMessageMedia({media:r,caption:c,type:e,parse_mode:"HTML",...i},{reply_markup:t,...o})}catch(r){if(a===!0)await this.reply(t,n,s,o);else throw r}}async editPhoto(e,t,n,s,i){return await this.editMedia("photo",e,t,n,s,i)}async editVideo(e,t,n,s,i){return await this.editMedia("video",e,t,n,s,i)}async editAudio(e,t,n,s,i){return await this.editMedia("audio",e,t,n,s,i)}async editDocument(e,t,n,s,i){return await this.editMedia("document",e,t,n,s,i)}async editAnimation(e,t,n,s,i){return await this.editMedia("animation",e,t,n,s,i)}async editVoice(e,t,n,s){return await this.editMedia("voice",e,t,n,s)}async editVideoNote(e,t,n,s){return await this.editMedia("video_note",e,t,n,s)}async editSticker(e,t,n,s){return await this.editMedia("sticker",e,t,n,s)}async editLocation(e,t,n,s){return await this.editMedia("location",e,t,n,s)}async editContact(e,t,n,s){return await this.editMedia("contact",e,t,n,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(e){try{return this.temp.isAnswer=!0,await this.ct.answerCallbackQuery(e)}catch{return null}}async setSession(e,t,n){try{let s={method:e,params:t,...n},i=await this.cacheSession.set(`${this.userId}`,s);return i&&(this.temp.session=s),i}catch{return null}}async getSession(){try{let e=await this.cacheSession.get(`${this.userId}`);return e&&(this.temp.session=e),e||null}catch{return null}}async clearSession(){try{let e=await this.cacheSession.delete(`${this.userId}`);return e&&(this.temp.session={}),e}catch{return null}}static buildData(e){let n=typeof e=="function"?{callbackData:e}:e||{},s=n.callbackData,i=this.prototype.addArgs.bind(this.prototype),o=n.name||"";return{name:o,intentText:n.intentText||o,intentCommandText:n.intentCommandText||o,intentCallbackData:o,callbackData:s?function(...r){return i(this.intentCallbackData,"colon",s(...r))}:function(){return this?.intentCallbackData},_positionArgText:n.intentText?n.intentText.split(this.prototype.getSeperatorTag("space")).length:void 0}}keyboardCols(e,t,n,s){let[i,o]=n.split("-"),a=parseInt(i),r=o?parseInt(o):null,c=t.length,l=e;for(let d=0;d<c;d++){let h=t[d];if(s(h,d),r===null)(d+1)%a===0&&d<c-1&&l.row();else{let m=c-(d+1);(m===r||m>r&&(d+1)%a===0)&&l.row()}}return e}bottomKeyboardT(e="1",t,n){return this.bottomKeyboard((s,i)=>this.keyboardCols(s,i,e,o=>s.text(o)),{baseId:t??void 0,data:n})}inlineKeyboardT(e,t="1",n,s){return this.inlineKeyboard((i,o)=>this.keyboardCols(i,o,t,(a,r)=>{let c=e[r],l=typeof c=="string"?c:c.data.callbackData();i.text(a,l)}),{baseId:n??void 0,data:s})}inlineKeyboard(e,t){let n=this.data.name;if(t?.cache===!0){let a=`${n}:${this.userLanguage}:i`,r=this.cacheKeyboard.get(a);if(!r){let c=new O.InlineKeyboard,l=this.templateManager.getKeyboard(n,t?.baseId,this.userLanguage,"inline",t?.data),d=e(c,l);return this.cacheKeyboard.set(a,d),d}return r}let s=new O.InlineKeyboard,i=this.templateManager.getKeyboard(n,t?.baseId,this.userLanguage,"inline",t?.data);return e(s,i)}bottomKeyboard(e,t){let n=this.data.name;if(t?.cache===!0){let a=`${n}:${this.userLanguage}:b`,r=this.cacheKeyboard.get(a);if(!r){let c=new O.Keyboard,l=this.templateManager.getKeyboard(n,t?.baseId,this.userLanguage,"bottom",t?.data),d=e(c,l);return d.resized(!0),this.cacheKeyboard.set(a,d),d}return r}let s=new O.Keyboard,i=this.templateManager.getKeyboard(n,t?.baseId,this.userLanguage,"bottom",t?.data),o=e(s,i);return o.resized(),o}getSeperatorTag(e="space"){return e=="space"?" ":":"}haveArgs(e="",t){return e.includes(this.getSeperatorTag(t))}addArgs(e="",t,n){let s=this.getSeperatorTag(t),i="";for(let o=0;o<n.length;o++){let a=n[o];a!=null&&a!==""&&(i+=s+a)}return e+i}getArgs(e="",t,n=1){if(!e)return[];let s=this.getSeperatorTag(t);return e.split(s).slice(n)}getIntent(e="",t,n=1){if(!e)return"";let s=this.getSeperatorTag(t),i=e.split(s);return n==1?i[0]:i.slice(0,n).join(s)}isSessionCallbackData(){return this.temp.session.method===this.methodSessionCallbackData()}isSessionArgsCallbackData(){return this.temp.session.method===this.methodSessionArgsCallbackData()}isSessionText(){return this.temp.session.method===this.methodSessionText()}isSessionArgsText(){return this.temp.session.method===this.methodSessionArgsText()}isSessionCommandText(){return this.temp.session.method===this.methodSessionCommandText()}isSessionCommandArgsText(){return this.temp.session.method===this.methodSessionCommandArgsText()}isSessionFreeText(){return this.temp.session.method===this.methodSessionFreeText()}isSessionCaptionPhoto(){return this.temp.session.method===this.methodSessionCaptionPhoto()}isSessionCaptionArgsPhoto(){return this.temp.session.method===this.methodSessionCaptionArgsPhoto()}isSessionCommandCaptionPhoto(){return this.temp.session.method===this.methodSessionCommandCaptionPhoto()}isSessionCommandCaptionArgsPhoto(){return this.temp.session.method===this.methodSessionCommandCaptionArgsPhoto()}isSessionFreePhoto(){return this.temp.session.method===this.methodSessionFreePhoto()}isSessionCaptionVideo(){return this.temp.session.method===this.methodSessionCaptionVideo()}isSessionCaptionArgsVideo(){return this.temp.session.method===this.methodSessionCaptionArgsVideo()}isSessionCommandCaptionVideo(){return this.temp.session.method===this.methodSessionCommandCaptionVideo()}isSessionCommandCaptionArgsVideo(){return this.temp.session.method===this.methodSessionCommandCaptionArgsVideo()}isSessionFreeVideo(){return this.temp.session.method===this.methodSessionFreeVideo()}isSessionCaptionAudio(){return this.temp.session.method===this.methodSessionCaptionAudio()}isSessionCaptionArgsAudio(){return this.temp.session.method===this.methodSessionCaptionArgsAudio()}isSessionCaptionCommandAudio(){return this.temp.session.method===this.methodSessionCaptionCommandAudio()}isSessionCaptionCommandArgsAudio(){return this.temp.session.method===this.methodSessionCaptionCommandArgsAudio()}isSessionFreeAudio(){return this.temp.session.method===this.methodSessionFreeAudio()}isSessionCaptionDocument(){return this.temp.session.method===this.methodSessionCaptionDocument()}isSessionCaptionArgsDocument(){return this.temp.session.method===this.methodSessionCaptionArgsDocument()}isSessionCommandCaptionDocument(){return this.temp.session.method===this.methodSessionCommandCaptionDocument()}isSessionCommandCaptionArgsDocument(){return this.temp.session.method===this.methodSessionCommandCaptionArgsDocument()}isSessionFreeDocument(){return this.temp.session.method===this.methodSessionFreeDocument()}isSessionCaptionAnimation(){return this.temp.session.method===this.methodSessionCaptionAnimation()}isSessionCaptionArgsAnimation(){return this.temp.session.method===this.methodSessionCaptionArgsAnimation()}isSessionCommandCaptionAnimation(){return this.temp.session.method===this.methodSessionCommandCaptionAnimation()}isSessionCommandCaptionArgsAnimation(){return this.temp.session.method===this.methodSessionCommandCaptionArgsAnimation()}isSessionFreeAnimation(){return this.temp.session.method===this.methodSessionFreeAnimation()}isSessionCaptionVoice(){return this.temp.session.method===this.methodSessionCaptionVoice()}isSessionCaptionArgsVoice(){return this.temp.session.method===this.methodSessionCaptionArgsVoice()}isSessionCommandCaptionVoice(){return this.temp.session.method===this.methodSessionCommandCaptionVoice()}isSessionCommandCaptionArgsVoice(){return this.temp.session.method===this.methodSessionCommandCaptionArgsVoice()}isSessionFreeVoice(){return this.temp.session.method===this.methodSessionFreeVoice()}isSessionFreeVideoNote(){return this.temp.session.method===this.methodSessionFreeVideoNote()}isSessionFreeSticker(){return this.temp.session.method===this.methodSessionFreeSticker()}isSessionFreeLocation(){return this.temp.session.method===this.methodSessionFreeLocation()}isSessionFreeContact(){return this.temp.session.method===this.methodSessionFreeContact()}sessionCallbackData(e){return this.setSession(this.methodSessionCallbackData(),e)}sessionArgsCallbackData(e){return this.setSession(this.methodSessionArgsCallbackData(),e)}sessionText(e){return this.setSession(this.methodSessionText(),e)}sessionArgsText(e){return this.setSession(this.methodSessionArgsText(),e)}sessionCommandText(e){return this.setSession(this.methodSessionCommandText(),e)}sessionCommandArgsText(e){return this.setSession(this.methodSessionCommandArgsText(),e)}sessionFreeText(e){return this.setSession(this.methodSessionFreeText(),e)}sessionCaptionPhoto(e){return this.setSession(this.methodSessionCaptionPhoto(),e)}sessionCaptionArgsPhoto(e){return this.setSession(this.methodSessionCaptionArgsPhoto(),e)}sessionCommandCaptionPhoto(e){return this.setSession(this.methodSessionCommandCaptionPhoto(),e)}sessionCommandCaptionArgsPhoto(e){return this.setSession(this.methodSessionCommandCaptionArgsPhoto(),e)}sessionFreePhoto(e){return this.setSession(this.methodSessionFreePhoto(),e)}sessionCaptionVideo(e){return this.setSession(this.methodSessionCaptionVideo(),e)}sessionCaptionArgsVideo(e){return this.setSession(this.methodSessionCaptionArgsVideo(),e)}sessionCommandCaptionVideo(e){return this.setSession(this.methodSessionCommandCaptionVideo(),e)}sessionCommandCaptionArgsVideo(e){return this.setSession(this.methodSessionCommandCaptionArgsVideo(),e)}sessionFreeVideo(e){return this.setSession(this.methodSessionFreeVideo(),e)}sessionCaptionAudio(e){return this.setSession(this.methodSessionCaptionAudio(),e)}sessionCaptionArgsAudio(e){return this.setSession(this.methodSessionCaptionArgsAudio(),e)}sessionCaptionCommandAudio(e){return this.setSession(this.methodSessionCaptionCommandAudio(),e)}sessionCaptionCommandArgsAudio(e){return this.setSession(this.methodSessionCaptionCommandArgsAudio(),e)}sessionFreeAudio(e){return this.setSession(this.methodSessionFreeAudio(),e)}sessionCaptionDocument(e){return this.setSession(this.methodSessionCaptionDocument(),e)}sessionCaptionArgsDocument(e){return this.setSession(this.methodSessionCaptionArgsDocument(),e)}sessionCommandCaptionDocument(e){return this.setSession(this.methodSessionCommandCaptionDocument(),e)}sessionCommandCaptionArgsDocument(e){return this.setSession(this.methodSessionCommandCaptionArgsDocument(),e)}sessionFreeDocument(e){return this.setSession(this.methodSessionFreeDocument(),e)}sessionCaptionAnimation(e){return this.setSession(this.methodSessionCaptionAnimation(),e)}sessionCaptionArgsAnimation(e){return this.setSession(this.methodSessionCaptionArgsAnimation(),e)}sessionCommandCaptionAnimation(e){return this.setSession(this.methodSessionCommandCaptionAnimation(),e)}sessionCommandCaptionArgsAnimation(e){return this.setSession(this.methodSessionCommandCaptionArgsAnimation(),e)}sessionFreeAnimation(e){return this.setSession(this.methodSessionFreeAnimation(),e)}sessionCaptionVoice(e){return this.setSession(this.methodSessionCaptionVoice(),e)}sessionCaptionArgsVoice(e){return this.setSession(this.methodSessionCaptionArgsVoice(),e)}sessionCommandCaptionVoice(e){return this.setSession(this.methodSessionCommandCaptionVoice(),e)}sessionCommandCaptionArgsVoice(e){return this.setSession(this.methodSessionCommandCaptionArgsVoice(),e)}sessionFreeVoice(e){return this.setSession(this.methodSessionFreeVoice(),e)}sessionFreeVideoNote(e){return this.setSession(this.methodSessionFreeVideoNote(),e)}sessionFreeSticker(e){return this.setSession(this.methodSessionFreeSticker(),e)}sessionFreeLocation(e){return this.setSession(this.methodSessionFreeLocation(),e)}sessionFreeContact(e){return this.setSession(this.methodSessionFreeContact(),e)}methodSession(e,t){return`${e}-${t||this.data.name}`}methodSessionCallbackData(e){return this.methodSession("1",e)}methodSessionArgsCallbackData(e){return this.methodSession("2",e)}methodSessionText(e){return this.methodSession("3",e)}methodSessionArgsText(e){return this.methodSession("4",e)}methodSessionCommandText(e){return this.methodSession("5",e)}methodSessionCommandArgsText(e){return this.methodSession("6",e)}methodSessionFreeText(e){return this.methodSession("7",e)}methodSessionCaptionPhoto(e){return this.methodSession("8",e)}methodSessionCaptionArgsPhoto(e){return this.methodSession("9",e)}methodSessionCommandCaptionPhoto(e){return this.methodSession("10",e)}methodSessionCommandCaptionArgsPhoto(e){return this.methodSession("11",e)}methodSessionFreePhoto(e){return this.methodSession("12",e)}methodSessionCaptionVideo(e){return this.methodSession("13",e)}methodSessionCaptionArgsVideo(e){return this.methodSession("14",e)}methodSessionCommandCaptionVideo(e){return this.methodSession("15",e)}methodSessionCommandCaptionArgsVideo(e){return this.methodSession("16",e)}methodSessionFreeVideo(e){return this.methodSession("17",e)}methodSessionCaptionAudio(e){return this.methodSession("18",e)}methodSessionCaptionArgsAudio(e){return this.methodSession("19",e)}methodSessionCaptionCommandAudio(e){return this.methodSession("20",e)}methodSessionCaptionCommandArgsAudio(e){return this.methodSession("21",e)}methodSessionFreeAudio(e){return this.methodSession("22",e)}methodSessionCaptionDocument(e){return this.methodSession("23",e)}methodSessionCaptionArgsDocument(e){return this.methodSession("24",e)}methodSessionCommandCaptionDocument(e){return this.methodSession("25",e)}methodSessionCommandCaptionArgsDocument(e){return this.methodSession("26",e)}methodSessionFreeDocument(e){return this.methodSession("27",e)}methodSessionCaptionAnimation(e){return this.methodSession("28",e)}methodSessionCaptionArgsAnimation(e){return this.methodSession("29",e)}methodSessionCommandCaptionAnimation(e){return this.methodSession("30",e)}methodSessionCommandCaptionArgsAnimation(e){return this.methodSession("31",e)}methodSessionFreeAnimation(e){return this.methodSession("32",e)}methodSessionCaptionVoice(e){return this.methodSession("33",e)}methodSessionCaptionArgsVoice(e){return this.methodSession("34",e)}methodSessionCommandCaptionVoice(e){return this.methodSession("35",e)}methodSessionCommandCaptionArgsVoice(e){return this.methodSession("36",e)}methodSessionFreeVoice(e){return this.methodSession("37",e)}methodSessionFreeVideoNote(e){return this.methodSession("38",e)}methodSessionFreeSticker(e){return this.methodSession("39",e)}methodSessionFreeLocation(e){return this.methodSession("40",e)}methodSessionFreeContact(e){return this.methodSession("41",e)}};var G=require("path"),F=require("fs"),he=require("module");var x=class{static{p(this,"PageManager")}static _getFile(e,t,n=0){let i=Object.values(e)[n];if(i===void 0)throw new Error(`File ${t} must have export (not default) class page`);return i}static getFilePath(){return(0,G.join)(process.cwd(),"src","pages")}static getFileSync(e,t=0){e||(e=this.getFilePath());let s=(0,he.createRequire)(e)(e);return this._getFile(s,e,t)}static async getFile(e,t=0){e||(e=this.getFilePath());let n=await import(`${e}?t=${Date.now()}`);return this._getFile(n,e,t)}static getFileManySync(e,t=0){if(e||(e=this.getFilePath()),!(0,F.existsSync)(e))throw new Error(`Directory ${e} is not found, please make it manually`);return(0,F.readdirSync)(e).map(s=>{let i=(0,G.join)(e,s);return{path:i,page:this.getFileSync(i,t)}})}static clearCacheRequire(e){if(e||(e=this.getFilePath()),!(0,F.existsSync)(e))throw new Error(`Directory ${e} is not found, please make it manually`);return(0,F.readdirSync)(e).forEach(n=>{let s=(0,G.join)(e,n);delete require.cache[require.resolve(s)]}),!0}};var le=require("fs"),me=require("url"),v=require("path");var w=require("path"),C=require("fs"),de=require("chokidar");var M=class{static{p(this,"TemplateEngine")}static _escape(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processScopeVariables(e){return e.replace(/\{\{(\w+)\}\}/g,(t,n)=>`\${(data && data["${n}"]) ?? ""}`)}static _processScopeExec(e){return e.replace(/{~\s*([\s\S]*?)\s*~}/g,(t,n)=>`\${(() => { try { return ${n} } catch(e) { try { with(data || {}) { return ${n} } } catch(ee) { return '' } } })()}`)}static _processBaseBlocks(e){let t=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,n={};for(let s of e.matchAll(t)){let i=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[i]=a}return n}static _processScriptBlocks(e){return e.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(t,n)=>{let s=n.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(e){return e.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(e){return e.replace(/<div>([\s\S]*?)<\/div>/gi,(t,n)=>n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processSwitchBlocks(e){let t=/<switch\b(?:\s+value="([^"]+)")?>([\s\S]*?)<\/switch>/gi;return e.replace(t,(n,s,i)=>{if(!s)return"";let o="",a=/<case\b(?:\s+is="([^"]+)")?>([\s\S]*?)<\/case>/gi,r=/<default>([\s\S]*?)<\/default>/gi,c;for(;(c=a.exec(i))!==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=>{o+=`case "${m}": `}),o+=`return \`${h}\`; `}let l=r.exec(i);if(l){let d=(l[1]||"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();o+=`default: return \`${d}\`; `}else o+="default: return ''; ";return`\${(() => { switch((data && data["${s}"])) { ${o} } })()}`})}static _processMapBlocks(e){let t=/<map(?:\s+([^>]*))?>([\s\S]*?)<\/map>/gi;return e.replace(t,(n,s,i)=>{let o={},a=/(\w+)="([^"]*)"/g;if(s)for(let h of s.matchAll(a))o[h[1]]=h[2];let r=o.src;if(!r)return"";let c=o.join??"\\n",l=i.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`\${(() => { const __arr = (data && data["${r}"]) || []; let __out = ""; for (let i = 0; i < __arr.length; i++) { const e = __arr[i]; if (i > 0) { __out += "${d}" } __out += \`${l}\`; } return __out; })()}`})}static _processMediaBlocks(e){let t=/<media(?:\s+([^>]*))?>([\s\S]*?)<\/media>/gi,n={};for(let s of e.matchAll(t)){let i=s[1],o=s[2],a={},r=/(\w+)="([^"]*)"/g;if(i)for(let m of i.matchAll(r))a[m[1]]=m[2];let c=a.lang||"default",l=a.type,d=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),h={type:l};a.src&&(h.src=a.src),d&&l!=="video_note"&&l!=="sticker"&&(h.caption=d),l==="location"&&(a.latitude&&(h.latitude=a.latitude),a.longitude&&(h.longitude=a.longitude),d&&(h.caption=d)),l==="contact"&&(a.phone&&(h.phone=a.phone),a.first_name&&(h.first_name=a.first_name),a.last_name&&(h.last_name=a.last_name),a.vcard&&(h.vcard=a.vcard),d&&(h.caption=d)),n[c]=h}return n}static _processMessageBlocks(e){let t=/<message(?:\s+([^>]*))?>([\s\S]*?)<\/message>/gi,n={};for(let[,s,i]of e.matchAll(t)){let o={},a=/(\w+)="([^"]*)"/g;if(s)for(let l of s.matchAll(a))o[l[1]]=l[2];let r=o.lang||"default",c=i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[r]=c}return n}static _processDescriptionBlocks(e){let t=/<description(?:\s+([^>]*))?>([\s\S]*?)<\/description>/gi,n={};for(let[,s,i]of e.matchAll(t)){let o={},a=/(\w+)="([^"]*)"/g;if(s)for(let d of s.matchAll(a))o[d[1]]=d[2];let r=o.lang||"default",c=o.scope||"default",l=i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[r]||(n[r]={}),n[r][c]=l}return n}static _processKeyboardBlocks(e){let t=/<keyboard(?:\s+([^>]*))?>([\s\S]*?)<\/keyboard>/gi,n={};for(let[,s,i]of e.matchAll(t)){let o={},a=/(\w+)="([^"]*)"/g;if(s)for(let d of s.matchAll(a))o[d[1]]=d[2];let r=o.lang||"default",c=o.type==="bottom"?"bottom":"inline",l=i.trim();n[r]||(n[r]={}),n[r][c]=l}return n}static _compileToFunction(e,t){let n;t?n=e.map(o=>`\`${o}\``).join(","):n=`\`${e}\``;let s=n;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),t){let i=`return [${s}]`;return new Function("data",i)}else{let i=`return ${s}`;return new Function("data",i)}}static compileBlockMedia(e,t){let n=t||this._processBaseBlocks(e),s={};for(let[i,o]of Object.entries(n)){let a=this._processMediaBlocks(o);s[i]={};for(let[r,c]of Object.entries(a)){let l={};for(let[d,h]of Object.entries(c)){if(d==="type"||typeof h!="string")continue;let m=this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(h)))));l[d]=this._compileToFunction(m,!1)}s[i][r]=d=>{let h={...c};for(let[m,g]of Object.entries(l))h[m]=g(d);return h}}}return s}static compileBlockMessage(e,t){let n=t||this._processBaseBlocks(e),s={};for(let[i,o]of Object.entries(n)){let a=this._processMessageBlocks(o);s[i]={};for(let[r,c]of Object.entries(a)){let l=this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(c)))));s[i][r]=this._compileToFunction(l,!1)}}return s}static compileBlockDescription(e,t){let n=t||this._processBaseBlocks(e),s={};for(let[i,o]of Object.entries(n)){let a=this._processDescriptionBlocks(o);s[i]={};for(let[r,c]of Object.entries(a))for(let[l,d]of Object.entries(c)){s[i][l]||(s[i][l]={});let h=this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(d)))));s[i][l][r]=this._compileToFunction(h,!1)}}return s}static compileBlockKeyboards(e,t){let n=t||this._processBaseBlocks(e),s={};for(let[i,o]of Object.entries(n)){let a=this._processKeyboardBlocks(o);s[i]={};for(let[r,c]of Object.entries(a)){s[i][r]={};for(let[l,d]of Object.entries(c)){let m=d.split(/(?<!\\),\s*/).map(g=>g.replace(/\\,/g,",").trim()).map(g=>this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(g))))));s[i][r][l]=this._compileToFunction(m,!0)}}}return s}static _extractBlock(e,t,n="default",s="all",i){let o=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,a=e,r=!1;for(let c of e.matchAll(o))if((c[2]??"default")===n){a=c[3]??"",r=!0;break}if(!r){let c=/<base\b/.test(e);if(!(n==="default"&&!c))return""}if(t){if(t==="all")return a;let c=Array.isArray(t)?t:[t],l=[];for(let h of c){let m=new RegExp(`([ \\t]*)<${h}(?:\\s+([^>]*))?>([\\s\\S]*?)<\\/${h}>`,"gi");for(let g of a.matchAll(m)){let _=g[2];if(i){let T=/lang="([^"]*)"/i,I=_?.match(T);if(((I?I[1]:void 0)||"default")!==i)continue}l.push({start:g.index,content:g[0],innerContent:g[3]??""})}}l.sort((h,m)=>h.start-m.start);let d=p(h=>{let m=h.split(`
|
|
1
|
+
"use strict";var ye=Object.create;var V=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var Te=Object.getPrototypeOf,be=Object.prototype.hasOwnProperty;var p=(u,e)=>V(u,"name",{value:e,configurable:!0});var Se=(u,e)=>{for(var t in e)V(u,t,{get:e[t],enumerable:!0})},ie=(u,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ce(e))!be.call(u,s)&&s!==t&&V(u,s,{get:()=>e[s],enumerable:!(n=fe(e,s))||n.enumerable});return u};var oe=(u,e,t)=>(t=u!=null?ye(Te(u)):{},ie(e||!u||!u.__esModule?V(t,"default",{value:u,enumerable:!0}):t,u)),ke=u=>ie(V({},"__esModule",{value:!0}),u);var _e={};Se(_e,{BlockKeyboard:()=>X,CacheExternal:()=>W,Ctx:()=>K,Gramstax:()=>J,LabelKeyboard:()=>Y,LoggingUtil:()=>Q,MockTelegramServer:()=>se,PageManager:()=>x,TemplateEngine:()=>M,TemplateManager:()=>$,WebhookQueue:()=>E,WorkerThreadExport:()=>Z,WorkerThreadGatewayClient:()=>j,WorkerThreadGatewayServer:()=>q,WorkerThreadInit:()=>ee,WorkerThreadLaunch:()=>N,WorkerThreadPool:()=>te,WorkerThreadRpc:()=>P,log:()=>z});module.exports=ke(_e);var we=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"),f=we();var ae=require("logging-pretty");var Q=class extends ae.LoggingPretty{static{p(this,"LoggingUtil")}timers=new Map;constructor(e){super(e)}errorMake(e,t,n){this.error(`[${t?`${t}:${n}`:n}] ${this._formatErrorObj(e)}`)}_formatErrorObj(e){return JSON.stringify(e instanceof Error?{message:e.message,stack:e.stack,name:e.name}:e,null,2)}time(e){this.timers.set(e,process.hrtime.bigint())}timeEnd(e,t){let n=this.timers.get(e);if(n===void 0){this.debug(`${e}: Timer was never started`);return}let s=(Number(process.hrtime.bigint()-n)/1e6).toFixed(3);this.timers.delete(e),t?this.debug(`${t} (took ${s}ms)`):this.debug(`${e} (took ${s}ms)`)}timeCheck(e){let t=this.timers.get(e);if(t!==void 0)return(Number(process.hrtime.bigint()-t)/1e6).toFixed(3)}timeLog(e,t){let n=this.timeCheck(e);if(n===void 0){this.debug(`${e}: Timer was never started`);return}t?this.debug(`${t} (${n}ms)`):this.debug(`${e} (${n}ms)`)}timeClear(){this.timers.clear()}timeActive(){return Array.from(this.timers.keys())}},z=new Q;var re=require("keyv"),ce=oe(require("@keyv/redis"),1);var W=class extends re.Keyv{constructor(t="memory",n,s,i){let o;t.startsWith("redis")&&(o=new ce.default(t)),t==="memory"&&(o=new Map),i?.forceStore&&(o=i.forceStore);super({store:o,namespace:s,ttl:n});this.url=t}static{p(this,"CacheExternal")}refreshLruCache(t){let n=this.store,s=this.opts.namespace?this.opts.namespace?.length+1:null,i=n.keys().toArray();for(let o=0;o<i.length;o++){let a=i[o];if(o==t)return;this.get(s?a.slice(s):a)}}};var H=require("timers/promises"),O=require("grammy");var K=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(e){this.ct.from.language_code=e}get msgText(){return this.ct.message?.text}get msgTextArgs(){return this.getArgs(this.msgText,"space",this.data?._positionArgText||this.temp?.data?._positionArgText)}get msgTextArg(){return this.msgTextArgs[0]}get msgTextCommandArgs(){return this.getArgs(this.msgText,"space")}get msgTextCommandArg(){return this.msgTextCommandArgs[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionArgs(){return this.getArgs(this.msgCaption,"space")}get msgCaptionArg(){return this.msgCaptionArgs[0]}get msgCaptionCommandArgs(){return this.getArgs(this.msgCaption,"space")}get msgCaptionCommandArg(){return this.msgCaptionCommandArgs[0]}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get msgDocument(){return this.ct.message?.document}get msgAnimation(){return this.ct.message?.animation}get msgVoice(){return this.ct.message?.voice}get msgVideoNote(){return this.ct.message?.video_note}get msgSticker(){return this.ct.message?.sticker}get msgLocation(){return this.ct.message?.location}get msgContact(){return this.ct.message?.contact}get msgWebAppData(){return this.ct.message?.web_app_data}get msgGift(){return this.ct.message?.gift}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataArgs(){return this.getArgs(this.callbackData,"colon")}get callbackDataArg(){return this.callbackDataArgs?.[0]}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(e){this.ct=e.ct,this.cacheSession=e.cacheSession,this.cacheKeyboard=e.cacheKeyboard,this.templateManager=e.templateManager,this.temp=e.temp}async broadcast(e,t,n,s,i,o,a=!1){try{this.temp.isAnswer=!0;let r=30,c=t.map(l=>this.templateManager.getMessage(this.data.name,i,l,s));for(let l=0;l<e.length;l++){let d=e[l],h=c[l];await this.ct.api.sendMessage(d,h,{parse_mode:"HTML",reply_markup:n,...o}),l+1==r&&await(0,H.setTimeout)(1200)}}catch(r){if(a)throw r}}async broadcastMedia(e,t,n,s,i,o,a=!1){try{this.temp.isAnswer=!0;let r=30,c=t.map(l=>this.templateManager.getMedia(this.data.name,i,l,s));for(let l=0;l<e.length;l++){let d=e[l],h=c[l];if(!h)continue;let m={parse_mode:"HTML",reply_markup:n,...o};h.type=="photo"&&await this.ct.api.sendPhoto(d,h.src,{caption:h.caption,...m}),h.type=="video"&&await this.ct.api.sendVideo(d,h.src,{caption:h.caption,...m}),h.type=="audio"&&await this.ct.api.sendAudio(d,h.src,{caption:h.caption,...m}),h.type=="document"&&await this.ct.api.sendDocument(d,h.src,{caption:h.caption,...m}),h.type=="animation"&&await this.ct.api.sendAnimation(d,h.src,{caption:h.caption,...m}),h.type=="voice"&&await this.ct.api.sendVoice(d,h.src,m),h.type=="video_note"&&await this.ct.api.sendVideoNote(d,h.src,m),h.type=="sticker"&&await this.ct.api.sendSticker(d,h.src,m),h.type=="location"&&await this.ct.api.sendLocation(d,parseInt(h.latitude),parseInt(h.longitude),m),h.type=="contact"&&await this.ct.api.sendContact(d,h.phone,h.first_name,{vcard:h.vcard,...m}),l+1==r&&await(0,H.setTimeout)(1200)}}catch(r){if(a)throw r}}async reply(e,t,n,s){this.temp.isAnswer=!0;let i=this.templateManager.getMessage(this.data.name,n,this.userLanguage,t);return await this.ct.reply(i,{parse_mode:"HTML",reply_markup:e,...s})}async replyMedia(e,t,n,s,i){this.temp.isAnswer=!0;let o=this.templateManager.getMedia(this.data.name,s,this.userLanguage,n),a={parse_mode:"HTML",reply_markup:t,...i};if(e=="photo")return await this.ct.replyWithPhoto(o.src,{caption:o.caption,...a});if(e=="video")return await this.ct.replyWithVideo(o.src,{caption:o.caption,...a});if(e=="audio")return await this.ct.replyWithAudio(o.src,{caption:o.caption,...a});if(e=="document")return await this.ct.replyWithDocument(o.src,{caption:o.caption,...a});if(e=="animation")return await this.ct.replyWithAnimation(o.src,{caption:o.caption,...a});if(e=="voice")return await this.ct.replyWithVoice(o.src,a);if(e=="video_note")return await this.ct.replyWithVideoNote(o.src,a);if(e=="sticker")return await this.ct.replyWithSticker(o.src,a);if(e=="location")return await this.ct.replyWithLocation(parseInt(o.latitude),parseInt(o.longitude),a);if(e=="contact")return await this.ct.replyWithContact(o.phone,o.first_name,{vcard:o.vcard,...a})}async replyPhoto(e,t,n,s){return this.replyMedia("photo",e,t,n,s)}async replyVideo(e,t,n,s){return this.replyMedia("video",e,t,n,s)}async replyAudio(e,t,n,s){return this.replyMedia("audio",e,t,n,s)}async replyDocument(e,t,n,s){return this.replyMedia("document",e,t,n,s)}async replyAnimation(e,t,n,s){return this.replyMedia("animation",e,t,n,s)}async replyVoice(e,t,n,s){return this.replyMedia("voice",e,t,n,s)}async replyVideoNote(e,t,n,s){return this.replyMedia("video_note",e,t,n,s)}async replySticker(e,t,n,s){return this.replyMedia("sticker",e,t,n,s)}async replyLocation(e,t,n,s){return this.replyMedia("location",e,t,n,s)}async replyContact(e,t,n,s){return this.replyMedia("contact",e,t,n,s)}async replyAction(e){return await this.ct.replyWithChatAction(e)}async edit(e,t,n,s,i=!0){try{this.temp.isAnswer=!0;let o=this.templateManager.getMessage(this.data.name,n,this.userLanguage,t);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:e,...s})}catch(o){if(i)await this.reply(e,t,n,s);else throw o}}async editMedia(e,t,n,s,i,o,a=!0){try{this.temp.isAnswer=!0;let{src:r,caption:c}=this.templateManager.getMedia(this.data.name,s,this.userLanguage,n);return e=="voice"?(await this.delete(),await this.replyVoice(t,n,s,i)):e=="video_note"?(await this.delete(),await this.replyVoice(t,n,s,i)):e=="sticker"?(await this.delete(),await this.replySticker(t,n,s,i)):e=="location"?(await this.delete(),await this.replyLocation(t,n,s,i)):e=="contact"?(await this.delete(),await this.replyContact(t,n,s,i)):await this.ct.editMessageMedia({media:r,caption:c,type:e,parse_mode:"HTML",...i},{reply_markup:t,...o})}catch(r){if(a===!0)await this.reply(t,n,s,o);else throw r}}async editPhoto(e,t,n,s,i){return await this.editMedia("photo",e,t,n,s,i)}async editVideo(e,t,n,s,i){return await this.editMedia("video",e,t,n,s,i)}async editAudio(e,t,n,s,i){return await this.editMedia("audio",e,t,n,s,i)}async editDocument(e,t,n,s,i){return await this.editMedia("document",e,t,n,s,i)}async editAnimation(e,t,n,s,i){return await this.editMedia("animation",e,t,n,s,i)}async editVoice(e,t,n,s){return await this.editMedia("voice",e,t,n,s)}async editVideoNote(e,t,n,s){return await this.editMedia("video_note",e,t,n,s)}async editSticker(e,t,n,s){return await this.editMedia("sticker",e,t,n,s)}async editLocation(e,t,n,s){return await this.editMedia("location",e,t,n,s)}async editContact(e,t,n,s){return await this.editMedia("contact",e,t,n,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(e){try{return this.temp.isAnswer=!0,await this.ct.answerCallbackQuery(e)}catch{return null}}async setSession(e,t,n){try{let s={method:e,params:t,...n},i=await this.cacheSession.set(`${this.userId}`,s);return i&&(this.temp.session=s),i}catch{return null}}async getSession(){try{let e=await this.cacheSession.get(`${this.userId}`);return e&&(this.temp.session=e),e||null}catch{return null}}async clearSession(){try{let e=await this.cacheSession.delete(`${this.userId}`);return e&&(this.temp.session={}),e}catch{return null}}static buildData(e){let n=typeof e=="function"?{callbackData:e}:e||{},s=n.callbackData,i=this.prototype.addArgs.bind(this.prototype),o=n.name||"";return{name:o,intentText:n.intentText||o,intentCommandText:n.intentCommandText||o,intentCallbackData:o,callbackData:s?function(...r){return i(this.intentCallbackData,"colon",s(...r))}:function(){return this?.intentCallbackData},_positionArgText:n.intentText?n.intentText.split(this.prototype.getSeperatorTag("space")).length:void 0}}keyboardCols(e,t,n,s){let[i,o]=n.split("-"),a=parseInt(i),r=o?parseInt(o):null,c=t.length,l=e;for(let d=0;d<c;d++){let h=t[d];if(s(h,d),r===null)(d+1)%a===0&&d<c-1&&l.row();else{let m=c-(d+1);(m===r||m>r&&(d+1)%a===0)&&l.row()}}return e}bottomKeyboardT(e="1",t,n){return this.bottomKeyboard((s,i)=>this.keyboardCols(s,i,e,o=>s.text(o)),{baseId:t??void 0,data:n})}inlineKeyboardT(e,t="1",n,s){return this.inlineKeyboard((i,o)=>this.keyboardCols(i,o,t,(a,r)=>{let c=e[r],l=typeof c=="string"?c:c.data.callbackData();i.text(a,l)}),{baseId:n??void 0,data:s})}inlineKeyboard(e,t){let n=this.data.name;if(t?.cache===!0){let a=`${n}:${this.userLanguage}:i`,r=this.cacheKeyboard.get(a);if(!r){let c=new O.InlineKeyboard,l=this.templateManager.getKeyboard(n,t?.baseId,this.userLanguage,"inline",t?.data),d=e(c,l);return this.cacheKeyboard.set(a,d),d}return r}let s=new O.InlineKeyboard,i=this.templateManager.getKeyboard(n,t?.baseId,this.userLanguage,"inline",t?.data);return e(s,i)}bottomKeyboard(e,t){let n=this.data.name;if(t?.cache===!0){let a=`${n}:${this.userLanguage}:b`,r=this.cacheKeyboard.get(a);if(!r){let c=new O.Keyboard,l=this.templateManager.getKeyboard(n,t?.baseId,this.userLanguage,"bottom",t?.data),d=e(c,l);return d.resized(!0),this.cacheKeyboard.set(a,d),d}return r}let s=new O.Keyboard,i=this.templateManager.getKeyboard(n,t?.baseId,this.userLanguage,"bottom",t?.data),o=e(s,i);return o.resized(),o}getSeperatorTag(e="space"){return e=="space"?" ":":"}haveArgs(e="",t){return e.includes(this.getSeperatorTag(t))}addArgs(e="",t,n){let s=this.getSeperatorTag(t),i="";for(let o=0;o<n.length;o++){let a=n[o];a!=null&&a!==""&&(i+=s+a)}return e+i}getArgs(e="",t,n=1){if(!e)return[];let s=this.getSeperatorTag(t);return e.split(s).slice(n)}getIntent(e="",t,n=1){if(!e)return"";let s=this.getSeperatorTag(t),i=e.split(s);return n==1?i[0]:i.slice(0,n).join(s)}isSessionCallbackData(){return this.temp.session.method===this.methodSessionCallbackData()}isSessionArgsCallbackData(){return this.temp.session.method===this.methodSessionArgsCallbackData()}isSessionText(){return this.temp.session.method===this.methodSessionText()}isSessionArgsText(){return this.temp.session.method===this.methodSessionArgsText()}isSessionCommandText(){return this.temp.session.method===this.methodSessionCommandText()}isSessionCommandArgsText(){return this.temp.session.method===this.methodSessionCommandArgsText()}isSessionFreeText(){return this.temp.session.method===this.methodSessionFreeText()}isSessionCaptionPhoto(){return this.temp.session.method===this.methodSessionCaptionPhoto()}isSessionCaptionArgsPhoto(){return this.temp.session.method===this.methodSessionCaptionArgsPhoto()}isSessionCommandCaptionPhoto(){return this.temp.session.method===this.methodSessionCommandCaptionPhoto()}isSessionCommandCaptionArgsPhoto(){return this.temp.session.method===this.methodSessionCommandCaptionArgsPhoto()}isSessionFreePhoto(){return this.temp.session.method===this.methodSessionFreePhoto()}isSessionCaptionVideo(){return this.temp.session.method===this.methodSessionCaptionVideo()}isSessionCaptionArgsVideo(){return this.temp.session.method===this.methodSessionCaptionArgsVideo()}isSessionCommandCaptionVideo(){return this.temp.session.method===this.methodSessionCommandCaptionVideo()}isSessionCommandCaptionArgsVideo(){return this.temp.session.method===this.methodSessionCommandCaptionArgsVideo()}isSessionFreeVideo(){return this.temp.session.method===this.methodSessionFreeVideo()}isSessionCaptionAudio(){return this.temp.session.method===this.methodSessionCaptionAudio()}isSessionCaptionArgsAudio(){return this.temp.session.method===this.methodSessionCaptionArgsAudio()}isSessionCaptionCommandAudio(){return this.temp.session.method===this.methodSessionCaptionCommandAudio()}isSessionCaptionCommandArgsAudio(){return this.temp.session.method===this.methodSessionCaptionCommandArgsAudio()}isSessionFreeAudio(){return this.temp.session.method===this.methodSessionFreeAudio()}isSessionCaptionDocument(){return this.temp.session.method===this.methodSessionCaptionDocument()}isSessionCaptionArgsDocument(){return this.temp.session.method===this.methodSessionCaptionArgsDocument()}isSessionCommandCaptionDocument(){return this.temp.session.method===this.methodSessionCommandCaptionDocument()}isSessionCommandCaptionArgsDocument(){return this.temp.session.method===this.methodSessionCommandCaptionArgsDocument()}isSessionFreeDocument(){return this.temp.session.method===this.methodSessionFreeDocument()}isSessionCaptionAnimation(){return this.temp.session.method===this.methodSessionCaptionAnimation()}isSessionCaptionArgsAnimation(){return this.temp.session.method===this.methodSessionCaptionArgsAnimation()}isSessionCommandCaptionAnimation(){return this.temp.session.method===this.methodSessionCommandCaptionAnimation()}isSessionCommandCaptionArgsAnimation(){return this.temp.session.method===this.methodSessionCommandCaptionArgsAnimation()}isSessionFreeAnimation(){return this.temp.session.method===this.methodSessionFreeAnimation()}isSessionCaptionVoice(){return this.temp.session.method===this.methodSessionCaptionVoice()}isSessionCaptionArgsVoice(){return this.temp.session.method===this.methodSessionCaptionArgsVoice()}isSessionCommandCaptionVoice(){return this.temp.session.method===this.methodSessionCommandCaptionVoice()}isSessionCommandCaptionArgsVoice(){return this.temp.session.method===this.methodSessionCommandCaptionArgsVoice()}isSessionFreeVoice(){return this.temp.session.method===this.methodSessionFreeVoice()}isSessionFreeVideoNote(){return this.temp.session.method===this.methodSessionFreeVideoNote()}isSessionFreeSticker(){return this.temp.session.method===this.methodSessionFreeSticker()}isSessionFreeLocation(){return this.temp.session.method===this.methodSessionFreeLocation()}isSessionFreeContact(){return this.temp.session.method===this.methodSessionFreeContact()}sessionCallbackData(e){return this.setSession(this.methodSessionCallbackData(),e)}sessionArgsCallbackData(e){return this.setSession(this.methodSessionArgsCallbackData(),e)}sessionText(e){return this.setSession(this.methodSessionText(),e)}sessionArgsText(e){return this.setSession(this.methodSessionArgsText(),e)}sessionCommandText(e){return this.setSession(this.methodSessionCommandText(),e)}sessionCommandArgsText(e){return this.setSession(this.methodSessionCommandArgsText(),e)}sessionFreeText(e){return this.setSession(this.methodSessionFreeText(),e)}sessionCaptionPhoto(e){return this.setSession(this.methodSessionCaptionPhoto(),e)}sessionCaptionArgsPhoto(e){return this.setSession(this.methodSessionCaptionArgsPhoto(),e)}sessionCommandCaptionPhoto(e){return this.setSession(this.methodSessionCommandCaptionPhoto(),e)}sessionCommandCaptionArgsPhoto(e){return this.setSession(this.methodSessionCommandCaptionArgsPhoto(),e)}sessionFreePhoto(e){return this.setSession(this.methodSessionFreePhoto(),e)}sessionCaptionVideo(e){return this.setSession(this.methodSessionCaptionVideo(),e)}sessionCaptionArgsVideo(e){return this.setSession(this.methodSessionCaptionArgsVideo(),e)}sessionCommandCaptionVideo(e){return this.setSession(this.methodSessionCommandCaptionVideo(),e)}sessionCommandCaptionArgsVideo(e){return this.setSession(this.methodSessionCommandCaptionArgsVideo(),e)}sessionFreeVideo(e){return this.setSession(this.methodSessionFreeVideo(),e)}sessionCaptionAudio(e){return this.setSession(this.methodSessionCaptionAudio(),e)}sessionCaptionArgsAudio(e){return this.setSession(this.methodSessionCaptionArgsAudio(),e)}sessionCaptionCommandAudio(e){return this.setSession(this.methodSessionCaptionCommandAudio(),e)}sessionCaptionCommandArgsAudio(e){return this.setSession(this.methodSessionCaptionCommandArgsAudio(),e)}sessionFreeAudio(e){return this.setSession(this.methodSessionFreeAudio(),e)}sessionCaptionDocument(e){return this.setSession(this.methodSessionCaptionDocument(),e)}sessionCaptionArgsDocument(e){return this.setSession(this.methodSessionCaptionArgsDocument(),e)}sessionCommandCaptionDocument(e){return this.setSession(this.methodSessionCommandCaptionDocument(),e)}sessionCommandCaptionArgsDocument(e){return this.setSession(this.methodSessionCommandCaptionArgsDocument(),e)}sessionFreeDocument(e){return this.setSession(this.methodSessionFreeDocument(),e)}sessionCaptionAnimation(e){return this.setSession(this.methodSessionCaptionAnimation(),e)}sessionCaptionArgsAnimation(e){return this.setSession(this.methodSessionCaptionArgsAnimation(),e)}sessionCommandCaptionAnimation(e){return this.setSession(this.methodSessionCommandCaptionAnimation(),e)}sessionCommandCaptionArgsAnimation(e){return this.setSession(this.methodSessionCommandCaptionArgsAnimation(),e)}sessionFreeAnimation(e){return this.setSession(this.methodSessionFreeAnimation(),e)}sessionCaptionVoice(e){return this.setSession(this.methodSessionCaptionVoice(),e)}sessionCaptionArgsVoice(e){return this.setSession(this.methodSessionCaptionArgsVoice(),e)}sessionCommandCaptionVoice(e){return this.setSession(this.methodSessionCommandCaptionVoice(),e)}sessionCommandCaptionArgsVoice(e){return this.setSession(this.methodSessionCommandCaptionArgsVoice(),e)}sessionFreeVoice(e){return this.setSession(this.methodSessionFreeVoice(),e)}sessionFreeVideoNote(e){return this.setSession(this.methodSessionFreeVideoNote(),e)}sessionFreeSticker(e){return this.setSession(this.methodSessionFreeSticker(),e)}sessionFreeLocation(e){return this.setSession(this.methodSessionFreeLocation(),e)}sessionFreeContact(e){return this.setSession(this.methodSessionFreeContact(),e)}methodSession(e,t){return`${e}-${t||this.data.name}`}methodSessionCallbackData(e){return this.methodSession("1",e)}methodSessionArgsCallbackData(e){return this.methodSession("2",e)}methodSessionText(e){return this.methodSession("3",e)}methodSessionArgsText(e){return this.methodSession("4",e)}methodSessionCommandText(e){return this.methodSession("5",e)}methodSessionCommandArgsText(e){return this.methodSession("6",e)}methodSessionFreeText(e){return this.methodSession("7",e)}methodSessionCaptionPhoto(e){return this.methodSession("8",e)}methodSessionCaptionArgsPhoto(e){return this.methodSession("9",e)}methodSessionCommandCaptionPhoto(e){return this.methodSession("10",e)}methodSessionCommandCaptionArgsPhoto(e){return this.methodSession("11",e)}methodSessionFreePhoto(e){return this.methodSession("12",e)}methodSessionCaptionVideo(e){return this.methodSession("13",e)}methodSessionCaptionArgsVideo(e){return this.methodSession("14",e)}methodSessionCommandCaptionVideo(e){return this.methodSession("15",e)}methodSessionCommandCaptionArgsVideo(e){return this.methodSession("16",e)}methodSessionFreeVideo(e){return this.methodSession("17",e)}methodSessionCaptionAudio(e){return this.methodSession("18",e)}methodSessionCaptionArgsAudio(e){return this.methodSession("19",e)}methodSessionCaptionCommandAudio(e){return this.methodSession("20",e)}methodSessionCaptionCommandArgsAudio(e){return this.methodSession("21",e)}methodSessionFreeAudio(e){return this.methodSession("22",e)}methodSessionCaptionDocument(e){return this.methodSession("23",e)}methodSessionCaptionArgsDocument(e){return this.methodSession("24",e)}methodSessionCommandCaptionDocument(e){return this.methodSession("25",e)}methodSessionCommandCaptionArgsDocument(e){return this.methodSession("26",e)}methodSessionFreeDocument(e){return this.methodSession("27",e)}methodSessionCaptionAnimation(e){return this.methodSession("28",e)}methodSessionCaptionArgsAnimation(e){return this.methodSession("29",e)}methodSessionCommandCaptionAnimation(e){return this.methodSession("30",e)}methodSessionCommandCaptionArgsAnimation(e){return this.methodSession("31",e)}methodSessionFreeAnimation(e){return this.methodSession("32",e)}methodSessionCaptionVoice(e){return this.methodSession("33",e)}methodSessionCaptionArgsVoice(e){return this.methodSession("34",e)}methodSessionCommandCaptionVoice(e){return this.methodSession("35",e)}methodSessionCommandCaptionArgsVoice(e){return this.methodSession("36",e)}methodSessionFreeVoice(e){return this.methodSession("37",e)}methodSessionFreeVideoNote(e){return this.methodSession("38",e)}methodSessionFreeSticker(e){return this.methodSession("39",e)}methodSessionFreeLocation(e){return this.methodSession("40",e)}methodSessionFreeContact(e){return this.methodSession("41",e)}};var G=require("path"),F=require("fs"),he=require("module");var x=class{static{p(this,"PageManager")}static _getFile(e,t,n=0){let i=Object.values(e)[n];if(i===void 0)throw new Error(`File ${t} must have export (not default) class page`);return i}static getFilePath(){return(0,G.join)(process.cwd(),"src","pages")}static getFileSync(e,t=0){e||(e=this.getFilePath());let s=(0,he.createRequire)(e)(e);return this._getFile(s,e,t)}static async getFile(e,t=0){e||(e=this.getFilePath());let n=await import(`${e}?t=${Date.now()}`);return this._getFile(n,e,t)}static getFileManySync(e,t=0){if(e||(e=this.getFilePath()),!(0,F.existsSync)(e))throw new Error(`Directory ${e} is not found, please make it manually`);return(0,F.readdirSync)(e).map(s=>{let i=(0,G.join)(e,s);return{path:i,page:this.getFileSync(i,t)}})}static clearCacheRequire(e){if(e||(e=this.getFilePath()),!(0,F.existsSync)(e))throw new Error(`Directory ${e} is not found, please make it manually`);return(0,F.readdirSync)(e).forEach(n=>{let s=(0,G.join)(e,n);delete require.cache[require.resolve(s)]}),!0}};var le=require("fs"),me=require("url"),v=require("path");var w=require("path"),C=require("fs"),de=require("chokidar");var M=class{static{p(this,"TemplateEngine")}static _escape(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processScopeVariables(e){return e.replace(/\{\{(\w+)\}\}/g,(t,n)=>`\${(data && data["${n}"]) ?? ""}`)}static _processScopeExec(e){return e.replace(/{~\s*([\s\S]*?)\s*~}/g,(t,n)=>`\${(() => { try { return ${n} } catch(e) { try { with(data || {}) { return ${n} } } catch(ee) { return '' } } })()}`)}static _processBaseBlocks(e){let t=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,n={};for(let s of e.matchAll(t)){let i=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[i]=a}return n}static _processScriptBlocks(e){return e.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(t,n)=>{let s=n.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(e){return e.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(e){return e.replace(/<div>([\s\S]*?)<\/div>/gi,(t,n)=>n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processSwitchBlocks(e){let t=/<switch\b(?:\s+value="([^"]+)")?>([\s\S]*?)<\/switch>/gi;return e.replace(t,(n,s,i)=>{if(!s)return"";let o="",a=/<case\b(?:\s+is="([^"]+)")?>([\s\S]*?)<\/case>/gi,r=/<default>([\s\S]*?)<\/default>/gi,c;for(;(c=a.exec(i))!==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=>{o+=`case "${m}": `}),o+=`return \`${h}\`; `}let l=r.exec(i);if(l){let d=(l[1]||"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();o+=`default: return \`${d}\`; `}else o+="default: return ''; ";return`\${(() => { switch((data && data["${s}"])) { ${o} } })()}`})}static _processMapBlocks(e){let t=/<map(?:\s+([^>]*))?>([\s\S]*?)<\/map>/gi;return e.replace(t,(n,s,i)=>{let o={},a=/(\w+)="([^"]*)"/g;if(s)for(let h of s.matchAll(a))o[h[1]]=h[2];let r=o.src;if(!r)return"";let c=o.join??"\\n",l=i.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`\${(() => { const __arr = (data && data["${r}"]) || []; let __out = ""; for (let i = 0; i < __arr.length; i++) { const e = __arr[i]; if (i > 0) { __out += "${d}" } __out += \`${l}\`; } return __out; })()}`})}static _processMediaBlocks(e){let t=/<media(?:\s+([^>]*))?>([\s\S]*?)<\/media>/gi,n={};for(let s of e.matchAll(t)){let i=s[1],o=s[2],a={},r=/(\w+)="([^"]*)"/g;if(i)for(let m of i.matchAll(r))a[m[1]]=m[2];let c=a.lang||"default",l=a.type,d=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),h={type:l};a.src&&(h.src=a.src),d&&l!=="video_note"&&l!=="sticker"&&(h.caption=d),l==="location"&&(a.latitude&&(h.latitude=a.latitude),a.longitude&&(h.longitude=a.longitude),d&&(h.caption=d)),l==="contact"&&(a.phone&&(h.phone=a.phone),a.first_name&&(h.first_name=a.first_name),a.last_name&&(h.last_name=a.last_name),a.vcard&&(h.vcard=a.vcard),d&&(h.caption=d)),n[c]=h}return n}static _processMessageBlocks(e){let t=/<message(?:\s+([^>]*))?>([\s\S]*?)<\/message>/gi,n={};for(let[,s,i]of e.matchAll(t)){let o={},a=/(\w+)="([^"]*)"/g;if(s)for(let l of s.matchAll(a))o[l[1]]=l[2];let r=o.lang||"default",c=i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[r]=c}return n}static _processDescriptionBlocks(e){let t=/<description(?:\s+([^>]*))?>([\s\S]*?)<\/description>/gi,n={};for(let[,s,i]of e.matchAll(t)){let o={},a=/(\w+)="([^"]*)"/g;if(s)for(let d of s.matchAll(a))o[d[1]]=d[2];let r=o.lang||"default",c=o.scope||"default",l=i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();n[r]||(n[r]={}),n[r][c]=l}return n}static _processKeyboardBlocks(e){let t=/<keyboard(?:\s+([^>]*))?>([\s\S]*?)<\/keyboard>/gi,n={};for(let[,s,i]of e.matchAll(t)){let o={},a=/(\w+)="([^"]*)"/g;if(s)for(let d of s.matchAll(a))o[d[1]]=d[2];let r=o.lang||"default",c=o.type==="bottom"?"bottom":"inline",l=i.trim();n[r]||(n[r]={}),n[r][c]=l}return n}static _compileToFunction(e,t){let n;t?n=e.map(o=>`\`${o}\``).join(","):n=`\`${e}\``;let s=n;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),t){let i=`return [${s}]`;return new Function("data",i)}else{let i=`return ${s}`;return new Function("data",i)}}static compileBlockMedia(e,t){let n=t||this._processBaseBlocks(e),s={};for(let[i,o]of Object.entries(n)){let a=this._processMediaBlocks(o);s[i]={};for(let[r,c]of Object.entries(a)){let l={};for(let[d,h]of Object.entries(c)){if(d==="type"||typeof h!="string")continue;let m=this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(h)))));l[d]=this._compileToFunction(m,!1)}s[i][r]=d=>{let h={...c};for(let[m,g]of Object.entries(l))h[m]=g(d);return h}}}return s}static compileBlockMessage(e,t){let n=t||this._processBaseBlocks(e),s={};for(let[i,o]of Object.entries(n)){let a=this._processMessageBlocks(o);s[i]={};for(let[r,c]of Object.entries(a)){let l=this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(c)))));s[i][r]=this._compileToFunction(l,!1)}}return s}static compileBlockDescription(e,t){let n=t||this._processBaseBlocks(e),s={};for(let[i,o]of Object.entries(n)){let a=this._processDescriptionBlocks(o);s[i]={};for(let[r,c]of Object.entries(a))for(let[l,d]of Object.entries(c)){s[i][l]||(s[i][l]={});let h=this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(d)))));s[i][l][r]=this._compileToFunction(h,!1)}}return s}static compileBlockKeyboards(e,t){let n=t||this._processBaseBlocks(e),s={};for(let[i,o]of Object.entries(n)){let a=this._processKeyboardBlocks(o);s[i]={};for(let[r,c]of Object.entries(a)){s[i][r]={};for(let[l,d]of Object.entries(c)){let m=d.split(/(?<!\\),\s*/).map(g=>g.replace(/\\,/g,",").trim()).map(g=>this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(g))))));s[i][r][l]=this._compileToFunction(m,!0)}}}return s}static _extractBlock(e,t,n="default",s="all",i){let o=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,a=e,r=!1;for(let c of e.matchAll(o))if((c[2]??"default")===n){a=c[3]??"",r=!0;break}if(!r){let c=/<base\b/.test(e);if(!(n==="default"&&!c))return""}if(t){if(t==="all")return a;let c=Array.isArray(t)?t:[t],l=[];for(let h of c){let m=new RegExp(`([ \\t]*)<${h}(?:\\s+([^>]*))?>([\\s\\S]*?)<\\/${h}>`,"gi");for(let g of a.matchAll(m)){let _=g[2];if(i){let T=/lang="([^"]*)"/i,I=_?.match(T);if(((I?I[1]:void 0)||"default")!==i)continue}l.push({start:g.index,content:g[0],innerContent:g[3]??""})}}l.sort((h,m)=>h.start-m.start);let d=p(h=>{let m=h.split(`
|
|
2
2
|
`);if(m.length<=1)return h.trim();let g=m.filter(T=>T.trim().length>0);if(g.length===0)return"";let _=g.reduce((T,I)=>{let k=I.match(/^([ \t]*)/),A=k?k[1].length:0;return A<T?A:T},1/0);return m.map(T=>T.length>=_?T.slice(_):T.trimStart()).join(`
|
|
3
3
|
`).trim()},"processResult");return s==="all"?l.map(m=>d(m.content)).join(`
|
|
4
4
|
`):l.map(m=>d(m.innerContent)).join(`
|
package/dist/src/index.d.cts
CHANGED
|
@@ -275,8 +275,6 @@ declare class Ctx {
|
|
|
275
275
|
get callbackData(): string;
|
|
276
276
|
get callbackDataArgs(): string[];
|
|
277
277
|
get callbackDataArg(): string;
|
|
278
|
-
get session(): ITTemp[`session`];
|
|
279
|
-
set session(v: ITTemp[`session`]);
|
|
280
278
|
ct: ITCt;
|
|
281
279
|
cacheSession: CacheExternal<ITCacheRpc>;
|
|
282
280
|
cacheKeyboard: Map<any, any>;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -275,8 +275,6 @@ declare class Ctx {
|
|
|
275
275
|
get callbackData(): string;
|
|
276
276
|
get callbackDataArgs(): string[];
|
|
277
277
|
get callbackDataArg(): string;
|
|
278
|
-
get session(): ITTemp[`session`];
|
|
279
|
-
set session(v: ITTemp[`session`]);
|
|
280
278
|
ct: ITCt;
|
|
281
279
|
cacheSession: CacheExternal<ITCacheRpc>;
|
|
282
280
|
cacheKeyboard: Map<any, any>;
|
package/dist/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var de=Object.defineProperty;var p=(g,e)=>de(g,"name",{value:e,configurable:!0}),N=(g=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(g,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):g)(function(g){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+g+'" is not supported')});import Ve from"path";import{fileURLToPath as le}from"url";var me=p(()=>le(import.meta.url),"getFilename");var f=me();import{LoggingPretty as pe}from"logging-pretty";var j=class extends pe{static{p(this,"LoggingUtil")}timers=new Map;constructor(e){super(e)}errorMake(e,t,s){this.error(`[${t?`${t}:${s}`:s}] ${this._formatErrorObj(e)}`)}_formatErrorObj(e){return JSON.stringify(e instanceof Error?{message:e.message,stack:e.stack,name:e.name}:e,null,2)}time(e){this.timers.set(e,process.hrtime.bigint())}timeEnd(e,t){let s=this.timers.get(e);if(s===void 0){this.debug(`${e}: Timer was never started`);return}let n=(Number(process.hrtime.bigint()-s)/1e6).toFixed(3);this.timers.delete(e),t?this.debug(`${t} (took ${n}ms)`):this.debug(`${e} (took ${n}ms)`)}timeCheck(e){let t=this.timers.get(e);if(t!==void 0)return(Number(process.hrtime.bigint()-t)/1e6).toFixed(3)}timeLog(e,t){let s=this.timeCheck(e);if(s===void 0){this.debug(`${e}: Timer was never started`);return}t?this.debug(`${t} (${s}ms)`):this.debug(`${e} (${s}ms)`)}timeClear(){this.timers.clear()}timeActive(){return Array.from(this.timers.keys())}},z=new j;import{Keyv as ue}from"keyv";import ge from"@keyv/redis";var F=class extends ue{constructor(t="memory",s,n,i){let o;t.startsWith("redis")&&(o=new ge(t)),t==="memory"&&(o=new Map),i?.forceStore&&(o=i.forceStore);super({store:o,namespace:n,ttl:s});this.url=t}static{p(this,"CacheExternal")}refreshLruCache(t){let s=this.store,n=this.opts.namespace?this.opts.namespace?.length+1:null,i=s.keys().toArray();for(let o=0;o<i.length;o++){let a=i[o];if(o==t)return;this.get(n?a.slice(n):a)}}};import{setTimeout as H}from"timers/promises";import{InlineKeyboard as J,Keyboard as U}from"grammy";var B=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(e){this.ct.from.language_code=e}get msgText(){return this.ct.message?.text}get msgTextArgs(){return this.getArgs(this.msgText,"space",this.data?._positionArgText||this.temp?.data?._positionArgText)}get msgTextArg(){return this.msgTextArgs[0]}get msgTextCommandArgs(){return this.getArgs(this.msgText,"space")}get msgTextCommandArg(){return this.msgTextCommandArgs[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionArgs(){return this.getArgs(this.msgCaption,"space")}get msgCaptionArg(){return this.msgCaptionArgs[0]}get msgCaptionCommandArgs(){return this.getArgs(this.msgCaption,"space")}get msgCaptionCommandArg(){return this.msgCaptionCommandArgs[0]}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get msgDocument(){return this.ct.message?.document}get msgAnimation(){return this.ct.message?.animation}get msgVoice(){return this.ct.message?.voice}get msgVideoNote(){return this.ct.message?.video_note}get msgSticker(){return this.ct.message?.sticker}get msgLocation(){return this.ct.message?.location}get msgContact(){return this.ct.message?.contact}get msgWebAppData(){return this.ct.message?.web_app_data}get msgGift(){return this.ct.message?.gift}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataArgs(){return this.getArgs(this.callbackData,"colon")}get callbackDataArg(){return this.callbackDataArgs?.[0]}get session(){return this.temp.session}set session(e){this.temp.session=e}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(e){this.ct=e.ct,this.cacheSession=e.cacheSession,this.cacheKeyboard=e.cacheKeyboard,this.templateManager=e.templateManager,this.temp=e.temp}async broadcast(e,t,s,n,i,o,a=!1){try{this.temp.isAnswer=!0;let r=30,c=t.map(l=>this.templateManager.getMessage(this.data.name,i,l,n));for(let l=0;l<e.length;l++){let d=e[l],h=c[l];await this.ct.api.sendMessage(d,h,{parse_mode:"HTML",reply_markup:s,...o}),l+1==r&&await H(1200)}}catch(r){if(a)throw r}}async broadcastMedia(e,t,s,n,i,o,a=!1){try{this.temp.isAnswer=!0;let r=30,c=t.map(l=>this.templateManager.getMedia(this.data.name,i,l,n));for(let l=0;l<e.length;l++){let d=e[l],h=c[l];if(!h)continue;let m={parse_mode:"HTML",reply_markup:s,...o};h.type=="photo"&&await this.ct.api.sendPhoto(d,h.src,{caption:h.caption,...m}),h.type=="video"&&await this.ct.api.sendVideo(d,h.src,{caption:h.caption,...m}),h.type=="audio"&&await this.ct.api.sendAudio(d,h.src,{caption:h.caption,...m}),h.type=="document"&&await this.ct.api.sendDocument(d,h.src,{caption:h.caption,...m}),h.type=="animation"&&await this.ct.api.sendAnimation(d,h.src,{caption:h.caption,...m}),h.type=="voice"&&await this.ct.api.sendVoice(d,h.src,m),h.type=="video_note"&&await this.ct.api.sendVideoNote(d,h.src,m),h.type=="sticker"&&await this.ct.api.sendSticker(d,h.src,m),h.type=="location"&&await this.ct.api.sendLocation(d,parseInt(h.latitude),parseInt(h.longitude),m),h.type=="contact"&&await this.ct.api.sendContact(d,h.phone,h.first_name,{vcard:h.vcard,...m}),l+1==r&&await H(1200)}}catch(r){if(a)throw r}}async reply(e,t,s,n){this.temp.isAnswer=!0;let i=this.templateManager.getMessage(this.data.name,s,this.userLanguage,t);return await this.ct.reply(i,{parse_mode:"HTML",reply_markup:e,...n})}async replyMedia(e,t,s,n,i){this.temp.isAnswer=!0;let o=this.templateManager.getMedia(this.data.name,n,this.userLanguage,s),a={parse_mode:"HTML",reply_markup:t,...i};if(e=="photo")return await this.ct.replyWithPhoto(o.src,{caption:o.caption,...a});if(e=="video")return await this.ct.replyWithVideo(o.src,{caption:o.caption,...a});if(e=="audio")return await this.ct.replyWithAudio(o.src,{caption:o.caption,...a});if(e=="document")return await this.ct.replyWithDocument(o.src,{caption:o.caption,...a});if(e=="animation")return await this.ct.replyWithAnimation(o.src,{caption:o.caption,...a});if(e=="voice")return await this.ct.replyWithVoice(o.src,a);if(e=="video_note")return await this.ct.replyWithVideoNote(o.src,a);if(e=="sticker")return await this.ct.replyWithSticker(o.src,a);if(e=="location")return await this.ct.replyWithLocation(parseInt(o.latitude),parseInt(o.longitude),a);if(e=="contact")return await this.ct.replyWithContact(o.phone,o.first_name,{vcard:o.vcard,...a})}async replyPhoto(e,t,s,n){return this.replyMedia("photo",e,t,s,n)}async replyVideo(e,t,s,n){return this.replyMedia("video",e,t,s,n)}async replyAudio(e,t,s,n){return this.replyMedia("audio",e,t,s,n)}async replyDocument(e,t,s,n){return this.replyMedia("document",e,t,s,n)}async replyAnimation(e,t,s,n){return this.replyMedia("animation",e,t,s,n)}async replyVoice(e,t,s,n){return this.replyMedia("voice",e,t,s,n)}async replyVideoNote(e,t,s,n){return this.replyMedia("video_note",e,t,s,n)}async replySticker(e,t,s,n){return this.replyMedia("sticker",e,t,s,n)}async replyLocation(e,t,s,n){return this.replyMedia("location",e,t,s,n)}async replyContact(e,t,s,n){return this.replyMedia("contact",e,t,s,n)}async replyAction(e){return await this.ct.replyWithChatAction(e)}async edit(e,t,s,n,i=!0){try{this.temp.isAnswer=!0;let o=this.templateManager.getMessage(this.data.name,s,this.userLanguage,t);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:e,...n})}catch(o){if(i)await this.reply(e,t,s,n);else throw o}}async editMedia(e,t,s,n,i,o,a=!0){try{this.temp.isAnswer=!0;let{src:r,caption:c}=this.templateManager.getMedia(this.data.name,n,this.userLanguage,s);return e=="voice"?(await this.delete(),await this.replyVoice(t,s,n,i)):e=="video_note"?(await this.delete(),await this.replyVoice(t,s,n,i)):e=="sticker"?(await this.delete(),await this.replySticker(t,s,n,i)):e=="location"?(await this.delete(),await this.replyLocation(t,s,n,i)):e=="contact"?(await this.delete(),await this.replyContact(t,s,n,i)):await this.ct.editMessageMedia({media:r,caption:c,type:e,parse_mode:"HTML",...i},{reply_markup:t,...o})}catch(r){if(a===!0)await this.reply(t,s,n,o);else throw r}}async editPhoto(e,t,s,n,i){return await this.editMedia("photo",e,t,s,n,i)}async editVideo(e,t,s,n,i){return await this.editMedia("video",e,t,s,n,i)}async editAudio(e,t,s,n,i){return await this.editMedia("audio",e,t,s,n,i)}async editDocument(e,t,s,n,i){return await this.editMedia("document",e,t,s,n,i)}async editAnimation(e,t,s,n,i){return await this.editMedia("animation",e,t,s,n,i)}async editVoice(e,t,s,n){return await this.editMedia("voice",e,t,s,n)}async editVideoNote(e,t,s,n){return await this.editMedia("video_note",e,t,s,n)}async editSticker(e,t,s,n){return await this.editMedia("sticker",e,t,s,n)}async editLocation(e,t,s,n){return await this.editMedia("location",e,t,s,n)}async editContact(e,t,s,n){return await this.editMedia("contact",e,t,s,n)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(e){try{return this.temp.isAnswer=!0,await this.ct.answerCallbackQuery(e)}catch{return null}}async setSession(e,t,s){try{let n={method:e,params:t,...s},i=await this.cacheSession.set(`${this.userId}`,n);return i&&(this.temp.session=n),i}catch{return null}}async getSession(){try{let e=await this.cacheSession.get(`${this.userId}`);return e&&(this.temp.session=e),e||null}catch{return null}}async clearSession(){try{let e=await this.cacheSession.delete(`${this.userId}`);return e&&(this.temp.session={}),e}catch{return null}}static buildData(e){let s=typeof e=="function"?{callbackData:e}:e||{},n=s.callbackData,i=this.prototype.addArgs.bind(this.prototype),o=s.name||"";return{name:o,intentText:s.intentText||o,intentCommandText:s.intentCommandText||o,intentCallbackData:o,callbackData:n?function(...r){return i(this.intentCallbackData,"colon",n(...r))}:function(){return this?.intentCallbackData},_positionArgText:s.intentText?s.intentText.split(this.prototype.getSeperatorTag("space")).length:void 0}}keyboardCols(e,t,s,n){let[i,o]=s.split("-"),a=parseInt(i),r=o?parseInt(o):null,c=t.length,l=e;for(let d=0;d<c;d++){let h=t[d];if(n(h,d),r===null)(d+1)%a===0&&d<c-1&&l.row();else{let m=c-(d+1);(m===r||m>r&&(d+1)%a===0)&&l.row()}}return e}bottomKeyboardT(e="1",t,s){return this.bottomKeyboard((n,i)=>this.keyboardCols(n,i,e,o=>n.text(o)),{baseId:t??void 0,data:s})}inlineKeyboardT(e,t="1",s,n){return this.inlineKeyboard((i,o)=>this.keyboardCols(i,o,t,(a,r)=>{let c=e[r],l=typeof c=="string"?c:c.data.callbackData();i.text(a,l)}),{baseId:s??void 0,data:n})}inlineKeyboard(e,t){let s=this.data.name;if(t?.cache===!0){let a=`${s}:${this.userLanguage}:i`,r=this.cacheKeyboard.get(a);if(!r){let c=new J,l=this.templateManager.getKeyboard(s,t?.baseId,this.userLanguage,"inline",t?.data),d=e(c,l);return this.cacheKeyboard.set(a,d),d}return r}let n=new J,i=this.templateManager.getKeyboard(s,t?.baseId,this.userLanguage,"inline",t?.data);return e(n,i)}bottomKeyboard(e,t){let s=this.data.name;if(t?.cache===!0){let a=`${s}:${this.userLanguage}:b`,r=this.cacheKeyboard.get(a);if(!r){let c=new U,l=this.templateManager.getKeyboard(s,t?.baseId,this.userLanguage,"bottom",t?.data),d=e(c,l);return d.resized(!0),this.cacheKeyboard.set(a,d),d}return r}let n=new U,i=this.templateManager.getKeyboard(s,t?.baseId,this.userLanguage,"bottom",t?.data),o=e(n,i);return o.resized(),o}getSeperatorTag(e="space"){return e=="space"?" ":":"}haveArgs(e="",t){return e.includes(this.getSeperatorTag(t))}addArgs(e="",t,s){let n=this.getSeperatorTag(t),i="";for(let o=0;o<s.length;o++){let a=s[o];a!=null&&a!==""&&(i+=n+a)}return e+i}getArgs(e="",t,s=1){if(!e)return[];let n=this.getSeperatorTag(t);return e.split(n).slice(s)}getIntent(e="",t,s=1){if(!e)return"";let n=this.getSeperatorTag(t),i=e.split(n);return s==1?i[0]:i.slice(0,s).join(n)}isSessionCallbackData(){return this.temp.session.method===this.methodSessionCallbackData()}isSessionArgsCallbackData(){return this.temp.session.method===this.methodSessionArgsCallbackData()}isSessionText(){return this.temp.session.method===this.methodSessionText()}isSessionArgsText(){return this.temp.session.method===this.methodSessionArgsText()}isSessionCommandText(){return this.temp.session.method===this.methodSessionCommandText()}isSessionCommandArgsText(){return this.temp.session.method===this.methodSessionCommandArgsText()}isSessionFreeText(){return this.temp.session.method===this.methodSessionFreeText()}isSessionCaptionPhoto(){return this.temp.session.method===this.methodSessionCaptionPhoto()}isSessionCaptionArgsPhoto(){return this.temp.session.method===this.methodSessionCaptionArgsPhoto()}isSessionCommandCaptionPhoto(){return this.temp.session.method===this.methodSessionCommandCaptionPhoto()}isSessionCommandCaptionArgsPhoto(){return this.temp.session.method===this.methodSessionCommandCaptionArgsPhoto()}isSessionFreePhoto(){return this.temp.session.method===this.methodSessionFreePhoto()}isSessionCaptionVideo(){return this.temp.session.method===this.methodSessionCaptionVideo()}isSessionCaptionArgsVideo(){return this.temp.session.method===this.methodSessionCaptionArgsVideo()}isSessionCommandCaptionVideo(){return this.temp.session.method===this.methodSessionCommandCaptionVideo()}isSessionCommandCaptionArgsVideo(){return this.temp.session.method===this.methodSessionCommandCaptionArgsVideo()}isSessionFreeVideo(){return this.temp.session.method===this.methodSessionFreeVideo()}isSessionCaptionAudio(){return this.temp.session.method===this.methodSessionCaptionAudio()}isSessionCaptionArgsAudio(){return this.temp.session.method===this.methodSessionCaptionArgsAudio()}isSessionCaptionCommandAudio(){return this.temp.session.method===this.methodSessionCaptionCommandAudio()}isSessionCaptionCommandArgsAudio(){return this.temp.session.method===this.methodSessionCaptionCommandArgsAudio()}isSessionFreeAudio(){return this.temp.session.method===this.methodSessionFreeAudio()}isSessionCaptionDocument(){return this.temp.session.method===this.methodSessionCaptionDocument()}isSessionCaptionArgsDocument(){return this.temp.session.method===this.methodSessionCaptionArgsDocument()}isSessionCommandCaptionDocument(){return this.temp.session.method===this.methodSessionCommandCaptionDocument()}isSessionCommandCaptionArgsDocument(){return this.temp.session.method===this.methodSessionCommandCaptionArgsDocument()}isSessionFreeDocument(){return this.temp.session.method===this.methodSessionFreeDocument()}isSessionCaptionAnimation(){return this.temp.session.method===this.methodSessionCaptionAnimation()}isSessionCaptionArgsAnimation(){return this.temp.session.method===this.methodSessionCaptionArgsAnimation()}isSessionCommandCaptionAnimation(){return this.temp.session.method===this.methodSessionCommandCaptionAnimation()}isSessionCommandCaptionArgsAnimation(){return this.temp.session.method===this.methodSessionCommandCaptionArgsAnimation()}isSessionFreeAnimation(){return this.temp.session.method===this.methodSessionFreeAnimation()}isSessionCaptionVoice(){return this.temp.session.method===this.methodSessionCaptionVoice()}isSessionCaptionArgsVoice(){return this.temp.session.method===this.methodSessionCaptionArgsVoice()}isSessionCommandCaptionVoice(){return this.temp.session.method===this.methodSessionCommandCaptionVoice()}isSessionCommandCaptionArgsVoice(){return this.temp.session.method===this.methodSessionCommandCaptionArgsVoice()}isSessionFreeVoice(){return this.temp.session.method===this.methodSessionFreeVoice()}isSessionFreeVideoNote(){return this.temp.session.method===this.methodSessionFreeVideoNote()}isSessionFreeSticker(){return this.temp.session.method===this.methodSessionFreeSticker()}isSessionFreeLocation(){return this.temp.session.method===this.methodSessionFreeLocation()}isSessionFreeContact(){return this.temp.session.method===this.methodSessionFreeContact()}sessionCallbackData(e){return this.setSession(this.methodSessionCallbackData(),e)}sessionArgsCallbackData(e){return this.setSession(this.methodSessionArgsCallbackData(),e)}sessionText(e){return this.setSession(this.methodSessionText(),e)}sessionArgsText(e){return this.setSession(this.methodSessionArgsText(),e)}sessionCommandText(e){return this.setSession(this.methodSessionCommandText(),e)}sessionCommandArgsText(e){return this.setSession(this.methodSessionCommandArgsText(),e)}sessionFreeText(e){return this.setSession(this.methodSessionFreeText(),e)}sessionCaptionPhoto(e){return this.setSession(this.methodSessionCaptionPhoto(),e)}sessionCaptionArgsPhoto(e){return this.setSession(this.methodSessionCaptionArgsPhoto(),e)}sessionCommandCaptionPhoto(e){return this.setSession(this.methodSessionCommandCaptionPhoto(),e)}sessionCommandCaptionArgsPhoto(e){return this.setSession(this.methodSessionCommandCaptionArgsPhoto(),e)}sessionFreePhoto(e){return this.setSession(this.methodSessionFreePhoto(),e)}sessionCaptionVideo(e){return this.setSession(this.methodSessionCaptionVideo(),e)}sessionCaptionArgsVideo(e){return this.setSession(this.methodSessionCaptionArgsVideo(),e)}sessionCommandCaptionVideo(e){return this.setSession(this.methodSessionCommandCaptionVideo(),e)}sessionCommandCaptionArgsVideo(e){return this.setSession(this.methodSessionCommandCaptionArgsVideo(),e)}sessionFreeVideo(e){return this.setSession(this.methodSessionFreeVideo(),e)}sessionCaptionAudio(e){return this.setSession(this.methodSessionCaptionAudio(),e)}sessionCaptionArgsAudio(e){return this.setSession(this.methodSessionCaptionArgsAudio(),e)}sessionCaptionCommandAudio(e){return this.setSession(this.methodSessionCaptionCommandAudio(),e)}sessionCaptionCommandArgsAudio(e){return this.setSession(this.methodSessionCaptionCommandArgsAudio(),e)}sessionFreeAudio(e){return this.setSession(this.methodSessionFreeAudio(),e)}sessionCaptionDocument(e){return this.setSession(this.methodSessionCaptionDocument(),e)}sessionCaptionArgsDocument(e){return this.setSession(this.methodSessionCaptionArgsDocument(),e)}sessionCommandCaptionDocument(e){return this.setSession(this.methodSessionCommandCaptionDocument(),e)}sessionCommandCaptionArgsDocument(e){return this.setSession(this.methodSessionCommandCaptionArgsDocument(),e)}sessionFreeDocument(e){return this.setSession(this.methodSessionFreeDocument(),e)}sessionCaptionAnimation(e){return this.setSession(this.methodSessionCaptionAnimation(),e)}sessionCaptionArgsAnimation(e){return this.setSession(this.methodSessionCaptionArgsAnimation(),e)}sessionCommandCaptionAnimation(e){return this.setSession(this.methodSessionCommandCaptionAnimation(),e)}sessionCommandCaptionArgsAnimation(e){return this.setSession(this.methodSessionCommandCaptionArgsAnimation(),e)}sessionFreeAnimation(e){return this.setSession(this.methodSessionFreeAnimation(),e)}sessionCaptionVoice(e){return this.setSession(this.methodSessionCaptionVoice(),e)}sessionCaptionArgsVoice(e){return this.setSession(this.methodSessionCaptionArgsVoice(),e)}sessionCommandCaptionVoice(e){return this.setSession(this.methodSessionCommandCaptionVoice(),e)}sessionCommandCaptionArgsVoice(e){return this.setSession(this.methodSessionCommandCaptionArgsVoice(),e)}sessionFreeVoice(e){return this.setSession(this.methodSessionFreeVoice(),e)}sessionFreeVideoNote(e){return this.setSession(this.methodSessionFreeVideoNote(),e)}sessionFreeSticker(e){return this.setSession(this.methodSessionFreeSticker(),e)}sessionFreeLocation(e){return this.setSession(this.methodSessionFreeLocation(),e)}sessionFreeContact(e){return this.setSession(this.methodSessionFreeContact(),e)}methodSession(e,t){return`${e}-${t||this.data.name}`}methodSessionCallbackData(e){return this.methodSession("1",e)}methodSessionArgsCallbackData(e){return this.methodSession("2",e)}methodSessionText(e){return this.methodSession("3",e)}methodSessionArgsText(e){return this.methodSession("4",e)}methodSessionCommandText(e){return this.methodSession("5",e)}methodSessionCommandArgsText(e){return this.methodSession("6",e)}methodSessionFreeText(e){return this.methodSession("7",e)}methodSessionCaptionPhoto(e){return this.methodSession("8",e)}methodSessionCaptionArgsPhoto(e){return this.methodSession("9",e)}methodSessionCommandCaptionPhoto(e){return this.methodSession("10",e)}methodSessionCommandCaptionArgsPhoto(e){return this.methodSession("11",e)}methodSessionFreePhoto(e){return this.methodSession("12",e)}methodSessionCaptionVideo(e){return this.methodSession("13",e)}methodSessionCaptionArgsVideo(e){return this.methodSession("14",e)}methodSessionCommandCaptionVideo(e){return this.methodSession("15",e)}methodSessionCommandCaptionArgsVideo(e){return this.methodSession("16",e)}methodSessionFreeVideo(e){return this.methodSession("17",e)}methodSessionCaptionAudio(e){return this.methodSession("18",e)}methodSessionCaptionArgsAudio(e){return this.methodSession("19",e)}methodSessionCaptionCommandAudio(e){return this.methodSession("20",e)}methodSessionCaptionCommandArgsAudio(e){return this.methodSession("21",e)}methodSessionFreeAudio(e){return this.methodSession("22",e)}methodSessionCaptionDocument(e){return this.methodSession("23",e)}methodSessionCaptionArgsDocument(e){return this.methodSession("24",e)}methodSessionCommandCaptionDocument(e){return this.methodSession("25",e)}methodSessionCommandCaptionArgsDocument(e){return this.methodSession("26",e)}methodSessionFreeDocument(e){return this.methodSession("27",e)}methodSessionCaptionAnimation(e){return this.methodSession("28",e)}methodSessionCaptionArgsAnimation(e){return this.methodSession("29",e)}methodSessionCommandCaptionAnimation(e){return this.methodSession("30",e)}methodSessionCommandCaptionArgsAnimation(e){return this.methodSession("31",e)}methodSessionFreeAnimation(e){return this.methodSession("32",e)}methodSessionCaptionVoice(e){return this.methodSession("33",e)}methodSessionCaptionArgsVoice(e){return this.methodSession("34",e)}methodSessionCommandCaptionVoice(e){return this.methodSession("35",e)}methodSessionCommandCaptionArgsVoice(e){return this.methodSession("36",e)}methodSessionFreeVoice(e){return this.methodSession("37",e)}methodSessionFreeVideoNote(e){return this.methodSession("38",e)}methodSessionFreeSticker(e){return this.methodSession("39",e)}methodSessionFreeLocation(e){return this.methodSession("40",e)}methodSessionFreeContact(e){return this.methodSession("41",e)}};import{join as q}from"path";import{existsSync as X,readdirSync as Y}from"fs";import{createRequire as ye}from"module";var _=class{static{p(this,"PageManager")}static _getFile(e,t,s=0){let i=Object.values(e)[s];if(i===void 0)throw new Error(`File ${t} must have export (not default) class page`);return i}static getFilePath(){return q(process.cwd(),"src","pages")}static getFileSync(e,t=0){e||(e=this.getFilePath());let n=ye(e)(e);return this._getFile(n,e,t)}static async getFile(e,t=0){e||(e=this.getFilePath());let s=await import(`${e}?t=${Date.now()}`);return this._getFile(s,e,t)}static getFileManySync(e,t=0){if(e||(e=this.getFilePath()),!X(e))throw new Error(`Directory ${e} is not found, please make it manually`);return Y(e).map(n=>{let i=q(e,n);return{path:i,page:this.getFileSync(i,t)}})}static clearCacheRequire(e){if(e||(e=this.getFilePath()),!X(e))throw new Error(`Directory ${e} is not found, please make it manually`);return Y(e).forEach(s=>{let n=q(e,s);delete N.cache[N.resolve(n)]}),!0}};import{readFileSync as be}from"fs";import{fileURLToPath as Se}from"url";import{dirname as ke,join as se,parse as we}from"path";import{basename as Q,join as R,extname as Z}from"path";import{readdirSync as fe,readFileSync as V,existsSync as D,statSync as O,writeFileSync as Ce}from"fs";import{watch as Te}from"chokidar";var A=class{static{p(this,"TemplateEngine")}static _escape(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processScopeVariables(e){return e.replace(/\{\{(\w+)\}\}/g,(t,s)=>`\${(data && data["${s}"]) ?? ""}`)}static _processScopeExec(e){return e.replace(/{~\s*([\s\S]*?)\s*~}/g,(t,s)=>`\${(() => { try { return ${s} } catch(e) { try { with(data || {}) { return ${s} } } catch(ee) { return '' } } })()}`)}static _processBaseBlocks(e){let t=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,s={};for(let n of e.matchAll(t)){let i=n[2]??"default",a=(n[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();s[i]=a}return s}static _processScriptBlocks(e){return e.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(t,s)=>{let n=s.trim();return n?`\${(() => { if (!data) return ''; try { with(data) { ${n} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(e){return e.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(e){return e.replace(/<div>([\s\S]*?)<\/div>/gi,(t,s)=>s.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processSwitchBlocks(e){let t=/<switch\b(?:\s+value="([^"]+)")?>([\s\S]*?)<\/switch>/gi;return e.replace(t,(s,n,i)=>{if(!n)return"";let o="",a=/<case\b(?:\s+is="([^"]+)")?>([\s\S]*?)<\/case>/gi,r=/<default>([\s\S]*?)<\/default>/gi,c;for(;(c=a.exec(i))!==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=>{o+=`case "${m}": `}),o+=`return \`${h}\`; `}let l=r.exec(i);if(l){let d=(l[1]||"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();o+=`default: return \`${d}\`; `}else o+="default: return ''; ";return`\${(() => { switch((data && data["${n}"])) { ${o} } })()}`})}static _processMapBlocks(e){let t=/<map(?:\s+([^>]*))?>([\s\S]*?)<\/map>/gi;return e.replace(t,(s,n,i)=>{let o={},a=/(\w+)="([^"]*)"/g;if(n)for(let h of n.matchAll(a))o[h[1]]=h[2];let r=o.src;if(!r)return"";let c=o.join??"\\n",l=i.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`\${(() => { const __arr = (data && data["${r}"]) || []; let __out = ""; for (let i = 0; i < __arr.length; i++) { const e = __arr[i]; if (i > 0) { __out += "${d}" } __out += \`${l}\`; } return __out; })()}`})}static _processMediaBlocks(e){let t=/<media(?:\s+([^>]*))?>([\s\S]*?)<\/media>/gi,s={};for(let n of e.matchAll(t)){let i=n[1],o=n[2],a={},r=/(\w+)="([^"]*)"/g;if(i)for(let m of i.matchAll(r))a[m[1]]=m[2];let c=a.lang||"default",l=a.type,d=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),h={type:l};a.src&&(h.src=a.src),d&&l!=="video_note"&&l!=="sticker"&&(h.caption=d),l==="location"&&(a.latitude&&(h.latitude=a.latitude),a.longitude&&(h.longitude=a.longitude),d&&(h.caption=d)),l==="contact"&&(a.phone&&(h.phone=a.phone),a.first_name&&(h.first_name=a.first_name),a.last_name&&(h.last_name=a.last_name),a.vcard&&(h.vcard=a.vcard),d&&(h.caption=d)),s[c]=h}return s}static _processMessageBlocks(e){let t=/<message(?:\s+([^>]*))?>([\s\S]*?)<\/message>/gi,s={};for(let[,n,i]of e.matchAll(t)){let o={},a=/(\w+)="([^"]*)"/g;if(n)for(let l of n.matchAll(a))o[l[1]]=l[2];let r=o.lang||"default",c=i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();s[r]=c}return s}static _processDescriptionBlocks(e){let t=/<description(?:\s+([^>]*))?>([\s\S]*?)<\/description>/gi,s={};for(let[,n,i]of e.matchAll(t)){let o={},a=/(\w+)="([^"]*)"/g;if(n)for(let d of n.matchAll(a))o[d[1]]=d[2];let r=o.lang||"default",c=o.scope||"default",l=i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();s[r]||(s[r]={}),s[r][c]=l}return s}static _processKeyboardBlocks(e){let t=/<keyboard(?:\s+([^>]*))?>([\s\S]*?)<\/keyboard>/gi,s={};for(let[,n,i]of e.matchAll(t)){let o={},a=/(\w+)="([^"]*)"/g;if(n)for(let d of n.matchAll(a))o[d[1]]=d[2];let r=o.lang||"default",c=o.type==="bottom"?"bottom":"inline",l=i.trim();s[r]||(s[r]={}),s[r][c]=l}return s}static _compileToFunction(e,t){let s;t?s=e.map(o=>`\`${o}\``).join(","):s=`\`${e}\``;let n=s;if(n=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(n))),t){let i=`return [${n}]`;return new Function("data",i)}else{let i=`return ${n}`;return new Function("data",i)}}static compileBlockMedia(e,t){let s=t||this._processBaseBlocks(e),n={};for(let[i,o]of Object.entries(s)){let a=this._processMediaBlocks(o);n[i]={};for(let[r,c]of Object.entries(a)){let l={};for(let[d,h]of Object.entries(c)){if(d==="type"||typeof h!="string")continue;let m=this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(h)))));l[d]=this._compileToFunction(m,!1)}n[i][r]=d=>{let h={...c};for(let[m,u]of Object.entries(l))h[m]=u(d);return h}}}return n}static compileBlockMessage(e,t){let s=t||this._processBaseBlocks(e),n={};for(let[i,o]of Object.entries(s)){let a=this._processMessageBlocks(o);n[i]={};for(let[r,c]of Object.entries(a)){let l=this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(c)))));n[i][r]=this._compileToFunction(l,!1)}}return n}static compileBlockDescription(e,t){let s=t||this._processBaseBlocks(e),n={};for(let[i,o]of Object.entries(s)){let a=this._processDescriptionBlocks(o);n[i]={};for(let[r,c]of Object.entries(a))for(let[l,d]of Object.entries(c)){n[i][l]||(n[i][l]={});let h=this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(d)))));n[i][l][r]=this._compileToFunction(h,!1)}}return n}static compileBlockKeyboards(e,t){let s=t||this._processBaseBlocks(e),n={};for(let[i,o]of Object.entries(s)){let a=this._processKeyboardBlocks(o);n[i]={};for(let[r,c]of Object.entries(a)){n[i][r]={};for(let[l,d]of Object.entries(c)){let m=d.split(/(?<!\\),\s*/).map(u=>u.replace(/\\,/g,",").trim()).map(u=>this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(u))))));n[i][r][l]=this._compileToFunction(m,!0)}}}return n}static _extractBlock(e,t,s="default",n="all",i){let o=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,a=e,r=!1;for(let c of e.matchAll(o))if((c[2]??"default")===s){a=c[3]??"",r=!0;break}if(!r){let c=/<base\b/.test(e);if(!(s==="default"&&!c))return""}if(t){if(t==="all")return a;let c=Array.isArray(t)?t:[t],l=[];for(let h of c){let m=new RegExp(`([ \\t]*)<${h}(?:\\s+([^>]*))?>([\\s\\S]*?)<\\/${h}>`,"gi");for(let u of a.matchAll(m)){let I=u[2];if(i){let T=/lang="([^"]*)"/i,w=I?.match(T);if(((w?w[1]:void 0)||"default")!==i)continue}l.push({start:u.index,content:u[0],innerContent:u[3]??""})}}l.sort((h,m)=>h.start-m.start);let d=p(h=>{let m=h.split(`
|
|
1
|
+
var de=Object.defineProperty;var p=(g,e)=>de(g,"name",{value:e,configurable:!0}),N=(g=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(g,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):g)(function(g){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+g+'" is not supported')});import Ve from"path";import{fileURLToPath as le}from"url";var me=p(()=>le(import.meta.url),"getFilename");var f=me();import{LoggingPretty as pe}from"logging-pretty";var j=class extends pe{static{p(this,"LoggingUtil")}timers=new Map;constructor(e){super(e)}errorMake(e,t,s){this.error(`[${t?`${t}:${s}`:s}] ${this._formatErrorObj(e)}`)}_formatErrorObj(e){return JSON.stringify(e instanceof Error?{message:e.message,stack:e.stack,name:e.name}:e,null,2)}time(e){this.timers.set(e,process.hrtime.bigint())}timeEnd(e,t){let s=this.timers.get(e);if(s===void 0){this.debug(`${e}: Timer was never started`);return}let n=(Number(process.hrtime.bigint()-s)/1e6).toFixed(3);this.timers.delete(e),t?this.debug(`${t} (took ${n}ms)`):this.debug(`${e} (took ${n}ms)`)}timeCheck(e){let t=this.timers.get(e);if(t!==void 0)return(Number(process.hrtime.bigint()-t)/1e6).toFixed(3)}timeLog(e,t){let s=this.timeCheck(e);if(s===void 0){this.debug(`${e}: Timer was never started`);return}t?this.debug(`${t} (${s}ms)`):this.debug(`${e} (${s}ms)`)}timeClear(){this.timers.clear()}timeActive(){return Array.from(this.timers.keys())}},z=new j;import{Keyv as ue}from"keyv";import ge from"@keyv/redis";var F=class extends ue{constructor(t="memory",s,n,i){let o;t.startsWith("redis")&&(o=new ge(t)),t==="memory"&&(o=new Map),i?.forceStore&&(o=i.forceStore);super({store:o,namespace:n,ttl:s});this.url=t}static{p(this,"CacheExternal")}refreshLruCache(t){let s=this.store,n=this.opts.namespace?this.opts.namespace?.length+1:null,i=s.keys().toArray();for(let o=0;o<i.length;o++){let a=i[o];if(o==t)return;this.get(n?a.slice(n):a)}}};import{setTimeout as H}from"timers/promises";import{InlineKeyboard as J,Keyboard as U}from"grammy";var B=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(e){this.ct.from.language_code=e}get msgText(){return this.ct.message?.text}get msgTextArgs(){return this.getArgs(this.msgText,"space",this.data?._positionArgText||this.temp?.data?._positionArgText)}get msgTextArg(){return this.msgTextArgs[0]}get msgTextCommandArgs(){return this.getArgs(this.msgText,"space")}get msgTextCommandArg(){return this.msgTextCommandArgs[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionArgs(){return this.getArgs(this.msgCaption,"space")}get msgCaptionArg(){return this.msgCaptionArgs[0]}get msgCaptionCommandArgs(){return this.getArgs(this.msgCaption,"space")}get msgCaptionCommandArg(){return this.msgCaptionCommandArgs[0]}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get msgDocument(){return this.ct.message?.document}get msgAnimation(){return this.ct.message?.animation}get msgVoice(){return this.ct.message?.voice}get msgVideoNote(){return this.ct.message?.video_note}get msgSticker(){return this.ct.message?.sticker}get msgLocation(){return this.ct.message?.location}get msgContact(){return this.ct.message?.contact}get msgWebAppData(){return this.ct.message?.web_app_data}get msgGift(){return this.ct.message?.gift}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataArgs(){return this.getArgs(this.callbackData,"colon")}get callbackDataArg(){return this.callbackDataArgs?.[0]}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(e){this.ct=e.ct,this.cacheSession=e.cacheSession,this.cacheKeyboard=e.cacheKeyboard,this.templateManager=e.templateManager,this.temp=e.temp}async broadcast(e,t,s,n,i,o,a=!1){try{this.temp.isAnswer=!0;let r=30,c=t.map(l=>this.templateManager.getMessage(this.data.name,i,l,n));for(let l=0;l<e.length;l++){let d=e[l],h=c[l];await this.ct.api.sendMessage(d,h,{parse_mode:"HTML",reply_markup:s,...o}),l+1==r&&await H(1200)}}catch(r){if(a)throw r}}async broadcastMedia(e,t,s,n,i,o,a=!1){try{this.temp.isAnswer=!0;let r=30,c=t.map(l=>this.templateManager.getMedia(this.data.name,i,l,n));for(let l=0;l<e.length;l++){let d=e[l],h=c[l];if(!h)continue;let m={parse_mode:"HTML",reply_markup:s,...o};h.type=="photo"&&await this.ct.api.sendPhoto(d,h.src,{caption:h.caption,...m}),h.type=="video"&&await this.ct.api.sendVideo(d,h.src,{caption:h.caption,...m}),h.type=="audio"&&await this.ct.api.sendAudio(d,h.src,{caption:h.caption,...m}),h.type=="document"&&await this.ct.api.sendDocument(d,h.src,{caption:h.caption,...m}),h.type=="animation"&&await this.ct.api.sendAnimation(d,h.src,{caption:h.caption,...m}),h.type=="voice"&&await this.ct.api.sendVoice(d,h.src,m),h.type=="video_note"&&await this.ct.api.sendVideoNote(d,h.src,m),h.type=="sticker"&&await this.ct.api.sendSticker(d,h.src,m),h.type=="location"&&await this.ct.api.sendLocation(d,parseInt(h.latitude),parseInt(h.longitude),m),h.type=="contact"&&await this.ct.api.sendContact(d,h.phone,h.first_name,{vcard:h.vcard,...m}),l+1==r&&await H(1200)}}catch(r){if(a)throw r}}async reply(e,t,s,n){this.temp.isAnswer=!0;let i=this.templateManager.getMessage(this.data.name,s,this.userLanguage,t);return await this.ct.reply(i,{parse_mode:"HTML",reply_markup:e,...n})}async replyMedia(e,t,s,n,i){this.temp.isAnswer=!0;let o=this.templateManager.getMedia(this.data.name,n,this.userLanguage,s),a={parse_mode:"HTML",reply_markup:t,...i};if(e=="photo")return await this.ct.replyWithPhoto(o.src,{caption:o.caption,...a});if(e=="video")return await this.ct.replyWithVideo(o.src,{caption:o.caption,...a});if(e=="audio")return await this.ct.replyWithAudio(o.src,{caption:o.caption,...a});if(e=="document")return await this.ct.replyWithDocument(o.src,{caption:o.caption,...a});if(e=="animation")return await this.ct.replyWithAnimation(o.src,{caption:o.caption,...a});if(e=="voice")return await this.ct.replyWithVoice(o.src,a);if(e=="video_note")return await this.ct.replyWithVideoNote(o.src,a);if(e=="sticker")return await this.ct.replyWithSticker(o.src,a);if(e=="location")return await this.ct.replyWithLocation(parseInt(o.latitude),parseInt(o.longitude),a);if(e=="contact")return await this.ct.replyWithContact(o.phone,o.first_name,{vcard:o.vcard,...a})}async replyPhoto(e,t,s,n){return this.replyMedia("photo",e,t,s,n)}async replyVideo(e,t,s,n){return this.replyMedia("video",e,t,s,n)}async replyAudio(e,t,s,n){return this.replyMedia("audio",e,t,s,n)}async replyDocument(e,t,s,n){return this.replyMedia("document",e,t,s,n)}async replyAnimation(e,t,s,n){return this.replyMedia("animation",e,t,s,n)}async replyVoice(e,t,s,n){return this.replyMedia("voice",e,t,s,n)}async replyVideoNote(e,t,s,n){return this.replyMedia("video_note",e,t,s,n)}async replySticker(e,t,s,n){return this.replyMedia("sticker",e,t,s,n)}async replyLocation(e,t,s,n){return this.replyMedia("location",e,t,s,n)}async replyContact(e,t,s,n){return this.replyMedia("contact",e,t,s,n)}async replyAction(e){return await this.ct.replyWithChatAction(e)}async edit(e,t,s,n,i=!0){try{this.temp.isAnswer=!0;let o=this.templateManager.getMessage(this.data.name,s,this.userLanguage,t);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:e,...n})}catch(o){if(i)await this.reply(e,t,s,n);else throw o}}async editMedia(e,t,s,n,i,o,a=!0){try{this.temp.isAnswer=!0;let{src:r,caption:c}=this.templateManager.getMedia(this.data.name,n,this.userLanguage,s);return e=="voice"?(await this.delete(),await this.replyVoice(t,s,n,i)):e=="video_note"?(await this.delete(),await this.replyVoice(t,s,n,i)):e=="sticker"?(await this.delete(),await this.replySticker(t,s,n,i)):e=="location"?(await this.delete(),await this.replyLocation(t,s,n,i)):e=="contact"?(await this.delete(),await this.replyContact(t,s,n,i)):await this.ct.editMessageMedia({media:r,caption:c,type:e,parse_mode:"HTML",...i},{reply_markup:t,...o})}catch(r){if(a===!0)await this.reply(t,s,n,o);else throw r}}async editPhoto(e,t,s,n,i){return await this.editMedia("photo",e,t,s,n,i)}async editVideo(e,t,s,n,i){return await this.editMedia("video",e,t,s,n,i)}async editAudio(e,t,s,n,i){return await this.editMedia("audio",e,t,s,n,i)}async editDocument(e,t,s,n,i){return await this.editMedia("document",e,t,s,n,i)}async editAnimation(e,t,s,n,i){return await this.editMedia("animation",e,t,s,n,i)}async editVoice(e,t,s,n){return await this.editMedia("voice",e,t,s,n)}async editVideoNote(e,t,s,n){return await this.editMedia("video_note",e,t,s,n)}async editSticker(e,t,s,n){return await this.editMedia("sticker",e,t,s,n)}async editLocation(e,t,s,n){return await this.editMedia("location",e,t,s,n)}async editContact(e,t,s,n){return await this.editMedia("contact",e,t,s,n)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(e){try{return this.temp.isAnswer=!0,await this.ct.answerCallbackQuery(e)}catch{return null}}async setSession(e,t,s){try{let n={method:e,params:t,...s},i=await this.cacheSession.set(`${this.userId}`,n);return i&&(this.temp.session=n),i}catch{return null}}async getSession(){try{let e=await this.cacheSession.get(`${this.userId}`);return e&&(this.temp.session=e),e||null}catch{return null}}async clearSession(){try{let e=await this.cacheSession.delete(`${this.userId}`);return e&&(this.temp.session={}),e}catch{return null}}static buildData(e){let s=typeof e=="function"?{callbackData:e}:e||{},n=s.callbackData,i=this.prototype.addArgs.bind(this.prototype),o=s.name||"";return{name:o,intentText:s.intentText||o,intentCommandText:s.intentCommandText||o,intentCallbackData:o,callbackData:n?function(...r){return i(this.intentCallbackData,"colon",n(...r))}:function(){return this?.intentCallbackData},_positionArgText:s.intentText?s.intentText.split(this.prototype.getSeperatorTag("space")).length:void 0}}keyboardCols(e,t,s,n){let[i,o]=s.split("-"),a=parseInt(i),r=o?parseInt(o):null,c=t.length,l=e;for(let d=0;d<c;d++){let h=t[d];if(n(h,d),r===null)(d+1)%a===0&&d<c-1&&l.row();else{let m=c-(d+1);(m===r||m>r&&(d+1)%a===0)&&l.row()}}return e}bottomKeyboardT(e="1",t,s){return this.bottomKeyboard((n,i)=>this.keyboardCols(n,i,e,o=>n.text(o)),{baseId:t??void 0,data:s})}inlineKeyboardT(e,t="1",s,n){return this.inlineKeyboard((i,o)=>this.keyboardCols(i,o,t,(a,r)=>{let c=e[r],l=typeof c=="string"?c:c.data.callbackData();i.text(a,l)}),{baseId:s??void 0,data:n})}inlineKeyboard(e,t){let s=this.data.name;if(t?.cache===!0){let a=`${s}:${this.userLanguage}:i`,r=this.cacheKeyboard.get(a);if(!r){let c=new J,l=this.templateManager.getKeyboard(s,t?.baseId,this.userLanguage,"inline",t?.data),d=e(c,l);return this.cacheKeyboard.set(a,d),d}return r}let n=new J,i=this.templateManager.getKeyboard(s,t?.baseId,this.userLanguage,"inline",t?.data);return e(n,i)}bottomKeyboard(e,t){let s=this.data.name;if(t?.cache===!0){let a=`${s}:${this.userLanguage}:b`,r=this.cacheKeyboard.get(a);if(!r){let c=new U,l=this.templateManager.getKeyboard(s,t?.baseId,this.userLanguage,"bottom",t?.data),d=e(c,l);return d.resized(!0),this.cacheKeyboard.set(a,d),d}return r}let n=new U,i=this.templateManager.getKeyboard(s,t?.baseId,this.userLanguage,"bottom",t?.data),o=e(n,i);return o.resized(),o}getSeperatorTag(e="space"){return e=="space"?" ":":"}haveArgs(e="",t){return e.includes(this.getSeperatorTag(t))}addArgs(e="",t,s){let n=this.getSeperatorTag(t),i="";for(let o=0;o<s.length;o++){let a=s[o];a!=null&&a!==""&&(i+=n+a)}return e+i}getArgs(e="",t,s=1){if(!e)return[];let n=this.getSeperatorTag(t);return e.split(n).slice(s)}getIntent(e="",t,s=1){if(!e)return"";let n=this.getSeperatorTag(t),i=e.split(n);return s==1?i[0]:i.slice(0,s).join(n)}isSessionCallbackData(){return this.temp.session.method===this.methodSessionCallbackData()}isSessionArgsCallbackData(){return this.temp.session.method===this.methodSessionArgsCallbackData()}isSessionText(){return this.temp.session.method===this.methodSessionText()}isSessionArgsText(){return this.temp.session.method===this.methodSessionArgsText()}isSessionCommandText(){return this.temp.session.method===this.methodSessionCommandText()}isSessionCommandArgsText(){return this.temp.session.method===this.methodSessionCommandArgsText()}isSessionFreeText(){return this.temp.session.method===this.methodSessionFreeText()}isSessionCaptionPhoto(){return this.temp.session.method===this.methodSessionCaptionPhoto()}isSessionCaptionArgsPhoto(){return this.temp.session.method===this.methodSessionCaptionArgsPhoto()}isSessionCommandCaptionPhoto(){return this.temp.session.method===this.methodSessionCommandCaptionPhoto()}isSessionCommandCaptionArgsPhoto(){return this.temp.session.method===this.methodSessionCommandCaptionArgsPhoto()}isSessionFreePhoto(){return this.temp.session.method===this.methodSessionFreePhoto()}isSessionCaptionVideo(){return this.temp.session.method===this.methodSessionCaptionVideo()}isSessionCaptionArgsVideo(){return this.temp.session.method===this.methodSessionCaptionArgsVideo()}isSessionCommandCaptionVideo(){return this.temp.session.method===this.methodSessionCommandCaptionVideo()}isSessionCommandCaptionArgsVideo(){return this.temp.session.method===this.methodSessionCommandCaptionArgsVideo()}isSessionFreeVideo(){return this.temp.session.method===this.methodSessionFreeVideo()}isSessionCaptionAudio(){return this.temp.session.method===this.methodSessionCaptionAudio()}isSessionCaptionArgsAudio(){return this.temp.session.method===this.methodSessionCaptionArgsAudio()}isSessionCaptionCommandAudio(){return this.temp.session.method===this.methodSessionCaptionCommandAudio()}isSessionCaptionCommandArgsAudio(){return this.temp.session.method===this.methodSessionCaptionCommandArgsAudio()}isSessionFreeAudio(){return this.temp.session.method===this.methodSessionFreeAudio()}isSessionCaptionDocument(){return this.temp.session.method===this.methodSessionCaptionDocument()}isSessionCaptionArgsDocument(){return this.temp.session.method===this.methodSessionCaptionArgsDocument()}isSessionCommandCaptionDocument(){return this.temp.session.method===this.methodSessionCommandCaptionDocument()}isSessionCommandCaptionArgsDocument(){return this.temp.session.method===this.methodSessionCommandCaptionArgsDocument()}isSessionFreeDocument(){return this.temp.session.method===this.methodSessionFreeDocument()}isSessionCaptionAnimation(){return this.temp.session.method===this.methodSessionCaptionAnimation()}isSessionCaptionArgsAnimation(){return this.temp.session.method===this.methodSessionCaptionArgsAnimation()}isSessionCommandCaptionAnimation(){return this.temp.session.method===this.methodSessionCommandCaptionAnimation()}isSessionCommandCaptionArgsAnimation(){return this.temp.session.method===this.methodSessionCommandCaptionArgsAnimation()}isSessionFreeAnimation(){return this.temp.session.method===this.methodSessionFreeAnimation()}isSessionCaptionVoice(){return this.temp.session.method===this.methodSessionCaptionVoice()}isSessionCaptionArgsVoice(){return this.temp.session.method===this.methodSessionCaptionArgsVoice()}isSessionCommandCaptionVoice(){return this.temp.session.method===this.methodSessionCommandCaptionVoice()}isSessionCommandCaptionArgsVoice(){return this.temp.session.method===this.methodSessionCommandCaptionArgsVoice()}isSessionFreeVoice(){return this.temp.session.method===this.methodSessionFreeVoice()}isSessionFreeVideoNote(){return this.temp.session.method===this.methodSessionFreeVideoNote()}isSessionFreeSticker(){return this.temp.session.method===this.methodSessionFreeSticker()}isSessionFreeLocation(){return this.temp.session.method===this.methodSessionFreeLocation()}isSessionFreeContact(){return this.temp.session.method===this.methodSessionFreeContact()}sessionCallbackData(e){return this.setSession(this.methodSessionCallbackData(),e)}sessionArgsCallbackData(e){return this.setSession(this.methodSessionArgsCallbackData(),e)}sessionText(e){return this.setSession(this.methodSessionText(),e)}sessionArgsText(e){return this.setSession(this.methodSessionArgsText(),e)}sessionCommandText(e){return this.setSession(this.methodSessionCommandText(),e)}sessionCommandArgsText(e){return this.setSession(this.methodSessionCommandArgsText(),e)}sessionFreeText(e){return this.setSession(this.methodSessionFreeText(),e)}sessionCaptionPhoto(e){return this.setSession(this.methodSessionCaptionPhoto(),e)}sessionCaptionArgsPhoto(e){return this.setSession(this.methodSessionCaptionArgsPhoto(),e)}sessionCommandCaptionPhoto(e){return this.setSession(this.methodSessionCommandCaptionPhoto(),e)}sessionCommandCaptionArgsPhoto(e){return this.setSession(this.methodSessionCommandCaptionArgsPhoto(),e)}sessionFreePhoto(e){return this.setSession(this.methodSessionFreePhoto(),e)}sessionCaptionVideo(e){return this.setSession(this.methodSessionCaptionVideo(),e)}sessionCaptionArgsVideo(e){return this.setSession(this.methodSessionCaptionArgsVideo(),e)}sessionCommandCaptionVideo(e){return this.setSession(this.methodSessionCommandCaptionVideo(),e)}sessionCommandCaptionArgsVideo(e){return this.setSession(this.methodSessionCommandCaptionArgsVideo(),e)}sessionFreeVideo(e){return this.setSession(this.methodSessionFreeVideo(),e)}sessionCaptionAudio(e){return this.setSession(this.methodSessionCaptionAudio(),e)}sessionCaptionArgsAudio(e){return this.setSession(this.methodSessionCaptionArgsAudio(),e)}sessionCaptionCommandAudio(e){return this.setSession(this.methodSessionCaptionCommandAudio(),e)}sessionCaptionCommandArgsAudio(e){return this.setSession(this.methodSessionCaptionCommandArgsAudio(),e)}sessionFreeAudio(e){return this.setSession(this.methodSessionFreeAudio(),e)}sessionCaptionDocument(e){return this.setSession(this.methodSessionCaptionDocument(),e)}sessionCaptionArgsDocument(e){return this.setSession(this.methodSessionCaptionArgsDocument(),e)}sessionCommandCaptionDocument(e){return this.setSession(this.methodSessionCommandCaptionDocument(),e)}sessionCommandCaptionArgsDocument(e){return this.setSession(this.methodSessionCommandCaptionArgsDocument(),e)}sessionFreeDocument(e){return this.setSession(this.methodSessionFreeDocument(),e)}sessionCaptionAnimation(e){return this.setSession(this.methodSessionCaptionAnimation(),e)}sessionCaptionArgsAnimation(e){return this.setSession(this.methodSessionCaptionArgsAnimation(),e)}sessionCommandCaptionAnimation(e){return this.setSession(this.methodSessionCommandCaptionAnimation(),e)}sessionCommandCaptionArgsAnimation(e){return this.setSession(this.methodSessionCommandCaptionArgsAnimation(),e)}sessionFreeAnimation(e){return this.setSession(this.methodSessionFreeAnimation(),e)}sessionCaptionVoice(e){return this.setSession(this.methodSessionCaptionVoice(),e)}sessionCaptionArgsVoice(e){return this.setSession(this.methodSessionCaptionArgsVoice(),e)}sessionCommandCaptionVoice(e){return this.setSession(this.methodSessionCommandCaptionVoice(),e)}sessionCommandCaptionArgsVoice(e){return this.setSession(this.methodSessionCommandCaptionArgsVoice(),e)}sessionFreeVoice(e){return this.setSession(this.methodSessionFreeVoice(),e)}sessionFreeVideoNote(e){return this.setSession(this.methodSessionFreeVideoNote(),e)}sessionFreeSticker(e){return this.setSession(this.methodSessionFreeSticker(),e)}sessionFreeLocation(e){return this.setSession(this.methodSessionFreeLocation(),e)}sessionFreeContact(e){return this.setSession(this.methodSessionFreeContact(),e)}methodSession(e,t){return`${e}-${t||this.data.name}`}methodSessionCallbackData(e){return this.methodSession("1",e)}methodSessionArgsCallbackData(e){return this.methodSession("2",e)}methodSessionText(e){return this.methodSession("3",e)}methodSessionArgsText(e){return this.methodSession("4",e)}methodSessionCommandText(e){return this.methodSession("5",e)}methodSessionCommandArgsText(e){return this.methodSession("6",e)}methodSessionFreeText(e){return this.methodSession("7",e)}methodSessionCaptionPhoto(e){return this.methodSession("8",e)}methodSessionCaptionArgsPhoto(e){return this.methodSession("9",e)}methodSessionCommandCaptionPhoto(e){return this.methodSession("10",e)}methodSessionCommandCaptionArgsPhoto(e){return this.methodSession("11",e)}methodSessionFreePhoto(e){return this.methodSession("12",e)}methodSessionCaptionVideo(e){return this.methodSession("13",e)}methodSessionCaptionArgsVideo(e){return this.methodSession("14",e)}methodSessionCommandCaptionVideo(e){return this.methodSession("15",e)}methodSessionCommandCaptionArgsVideo(e){return this.methodSession("16",e)}methodSessionFreeVideo(e){return this.methodSession("17",e)}methodSessionCaptionAudio(e){return this.methodSession("18",e)}methodSessionCaptionArgsAudio(e){return this.methodSession("19",e)}methodSessionCaptionCommandAudio(e){return this.methodSession("20",e)}methodSessionCaptionCommandArgsAudio(e){return this.methodSession("21",e)}methodSessionFreeAudio(e){return this.methodSession("22",e)}methodSessionCaptionDocument(e){return this.methodSession("23",e)}methodSessionCaptionArgsDocument(e){return this.methodSession("24",e)}methodSessionCommandCaptionDocument(e){return this.methodSession("25",e)}methodSessionCommandCaptionArgsDocument(e){return this.methodSession("26",e)}methodSessionFreeDocument(e){return this.methodSession("27",e)}methodSessionCaptionAnimation(e){return this.methodSession("28",e)}methodSessionCaptionArgsAnimation(e){return this.methodSession("29",e)}methodSessionCommandCaptionAnimation(e){return this.methodSession("30",e)}methodSessionCommandCaptionArgsAnimation(e){return this.methodSession("31",e)}methodSessionFreeAnimation(e){return this.methodSession("32",e)}methodSessionCaptionVoice(e){return this.methodSession("33",e)}methodSessionCaptionArgsVoice(e){return this.methodSession("34",e)}methodSessionCommandCaptionVoice(e){return this.methodSession("35",e)}methodSessionCommandCaptionArgsVoice(e){return this.methodSession("36",e)}methodSessionFreeVoice(e){return this.methodSession("37",e)}methodSessionFreeVideoNote(e){return this.methodSession("38",e)}methodSessionFreeSticker(e){return this.methodSession("39",e)}methodSessionFreeLocation(e){return this.methodSession("40",e)}methodSessionFreeContact(e){return this.methodSession("41",e)}};import{join as q}from"path";import{existsSync as X,readdirSync as Y}from"fs";import{createRequire as ye}from"module";var _=class{static{p(this,"PageManager")}static _getFile(e,t,s=0){let i=Object.values(e)[s];if(i===void 0)throw new Error(`File ${t} must have export (not default) class page`);return i}static getFilePath(){return q(process.cwd(),"src","pages")}static getFileSync(e,t=0){e||(e=this.getFilePath());let n=ye(e)(e);return this._getFile(n,e,t)}static async getFile(e,t=0){e||(e=this.getFilePath());let s=await import(`${e}?t=${Date.now()}`);return this._getFile(s,e,t)}static getFileManySync(e,t=0){if(e||(e=this.getFilePath()),!X(e))throw new Error(`Directory ${e} is not found, please make it manually`);return Y(e).map(n=>{let i=q(e,n);return{path:i,page:this.getFileSync(i,t)}})}static clearCacheRequire(e){if(e||(e=this.getFilePath()),!X(e))throw new Error(`Directory ${e} is not found, please make it manually`);return Y(e).forEach(s=>{let n=q(e,s);delete N.cache[N.resolve(n)]}),!0}};import{readFileSync as be}from"fs";import{fileURLToPath as Se}from"url";import{dirname as ke,join as se,parse as we}from"path";import{basename as Q,join as R,extname as Z}from"path";import{readdirSync as fe,readFileSync as V,existsSync as D,statSync as O,writeFileSync as Ce}from"fs";import{watch as Te}from"chokidar";var A=class{static{p(this,"TemplateEngine")}static _escape(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processScopeVariables(e){return e.replace(/\{\{(\w+)\}\}/g,(t,s)=>`\${(data && data["${s}"]) ?? ""}`)}static _processScopeExec(e){return e.replace(/{~\s*([\s\S]*?)\s*~}/g,(t,s)=>`\${(() => { try { return ${s} } catch(e) { try { with(data || {}) { return ${s} } } catch(ee) { return '' } } })()}`)}static _processBaseBlocks(e){let t=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,s={};for(let n of e.matchAll(t)){let i=n[2]??"default",a=(n[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();s[i]=a}return s}static _processScriptBlocks(e){return e.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(t,s)=>{let n=s.trim();return n?`\${(() => { if (!data) return ''; try { with(data) { ${n} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(e){return e.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(e){return e.replace(/<div>([\s\S]*?)<\/div>/gi,(t,s)=>s.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processSwitchBlocks(e){let t=/<switch\b(?:\s+value="([^"]+)")?>([\s\S]*?)<\/switch>/gi;return e.replace(t,(s,n,i)=>{if(!n)return"";let o="",a=/<case\b(?:\s+is="([^"]+)")?>([\s\S]*?)<\/case>/gi,r=/<default>([\s\S]*?)<\/default>/gi,c;for(;(c=a.exec(i))!==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=>{o+=`case "${m}": `}),o+=`return \`${h}\`; `}let l=r.exec(i);if(l){let d=(l[1]||"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();o+=`default: return \`${d}\`; `}else o+="default: return ''; ";return`\${(() => { switch((data && data["${n}"])) { ${o} } })()}`})}static _processMapBlocks(e){let t=/<map(?:\s+([^>]*))?>([\s\S]*?)<\/map>/gi;return e.replace(t,(s,n,i)=>{let o={},a=/(\w+)="([^"]*)"/g;if(n)for(let h of n.matchAll(a))o[h[1]]=h[2];let r=o.src;if(!r)return"";let c=o.join??"\\n",l=i.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`\${(() => { const __arr = (data && data["${r}"]) || []; let __out = ""; for (let i = 0; i < __arr.length; i++) { const e = __arr[i]; if (i > 0) { __out += "${d}" } __out += \`${l}\`; } return __out; })()}`})}static _processMediaBlocks(e){let t=/<media(?:\s+([^>]*))?>([\s\S]*?)<\/media>/gi,s={};for(let n of e.matchAll(t)){let i=n[1],o=n[2],a={},r=/(\w+)="([^"]*)"/g;if(i)for(let m of i.matchAll(r))a[m[1]]=m[2];let c=a.lang||"default",l=a.type,d=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),h={type:l};a.src&&(h.src=a.src),d&&l!=="video_note"&&l!=="sticker"&&(h.caption=d),l==="location"&&(a.latitude&&(h.latitude=a.latitude),a.longitude&&(h.longitude=a.longitude),d&&(h.caption=d)),l==="contact"&&(a.phone&&(h.phone=a.phone),a.first_name&&(h.first_name=a.first_name),a.last_name&&(h.last_name=a.last_name),a.vcard&&(h.vcard=a.vcard),d&&(h.caption=d)),s[c]=h}return s}static _processMessageBlocks(e){let t=/<message(?:\s+([^>]*))?>([\s\S]*?)<\/message>/gi,s={};for(let[,n,i]of e.matchAll(t)){let o={},a=/(\w+)="([^"]*)"/g;if(n)for(let l of n.matchAll(a))o[l[1]]=l[2];let r=o.lang||"default",c=i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();s[r]=c}return s}static _processDescriptionBlocks(e){let t=/<description(?:\s+([^>]*))?>([\s\S]*?)<\/description>/gi,s={};for(let[,n,i]of e.matchAll(t)){let o={},a=/(\w+)="([^"]*)"/g;if(n)for(let d of n.matchAll(a))o[d[1]]=d[2];let r=o.lang||"default",c=o.scope||"default",l=i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();s[r]||(s[r]={}),s[r][c]=l}return s}static _processKeyboardBlocks(e){let t=/<keyboard(?:\s+([^>]*))?>([\s\S]*?)<\/keyboard>/gi,s={};for(let[,n,i]of e.matchAll(t)){let o={},a=/(\w+)="([^"]*)"/g;if(n)for(let d of n.matchAll(a))o[d[1]]=d[2];let r=o.lang||"default",c=o.type==="bottom"?"bottom":"inline",l=i.trim();s[r]||(s[r]={}),s[r][c]=l}return s}static _compileToFunction(e,t){let s;t?s=e.map(o=>`\`${o}\``).join(","):s=`\`${e}\``;let n=s;if(n=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(n))),t){let i=`return [${n}]`;return new Function("data",i)}else{let i=`return ${n}`;return new Function("data",i)}}static compileBlockMedia(e,t){let s=t||this._processBaseBlocks(e),n={};for(let[i,o]of Object.entries(s)){let a=this._processMediaBlocks(o);n[i]={};for(let[r,c]of Object.entries(a)){let l={};for(let[d,h]of Object.entries(c)){if(d==="type"||typeof h!="string")continue;let m=this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(h)))));l[d]=this._compileToFunction(m,!1)}n[i][r]=d=>{let h={...c};for(let[m,u]of Object.entries(l))h[m]=u(d);return h}}}return n}static compileBlockMessage(e,t){let s=t||this._processBaseBlocks(e),n={};for(let[i,o]of Object.entries(s)){let a=this._processMessageBlocks(o);n[i]={};for(let[r,c]of Object.entries(a)){let l=this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(c)))));n[i][r]=this._compileToFunction(l,!1)}}return n}static compileBlockDescription(e,t){let s=t||this._processBaseBlocks(e),n={};for(let[i,o]of Object.entries(s)){let a=this._processDescriptionBlocks(o);n[i]={};for(let[r,c]of Object.entries(a))for(let[l,d]of Object.entries(c)){n[i][l]||(n[i][l]={});let h=this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(d)))));n[i][l][r]=this._compileToFunction(h,!1)}}return n}static compileBlockKeyboards(e,t){let s=t||this._processBaseBlocks(e),n={};for(let[i,o]of Object.entries(s)){let a=this._processKeyboardBlocks(o);n[i]={};for(let[r,c]of Object.entries(a)){n[i][r]={};for(let[l,d]of Object.entries(c)){let m=d.split(/(?<!\\),\s*/).map(u=>u.replace(/\\,/g,",").trim()).map(u=>this._processScopeVariables(this._processScopeExec(this._processSwitchBlocks(this._processMapBlocks(this._processScriptBlocks(u))))));n[i][r][l]=this._compileToFunction(m,!0)}}}return n}static _extractBlock(e,t,s="default",n="all",i){let o=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,a=e,r=!1;for(let c of e.matchAll(o))if((c[2]??"default")===s){a=c[3]??"",r=!0;break}if(!r){let c=/<base\b/.test(e);if(!(s==="default"&&!c))return""}if(t){if(t==="all")return a;let c=Array.isArray(t)?t:[t],l=[];for(let h of c){let m=new RegExp(`([ \\t]*)<${h}(?:\\s+([^>]*))?>([\\s\\S]*?)<\\/${h}>`,"gi");for(let u of a.matchAll(m)){let I=u[2];if(i){let T=/lang="([^"]*)"/i,w=I?.match(T);if(((w?w[1]:void 0)||"default")!==i)continue}l.push({start:u.index,content:u[0],innerContent:u[3]??""})}}l.sort((h,m)=>h.start-m.start);let d=p(h=>{let m=h.split(`
|
|
2
2
|
`);if(m.length<=1)return h.trim();let u=m.filter(T=>T.trim().length>0);if(u.length===0)return"";let I=u.reduce((T,w)=>{let k=w.match(/^([ \t]*)/),x=k?k[1].length:0;return x<T?x:T},1/0);return m.map(T=>T.length>=I?T.slice(I):T.trimStart()).join(`
|
|
3
3
|
`).trim()},"processResult");return n==="all"?l.map(m=>d(m.content)).join(`
|
|
4
4
|
`):l.map(m=>d(m.innerContent)).join(`
|