gramstax 0.0.20 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var G=Object.create;var v=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var h=(u,i)=>v(u,"name",{value:i,configurable:!0});var X=(u,i)=>{for(var t in i)v(u,t,{get:i[t],enumerable:!0})},O=(u,i,t,e)=>{if(i&&typeof i=="object"||typeof i=="function")for(let s of U(i))!q.call(u,s)&&s!==t&&v(u,s,{get:()=>i[s],enumerable:!(e=H(i,s))||e.enumerable});return u};var Y=(u,i,t)=>(t=u!=null?G(J(u)):{},O(i||!u||!u.__esModule?v(t,"default",{value:u,enumerable:!0}):t,u)),Z=u=>O(v({},"__esModule",{value:!0}),u);var ii={};X(ii,{BaseGeneral:()=>I,CacheExternal:()=>x,Ctx:()=>T,Gramstax:()=>_,TemplateEngine:()=>C,TemplateManager:()=>k});module.exports=Z(ii);var R=require("logging-pretty");var I=class{static{h(this,"BaseGeneral")}static log=new R.LoggingPretty;static logError(i,t){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${t}]: ${String(i)}`)}logError(i,t,e){this.constructor.log.error(`[${t||this.constructor.name}:${e}] ${String(i)}`)}};var K=require("keyv"),N=Y(require("@keyv/redis"),1);var x=class extends K.Keyv{constructor(t="memory",e,s,o){let n;t.startsWith("redis")&&(n=new N.default(t)),t==="memory"&&(n=new Map),o?.forceStore&&(n=o.forceStore);super({store:n,namespace:e,ttl:s});this.url=t}static{h(this,"CacheExternal")}};var E=require("timers/promises");var S=require("grammy");var T=class extends I{static{h(this,"Ctx")}static template;static data;data=this.constructor.data;get isPremium(){return this.ct.from?.is_premium??!1}get isBot(){return this.ct.from?.is_bot??!1}get userid(){return this.ct.from?.id}get username(){return this.ct.from?.username}get fullname(){return`${this.ct.from?.first_name||""}${this.ct.from?.last_name||""}`}get firstname(){return this.ct.from?.first_name}get lastname(){return this.ct.from?.last_name}get msgText(){return this.ct.message?.text}get msgTextIntent(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ")[0]:""}get msgTextPayloads(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ").slice(1):[]}get msgTextPayload(){return this.msgTextPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionIntent(){return this.msgCaption&&this.msgCaption.indexOf(" ")!=-1?this.msgCaption.split(" ")[0]:""}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataIntent(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":")[0]:""}get callbackDataPayloads(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":").slice(1):[]}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}get callbackDataParts(){return this.callbackDataPayload&&this.callbackDataPayload.indexOf("+")!=-1?this.callbackDataPayload.split("+"):[]}get languageCode(){return this.ct.from?.language_code}set languageCode(i){this.ct.from.language_code=i}set session(i){this.temp.session=i}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(i){super(),this.ct=i.ct,this.cacheSession=i.cacheSession,this.cacheKeyboard=i.cacheKeyboard,this.templateManager=i.templateManager,this.temp=i.temp,i?.data&&(this.temp.data=i.data)}async broadcast(i,t,e,s,o,n){let r=t.map(d=>this.templateManager.getMessage(this.data.name,o,d,s));for(let d=0;d<i.length;d++){let l=i[d],c=r[d];await this.ct.api.sendMessage(l,c,{parse_mode:"HTML",reply_markup:e,...n}),d+1==30&&await(0,E.setTimeout)(1200)}}async reply(i,t,e,s){let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,t);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:i,...s})}async replyMedia(i,t,e,s,o){let n=this.templateManager.getMedia(this.data.name,s,this.languageCode,e),a={parse_mode:"HTML",reply_markup:t,...o};if(i=="photo")return await this.ct.replyWithPhoto(n.src,{caption:n.caption,...a});if(i=="video")return await this.ct.replyWithVideo(n.src,{caption:n.caption,...a});if(i=="audio")return await this.ct.replyWithAudio(n.src,{caption:n.caption,...a});if(i=="document")return await this.ct.replyWithDocument(n.src,{caption:n.caption,...a});if(i=="animation")return await this.ct.replyWithAnimation(n.src,{caption:n.caption,...a});if(i=="voice")return await this.ct.replyWithVoice(n.src,a);if(i=="video_note")return await this.ct.replyWithVideoNote(n.src,a);if(i=="sticker")return await this.ct.replyWithSticker(n.src,a);if(i=="location")return await this.ct.replyWithLocation(n.latitude,n.longitude,a);if(i=="contact")return await this.ct.replyWithContact(n.phone,n.first_name,{vcard:n.vcard,...a})}async replyPhoto(i,t,e,s){return this.replyMedia("photo",i,t,e,s)}async replyVideo(i,t,e,s){return this.replyMedia("video",i,t,e,s)}async replyAudio(i,t,e,s){return this.replyMedia("audio",i,t,e,s)}async replyDocument(i,t,e,s){return this.replyMedia("document",i,t,e,s)}async replyAnimation(i,t,e,s){return this.replyMedia("animation",i,t,e,s)}async replyVoice(i,t,e,s){return this.replyMedia("voice",i,t,e,s)}async replyVideoNote(i,t,e,s){return this.replyMedia("video_note",i,t,e,s)}async replySticker(i,t,e,s){return this.replyMedia("sticker",i,t,e,s)}async replyLocation(i,t,e,s){return this.replyMedia("location",i,t,e,s)}async replyContact(i,t,e,s){return this.replyMedia("contact",i,t,e,s)}async replyAction(i){return await this.ct.replyWithChatAction(i)}async edit(i,t,e,s){try{let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,t);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:i,...s})}catch{await this.reply(i,t,e,s)}}async editMedia(i,t,e,s,o,n){try{let{src:a,caption:r}=this.templateManager.getMedia(this.data.name,s,this.languageCode,e);return i=="voice"?(await this.delete(),await this.replyVoice(t,e,s,o)):i=="video_note"?(await this.delete(),await this.replyVoice(t,e,s,o)):i=="sticker"?(await this.delete(),await this.replySticker(t,e,s,o)):i=="location"?(await this.delete(),await this.replyLocation(t,e,s,o)):i=="contact"?(await this.delete(),await this.replyContact(t,e,s,o)):await this.ct.editMessageMedia({media:a,caption:r,type:i,parse_mode:"HTML",...o},{reply_markup:t,...n})}catch{await this.reply(t,e,s,n)}}async editPhoto(i,t,e,s,o){return await this.editMedia("photo",i,t,e,s,o)}async editVideo(i,t,e,s,o){return await this.editMedia("video",i,t,e,s,o)}async editAudio(i,t,e,s,o){return await this.editMedia("audio",i,t,e,s,o)}async editDocument(i,t,e,s,o){return await this.editMedia("document",i,t,e,s,o)}async editAnimation(i,t,e,s,o){return await this.editMedia("animation",i,t,e,s,o)}async editVoice(i,t,e,s){return await this.editMedia("voice",i,t,e,s)}async editVideoNote(i,t,e,s){return await this.editMedia("video_note",i,t,e,s)}async editSticker(i,t,e,s){return await this.editMedia("sticker",i,t,e,s)}async editLocation(i,t,e,s){return await this.editMedia("location",i,t,e,s)}async editContact(i,t,e,s){return await this.editMedia("contact",i,t,e,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(i){try{return await this.ct.answerCallbackQuery(i)}catch{return null}}async sessionSet(i,t,e){try{let s={method:i,params:t,...e},o=await this.cacheSession.set(`${this.userid}`,s);return o&&(this.session=s),o}catch{return null}}async sessionGet(){try{let i=await this.cacheSession.get(`${this.userid}`);return i&&(this.session=i),i||null}catch{return null}}async sessionClear(){try{let i=await this.cacheSession.delete(`${this.userid}`);return i&&(this.session={}),i}catch{return null}}static buildData(i){return{name:"",callbackData:i?function(...t){let e=i(...t);return`${this.name}${e===void 0?"":`:${e}`}`}:function(){return this?.name}}}buildInlineKeyboard(i,t){let e=this.data.name;if(t?.cache===!0){let a=`${e}:${this.languageCode}:i`,r=this.cacheKeyboard.get(a);if(!r){let d=new S.InlineKeyboard,l=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"inline",t?.data),c=i(d,l);return this.cacheKeyboard.set(a,c),c}return r}let s=new S.InlineKeyboard,o=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"inline",t?.data);return i(s,o)}buildBottomKeyboard(i,t){let e=this.data.name;if(t?.cache===!0){let a=`${e}:${this.languageCode}:b`,r=this.cacheKeyboard.get(a);if(!r){let d=new S.Keyboard,l=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"bottom",t?.data),c=i(d,l);return c.resized(!0),this.cacheKeyboard.set(a,c),c}return r}let s=new S.Keyboard,o=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"bottom",t?.data),n=i(s,o);return n.resized(),n}validateSessionCallback(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallback(t)}validateSessionCallbackPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallbackPayload(t)}validateSessionText(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodText(t)}validateSessionTextPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextPayload(t)}validateSessionTextCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommand(t)}validateSessionTextCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommandPayload(t)}validateSessionTextFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextFree(t)}validateSessionPhotoCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaption(t)}validateSessionPhotoCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionPayload(t)}validateSessionPhotoCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommand(t)}validateSessionPhotoCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommandPayload(t)}validateSessionPhotoFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoFree(t)}validateSessionVideoCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaption(t)}validateSessionVideoCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionPayload(t)}validateSessionVideoCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommand(t)}validateSessionVideoCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommandPayload(t)}validateSessionVideoFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoFree(t)}validateSessionAudioCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaption(t)}validateSessionAudioCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionPayload(t)}validateSessionAudioCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommand(t)}validateSessionAudioCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommandPayload(t)}validateSessionAudioFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioFree(t)}validateSessionDocumentCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaption(t)}validateSessionDocumentCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionPayload(t)}validateSessionDocumentCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommand(t)}validateSessionDocumentCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommandPayload(t)}validateSessionDocumentFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentFree(t)}validateSessionAnimationCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaption(t)}validateSessionAnimationCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionPayload(t)}validateSessionAnimationCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommand(t)}validateSessionAnimationCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommandPayload(t)}validateSessionAnimationFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationFree(t)}validateSessionVoiceCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaption(t)}validateSessionVoiceCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionPayload(t)}validateSessionVoiceCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommand(t)}validateSessionVoiceCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommandPayload(t)}validateSessionVoiceFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceFree(t)}validateSessionVideoNoteCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaption(t)}validateSessionVideoNoteCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionPayload(t)}validateSessionVideoNoteCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommand(t)}validateSessionVideoNoteCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommandPayload(t)}validateSessionVideoNoteFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteFree(t)}validateSessionStickerFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodStickerFree(t)}validateSessionLocationFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodLocationFree(t)}validateSessionContactFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodContactFree(t)}sessionCallback(i,t){return this.sessionSet(this.buildSessionMethodCallback(t),i)}sessionCallbackPayload(i,t){return this.sessionSet(this.buildSessionMethodCallbackPayload(t),i)}sessionText(i,t){return this.sessionSet(this.buildSessionMethodText(t),i)}sessionTextPayload(i,t){return this.sessionSet(this.buildSessionMethodTextPayload(t),i)}sessionTextCommand(i,t){return this.sessionSet(this.buildSessionMethodTextCommand(t),i)}sessionTextCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodTextCommandPayload(t),i)}sessionTextFree(i,t){return this.sessionSet(this.buildSessionMethodTextFree(t),i)}sessionPhotoCaption(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaption(t),i)}sessionPhotoCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaptionPayload(t),i)}sessionPhotoCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommand(t),i)}sessionPhotoCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommandPayload(t),i)}sessionPhotoFree(i,t){return this.sessionSet(this.buildSessionMethodPhotoFree(t),i)}sessionVideoCaption(i,t){return this.sessionSet(this.buildSessionMethodVideoCaption(t),i)}sessionVideoCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoCaptionPayload(t),i)}sessionVideoCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodVideoCaptionCommand(t),i)}sessionVideoCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoCaptionCommandPayload(t),i)}sessionVideoFree(i,t){return this.sessionSet(this.buildSessionMethodVideoFree(t),i)}sessionAudioCaption(i,t){return this.sessionSet(this.buildSessionMethodAudioCaption(t),i)}sessionAudioCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodAudioCaptionPayload(t),i)}sessionAudioCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodAudioCaptionCommand(t),i)}sessionAudioCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodAudioCaptionCommandPayload(t),i)}sessionAudioFree(i,t){return this.sessionSet(this.buildSessionMethodAudioFree(t),i)}sessionDocumentCaption(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaption(t),i)}sessionDocumentCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaptionPayload(t),i)}sessionDocumentCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommand(t),i)}sessionDocumentCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommandPayload(t),i)}sessionDocumentFree(i,t){return this.sessionSet(this.buildSessionMethodDocumentFree(t),i)}sessionAnimationCaption(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaption(t),i)}sessionAnimationCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaptionPayload(t),i)}sessionAnimationCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommand(t),i)}sessionAnimationCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommandPayload(t),i)}sessionAnimationFree(i,t){return this.sessionSet(this.buildSessionMethodAnimationFree(t),i)}sessionVoiceCaption(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaption(t),i)}sessionVoiceCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaptionPayload(t),i)}sessionVoiceCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommand(t),i)}sessionVoiceCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommandPayload(t),i)}sessionVoiceFree(i,t){return this.sessionSet(this.buildSessionMethodVoiceFree(t),i)}sessionVideoNoteCaption(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaption(t),i)}sessionVideoNoteCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionPayload(t),i)}sessionVideoNoteCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommand(t),i)}sessionVideoNoteCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommandPayload(t),i)}sessionVideoNoteFree(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteFree(t),i)}sessionStickerFree(i,t){return this.sessionSet(this.buildSessionMethodStickerFree(t),i)}sessionLocationFree(i,t){return this.sessionSet(this.buildSessionMethodLocationFree(t),i)}sessionContactFree(i,t){return this.sessionSet(this.buildSessionMethodContactFree(t),i)}sessionToCallback(i,t){return this.sessionCallback({...this.session.params,...i},t)}sessionToCallbackPayload(i,t){return this.sessionCallbackPayload({...this.session.params,...i},t)}sessionToText(i,t){return this.sessionText({...this.session.params,...i},t)}sessionToTextPayload(i,t){return this.sessionTextPayload({...this.session.params,...i},t)}sessionToTextCommand(i,t){return this.sessionTextCommand({...this.session.params,...i},t)}sessionToTextCommandPayload(i,t){return this.sessionTextCommandPayload({...this.session.params,...i},t)}sessionToTextFree(i,t){return this.sessionTextFree({...this.session.params,...i},t)}sessionToPhotoCaption(i,t){return this.sessionPhotoCaption({...this.session.params,...i},t)}sessionToPhotoCaptionPayload(i,t){return this.sessionPhotoCaptionPayload({...this.session.params,...i},t)}sessionToPhotoCaptionCommand(i,t){return this.sessionPhotoCaptionCommand({...this.session.params,...i},t)}sessionToPhotoCaptionCommandPayload(i,t){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...i},t)}sessionToPhotoFree(i,t){return this.sessionPhotoFree({...this.session.params,...i},t)}sessionToVideoCaption(i,t){return this.sessionVideoCaption({...this.session.params,...i},t)}sessionToVideoCaptionPayload(i,t){return this.sessionVideoCaptionPayload({...this.session.params,...i},t)}sessionToVideoCaptionCommand(i,t){return this.sessionVideoCaptionCommand({...this.session.params,...i},t)}sessionToVideoCaptionCommandPayload(i,t){return this.sessionVideoCaptionCommandPayload({...this.session.params,...i},t)}sessionToVideoFree(i,t){return this.sessionVideoFree({...this.session.params,...i},t)}sessionToAudioCaption(i,t){return this.sessionAudioCaption({...this.session.params,...i},t)}sessionToAudioCaptionPayload(i,t){return this.sessionAudioCaptionPayload({...this.session.params,...i},t)}sessionToAudioCaptionCommand(i,t){return this.sessionAudioCaptionCommand({...this.session.params,...i},t)}sessionToAudioCaptionCommandPayload(i,t){return this.sessionAudioCaptionCommandPayload({...this.session.params,...i},t)}sessionToAudioFree(i,t){return this.sessionAudioFree({...this.session.params,...i},t)}sessionToDocumentCaption(i,t){return this.sessionDocumentCaption({...this.session.params,...i},t)}sessionToDocumentCaptionPayload(i,t){return this.sessionDocumentCaptionPayload({...this.session.params,...i},t)}sessionToDocumentCaptionCommand(i,t){return this.sessionDocumentCaptionCommand({...this.session.params,...i},t)}sessionToDocumentCaptionCommandPayload(i,t){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...i},t)}sessionToDocumentFree(i,t){return this.sessionDocumentFree({...this.session.params,...i},t)}sessionToAnimationCaption(i,t){return this.sessionAnimationCaption({...this.session.params,...i},t)}sessionToAnimationCaptionPayload(i,t){return this.sessionAnimationCaptionPayload({...this.session.params,...i},t)}sessionToAnimationCaptionCommand(i,t){return this.sessionAnimationCaptionCommand({...this.session.params,...i},t)}sessionToAnimationCaptionCommandPayload(i,t){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...i},t)}sessionToAnimationFree(i,t){return this.sessionAnimationFree({...this.session.params,...i},t)}sessionToVoiceCaption(i,t){return this.sessionVoiceCaption({...this.session.params,...i},t)}sessionToVoiceCaptionPayload(i,t){return this.sessionVoiceCaptionPayload({...this.session.params,...i},t)}sessionToVoiceCaptionCommand(i,t){return this.sessionVoiceCaptionCommand({...this.session.params,...i},t)}sessionToVoiceCaptionCommandPayload(i,t){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...i},t)}sessionToVoiceFree(i,t){return this.sessionVoiceFree({...this.session.params,...i},t)}sessionToVideoNoteCaption(i,t){return this.sessionVideoNoteCaption({...this.session.params,...i},t)}sessionToVideoNoteCaptionPayload(i,t){return this.sessionVideoNoteCaptionPayload({...this.session.params,...i},t)}sessionToVideoNoteCaptionCommand(i,t){return this.sessionVideoNoteCaptionCommand({...this.session.params,...i},t)}sessionToVideoNoteCaptionCommandPayload(i,t){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...i},t)}sessionToVideoNoteFree(i,t){return this.sessionVideoNoteFree({...this.session.params,...i},t)}sessionToStickerFree(i,t){return this.sessionStickerFree({...this.session.params,...i},t)}sessionToLocationFree(i,t){return this.sessionLocationFree({...this.session.params,...i},t)}sessionToContactFree(i,t){return this.sessionContactFree({...this.session.params,...i},t)}buildIntent(i,t=!0){i||(i=t?this.data.callbackData():this.data.name);let e=t?":":" ";return i?.indexOf?.(e)!=-1?i?.split?.(e)?.[0]:i}buildSessionMethod(i,t){return`${i}-${t||this.data.name}`}buildSessionMethodCallback(i){return this.buildSessionMethod("1",i)}buildSessionMethodCallbackPayload(i){return this.buildSessionMethod("2",i)}buildSessionMethodText(i){return this.buildSessionMethod("3",i)}buildSessionMethodTextPayload(i){return this.buildSessionMethod("4",i)}buildSessionMethodTextCommand(i){return this.buildSessionMethod("5",i)}buildSessionMethodTextCommandPayload(i){return this.buildSessionMethod("6",i)}buildSessionMethodTextFree(i){return this.buildSessionMethod("7",i)}buildSessionMethodPhotoCaption(i){return this.buildSessionMethod("8",i)}buildSessionMethodPhotoCaptionPayload(i){return this.buildSessionMethod("9",i)}buildSessionMethodPhotoCaptionCommand(i){return this.buildSessionMethod("10",i)}buildSessionMethodPhotoCaptionCommandPayload(i){return this.buildSessionMethod("11",i)}buildSessionMethodPhotoFree(i){return this.buildSessionMethod("12",i)}buildSessionMethodVideoCaption(i){return this.buildSessionMethod("13",i)}buildSessionMethodVideoCaptionPayload(i){return this.buildSessionMethod("14",i)}buildSessionMethodVideoCaptionCommand(i){return this.buildSessionMethod("15",i)}buildSessionMethodVideoCaptionCommandPayload(i){return this.buildSessionMethod("16",i)}buildSessionMethodVideoFree(i){return this.buildSessionMethod("17",i)}buildSessionMethodAudioCaption(i){return this.buildSessionMethod("18",i)}buildSessionMethodAudioCaptionPayload(i){return this.buildSessionMethod("19",i)}buildSessionMethodAudioCaptionCommand(i){return this.buildSessionMethod("20",i)}buildSessionMethodAudioCaptionCommandPayload(i){return this.buildSessionMethod("21",i)}buildSessionMethodAudioFree(i){return this.buildSessionMethod("22",i)}buildSessionMethodDocumentCaption(i){return this.buildSessionMethod("23",i)}buildSessionMethodDocumentCaptionPayload(i){return this.buildSessionMethod("24",i)}buildSessionMethodDocumentCaptionCommand(i){return this.buildSessionMethod("25",i)}buildSessionMethodDocumentCaptionCommandPayload(i){return this.buildSessionMethod("26",i)}buildSessionMethodDocumentFree(i){return this.buildSessionMethod("27",i)}buildSessionMethodAnimationCaption(i){return this.buildSessionMethod("28",i)}buildSessionMethodAnimationCaptionPayload(i){return this.buildSessionMethod("29",i)}buildSessionMethodAnimationCaptionCommand(i){return this.buildSessionMethod("30",i)}buildSessionMethodAnimationCaptionCommandPayload(i){return this.buildSessionMethod("31",i)}buildSessionMethodAnimationFree(i){return this.buildSessionMethod("32",i)}buildSessionMethodVoiceCaption(i){return this.buildSessionMethod("33",i)}buildSessionMethodVoiceCaptionPayload(i){return this.buildSessionMethod("34",i)}buildSessionMethodVoiceCaptionCommand(i){return this.buildSessionMethod("35",i)}buildSessionMethodVoiceCaptionCommandPayload(i){return this.buildSessionMethod("36",i)}buildSessionMethodVoiceFree(i){return this.buildSessionMethod("37",i)}buildSessionMethodVideoNoteCaption(i){return this.buildSessionMethod("38",i)}buildSessionMethodVideoNoteCaptionPayload(i){return this.buildSessionMethod("39",i)}buildSessionMethodVideoNoteCaptionCommand(i){return this.buildSessionMethod("40",i)}buildSessionMethodVideoNoteCaptionCommandPayload(i){return this.buildSessionMethod("41",i)}buildSessionMethodVideoNoteFree(i){return this.buildSessionMethod("42",i)}buildSessionMethodStickerFree(i){return this.buildSessionMethod("43",i)}buildSessionMethodLocationFree(i){return this.buildSessionMethod("44",i)}buildSessionMethodContactFree(i){return this.buildSessionMethod("45",i)}};var $=require("bun"),P=require("path");var W=require("logging-pretty");var C=class{static{h(this,"TemplateEngine")}static _escape(i){return i.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(i){return i.replace(/\{\{(\w+)\}\}/g,(t,e)=>`\${(data && data["${e}"]) ?? ""}`)}static _processBaseBlocks(i){let t=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,e={};for(let s of i.matchAll(t)){let o=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[o]=a}return e}static _processScriptBlocks(i){return i.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(t,e)=>{let s=e.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(i){return i.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(i){return i.replace(/<div>([\s\S]*?)<\/div>/gi,(t,e)=>e.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(i){let t=/<media\s+([^>]+)>([\s\S]*?)<\/media>/gi,e={};for(let s of i.matchAll(t)){let o=s[1],n=s[2],a={},r=/(\w+)="([^"]*)"/g;for(let m of o.matchAll(r))a[m[1]]=m[2];if(!a.lang)continue;let d=a.lang,l=a.type,c=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),p={type:l};a.src&&(p.src=a.src),c&&l!=="video_note"&&l!=="sticker"&&(p.caption=c),l==="location"&&(a.latitude&&(p.latitude=a.latitude),a.longitude&&(p.longitude=a.longitude),c&&(p.caption=c)),l==="contact"&&(a.phone&&(p.phone=a.phone),a.first_name&&(p.first_name=a.first_name),a.last_name&&(p.last_name=a.last_name),a.vcard&&(p.vcard=a.vcard),c&&(p.caption=c)),e[d]=p}return e}static _processMessageBlocks(i){let t=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,e={};for(let[,s,o]of i.matchAll(t)){let n=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[s]=n}return e}static _processKeyboardBlocks(i){let t=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\stype="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,e={};for(let[,s,o,n]of i.matchAll(t)){let a=o==="bottom"?"bottom":"inline",r=n.trim();e[s]||(e[s]={}),e[s][a]=r}return e}static _compileToFunction(i,t){let e;t?e=i.map(n=>`\`${n}\``).join(","):e=`\`${i}\``;let s=e;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),t){let o=`return [${s}]`;return new Function("data",o)}else{let o=`return ${s}`;return new Function("data",o)}}static compileMedia(i){let t=this._processBaseBlocks(i),e={};for(let[s,o]of Object.entries(t)){let n=this._processMediaBlocks(o);e[s]={};for(let[a,r]of Object.entries(n))if(r.caption){let d=this._processVariables(this._processScriptBlocks(r.caption)),l=this._compileToFunction(d,!1);e[s][a]=c=>({...r,caption:l(c)})}else e[s][a]=()=>r}return e}static compileMessages(i){let t=this._processBaseBlocks(i),e={};for(let[s,o]of Object.entries(t)){let n=this._processMessageBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){let d=this._processVariables(this._processScriptBlocks(r));e[s][a]=this._compileToFunction(d,!1)}}return e}static compileKeyboards(i){let t=this._processBaseBlocks(i),e={};for(let[s,o]of Object.entries(t)){let n=this._processKeyboardBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){e[s][a]={};for(let[d,l]of Object.entries(r)){let p=l.split(/(?<!\\),\s*/).map(m=>m.replace(/\\,/g,",").trim()).map(m=>this._processVariables(this._processScriptBlocks(m)));e[s][a][d]=this._compileToFunction(p,!0)}}}return e}};var M=class{static{h(this,"HelperPage")}static _getPage(i,t,e=!0){let o=Object.values(i)[0];if(o===void 0)throw new Error(`File ${t} must have export (not default) class page`);return e===!0&&(o.template=void 0),o}static getPageSync(i,t=!0){let e=require(i);return this._getPage(e,i,t)}static async getPage(i,t=!0){let e=await import(`${i}?t=${Date.now()}`);return this._getPage(e,i,t)}};var B=require("fs/promises"),L=require("chokidar"),f=require("path"),y=require("fs");var k=class{static{h(this,"TemplateManager")}_map=new Map;_engine=C;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_forceLanguage;_isWatchEnabled;constructor(i){let{path:t,enableWatch:e=!1,forceLanguage:s}=i;this._path=t,this._forceLanguage=s,this._isWatchEnabled=e,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(!this._path||!Array.isArray(this._path))throw new Error("Path must be set as string array");for(let i=0;i<this._path.length;i++){let t=this._path[i];if(!(0,y.existsSync)(t))throw new Error(`Template base path is not exists: ${t}`);if(!(0,y.statSync)(t).isDirectory())throw new Error(`Template base path is not a directory: ${t}`)}return!0}catch(i){throw new Error(`Failed to validate Template base path: ${i}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let i=0;i<this._path.length;i++){let t=this._path[i],e=(0,L.watch)(t,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[i]=e,e.on("change",this._handleFileChange.bind(this)),e.on("add",this._handleFileAdd.bind(this)),e.on("unlink",this._handleFileDelete.bind(this)),e.on("error",this._handleWatchError.bind(this))}}async _handleFileChange(i){let t=(0,f.basename)(i);this._isValidFile(t)&&await this._loadFile(t,!1)}async _handleFileAdd(i){let t=(0,f.basename)(i);this._isValidFile(t)&&await this._loadFile(t,!1)}_handleFileDelete(i){let t=(0,f.basename)(i),e=this._getKey(t);this._map.has(e)&&this._map.delete(e)}_handleWatchError(i){}_loadAllFiles(){for(let i=0;i<this._path.length;i++){let t=this._path[i],s=(0,y.readdirSync)(t,"utf8").filter(o=>this._isValidFile(o));for(let o of s)this._loadFile(o,!0)}}async _loadFile(i,t=!0){for(let e=0;e<this._path.length;e++){let s=this._path[e],o=(0,f.join)(s,i),n=this._getExtension(i),a=this._getKey(i);if(n==".html"){let r=t?(0,y.readFileSync)(o,"utf8"):await(0,B.readFile)(o,"utf8");this._compile(a,r)}else if(n==".ts"){let r=await M.getPage(o,!1);r?.template!==void 0&&this._compile(a,r.template),r.template=void 0}else throw new Error(`File ${i} is not support`)}}_getExtension(i){return(0,f.extname)(i).toLowerCase()}_isValidFile(i){return this._supportedExtensions.has(this._getExtension(i))}_getKey(i){return i.replace(/\.[^/.]+$/,"")}_compile(i,t,e){let s=this._map.get(i),o=s||{},n=!1;(e===void 0||e?.media===!1||s?.media===void 0)&&(o.media=C.compileMedia(t),n=!0),(e===void 0||e?.message===!1||s?.message===void 0)&&(o.message=C.compileMessages(t),n=!0),(e===void 0||e?.keyboard===!1||s?.keyboard===void 0)&&(o.keyboard=C.compileKeyboards(t),n=!0),n&&this._map.set(i,o)}getMedia(i,t="default",e="en",s){let n=this._map.get(i)?.media?.[t]?.[this._forceLanguage||e];if(!n)return{};try{return n(s)}catch{return{}}}getMessage(i,t="default",e="en",s){let n=this._map.get(i)?.message?.[t]?.[this._forceLanguage||e];if(!n)return"";try{return n(s)}catch{return""}}getKeyboard(i,t="default",e="en",s="inline",o){let a=this._map.get(i)?.keyboard?.[t]?.[this._forceLanguage||e]?.[s];if(!a)return[];try{return a(o)}catch{return[]}}async write(i,t){if(this._getExtension(i)!=".html")return null;for(let e=0;e<this._path.length;e++){let s=(0,f.join)(this._path[e],i);if((0,y.existsSync)(s))return(0,y.writeFileSync)(s,t,"utf8"),await this._loadFile(i,!1),!0}return null}getAvailable(){return Array.from(this._map.keys())}has(i){return this._map.has(i)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(i,t)=>typeof t=="function"?t.toString():t).length}}async destroy(){if(this._watcher)for(let i of this._watcher)await i.close();this._map.clear()}};var F=require("fs"),w=require("grammy");var _=class{static{h(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;constructor(i){if(!i?.token||i?.token?.length==0)throw new Error("Token is not valid or empty");this.log=i.log===null?void 0:i.log===void 0?new W.LoggingPretty:i.log,this.cacheSession=i.cacheSession||new x("memory","session"),this.cacheKeyboard=i.cacheKeyboard||new Map,this.templateManager=i.templateManager||new k({path:[(0,P.join)(process.cwd(),"src","pages")]}),this.bot=this.createBot(i.token),this.bot.catch(this.onCatch),this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this)),this.bot.on("message:text",this.onMessageText.bind(this)),this.bot.on("message:photo",this.onMessagePhoto.bind(this)),this.bot.on("message:video",this.onMessageVideo.bind(this)),this.bot.on("message:audio",this.onMessageAudio.bind(this)),this.bot.on("message:document",this.onMessageDocument.bind(this)),this.bot.on("message:animation",this.onMessageAnimation.bind(this)),this.bot.on("message:voice",this.onMessageVoice.bind(this)),this.bot.on("message:video_note",this.onMessageVideoNote.bind(this)),this.bot.on("message:sticker",this.onMessageSticker.bind(this)),this.bot.on("message:location",this.onMessageLocation.bind(this)),this.bot.on("message:contact",this.onMessageContact.bind(this)),this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),i.deploy.startsWith("polling")?this.runPolling():i.deploy.startsWith("webhook")&&this.runWebhook(i.deploy.split("webhook:")[1])}onCatch(i){this.log?.error?.(`[Bot.catch]: ${String(i)}`)}onStart(i,t,e){let{username:s}=i;t=="polling"?this.log?.success?.(`Telegram bot polling started: ${s}`):this.log?.success?.(`Telegram bot webhook started: ${s} (${e})`)}createBot(i){return new w.Bot(i)}createCtx(i){return new T({ct:i,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:h(async i=>{this.onStart(i,"polling",null)},"onStart")})}async runWebhook(i){let t=(0,w.webhookCallback)(this.bot,"bun"),e="/telegram-webhook";(0,$.serve)({fetch(a){let{pathname:r}=new URL(a.url);if(r===e)return a.method==="POST"?t(a):new Response("OK",{status:200});if(r==="/"&&a.method==="GET"){let d=new Date().toISOString();return new Response(JSON.stringify({timestamp:d}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}});let s=await this.bot.api.getWebhookInfo(),o=i.endsWith("/")?i.slice(0,-1)+e:i+e;s.url!=o&&await this.bot.api.setWebhook(o);let n=await this.bot.api.getMe();this.onStart(n,"webhook",o)}pageBuildData(i,t){i?.data===void 0&&(i.data=i.buildData()),i.data.name=(0,P.parse)(t).name}pageSorts(i,t){let e=i.data.name,s=i.prototype,o="Payload",n="Command",a="Caption",r="Free",d=t.dynamic,l=t.dynamicSpesific,c=h(b=>b.charAt(0).toUpperCase()+b.slice(1),"upFirst"),p=h(b=>b.replace(o,"").replace(n,"").replace(a,"").replace(r,""),"getPureFuncName"),m=h((b,g)=>s[`buildSessionMethod${c(b)}`](g),"buildSessionMethod");t.all[e]=i;for(let b=0;b<t.lenListFuncStaticSession;b++){let g=t.listFuncStaticSession[b],j=t.static[g],Q=t.staticIntent[g],D=t.staticSession[g],V={name:e,func:g},A=j||Q;if(A!==void 0){let z=g.includes(n)?`/${e}`:e;A[s.buildIntent(z,g.startsWith("callback"))]=V}D!==void 0&&(D[m(g,e)]=V),g.toLowerCase().endsWith("free")&&l[p(g)].push(V)}s.free&&d.push(e)}pageLoads(){this.log?.info?.("Load pages..");let i=(0,P.join)(process.cwd(),"src","pages");if(!(0,F.existsSync)(i))throw new Error(`Directory ${i} is not found, please make it manually`);let t=(0,F.readdirSync)(i),e={},s=e,o=e,n=[],a=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],r=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],d=[...a,...r,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],l=h((p,m)=>Object.fromEntries(p.map(b=>[b,{...m}])),"makeObject"),c={all:{},dynamic:[],dynamicSpesific:{text:n,photo:n,video:n,audio:n,document:n,animation:n,voice:n,videoNote:n,sticker:n,location:n,contact:n},static:l(a,e),staticIntent:l(r,s),staticSession:l(d,o),listFuncStatic:a,listFuncStaticIntent:r,listFuncStaticSession:d,lenListFuncStatic:a.length,lenListFuncStaticIntent:r.length,lenListFuncStaticSession:d.length};for(let p of t){let m=(0,P.join)(i,p),b=M.getPageSync(m,!0);this.pageBuildData(b,m),this.pageSorts(b,c)}return this.log?.info?.(`Finish load pages with total (${Object.keys(c.all).length})`),c}async pageRoutes(i,t){let e,s;if(e===void 0){let n=i.callbackData,a=i.msgText,r=i.msgCaption,d=this.pages.static;for(let l=0;l<this.pages.lenListFuncStatic;l++){let c=this.pages.listFuncStatic[l];if(s=d[c][n||a||r],s)break}s!==void 0&&(e=this.pages.all[s.name])}if(e===void 0){let n=await i.sessionGet();if(n){let a=n.method,r=this.pages.staticSession;for(let d=0;d<this.pages.lenListFuncStaticSession;d++){let l=this.pages.listFuncStaticSession[d];if(s=r[l][a],s)break}s!==void 0&&(e=this.pages.all[s.name])}}if(e===void 0){let n=i.callbackDataIntent,a=i.msgTextIntent,r=i.msgCaptionIntent,d=this.pages.staticIntent;for(let l=0;l<this.pages.lenListFuncStaticIntent;l++){let c=this.pages.listFuncStaticIntent[l];if(s=d[c][n||a||r],s)break}s!==void 0&&(e=this.pages.all[s.name])}if(e!==void 0&&s!==void 0)return await new e(i)[s.func]?.();let o=this.pages.dynamicSpesific[t]||[];for(let n=0;n<o.length;n++){let a=o[n];if(a===void 0)continue;let r=this.pages.all[a.func];if(r===void 0)continue;let l=await new r(i)[a.name]?.();if(l!==null)return l}for(let n=0;n<this.pages.dynamic.length;n++){let a=this.pages.dynamic[n];if(a===void 0)continue;let r=this.pages.all[a];if(r===void 0)continue;let l=await new r(i).free?.();if(l!==null)return l}return null}async hookBeforeRoute(i,t){return!0}async hookErrorPage(i,t,e,s){}async hookErrorInputNotFoundPage(i){}async onMessage(i,t){let e=this.createCtx(i);try{if(await this.hookBeforeRoute(e,t)===!1)return;await this.pageRoutes(e,t)===null&&await this.hookErrorInputNotFoundPage(e)}catch(s){await this.hookErrorPage(e,t,s,!1)}}async onCallbackQueryData(i){let t=this.createCtx(i);try{if(await t.callbackQueryAnswer(),await this.hookBeforeRoute(t,"onCallbackQueryData")===!1)return;await this.pageRoutes(t,"callback")}catch(e){await this.hookErrorPage(t,"onCallbackQueryData",e,!0)}}async onMessageText(i){await this.onMessage(i,"onMessageText")}async onMessagePhoto(i){await this.onMessage(i,"onMessagePhoto")}async onMessageVideo(i){await this.onMessage(i,"onMessageVideo")}async onMessageAudio(i){await this.onMessage(i,"onMessageAudio")}async onMessageDocument(i){await this.onMessage(i,"onMessageDocument")}async onMessageAnimation(i){await this.onMessage(i,"onMessageAnimation")}async onMessageVoice(i){await this.onMessage(i,"onMessageVoice")}async onMessageVideoNote(i){await this.onMessage(i,"onMessageVideoNote")}async onMessageSticker(i){await this.onMessage(i,"onMessageSticker")}async onMessageLocation(i){await this.onMessage(i,"onMessageLocation")}async onMessageContact(i){await this.onMessage(i,"onMessageContact")}};0&&(module.exports={BaseGeneral,CacheExternal,Ctx,Gramstax,TemplateEngine,TemplateManager});
1
+ "use strict";var G=Object.create;var I=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var h=(p,t)=>I(p,"name",{value:t,configurable:!0});var X=(p,t)=>{for(var i in t)I(p,i,{get:t[i],enumerable:!0})},O=(p,t,i,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of U(t))!q.call(p,s)&&s!==i&&I(p,s,{get:()=>t[s],enumerable:!(e=H(t,s))||e.enumerable});return p};var Y=(p,t,i)=>(i=p!=null?G(J(p)):{},O(t||!p||!p.__esModule?I(i,"default",{value:p,enumerable:!0}):i,p)),Z=p=>O(I({},"__esModule",{value:!0}),p);var tt={};X(tt,{BaseGeneral:()=>x,CacheExternal:()=>T,Ctx:()=>k,Gramstax:()=>_,TemplateEngine:()=>C,TemplateManager:()=>F});module.exports=Z(tt);var R=require("logging-pretty");var x=class{static{h(this,"BaseGeneral")}static log=new R.LoggingPretty;static logError(t,i){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${i}]: ${String(t)}`)}logError(t,i,e){this.constructor.log.error(`[${i||this.constructor.name}:${e}] ${String(t)}`)}};var K=require("keyv"),N=Y(require("@keyv/redis"),1);var T=class extends K.Keyv{constructor(i="memory",e,s,o){let n;i.startsWith("redis")&&(n=new N.default(i)),i==="memory"&&(n=new Map),o?.forceStore&&(n=o.forceStore);super({store:n,namespace:e,ttl:s});this.url=i}static{h(this,"CacheExternal")}};var E=require("timers/promises");var S=require("grammy");var k=class extends x{static{h(this,"Ctx")}static template;static data;data=this.constructor.data;get isPremium(){return this.ct.from?.is_premium??!1}get isBot(){return this.ct.from?.is_bot??!1}get userid(){return this.ct.from?.id}get username(){return this.ct.from?.username}get fullname(){return`${this.ct.from?.first_name||""}${this.ct.from?.last_name||""}`}get firstname(){return this.ct.from?.first_name}get lastname(){return this.ct.from?.last_name}get msgText(){return this.ct.message?.text}get msgTextIntent(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ")[0]:""}get msgTextPayloads(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ").slice(1):[]}get msgTextPayload(){return this.msgTextPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionIntent(){return this.msgCaption&&this.msgCaption.indexOf(" ")!=-1?this.msgCaption.split(" ")[0]:""}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataIntent(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":")[0]:""}get callbackDataPayloads(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":").slice(1):[]}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}get callbackDataParts(){return this.callbackDataPayload&&this.callbackDataPayload.indexOf("+")!=-1?this.callbackDataPayload.split("+"):[]}get languageCode(){return this.ct.from?.language_code}set languageCode(t){this.ct.from.language_code=t}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){super(),this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp,t?.data&&(this.temp.data=t.data)}async broadcast(t,i,e,s,o,n){let r=i.map(c=>this.templateManager.getMessage(this.data.name,o,c,s));for(let c=0;c<t.length;c++){let d=t[c],l=r[c];await this.ct.api.sendMessage(d,l,{parse_mode:"HTML",reply_markup:e,...n}),c+1==30&&await(0,E.setTimeout)(1200)}}async reply(t,i,e,s){let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,i);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,i,e,s,o){let n=this.templateManager.getMedia(this.data.name,s,this.languageCode,e),a={parse_mode:"HTML",reply_markup:i,...o};if(t=="photo")return await this.ct.replyWithPhoto(n.src,{caption:n.caption,...a});if(t=="video")return await this.ct.replyWithVideo(n.src,{caption:n.caption,...a});if(t=="audio")return await this.ct.replyWithAudio(n.src,{caption:n.caption,...a});if(t=="document")return await this.ct.replyWithDocument(n.src,{caption:n.caption,...a});if(t=="animation")return await this.ct.replyWithAnimation(n.src,{caption:n.caption,...a});if(t=="voice")return await this.ct.replyWithVoice(n.src,a);if(t=="video_note")return await this.ct.replyWithVideoNote(n.src,a);if(t=="sticker")return await this.ct.replyWithSticker(n.src,a);if(t=="location")return await this.ct.replyWithLocation(n.latitude,n.longitude,a);if(t=="contact")return await this.ct.replyWithContact(n.phone,n.first_name,{vcard:n.vcard,...a})}async replyPhoto(t,i,e,s){return this.replyMedia("photo",t,i,e,s)}async replyVideo(t,i,e,s){return this.replyMedia("video",t,i,e,s)}async replyAudio(t,i,e,s){return this.replyMedia("audio",t,i,e,s)}async replyDocument(t,i,e,s){return this.replyMedia("document",t,i,e,s)}async replyAnimation(t,i,e,s){return this.replyMedia("animation",t,i,e,s)}async replyVoice(t,i,e,s){return this.replyMedia("voice",t,i,e,s)}async replyVideoNote(t,i,e,s){return this.replyMedia("video_note",t,i,e,s)}async replySticker(t,i,e,s){return this.replyMedia("sticker",t,i,e,s)}async replyLocation(t,i,e,s){return this.replyMedia("location",t,i,e,s)}async replyContact(t,i,e,s){return this.replyMedia("contact",t,i,e,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,i,e,s){try{let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,i);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:t,...s})}catch{await this.reply(t,i,e,s)}}async editMedia(t,i,e,s,o,n){try{let{src:a,caption:r}=this.templateManager.getMedia(this.data.name,s,this.languageCode,e);return t=="voice"?(await this.delete(),await this.replyVoice(i,e,s,o)):t=="video_note"?(await this.delete(),await this.replyVoice(i,e,s,o)):t=="sticker"?(await this.delete(),await this.replySticker(i,e,s,o)):t=="location"?(await this.delete(),await this.replyLocation(i,e,s,o)):t=="contact"?(await this.delete(),await this.replyContact(i,e,s,o)):await this.ct.editMessageMedia({media:a,caption:r,type:t,parse_mode:"HTML",...o},{reply_markup:i,...n})}catch{await this.reply(i,e,s,n)}}async editPhoto(t,i,e,s,o){return await this.editMedia("photo",t,i,e,s,o)}async editVideo(t,i,e,s,o){return await this.editMedia("video",t,i,e,s,o)}async editAudio(t,i,e,s,o){return await this.editMedia("audio",t,i,e,s,o)}async editDocument(t,i,e,s,o){return await this.editMedia("document",t,i,e,s,o)}async editAnimation(t,i,e,s,o){return await this.editMedia("animation",t,i,e,s,o)}async editVoice(t,i,e,s){return await this.editMedia("voice",t,i,e,s)}async editVideoNote(t,i,e,s){return await this.editMedia("video_note",t,i,e,s)}async editSticker(t,i,e,s){return await this.editMedia("sticker",t,i,e,s)}async editLocation(t,i,e,s){return await this.editMedia("location",t,i,e,s)}async editContact(t,i,e,s){return await this.editMedia("contact",t,i,e,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,i,e){try{let s={method:t,params:i,...e},o=await this.cacheSession.set(`${this.userid}`,s);return o&&(this.session=s),o}catch{return null}}async sessionGet(){try{let t=await this.cacheSession.get(`${this.userid}`);return t&&(this.session=t),t||null}catch{return null}}async sessionClear(){try{let t=await this.cacheSession.delete(`${this.userid}`);return t&&(this.session={}),t}catch{return null}}static buildData(t){return{name:"",callbackData:t?function(...i){let e=t(...i);return`${this.name}${e===void 0?"":`:${e}`}`}:function(){return this?.name}}}inlineKeyboard(t,i){let e=this.data.name;if(i?.cache===!0){let a=`${e}:${this.languageCode}:i`,r=this.cacheKeyboard.get(a);if(!r){let c=new S.InlineKeyboard,d=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"inline",i?.data),l=t(c,d);return this.cacheKeyboard.set(a,l),l}return r}let s=new S.InlineKeyboard,o=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"inline",i?.data);return t(s,o)}bottomKeyboard(t,i){let e=this.data.name;if(i?.cache===!0){let a=`${e}:${this.languageCode}:b`,r=this.cacheKeyboard.get(a);if(!r){let c=new S.Keyboard,d=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"bottom",i?.data),l=t(c,d);return l.resized(!0),this.cacheKeyboard.set(a,l),l}return r}let s=new S.Keyboard,o=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"bottom",i?.data),n=t(s,o);return n.resized(),n}validateSessionCallback(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallback(i)}validateSessionCallbackPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallbackPayload(i)}validateSessionText(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionText(i)}validateSessionTextPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextPayload(i)}validateSessionTextCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommand(i)}validateSessionTextCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommandPayload(i)}validateSessionTextFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextFree(i)}validateSessionPhotoCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaption(i)}validateSessionPhotoCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionPayload(i)}validateSessionPhotoCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommand(i)}validateSessionPhotoCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommandPayload(i)}validateSessionPhotoFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoFree(i)}validateSessionVideoCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaption(i)}validateSessionVideoCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionPayload(i)}validateSessionVideoCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommand(i)}validateSessionVideoCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommandPayload(i)}validateSessionVideoFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoFree(i)}validateSessionAudioCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaption(i)}validateSessionAudioCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionPayload(i)}validateSessionAudioCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommand(i)}validateSessionAudioCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommandPayload(i)}validateSessionAudioFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioFree(i)}validateSessionDocumentCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaption(i)}validateSessionDocumentCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionPayload(i)}validateSessionDocumentCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommand(i)}validateSessionDocumentCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommandPayload(i)}validateSessionDocumentFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentFree(i)}validateSessionAnimationCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaption(i)}validateSessionAnimationCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionPayload(i)}validateSessionAnimationCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommand(i)}validateSessionAnimationCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommandPayload(i)}validateSessionAnimationFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationFree(i)}validateSessionVoiceCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaption(i)}validateSessionVoiceCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionPayload(i)}validateSessionVoiceCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommand(i)}validateSessionVoiceCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommandPayload(i)}validateSessionVoiceFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceFree(i)}validateSessionVideoNoteCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaption(i)}validateSessionVideoNoteCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionPayload(i)}validateSessionVideoNoteCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommand(i)}validateSessionVideoNoteCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommandPayload(i)}validateSessionVideoNoteFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteFree(i)}validateSessionStickerFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionStickerFree(i)}validateSessionLocationFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionLocationFree(i)}validateSessionContactFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionContactFree(i)}sessionCallback(t,i){return this.sessionSet(this.methodSessionCallback(i),t)}sessionCallbackPayload(t,i){return this.sessionSet(this.methodSessionCallbackPayload(i),t)}sessionText(t,i){return this.sessionSet(this.methodSessionText(i),t)}sessionTextPayload(t,i){return this.sessionSet(this.methodSessionTextPayload(i),t)}sessionTextCommand(t,i){return this.sessionSet(this.methodSessionTextCommand(i),t)}sessionTextCommandPayload(t,i){return this.sessionSet(this.methodSessionTextCommandPayload(i),t)}sessionTextFree(t,i){return this.sessionSet(this.methodSessionTextFree(i),t)}sessionPhotoCaption(t,i){return this.sessionSet(this.methodSessionPhotoCaption(i),t)}sessionPhotoCaptionPayload(t,i){return this.sessionSet(this.methodSessionPhotoCaptionPayload(i),t)}sessionPhotoCaptionCommand(t,i){return this.sessionSet(this.methodSessionPhotoCaptionCommand(i),t)}sessionPhotoCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionPhotoCaptionCommandPayload(i),t)}sessionPhotoFree(t,i){return this.sessionSet(this.methodSessionPhotoFree(i),t)}sessionVideoCaption(t,i){return this.sessionSet(this.methodSessionVideoCaption(i),t)}sessionVideoCaptionPayload(t,i){return this.sessionSet(this.methodSessionVideoCaptionPayload(i),t)}sessionVideoCaptionCommand(t,i){return this.sessionSet(this.methodSessionVideoCaptionCommand(i),t)}sessionVideoCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionVideoCaptionCommandPayload(i),t)}sessionVideoFree(t,i){return this.sessionSet(this.methodSessionVideoFree(i),t)}sessionAudioCaption(t,i){return this.sessionSet(this.methodSessionAudioCaption(i),t)}sessionAudioCaptionPayload(t,i){return this.sessionSet(this.methodSessionAudioCaptionPayload(i),t)}sessionAudioCaptionCommand(t,i){return this.sessionSet(this.methodSessionAudioCaptionCommand(i),t)}sessionAudioCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionAudioCaptionCommandPayload(i),t)}sessionAudioFree(t,i){return this.sessionSet(this.methodSessionAudioFree(i),t)}sessionDocumentCaption(t,i){return this.sessionSet(this.methodSessionDocumentCaption(i),t)}sessionDocumentCaptionPayload(t,i){return this.sessionSet(this.methodSessionDocumentCaptionPayload(i),t)}sessionDocumentCaptionCommand(t,i){return this.sessionSet(this.methodSessionDocumentCaptionCommand(i),t)}sessionDocumentCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionDocumentCaptionCommandPayload(i),t)}sessionDocumentFree(t,i){return this.sessionSet(this.methodSessionDocumentFree(i),t)}sessionAnimationCaption(t,i){return this.sessionSet(this.methodSessionAnimationCaption(i),t)}sessionAnimationCaptionPayload(t,i){return this.sessionSet(this.methodSessionAnimationCaptionPayload(i),t)}sessionAnimationCaptionCommand(t,i){return this.sessionSet(this.methodSessionAnimationCaptionCommand(i),t)}sessionAnimationCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionAnimationCaptionCommandPayload(i),t)}sessionAnimationFree(t,i){return this.sessionSet(this.methodSessionAnimationFree(i),t)}sessionVoiceCaption(t,i){return this.sessionSet(this.methodSessionVoiceCaption(i),t)}sessionVoiceCaptionPayload(t,i){return this.sessionSet(this.methodSessionVoiceCaptionPayload(i),t)}sessionVoiceCaptionCommand(t,i){return this.sessionSet(this.methodSessionVoiceCaptionCommand(i),t)}sessionVoiceCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionVoiceCaptionCommandPayload(i),t)}sessionVoiceFree(t,i){return this.sessionSet(this.methodSessionVoiceFree(i),t)}sessionVideoNoteCaption(t,i){return this.sessionSet(this.methodSessionVideoNoteCaption(i),t)}sessionVideoNoteCaptionPayload(t,i){return this.sessionSet(this.methodSessionVideoNoteCaptionPayload(i),t)}sessionVideoNoteCaptionCommand(t,i){return this.sessionSet(this.methodSessionVideoNoteCaptionCommand(i),t)}sessionVideoNoteCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionVideoNoteCaptionCommandPayload(i),t)}sessionVideoNoteFree(t,i){return this.sessionSet(this.methodSessionVideoNoteFree(i),t)}sessionStickerFree(t,i){return this.sessionSet(this.methodSessionStickerFree(i),t)}sessionLocationFree(t,i){return this.sessionSet(this.methodSessionLocationFree(i),t)}sessionContactFree(t,i){return this.sessionSet(this.methodSessionContactFree(i),t)}sessionToCallback(t,i){return this.sessionCallback({...this.session.params,...t},i)}sessionToCallbackPayload(t,i){return this.sessionCallbackPayload({...this.session.params,...t},i)}sessionToText(t,i){return this.sessionText({...this.session.params,...t},i)}sessionToTextPayload(t,i){return this.sessionTextPayload({...this.session.params,...t},i)}sessionToTextCommand(t,i){return this.sessionTextCommand({...this.session.params,...t},i)}sessionToTextCommandPayload(t,i){return this.sessionTextCommandPayload({...this.session.params,...t},i)}sessionToTextFree(t,i){return this.sessionTextFree({...this.session.params,...t},i)}sessionToPhotoCaption(t,i){return this.sessionPhotoCaption({...this.session.params,...t},i)}sessionToPhotoCaptionPayload(t,i){return this.sessionPhotoCaptionPayload({...this.session.params,...t},i)}sessionToPhotoCaptionCommand(t,i){return this.sessionPhotoCaptionCommand({...this.session.params,...t},i)}sessionToPhotoCaptionCommandPayload(t,i){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...t},i)}sessionToPhotoFree(t,i){return this.sessionPhotoFree({...this.session.params,...t},i)}sessionToVideoCaption(t,i){return this.sessionVideoCaption({...this.session.params,...t},i)}sessionToVideoCaptionPayload(t,i){return this.sessionVideoCaptionPayload({...this.session.params,...t},i)}sessionToVideoCaptionCommand(t,i){return this.sessionVideoCaptionCommand({...this.session.params,...t},i)}sessionToVideoCaptionCommandPayload(t,i){return this.sessionVideoCaptionCommandPayload({...this.session.params,...t},i)}sessionToVideoFree(t,i){return this.sessionVideoFree({...this.session.params,...t},i)}sessionToAudioCaption(t,i){return this.sessionAudioCaption({...this.session.params,...t},i)}sessionToAudioCaptionPayload(t,i){return this.sessionAudioCaptionPayload({...this.session.params,...t},i)}sessionToAudioCaptionCommand(t,i){return this.sessionAudioCaptionCommand({...this.session.params,...t},i)}sessionToAudioCaptionCommandPayload(t,i){return this.sessionAudioCaptionCommandPayload({...this.session.params,...t},i)}sessionToAudioFree(t,i){return this.sessionAudioFree({...this.session.params,...t},i)}sessionToDocumentCaption(t,i){return this.sessionDocumentCaption({...this.session.params,...t},i)}sessionToDocumentCaptionPayload(t,i){return this.sessionDocumentCaptionPayload({...this.session.params,...t},i)}sessionToDocumentCaptionCommand(t,i){return this.sessionDocumentCaptionCommand({...this.session.params,...t},i)}sessionToDocumentCaptionCommandPayload(t,i){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...t},i)}sessionToDocumentFree(t,i){return this.sessionDocumentFree({...this.session.params,...t},i)}sessionToAnimationCaption(t,i){return this.sessionAnimationCaption({...this.session.params,...t},i)}sessionToAnimationCaptionPayload(t,i){return this.sessionAnimationCaptionPayload({...this.session.params,...t},i)}sessionToAnimationCaptionCommand(t,i){return this.sessionAnimationCaptionCommand({...this.session.params,...t},i)}sessionToAnimationCaptionCommandPayload(t,i){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...t},i)}sessionToAnimationFree(t,i){return this.sessionAnimationFree({...this.session.params,...t},i)}sessionToVoiceCaption(t,i){return this.sessionVoiceCaption({...this.session.params,...t},i)}sessionToVoiceCaptionPayload(t,i){return this.sessionVoiceCaptionPayload({...this.session.params,...t},i)}sessionToVoiceCaptionCommand(t,i){return this.sessionVoiceCaptionCommand({...this.session.params,...t},i)}sessionToVoiceCaptionCommandPayload(t,i){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...t},i)}sessionToVoiceFree(t,i){return this.sessionVoiceFree({...this.session.params,...t},i)}sessionToVideoNoteCaption(t,i){return this.sessionVideoNoteCaption({...this.session.params,...t},i)}sessionToVideoNoteCaptionPayload(t,i){return this.sessionVideoNoteCaptionPayload({...this.session.params,...t},i)}sessionToVideoNoteCaptionCommand(t,i){return this.sessionVideoNoteCaptionCommand({...this.session.params,...t},i)}sessionToVideoNoteCaptionCommandPayload(t,i){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...t},i)}sessionToVideoNoteFree(t,i){return this.sessionVideoNoteFree({...this.session.params,...t},i)}sessionToStickerFree(t,i){return this.sessionStickerFree({...this.session.params,...t},i)}sessionToLocationFree(t,i){return this.sessionLocationFree({...this.session.params,...t},i)}sessionToContactFree(t,i){return this.sessionContactFree({...this.session.params,...t},i)}buildIntent(t,i=!0){t||(t=i?this.data.callbackData():this.data.name);let e=i?":":" ";return t?.indexOf?.(e)!=-1?t?.split?.(e)?.[0]:t}methodSession(t,i){return`${t}-${i||this.data.name}`}methodSessionCallback(t){return this.methodSession("1",t)}methodSessionCallbackPayload(t){return this.methodSession("2",t)}methodSessionText(t){return this.methodSession("3",t)}methodSessionTextPayload(t){return this.methodSession("4",t)}methodSessionTextCommand(t){return this.methodSession("5",t)}methodSessionTextCommandPayload(t){return this.methodSession("6",t)}methodSessionTextFree(t){return this.methodSession("7",t)}methodSessionPhotoCaption(t){return this.methodSession("8",t)}methodSessionPhotoCaptionPayload(t){return this.methodSession("9",t)}methodSessionPhotoCaptionCommand(t){return this.methodSession("10",t)}methodSessionPhotoCaptionCommandPayload(t){return this.methodSession("11",t)}methodSessionPhotoFree(t){return this.methodSession("12",t)}methodSessionVideoCaption(t){return this.methodSession("13",t)}methodSessionVideoCaptionPayload(t){return this.methodSession("14",t)}methodSessionVideoCaptionCommand(t){return this.methodSession("15",t)}methodSessionVideoCaptionCommandPayload(t){return this.methodSession("16",t)}methodSessionVideoFree(t){return this.methodSession("17",t)}methodSessionAudioCaption(t){return this.methodSession("18",t)}methodSessionAudioCaptionPayload(t){return this.methodSession("19",t)}methodSessionAudioCaptionCommand(t){return this.methodSession("20",t)}methodSessionAudioCaptionCommandPayload(t){return this.methodSession("21",t)}methodSessionAudioFree(t){return this.methodSession("22",t)}methodSessionDocumentCaption(t){return this.methodSession("23",t)}methodSessionDocumentCaptionPayload(t){return this.methodSession("24",t)}methodSessionDocumentCaptionCommand(t){return this.methodSession("25",t)}methodSessionDocumentCaptionCommandPayload(t){return this.methodSession("26",t)}methodSessionDocumentFree(t){return this.methodSession("27",t)}methodSessionAnimationCaption(t){return this.methodSession("28",t)}methodSessionAnimationCaptionPayload(t){return this.methodSession("29",t)}methodSessionAnimationCaptionCommand(t){return this.methodSession("30",t)}methodSessionAnimationCaptionCommandPayload(t){return this.methodSession("31",t)}methodSessionAnimationFree(t){return this.methodSession("32",t)}methodSessionVoiceCaption(t){return this.methodSession("33",t)}methodSessionVoiceCaptionPayload(t){return this.methodSession("34",t)}methodSessionVoiceCaptionCommand(t){return this.methodSession("35",t)}methodSessionVoiceCaptionCommandPayload(t){return this.methodSession("36",t)}methodSessionVoiceFree(t){return this.methodSession("37",t)}methodSessionVideoNoteCaption(t){return this.methodSession("38",t)}methodSessionVideoNoteCaptionPayload(t){return this.methodSession("39",t)}methodSessionVideoNoteCaptionCommand(t){return this.methodSession("40",t)}methodSessionVideoNoteCaptionCommandPayload(t){return this.methodSession("41",t)}methodSessionVideoNoteFree(t){return this.methodSession("42",t)}methodSessionStickerFree(t){return this.methodSession("43",t)}methodSessionLocationFree(t){return this.methodSession("44",t)}methodSessionContactFree(t){return this.methodSession("45",t)}};var $=require("bun"),v=require("path");var W=require("logging-pretty");var C=class{static{h(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(i,e)=>`\${(data && data["${e}"]) ?? ""}`)}static _processBaseBlocks(t){let i=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,e={};for(let s of t.matchAll(i)){let o=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[o]=a}return e}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(i,e)=>{let s=e.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(t){return t.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(t){return t.replace(/<div>([\s\S]*?)<\/div>/gi,(i,e)=>e.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(t){let i=/<media\s+([^>]+)>([\s\S]*?)<\/media>/gi,e={};for(let s of t.matchAll(i)){let o=s[1],n=s[2],a={},r=/(\w+)="([^"]*)"/g;for(let g of o.matchAll(r))a[g[1]]=g[2];if(!a.lang)continue;let c=a.lang,d=a.type,l=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),u={type:d};a.src&&(u.src=a.src),l&&d!=="video_note"&&d!=="sticker"&&(u.caption=l),d==="location"&&(a.latitude&&(u.latitude=a.latitude),a.longitude&&(u.longitude=a.longitude),l&&(u.caption=l)),d==="contact"&&(a.phone&&(u.phone=a.phone),a.first_name&&(u.first_name=a.first_name),a.last_name&&(u.last_name=a.last_name),a.vcard&&(u.vcard=a.vcard),l&&(u.caption=l)),e[c]=u}return e}static _processMessageBlocks(t){let i=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,e={};for(let[,s,o]of t.matchAll(i)){let n=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[s]=n}return e}static _processKeyboardBlocks(t){let i=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\stype="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,e={};for(let[,s,o,n]of t.matchAll(i)){let a=o==="bottom"?"bottom":"inline",r=n.trim();e[s]||(e[s]={}),e[s][a]=r}return e}static _compileToFunction(t,i){let e;i?e=t.map(n=>`\`${n}\``).join(","):e=`\`${t}\``;let s=e;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),i){let o=`return [${s}]`;return new Function("data",o)}else{let o=`return ${s}`;return new Function("data",o)}}static compileMedia(t){let i=this._processBaseBlocks(t),e={};for(let[s,o]of Object.entries(i)){let n=this._processMediaBlocks(o);e[s]={};for(let[a,r]of Object.entries(n))if(r.caption){let c=this._processVariables(this._processScriptBlocks(r.caption)),d=this._compileToFunction(c,!1);e[s][a]=l=>({...r,caption:d(l)})}else e[s][a]=()=>r}return e}static compileMessages(t){let i=this._processBaseBlocks(t),e={};for(let[s,o]of Object.entries(i)){let n=this._processMessageBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){let c=this._processVariables(this._processScriptBlocks(r));e[s][a]=this._compileToFunction(c,!1)}}return e}static compileKeyboards(t){let i=this._processBaseBlocks(t),e={};for(let[s,o]of Object.entries(i)){let n=this._processKeyboardBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){e[s][a]={};for(let[c,d]of Object.entries(r)){let u=d.split(/(?<!\\),\s*/).map(g=>g.replace(/\\,/g,",").trim()).map(g=>this._processVariables(this._processScriptBlocks(g)));e[s][a][c]=this._compileToFunction(u,!0)}}}return e}};var P=class{static{h(this,"HelperPage")}static _getPage(t,i,e=!0){let o=Object.values(t)[0];if(o===void 0)throw new Error(`File ${i} must have export (not default) class page`);return e===!0&&(o.template=void 0),o}static getPageSync(t,i=!0){let e=require(t);return this._getPage(e,t,i)}static async getPage(t,i=!0){let e=await import(`${t}?t=${Date.now()}`);return this._getPage(e,t,i)}};var B=require("fs/promises"),L=require("chokidar"),f=require("path"),b=require("fs");var F=class{static{h(this,"TemplateManager")}_map=new Map;_engine=C;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_forceLanguage;_isWatchEnabled;constructor(t){let{path:i,enableWatch:e=!1,forceLanguage:s}=t;this._path=i,this._forceLanguage=s,this._isWatchEnabled=e,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(!this._path||!Array.isArray(this._path))throw new Error("Path must be set as string array");for(let t=0;t<this._path.length;t++){let i=this._path[t];if(!(0,b.existsSync)(i))throw new Error(`Template base path is not exists: ${i}`);if(!(0,b.statSync)(i).isDirectory())throw new Error(`Template base path is not a directory: ${i}`)}return!0}catch(t){throw new Error(`Failed to validate Template base path: ${t}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let t=0;t<this._path.length;t++){let i=this._path[t],e=(0,L.watch)(i,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[t]=e,e.on("change",this._handleFileChange.bind(this)),e.on("add",this._handleFileAdd.bind(this)),e.on("unlink",this._handleFileDelete.bind(this)),e.on("error",this._handleWatchError.bind(this))}}async _handleFileChange(t){let i=(0,f.basename)(t);this._isValidFile(i)&&await this._loadFile(i,!1)}async _handleFileAdd(t){let i=(0,f.basename)(t);this._isValidFile(i)&&await this._loadFile(i,!1)}_handleFileDelete(t){let i=(0,f.basename)(t),e=this._getKey(i);this._map.has(e)&&this._map.delete(e)}_handleWatchError(t){}_loadAllFiles(){for(let t=0;t<this._path.length;t++){let i=this._path[t],s=(0,b.readdirSync)(i,"utf8").filter(o=>this._isValidFile(o));for(let o of s)this._loadFile(o,!0)}}async _loadFile(t,i=!0){for(let e=0;e<this._path.length;e++){let s=this._path[e],o=(0,f.join)(s,t),n=this._getExtension(t),a=this._getKey(t);if(n==".html"){let r=i?(0,b.readFileSync)(o,"utf8"):await(0,B.readFile)(o,"utf8");this._compile(a,r)}else if(n==".ts"){let r=await P.getPage(o,!1);r?.template!==void 0&&this._compile(a,r.template),r.template=void 0}else throw new Error(`File ${t} is not support`)}}_getExtension(t){return(0,f.extname)(t).toLowerCase()}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,i,e){let s=this._map.get(t),o=s||{},n=!1;(e===void 0||e?.media===!1||s?.media===void 0)&&(o.media=C.compileMedia(i),n=!0),(e===void 0||e?.message===!1||s?.message===void 0)&&(o.message=C.compileMessages(i),n=!0),(e===void 0||e?.keyboard===!1||s?.keyboard===void 0)&&(o.keyboard=C.compileKeyboards(i),n=!0),n&&this._map.set(t,o)}getMedia(t,i="default",e="en",s){let n=this._map.get(t)?.media?.[i]?.[this._forceLanguage||e];if(!n)return{};try{return n(s)}catch{return{}}}getMessage(t,i="default",e="en",s){let n=this._map.get(t)?.message?.[i]?.[this._forceLanguage||e];if(!n)return"";try{return n(s)}catch{return""}}getKeyboard(t,i="default",e="en",s="inline",o){let a=this._map.get(t)?.keyboard?.[i]?.[this._forceLanguage||e]?.[s];if(!a)return[];try{return a(o)}catch{return[]}}async write(t,i){if(this._getExtension(t)!=".html")return null;for(let e=0;e<this._path.length;e++){let s=(0,f.join)(this._path[e],t);if((0,b.existsSync)(s))return(0,b.writeFileSync)(s,i,"utf8"),await this._loadFile(t,!1),!0}return null}getAvailable(){return Array.from(this._map.keys())}has(t){return this._map.has(t)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(t,i)=>typeof i=="function"?i.toString():i).length}}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};var M=require("fs"),w=require("grammy");var _=class{static{h(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");this.log=t.log===null?void 0:t.log===void 0?new W.LoggingPretty:t.log,this.cacheSession=t.cacheSession||new T("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new F({path:[(0,v.join)(process.cwd(),"src","pages")]}),this.bot=this.createBot(t.token),this.bot.catch(this.onCatch),this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this)),this.bot.on("message:text",this.onMessageText.bind(this)),this.bot.on("message:photo",this.onMessagePhoto.bind(this)),this.bot.on("message:video",this.onMessageVideo.bind(this)),this.bot.on("message:audio",this.onMessageAudio.bind(this)),this.bot.on("message:document",this.onMessageDocument.bind(this)),this.bot.on("message:animation",this.onMessageAnimation.bind(this)),this.bot.on("message:voice",this.onMessageVoice.bind(this)),this.bot.on("message:video_note",this.onMessageVideoNote.bind(this)),this.bot.on("message:sticker",this.onMessageSticker.bind(this)),this.bot.on("message:location",this.onMessageLocation.bind(this)),this.bot.on("message:contact",this.onMessageContact.bind(this)),this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),t.deploy.startsWith("polling")?this.runPolling():t.deploy.startsWith("webhook")&&this.runWebhook(t.deploy.split("webhook:")[1])}onCatch(t){this.log?.error?.(`[Bot.catch]: ${String(t)}`)}onStart(t,i,e){let{username:s}=t;i=="polling"?this.log?.success?.(`Telegram bot polling started: ${s}`):this.log?.success?.(`Telegram bot webhook started: ${s} (${e})`)}createBot(t){return new w.Bot(t)}createCtx(t){return new k({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:h(async t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let i=(0,w.webhookCallback)(this.bot,"bun"),e="/telegram-webhook";(0,$.serve)({fetch(a){let{pathname:r}=new URL(a.url);if(r===e)return a.method==="POST"?i(a):new Response("OK",{status:200});if(r==="/"&&a.method==="GET"){let c=new Date().toISOString();return new Response(JSON.stringify({timestamp:c}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}});let s=await this.bot.api.getWebhookInfo(),o=t.endsWith("/")?t.slice(0,-1)+e:t+e;s.url!=o&&await this.bot.api.setWebhook(o);let n=await this.bot.api.getMe();this.onStart(n,"webhook",o)}pageBuildData(t,i){t?.data===void 0&&(t.data=t.buildData()),t.data.name=(0,v.parse)(i).name}pageSorts(t,i){let e=t.data.name,s=t.prototype,o="Payload",n="Command",a="Caption",r="Free",c=i.dynamic,d=i.dynamicSpesific,l=h(m=>m.charAt(0).toUpperCase()+m.slice(1),"upFirst"),u=h(m=>m.replace(o,"").replace(n,"").replace(a,"").replace(r,""),"getPureFuncName"),g=h((m,y)=>s[`methodSession${l(m)}`](y),"methodSession");i.all[e]=t;for(let m=0;m<i.lenListFuncStaticSession;m++){let y=i.listFuncStaticSession[m],j=i.static[y],Q=i.staticIntent[y],D=i.staticSession[y],V={name:e,func:y},A=j||Q;if(A!==void 0){let z=y.includes(n)?`/${e}`:e;A[s.buildIntent(z,y.startsWith("callback"))]=V}D!==void 0&&(D[g(y,e)]=V),y.toLowerCase().endsWith("free")&&d[u(y)].push(V)}s.free&&c.push(e)}pageLoads(){this.log?.info?.("Load pages..");let t=(0,v.join)(process.cwd(),"src","pages");if(!(0,M.existsSync)(t))throw new Error(`Directory ${t} is not found, please make it manually`);let i=(0,M.readdirSync)(t),e={},s=e,o=e,n=[],a=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],r=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],c=[...a,...r,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],d=h((u,g)=>Object.fromEntries(u.map(m=>[m,{...g}])),"makeObject"),l={all:{},dynamic:[],dynamicSpesific:{text:n,photo:n,video:n,audio:n,document:n,animation:n,voice:n,videoNote:n,sticker:n,location:n,contact:n},static:d(a,e),staticIntent:d(r,s),staticSession:d(c,o),listFuncStatic:a,listFuncStaticIntent:r,listFuncStaticSession:c,lenListFuncStatic:a.length,lenListFuncStaticIntent:r.length,lenListFuncStaticSession:c.length};for(let u of i){let g=(0,v.join)(t,u),m=P.getPageSync(g,!0);this.pageBuildData(m,g),this.pageSorts(m,l)}return this.log?.info?.(`Finish load pages with total (${Object.keys(l.all).length})`),l}async pageRoutes(t,i){let e,s;if(e===void 0){let n=t.callbackData,a=t.msgText,r=t.msgCaption,c=this.pages.static;for(let d=0;d<this.pages.lenListFuncStatic;d++){let l=this.pages.listFuncStatic[d];if(s=c[l][n||a||r],s)break}s!==void 0&&(e=this.pages.all[s.name])}if(e===void 0){let n=await t.sessionGet();if(n){let a=n.method,r=this.pages.staticSession;for(let c=0;c<this.pages.lenListFuncStaticSession;c++){let d=this.pages.listFuncStaticSession[c];if(s=r[d][a],s)break}s!==void 0&&(e=this.pages.all[s.name])}}if(e===void 0){let n=t.callbackDataIntent,a=t.msgTextIntent,r=t.msgCaptionIntent,c=this.pages.staticIntent;for(let d=0;d<this.pages.lenListFuncStaticIntent;d++){let l=this.pages.listFuncStaticIntent[d];if(s=c[l][n||a||r],s)break}s!==void 0&&(e=this.pages.all[s.name])}if(e!==void 0&&s!==void 0)return await new e(t)[s.func]?.();let o=this.pages.dynamicSpesific[i]||[];for(let n=0;n<o.length;n++){let a=o[n];if(a===void 0)continue;let r=this.pages.all[a.func];if(r===void 0)continue;let d=await new r(t)[a.name]?.();if(d!==null)return d}for(let n=0;n<this.pages.dynamic.length;n++){let a=this.pages.dynamic[n];if(a===void 0)continue;let r=this.pages.all[a];if(r===void 0)continue;let d=await new r(t).free?.();if(d!==null)return d}return null}async hookBeforeRoute(t,i){return!0}async hookErrorPage(t,i,e,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,i){let e=this.createCtx(t);try{if(await this.hookBeforeRoute(e,i)===!1)return;await this.pageRoutes(e,i)===null&&await this.hookErrorInputNotFoundPage(e)}catch(s){await this.hookErrorPage(e,i,s,!1)}}async onCallbackQueryData(t){let i=this.createCtx(t);try{if(await i.callbackQueryAnswer(),await this.hookBeforeRoute(i,"onCallbackQueryData")===!1)return;await this.pageRoutes(i,"callback")}catch(e){await this.hookErrorPage(i,"onCallbackQueryData",e,!0)}}async onMessageText(t){await this.onMessage(t,"onMessageText")}async onMessagePhoto(t){await this.onMessage(t,"onMessagePhoto")}async onMessageVideo(t){await this.onMessage(t,"onMessageVideo")}async onMessageAudio(t){await this.onMessage(t,"onMessageAudio")}async onMessageDocument(t){await this.onMessage(t,"onMessageDocument")}async onMessageAnimation(t){await this.onMessage(t,"onMessageAnimation")}async onMessageVoice(t){await this.onMessage(t,"onMessageVoice")}async onMessageVideoNote(t){await this.onMessage(t,"onMessageVideoNote")}async onMessageSticker(t){await this.onMessage(t,"onMessageSticker")}async onMessageLocation(t){await this.onMessage(t,"onMessageLocation")}async onMessageContact(t){await this.onMessage(t,"onMessageContact")}};0&&(module.exports={BaseGeneral,CacheExternal,Ctx,Gramstax,TemplateEngine,TemplateManager});
@@ -1,7 +1,7 @@
1
1
  import { LoggingPretty } from 'logging-pretty';
2
2
  import { Keyv } from 'keyv';
3
3
  import * as grammy from 'grammy';
4
- import { Context, InlineKeyboard, Bot, BotError } from 'grammy';
4
+ import { Context, Keyboard, InlineKeyboard, Bot, BotError } from 'grammy';
5
5
  import * as grammy_types from 'grammy/types';
6
6
  import { UserFromGetMe } from 'grammy/types';
7
7
  import { FSWatcher } from 'chokidar';
@@ -181,7 +181,7 @@ declare class TemplateManager {
181
181
  }
182
182
 
183
183
  type IInlineKb = InlineKeyboard
184
- type IBottomKb = IBottomKb
184
+ type IBottomKb = Keyboard
185
185
  type IKb = IBottomKb | IInlineKb
186
186
  type ICt = Context
187
187
  type IOptReply = Parameters<Context[`reply`]>[1]
@@ -302,12 +302,12 @@ declare class Ctx extends BaseGeneral {
302
302
  name: string;
303
303
  }) => string);
304
304
  };
305
- buildInlineKeyboard(callback: (kb: IInlineKb, arr: any[]) => IInlineKb, params?: {
305
+ inlineKeyboard(callback: (kb: IInlineKb, arr: any[]) => IInlineKb, params?: {
306
306
  baseId?: any;
307
307
  data?: IData;
308
308
  cache?: boolean;
309
309
  }): IInlineKb;
310
- buildBottomKeyboard(callback: (kb: IBottomKb, arr: any[]) => IBottomKb, params?: {
310
+ bottomKeyboard(callback: (kb: IBottomKb, arr: any[]) => IBottomKb, params?: {
311
311
  baseId?: any;
312
312
  data?: IData;
313
313
  cache?: boolean;
@@ -497,52 +497,52 @@ declare class Ctx extends BaseGeneral {
497
497
  sessionToLocationFree(paramsAdd?: any, name?: string): Promise<boolean | null>;
498
498
  sessionToContactFree(paramsAdd?: any, name?: string): Promise<boolean | null>;
499
499
  buildIntent(str?: string, fbCallbackData?: boolean): string;
500
- buildSessionMethod(prefix: string, name: string | undefined): string;
501
- buildSessionMethodCallback(name?: string): string;
502
- buildSessionMethodCallbackPayload(name?: string): string;
503
- buildSessionMethodText(name?: string): string;
504
- buildSessionMethodTextPayload(name?: string): string;
505
- buildSessionMethodTextCommand(name?: string): string;
506
- buildSessionMethodTextCommandPayload(name?: string): string;
507
- buildSessionMethodTextFree(name?: string): string;
508
- buildSessionMethodPhotoCaption(name?: string): string;
509
- buildSessionMethodPhotoCaptionPayload(name?: string): string;
510
- buildSessionMethodPhotoCaptionCommand(name?: string): string;
511
- buildSessionMethodPhotoCaptionCommandPayload(name?: string): string;
512
- buildSessionMethodPhotoFree(name?: string): string;
513
- buildSessionMethodVideoCaption(name?: string): string;
514
- buildSessionMethodVideoCaptionPayload(name?: string): string;
515
- buildSessionMethodVideoCaptionCommand(name?: string): string;
516
- buildSessionMethodVideoCaptionCommandPayload(name?: string): string;
517
- buildSessionMethodVideoFree(name?: string): string;
518
- buildSessionMethodAudioCaption(name?: string): string;
519
- buildSessionMethodAudioCaptionPayload(name?: string): string;
520
- buildSessionMethodAudioCaptionCommand(name?: string): string;
521
- buildSessionMethodAudioCaptionCommandPayload(name?: string): string;
522
- buildSessionMethodAudioFree(name?: string): string;
523
- buildSessionMethodDocumentCaption(name?: string): string;
524
- buildSessionMethodDocumentCaptionPayload(name?: string): string;
525
- buildSessionMethodDocumentCaptionCommand(name?: string): string;
526
- buildSessionMethodDocumentCaptionCommandPayload(name?: string): string;
527
- buildSessionMethodDocumentFree(name?: string): string;
528
- buildSessionMethodAnimationCaption(name?: string): string;
529
- buildSessionMethodAnimationCaptionPayload(name?: string): string;
530
- buildSessionMethodAnimationCaptionCommand(name?: string): string;
531
- buildSessionMethodAnimationCaptionCommandPayload(name?: string): string;
532
- buildSessionMethodAnimationFree(name?: string): string;
533
- buildSessionMethodVoiceCaption(name?: string): string;
534
- buildSessionMethodVoiceCaptionPayload(name?: string): string;
535
- buildSessionMethodVoiceCaptionCommand(name?: string): string;
536
- buildSessionMethodVoiceCaptionCommandPayload(name?: string): string;
537
- buildSessionMethodVoiceFree(name?: string): string;
538
- buildSessionMethodVideoNoteCaption(name?: string): string;
539
- buildSessionMethodVideoNoteCaptionPayload(name?: string): string;
540
- buildSessionMethodVideoNoteCaptionCommand(name?: string): string;
541
- buildSessionMethodVideoNoteCaptionCommandPayload(name?: string): string;
542
- buildSessionMethodVideoNoteFree(name?: string): string;
543
- buildSessionMethodStickerFree(name?: string): string;
544
- buildSessionMethodLocationFree(name?: string): string;
545
- buildSessionMethodContactFree(name?: string): string;
500
+ methodSession(prefix: string, name: string | undefined): string;
501
+ methodSessionCallback(name?: string): string;
502
+ methodSessionCallbackPayload(name?: string): string;
503
+ methodSessionText(name?: string): string;
504
+ methodSessionTextPayload(name?: string): string;
505
+ methodSessionTextCommand(name?: string): string;
506
+ methodSessionTextCommandPayload(name?: string): string;
507
+ methodSessionTextFree(name?: string): string;
508
+ methodSessionPhotoCaption(name?: string): string;
509
+ methodSessionPhotoCaptionPayload(name?: string): string;
510
+ methodSessionPhotoCaptionCommand(name?: string): string;
511
+ methodSessionPhotoCaptionCommandPayload(name?: string): string;
512
+ methodSessionPhotoFree(name?: string): string;
513
+ methodSessionVideoCaption(name?: string): string;
514
+ methodSessionVideoCaptionPayload(name?: string): string;
515
+ methodSessionVideoCaptionCommand(name?: string): string;
516
+ methodSessionVideoCaptionCommandPayload(name?: string): string;
517
+ methodSessionVideoFree(name?: string): string;
518
+ methodSessionAudioCaption(name?: string): string;
519
+ methodSessionAudioCaptionPayload(name?: string): string;
520
+ methodSessionAudioCaptionCommand(name?: string): string;
521
+ methodSessionAudioCaptionCommandPayload(name?: string): string;
522
+ methodSessionAudioFree(name?: string): string;
523
+ methodSessionDocumentCaption(name?: string): string;
524
+ methodSessionDocumentCaptionPayload(name?: string): string;
525
+ methodSessionDocumentCaptionCommand(name?: string): string;
526
+ methodSessionDocumentCaptionCommandPayload(name?: string): string;
527
+ methodSessionDocumentFree(name?: string): string;
528
+ methodSessionAnimationCaption(name?: string): string;
529
+ methodSessionAnimationCaptionPayload(name?: string): string;
530
+ methodSessionAnimationCaptionCommand(name?: string): string;
531
+ methodSessionAnimationCaptionCommandPayload(name?: string): string;
532
+ methodSessionAnimationFree(name?: string): string;
533
+ methodSessionVoiceCaption(name?: string): string;
534
+ methodSessionVoiceCaptionPayload(name?: string): string;
535
+ methodSessionVoiceCaptionCommand(name?: string): string;
536
+ methodSessionVoiceCaptionCommandPayload(name?: string): string;
537
+ methodSessionVoiceFree(name?: string): string;
538
+ methodSessionVideoNoteCaption(name?: string): string;
539
+ methodSessionVideoNoteCaptionPayload(name?: string): string;
540
+ methodSessionVideoNoteCaptionCommand(name?: string): string;
541
+ methodSessionVideoNoteCaptionCommandPayload(name?: string): string;
542
+ methodSessionVideoNoteFree(name?: string): string;
543
+ methodSessionStickerFree(name?: string): string;
544
+ methodSessionLocationFree(name?: string): string;
545
+ methodSessionContactFree(name?: string): string;
546
546
  }
547
547
 
548
548
  declare class Gramstax<ICtx extends Ctx = Ctx, IBot extends Bot = Bot> {
@@ -1,7 +1,7 @@
1
1
  import { LoggingPretty } from 'logging-pretty';
2
2
  import { Keyv } from 'keyv';
3
3
  import * as grammy from 'grammy';
4
- import { Context, InlineKeyboard, Bot, BotError } from 'grammy';
4
+ import { Context, Keyboard, InlineKeyboard, Bot, BotError } from 'grammy';
5
5
  import * as grammy_types from 'grammy/types';
6
6
  import { UserFromGetMe } from 'grammy/types';
7
7
  import { FSWatcher } from 'chokidar';
@@ -181,7 +181,7 @@ declare class TemplateManager {
181
181
  }
182
182
 
183
183
  type IInlineKb = InlineKeyboard
184
- type IBottomKb = IBottomKb
184
+ type IBottomKb = Keyboard
185
185
  type IKb = IBottomKb | IInlineKb
186
186
  type ICt = Context
187
187
  type IOptReply = Parameters<Context[`reply`]>[1]
@@ -302,12 +302,12 @@ declare class Ctx extends BaseGeneral {
302
302
  name: string;
303
303
  }) => string);
304
304
  };
305
- buildInlineKeyboard(callback: (kb: IInlineKb, arr: any[]) => IInlineKb, params?: {
305
+ inlineKeyboard(callback: (kb: IInlineKb, arr: any[]) => IInlineKb, params?: {
306
306
  baseId?: any;
307
307
  data?: IData;
308
308
  cache?: boolean;
309
309
  }): IInlineKb;
310
- buildBottomKeyboard(callback: (kb: IBottomKb, arr: any[]) => IBottomKb, params?: {
310
+ bottomKeyboard(callback: (kb: IBottomKb, arr: any[]) => IBottomKb, params?: {
311
311
  baseId?: any;
312
312
  data?: IData;
313
313
  cache?: boolean;
@@ -497,52 +497,52 @@ declare class Ctx extends BaseGeneral {
497
497
  sessionToLocationFree(paramsAdd?: any, name?: string): Promise<boolean | null>;
498
498
  sessionToContactFree(paramsAdd?: any, name?: string): Promise<boolean | null>;
499
499
  buildIntent(str?: string, fbCallbackData?: boolean): string;
500
- buildSessionMethod(prefix: string, name: string | undefined): string;
501
- buildSessionMethodCallback(name?: string): string;
502
- buildSessionMethodCallbackPayload(name?: string): string;
503
- buildSessionMethodText(name?: string): string;
504
- buildSessionMethodTextPayload(name?: string): string;
505
- buildSessionMethodTextCommand(name?: string): string;
506
- buildSessionMethodTextCommandPayload(name?: string): string;
507
- buildSessionMethodTextFree(name?: string): string;
508
- buildSessionMethodPhotoCaption(name?: string): string;
509
- buildSessionMethodPhotoCaptionPayload(name?: string): string;
510
- buildSessionMethodPhotoCaptionCommand(name?: string): string;
511
- buildSessionMethodPhotoCaptionCommandPayload(name?: string): string;
512
- buildSessionMethodPhotoFree(name?: string): string;
513
- buildSessionMethodVideoCaption(name?: string): string;
514
- buildSessionMethodVideoCaptionPayload(name?: string): string;
515
- buildSessionMethodVideoCaptionCommand(name?: string): string;
516
- buildSessionMethodVideoCaptionCommandPayload(name?: string): string;
517
- buildSessionMethodVideoFree(name?: string): string;
518
- buildSessionMethodAudioCaption(name?: string): string;
519
- buildSessionMethodAudioCaptionPayload(name?: string): string;
520
- buildSessionMethodAudioCaptionCommand(name?: string): string;
521
- buildSessionMethodAudioCaptionCommandPayload(name?: string): string;
522
- buildSessionMethodAudioFree(name?: string): string;
523
- buildSessionMethodDocumentCaption(name?: string): string;
524
- buildSessionMethodDocumentCaptionPayload(name?: string): string;
525
- buildSessionMethodDocumentCaptionCommand(name?: string): string;
526
- buildSessionMethodDocumentCaptionCommandPayload(name?: string): string;
527
- buildSessionMethodDocumentFree(name?: string): string;
528
- buildSessionMethodAnimationCaption(name?: string): string;
529
- buildSessionMethodAnimationCaptionPayload(name?: string): string;
530
- buildSessionMethodAnimationCaptionCommand(name?: string): string;
531
- buildSessionMethodAnimationCaptionCommandPayload(name?: string): string;
532
- buildSessionMethodAnimationFree(name?: string): string;
533
- buildSessionMethodVoiceCaption(name?: string): string;
534
- buildSessionMethodVoiceCaptionPayload(name?: string): string;
535
- buildSessionMethodVoiceCaptionCommand(name?: string): string;
536
- buildSessionMethodVoiceCaptionCommandPayload(name?: string): string;
537
- buildSessionMethodVoiceFree(name?: string): string;
538
- buildSessionMethodVideoNoteCaption(name?: string): string;
539
- buildSessionMethodVideoNoteCaptionPayload(name?: string): string;
540
- buildSessionMethodVideoNoteCaptionCommand(name?: string): string;
541
- buildSessionMethodVideoNoteCaptionCommandPayload(name?: string): string;
542
- buildSessionMethodVideoNoteFree(name?: string): string;
543
- buildSessionMethodStickerFree(name?: string): string;
544
- buildSessionMethodLocationFree(name?: string): string;
545
- buildSessionMethodContactFree(name?: string): string;
500
+ methodSession(prefix: string, name: string | undefined): string;
501
+ methodSessionCallback(name?: string): string;
502
+ methodSessionCallbackPayload(name?: string): string;
503
+ methodSessionText(name?: string): string;
504
+ methodSessionTextPayload(name?: string): string;
505
+ methodSessionTextCommand(name?: string): string;
506
+ methodSessionTextCommandPayload(name?: string): string;
507
+ methodSessionTextFree(name?: string): string;
508
+ methodSessionPhotoCaption(name?: string): string;
509
+ methodSessionPhotoCaptionPayload(name?: string): string;
510
+ methodSessionPhotoCaptionCommand(name?: string): string;
511
+ methodSessionPhotoCaptionCommandPayload(name?: string): string;
512
+ methodSessionPhotoFree(name?: string): string;
513
+ methodSessionVideoCaption(name?: string): string;
514
+ methodSessionVideoCaptionPayload(name?: string): string;
515
+ methodSessionVideoCaptionCommand(name?: string): string;
516
+ methodSessionVideoCaptionCommandPayload(name?: string): string;
517
+ methodSessionVideoFree(name?: string): string;
518
+ methodSessionAudioCaption(name?: string): string;
519
+ methodSessionAudioCaptionPayload(name?: string): string;
520
+ methodSessionAudioCaptionCommand(name?: string): string;
521
+ methodSessionAudioCaptionCommandPayload(name?: string): string;
522
+ methodSessionAudioFree(name?: string): string;
523
+ methodSessionDocumentCaption(name?: string): string;
524
+ methodSessionDocumentCaptionPayload(name?: string): string;
525
+ methodSessionDocumentCaptionCommand(name?: string): string;
526
+ methodSessionDocumentCaptionCommandPayload(name?: string): string;
527
+ methodSessionDocumentFree(name?: string): string;
528
+ methodSessionAnimationCaption(name?: string): string;
529
+ methodSessionAnimationCaptionPayload(name?: string): string;
530
+ methodSessionAnimationCaptionCommand(name?: string): string;
531
+ methodSessionAnimationCaptionCommandPayload(name?: string): string;
532
+ methodSessionAnimationFree(name?: string): string;
533
+ methodSessionVoiceCaption(name?: string): string;
534
+ methodSessionVoiceCaptionPayload(name?: string): string;
535
+ methodSessionVoiceCaptionCommand(name?: string): string;
536
+ methodSessionVoiceCaptionCommandPayload(name?: string): string;
537
+ methodSessionVoiceFree(name?: string): string;
538
+ methodSessionVideoNoteCaption(name?: string): string;
539
+ methodSessionVideoNoteCaptionPayload(name?: string): string;
540
+ methodSessionVideoNoteCaptionCommand(name?: string): string;
541
+ methodSessionVideoNoteCaptionCommandPayload(name?: string): string;
542
+ methodSessionVideoNoteFree(name?: string): string;
543
+ methodSessionStickerFree(name?: string): string;
544
+ methodSessionLocationFree(name?: string): string;
545
+ methodSessionContactFree(name?: string): string;
546
546
  }
547
547
 
548
548
  declare class Gramstax<ICtx extends Ctx = Ctx, IBot extends Bot = Bot> {
package/dist/src/index.js CHANGED
@@ -1 +1 @@
1
- var N=Object.defineProperty;var p=(b,i)=>N(b,"name",{value:i,configurable:!0}),F=(b=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(b,{get:(i,t)=>(typeof require<"u"?require:i)[t]}):b)(function(b){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+b+'" is not supported')});import{LoggingPretty as E}from"logging-pretty";var C=class{static{p(this,"BaseGeneral")}static log=new E;static logError(i,t){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${t}]: ${String(i)}`)}logError(i,t,e){this.constructor.log.error(`[${t||this.constructor.name}:${e}] ${String(i)}`)}};import{Keyv as B}from"keyv";import L from"@keyv/redis";var S=class extends B{constructor(t="memory",e,s,o){let n;t.startsWith("redis")&&(n=new L(t)),t==="memory"&&(n=new Map),o?.forceStore&&(n=o.forceStore);super({store:n,namespace:e,ttl:s});this.url=t}static{p(this,"CacheExternal")}};import{setTimeout as $}from"timers/promises";import{InlineKeyboard as w,Keyboard as V}from"grammy";var M=class extends C{static{p(this,"Ctx")}static template;static data;data=this.constructor.data;get isPremium(){return this.ct.from?.is_premium??!1}get isBot(){return this.ct.from?.is_bot??!1}get userid(){return this.ct.from?.id}get username(){return this.ct.from?.username}get fullname(){return`${this.ct.from?.first_name||""}${this.ct.from?.last_name||""}`}get firstname(){return this.ct.from?.first_name}get lastname(){return this.ct.from?.last_name}get msgText(){return this.ct.message?.text}get msgTextIntent(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ")[0]:""}get msgTextPayloads(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ").slice(1):[]}get msgTextPayload(){return this.msgTextPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionIntent(){return this.msgCaption&&this.msgCaption.indexOf(" ")!=-1?this.msgCaption.split(" ")[0]:""}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataIntent(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":")[0]:""}get callbackDataPayloads(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":").slice(1):[]}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}get callbackDataParts(){return this.callbackDataPayload&&this.callbackDataPayload.indexOf("+")!=-1?this.callbackDataPayload.split("+"):[]}get languageCode(){return this.ct.from?.language_code}set languageCode(i){this.ct.from.language_code=i}set session(i){this.temp.session=i}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(i){super(),this.ct=i.ct,this.cacheSession=i.cacheSession,this.cacheKeyboard=i.cacheKeyboard,this.templateManager=i.templateManager,this.temp=i.temp,i?.data&&(this.temp.data=i.data)}async broadcast(i,t,e,s,o,n){let r=t.map(d=>this.templateManager.getMessage(this.data.name,o,d,s));for(let d=0;d<i.length;d++){let l=i[d],c=r[d];await this.ct.api.sendMessage(l,c,{parse_mode:"HTML",reply_markup:e,...n}),d+1==30&&await $(1200)}}async reply(i,t,e,s){let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,t);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:i,...s})}async replyMedia(i,t,e,s,o){let n=this.templateManager.getMedia(this.data.name,s,this.languageCode,e),a={parse_mode:"HTML",reply_markup:t,...o};if(i=="photo")return await this.ct.replyWithPhoto(n.src,{caption:n.caption,...a});if(i=="video")return await this.ct.replyWithVideo(n.src,{caption:n.caption,...a});if(i=="audio")return await this.ct.replyWithAudio(n.src,{caption:n.caption,...a});if(i=="document")return await this.ct.replyWithDocument(n.src,{caption:n.caption,...a});if(i=="animation")return await this.ct.replyWithAnimation(n.src,{caption:n.caption,...a});if(i=="voice")return await this.ct.replyWithVoice(n.src,a);if(i=="video_note")return await this.ct.replyWithVideoNote(n.src,a);if(i=="sticker")return await this.ct.replyWithSticker(n.src,a);if(i=="location")return await this.ct.replyWithLocation(n.latitude,n.longitude,a);if(i=="contact")return await this.ct.replyWithContact(n.phone,n.first_name,{vcard:n.vcard,...a})}async replyPhoto(i,t,e,s){return this.replyMedia("photo",i,t,e,s)}async replyVideo(i,t,e,s){return this.replyMedia("video",i,t,e,s)}async replyAudio(i,t,e,s){return this.replyMedia("audio",i,t,e,s)}async replyDocument(i,t,e,s){return this.replyMedia("document",i,t,e,s)}async replyAnimation(i,t,e,s){return this.replyMedia("animation",i,t,e,s)}async replyVoice(i,t,e,s){return this.replyMedia("voice",i,t,e,s)}async replyVideoNote(i,t,e,s){return this.replyMedia("video_note",i,t,e,s)}async replySticker(i,t,e,s){return this.replyMedia("sticker",i,t,e,s)}async replyLocation(i,t,e,s){return this.replyMedia("location",i,t,e,s)}async replyContact(i,t,e,s){return this.replyMedia("contact",i,t,e,s)}async replyAction(i){return await this.ct.replyWithChatAction(i)}async edit(i,t,e,s){try{let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,t);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:i,...s})}catch{await this.reply(i,t,e,s)}}async editMedia(i,t,e,s,o,n){try{let{src:a,caption:r}=this.templateManager.getMedia(this.data.name,s,this.languageCode,e);return i=="voice"?(await this.delete(),await this.replyVoice(t,e,s,o)):i=="video_note"?(await this.delete(),await this.replyVoice(t,e,s,o)):i=="sticker"?(await this.delete(),await this.replySticker(t,e,s,o)):i=="location"?(await this.delete(),await this.replyLocation(t,e,s,o)):i=="contact"?(await this.delete(),await this.replyContact(t,e,s,o)):await this.ct.editMessageMedia({media:a,caption:r,type:i,parse_mode:"HTML",...o},{reply_markup:t,...n})}catch{await this.reply(t,e,s,n)}}async editPhoto(i,t,e,s,o){return await this.editMedia("photo",i,t,e,s,o)}async editVideo(i,t,e,s,o){return await this.editMedia("video",i,t,e,s,o)}async editAudio(i,t,e,s,o){return await this.editMedia("audio",i,t,e,s,o)}async editDocument(i,t,e,s,o){return await this.editMedia("document",i,t,e,s,o)}async editAnimation(i,t,e,s,o){return await this.editMedia("animation",i,t,e,s,o)}async editVoice(i,t,e,s){return await this.editMedia("voice",i,t,e,s)}async editVideoNote(i,t,e,s){return await this.editMedia("video_note",i,t,e,s)}async editSticker(i,t,e,s){return await this.editMedia("sticker",i,t,e,s)}async editLocation(i,t,e,s){return await this.editMedia("location",i,t,e,s)}async editContact(i,t,e,s){return await this.editMedia("contact",i,t,e,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(i){try{return await this.ct.answerCallbackQuery(i)}catch{return null}}async sessionSet(i,t,e){try{let s={method:i,params:t,...e},o=await this.cacheSession.set(`${this.userid}`,s);return o&&(this.session=s),o}catch{return null}}async sessionGet(){try{let i=await this.cacheSession.get(`${this.userid}`);return i&&(this.session=i),i||null}catch{return null}}async sessionClear(){try{let i=await this.cacheSession.delete(`${this.userid}`);return i&&(this.session={}),i}catch{return null}}static buildData(i){return{name:"",callbackData:i?function(...t){let e=i(...t);return`${this.name}${e===void 0?"":`:${e}`}`}:function(){return this?.name}}}buildInlineKeyboard(i,t){let e=this.data.name;if(t?.cache===!0){let a=`${e}:${this.languageCode}:i`,r=this.cacheKeyboard.get(a);if(!r){let d=new w,l=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"inline",t?.data),c=i(d,l);return this.cacheKeyboard.set(a,c),c}return r}let s=new w,o=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"inline",t?.data);return i(s,o)}buildBottomKeyboard(i,t){let e=this.data.name;if(t?.cache===!0){let a=`${e}:${this.languageCode}:b`,r=this.cacheKeyboard.get(a);if(!r){let d=new V,l=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"bottom",t?.data),c=i(d,l);return c.resized(!0),this.cacheKeyboard.set(a,c),c}return r}let s=new V,o=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"bottom",t?.data),n=i(s,o);return n.resized(),n}validateSessionCallback(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallback(t)}validateSessionCallbackPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallbackPayload(t)}validateSessionText(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodText(t)}validateSessionTextPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextPayload(t)}validateSessionTextCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommand(t)}validateSessionTextCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommandPayload(t)}validateSessionTextFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextFree(t)}validateSessionPhotoCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaption(t)}validateSessionPhotoCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionPayload(t)}validateSessionPhotoCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommand(t)}validateSessionPhotoCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommandPayload(t)}validateSessionPhotoFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoFree(t)}validateSessionVideoCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaption(t)}validateSessionVideoCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionPayload(t)}validateSessionVideoCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommand(t)}validateSessionVideoCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommandPayload(t)}validateSessionVideoFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoFree(t)}validateSessionAudioCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaption(t)}validateSessionAudioCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionPayload(t)}validateSessionAudioCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommand(t)}validateSessionAudioCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommandPayload(t)}validateSessionAudioFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioFree(t)}validateSessionDocumentCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaption(t)}validateSessionDocumentCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionPayload(t)}validateSessionDocumentCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommand(t)}validateSessionDocumentCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommandPayload(t)}validateSessionDocumentFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentFree(t)}validateSessionAnimationCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaption(t)}validateSessionAnimationCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionPayload(t)}validateSessionAnimationCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommand(t)}validateSessionAnimationCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommandPayload(t)}validateSessionAnimationFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationFree(t)}validateSessionVoiceCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaption(t)}validateSessionVoiceCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionPayload(t)}validateSessionVoiceCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommand(t)}validateSessionVoiceCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommandPayload(t)}validateSessionVoiceFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceFree(t)}validateSessionVideoNoteCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaption(t)}validateSessionVideoNoteCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionPayload(t)}validateSessionVideoNoteCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommand(t)}validateSessionVideoNoteCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommandPayload(t)}validateSessionVideoNoteFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteFree(t)}validateSessionStickerFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodStickerFree(t)}validateSessionLocationFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodLocationFree(t)}validateSessionContactFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodContactFree(t)}sessionCallback(i,t){return this.sessionSet(this.buildSessionMethodCallback(t),i)}sessionCallbackPayload(i,t){return this.sessionSet(this.buildSessionMethodCallbackPayload(t),i)}sessionText(i,t){return this.sessionSet(this.buildSessionMethodText(t),i)}sessionTextPayload(i,t){return this.sessionSet(this.buildSessionMethodTextPayload(t),i)}sessionTextCommand(i,t){return this.sessionSet(this.buildSessionMethodTextCommand(t),i)}sessionTextCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodTextCommandPayload(t),i)}sessionTextFree(i,t){return this.sessionSet(this.buildSessionMethodTextFree(t),i)}sessionPhotoCaption(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaption(t),i)}sessionPhotoCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaptionPayload(t),i)}sessionPhotoCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommand(t),i)}sessionPhotoCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommandPayload(t),i)}sessionPhotoFree(i,t){return this.sessionSet(this.buildSessionMethodPhotoFree(t),i)}sessionVideoCaption(i,t){return this.sessionSet(this.buildSessionMethodVideoCaption(t),i)}sessionVideoCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoCaptionPayload(t),i)}sessionVideoCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodVideoCaptionCommand(t),i)}sessionVideoCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoCaptionCommandPayload(t),i)}sessionVideoFree(i,t){return this.sessionSet(this.buildSessionMethodVideoFree(t),i)}sessionAudioCaption(i,t){return this.sessionSet(this.buildSessionMethodAudioCaption(t),i)}sessionAudioCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodAudioCaptionPayload(t),i)}sessionAudioCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodAudioCaptionCommand(t),i)}sessionAudioCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodAudioCaptionCommandPayload(t),i)}sessionAudioFree(i,t){return this.sessionSet(this.buildSessionMethodAudioFree(t),i)}sessionDocumentCaption(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaption(t),i)}sessionDocumentCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaptionPayload(t),i)}sessionDocumentCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommand(t),i)}sessionDocumentCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommandPayload(t),i)}sessionDocumentFree(i,t){return this.sessionSet(this.buildSessionMethodDocumentFree(t),i)}sessionAnimationCaption(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaption(t),i)}sessionAnimationCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaptionPayload(t),i)}sessionAnimationCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommand(t),i)}sessionAnimationCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommandPayload(t),i)}sessionAnimationFree(i,t){return this.sessionSet(this.buildSessionMethodAnimationFree(t),i)}sessionVoiceCaption(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaption(t),i)}sessionVoiceCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaptionPayload(t),i)}sessionVoiceCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommand(t),i)}sessionVoiceCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommandPayload(t),i)}sessionVoiceFree(i,t){return this.sessionSet(this.buildSessionMethodVoiceFree(t),i)}sessionVideoNoteCaption(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaption(t),i)}sessionVideoNoteCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionPayload(t),i)}sessionVideoNoteCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommand(t),i)}sessionVideoNoteCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommandPayload(t),i)}sessionVideoNoteFree(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteFree(t),i)}sessionStickerFree(i,t){return this.sessionSet(this.buildSessionMethodStickerFree(t),i)}sessionLocationFree(i,t){return this.sessionSet(this.buildSessionMethodLocationFree(t),i)}sessionContactFree(i,t){return this.sessionSet(this.buildSessionMethodContactFree(t),i)}sessionToCallback(i,t){return this.sessionCallback({...this.session.params,...i},t)}sessionToCallbackPayload(i,t){return this.sessionCallbackPayload({...this.session.params,...i},t)}sessionToText(i,t){return this.sessionText({...this.session.params,...i},t)}sessionToTextPayload(i,t){return this.sessionTextPayload({...this.session.params,...i},t)}sessionToTextCommand(i,t){return this.sessionTextCommand({...this.session.params,...i},t)}sessionToTextCommandPayload(i,t){return this.sessionTextCommandPayload({...this.session.params,...i},t)}sessionToTextFree(i,t){return this.sessionTextFree({...this.session.params,...i},t)}sessionToPhotoCaption(i,t){return this.sessionPhotoCaption({...this.session.params,...i},t)}sessionToPhotoCaptionPayload(i,t){return this.sessionPhotoCaptionPayload({...this.session.params,...i},t)}sessionToPhotoCaptionCommand(i,t){return this.sessionPhotoCaptionCommand({...this.session.params,...i},t)}sessionToPhotoCaptionCommandPayload(i,t){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...i},t)}sessionToPhotoFree(i,t){return this.sessionPhotoFree({...this.session.params,...i},t)}sessionToVideoCaption(i,t){return this.sessionVideoCaption({...this.session.params,...i},t)}sessionToVideoCaptionPayload(i,t){return this.sessionVideoCaptionPayload({...this.session.params,...i},t)}sessionToVideoCaptionCommand(i,t){return this.sessionVideoCaptionCommand({...this.session.params,...i},t)}sessionToVideoCaptionCommandPayload(i,t){return this.sessionVideoCaptionCommandPayload({...this.session.params,...i},t)}sessionToVideoFree(i,t){return this.sessionVideoFree({...this.session.params,...i},t)}sessionToAudioCaption(i,t){return this.sessionAudioCaption({...this.session.params,...i},t)}sessionToAudioCaptionPayload(i,t){return this.sessionAudioCaptionPayload({...this.session.params,...i},t)}sessionToAudioCaptionCommand(i,t){return this.sessionAudioCaptionCommand({...this.session.params,...i},t)}sessionToAudioCaptionCommandPayload(i,t){return this.sessionAudioCaptionCommandPayload({...this.session.params,...i},t)}sessionToAudioFree(i,t){return this.sessionAudioFree({...this.session.params,...i},t)}sessionToDocumentCaption(i,t){return this.sessionDocumentCaption({...this.session.params,...i},t)}sessionToDocumentCaptionPayload(i,t){return this.sessionDocumentCaptionPayload({...this.session.params,...i},t)}sessionToDocumentCaptionCommand(i,t){return this.sessionDocumentCaptionCommand({...this.session.params,...i},t)}sessionToDocumentCaptionCommandPayload(i,t){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...i},t)}sessionToDocumentFree(i,t){return this.sessionDocumentFree({...this.session.params,...i},t)}sessionToAnimationCaption(i,t){return this.sessionAnimationCaption({...this.session.params,...i},t)}sessionToAnimationCaptionPayload(i,t){return this.sessionAnimationCaptionPayload({...this.session.params,...i},t)}sessionToAnimationCaptionCommand(i,t){return this.sessionAnimationCaptionCommand({...this.session.params,...i},t)}sessionToAnimationCaptionCommandPayload(i,t){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...i},t)}sessionToAnimationFree(i,t){return this.sessionAnimationFree({...this.session.params,...i},t)}sessionToVoiceCaption(i,t){return this.sessionVoiceCaption({...this.session.params,...i},t)}sessionToVoiceCaptionPayload(i,t){return this.sessionVoiceCaptionPayload({...this.session.params,...i},t)}sessionToVoiceCaptionCommand(i,t){return this.sessionVoiceCaptionCommand({...this.session.params,...i},t)}sessionToVoiceCaptionCommandPayload(i,t){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...i},t)}sessionToVoiceFree(i,t){return this.sessionVoiceFree({...this.session.params,...i},t)}sessionToVideoNoteCaption(i,t){return this.sessionVideoNoteCaption({...this.session.params,...i},t)}sessionToVideoNoteCaptionPayload(i,t){return this.sessionVideoNoteCaptionPayload({...this.session.params,...i},t)}sessionToVideoNoteCaptionCommand(i,t){return this.sessionVideoNoteCaptionCommand({...this.session.params,...i},t)}sessionToVideoNoteCaptionCommandPayload(i,t){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...i},t)}sessionToVideoNoteFree(i,t){return this.sessionVideoNoteFree({...this.session.params,...i},t)}sessionToStickerFree(i,t){return this.sessionStickerFree({...this.session.params,...i},t)}sessionToLocationFree(i,t){return this.sessionLocationFree({...this.session.params,...i},t)}sessionToContactFree(i,t){return this.sessionContactFree({...this.session.params,...i},t)}buildIntent(i,t=!0){i||(i=t?this.data.callbackData():this.data.name);let e=t?":":" ";return i?.indexOf?.(e)!=-1?i?.split?.(e)?.[0]:i}buildSessionMethod(i,t){return`${i}-${t||this.data.name}`}buildSessionMethodCallback(i){return this.buildSessionMethod("1",i)}buildSessionMethodCallbackPayload(i){return this.buildSessionMethod("2",i)}buildSessionMethodText(i){return this.buildSessionMethod("3",i)}buildSessionMethodTextPayload(i){return this.buildSessionMethod("4",i)}buildSessionMethodTextCommand(i){return this.buildSessionMethod("5",i)}buildSessionMethodTextCommandPayload(i){return this.buildSessionMethod("6",i)}buildSessionMethodTextFree(i){return this.buildSessionMethod("7",i)}buildSessionMethodPhotoCaption(i){return this.buildSessionMethod("8",i)}buildSessionMethodPhotoCaptionPayload(i){return this.buildSessionMethod("9",i)}buildSessionMethodPhotoCaptionCommand(i){return this.buildSessionMethod("10",i)}buildSessionMethodPhotoCaptionCommandPayload(i){return this.buildSessionMethod("11",i)}buildSessionMethodPhotoFree(i){return this.buildSessionMethod("12",i)}buildSessionMethodVideoCaption(i){return this.buildSessionMethod("13",i)}buildSessionMethodVideoCaptionPayload(i){return this.buildSessionMethod("14",i)}buildSessionMethodVideoCaptionCommand(i){return this.buildSessionMethod("15",i)}buildSessionMethodVideoCaptionCommandPayload(i){return this.buildSessionMethod("16",i)}buildSessionMethodVideoFree(i){return this.buildSessionMethod("17",i)}buildSessionMethodAudioCaption(i){return this.buildSessionMethod("18",i)}buildSessionMethodAudioCaptionPayload(i){return this.buildSessionMethod("19",i)}buildSessionMethodAudioCaptionCommand(i){return this.buildSessionMethod("20",i)}buildSessionMethodAudioCaptionCommandPayload(i){return this.buildSessionMethod("21",i)}buildSessionMethodAudioFree(i){return this.buildSessionMethod("22",i)}buildSessionMethodDocumentCaption(i){return this.buildSessionMethod("23",i)}buildSessionMethodDocumentCaptionPayload(i){return this.buildSessionMethod("24",i)}buildSessionMethodDocumentCaptionCommand(i){return this.buildSessionMethod("25",i)}buildSessionMethodDocumentCaptionCommandPayload(i){return this.buildSessionMethod("26",i)}buildSessionMethodDocumentFree(i){return this.buildSessionMethod("27",i)}buildSessionMethodAnimationCaption(i){return this.buildSessionMethod("28",i)}buildSessionMethodAnimationCaptionPayload(i){return this.buildSessionMethod("29",i)}buildSessionMethodAnimationCaptionCommand(i){return this.buildSessionMethod("30",i)}buildSessionMethodAnimationCaptionCommandPayload(i){return this.buildSessionMethod("31",i)}buildSessionMethodAnimationFree(i){return this.buildSessionMethod("32",i)}buildSessionMethodVoiceCaption(i){return this.buildSessionMethod("33",i)}buildSessionMethodVoiceCaptionPayload(i){return this.buildSessionMethod("34",i)}buildSessionMethodVoiceCaptionCommand(i){return this.buildSessionMethod("35",i)}buildSessionMethodVoiceCaptionCommandPayload(i){return this.buildSessionMethod("36",i)}buildSessionMethodVoiceFree(i){return this.buildSessionMethod("37",i)}buildSessionMethodVideoNoteCaption(i){return this.buildSessionMethod("38",i)}buildSessionMethodVideoNoteCaptionPayload(i){return this.buildSessionMethod("39",i)}buildSessionMethodVideoNoteCaptionCommand(i){return this.buildSessionMethod("40",i)}buildSessionMethodVideoNoteCaptionCommandPayload(i){return this.buildSessionMethod("41",i)}buildSessionMethodVideoNoteFree(i){return this.buildSessionMethod("42",i)}buildSessionMethodStickerFree(i){return this.buildSessionMethod("43",i)}buildSessionMethodLocationFree(i){return this.buildSessionMethod("44",i)}buildSessionMethodContactFree(i){return this.buildSessionMethod("45",i)}};import{serve as J}from"bun";import{join as x,parse as q}from"path";import{LoggingPretty as X}from"logging-pretty";var y=class{static{p(this,"TemplateEngine")}static _escape(i){return i.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(i){return i.replace(/\{\{(\w+)\}\}/g,(t,e)=>`\${(data && data["${e}"]) ?? ""}`)}static _processBaseBlocks(i){let t=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,e={};for(let s of i.matchAll(t)){let o=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[o]=a}return e}static _processScriptBlocks(i){return i.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(t,e)=>{let s=e.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(i){return i.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(i){return i.replace(/<div>([\s\S]*?)<\/div>/gi,(t,e)=>e.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(i){let t=/<media\s+([^>]+)>([\s\S]*?)<\/media>/gi,e={};for(let s of i.matchAll(t)){let o=s[1],n=s[2],a={},r=/(\w+)="([^"]*)"/g;for(let m of o.matchAll(r))a[m[1]]=m[2];if(!a.lang)continue;let d=a.lang,l=a.type,c=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),u={type:l};a.src&&(u.src=a.src),c&&l!=="video_note"&&l!=="sticker"&&(u.caption=c),l==="location"&&(a.latitude&&(u.latitude=a.latitude),a.longitude&&(u.longitude=a.longitude),c&&(u.caption=c)),l==="contact"&&(a.phone&&(u.phone=a.phone),a.first_name&&(u.first_name=a.first_name),a.last_name&&(u.last_name=a.last_name),a.vcard&&(u.vcard=a.vcard),c&&(u.caption=c)),e[d]=u}return e}static _processMessageBlocks(i){let t=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,e={};for(let[,s,o]of i.matchAll(t)){let n=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[s]=n}return e}static _processKeyboardBlocks(i){let t=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\stype="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,e={};for(let[,s,o,n]of i.matchAll(t)){let a=o==="bottom"?"bottom":"inline",r=n.trim();e[s]||(e[s]={}),e[s][a]=r}return e}static _compileToFunction(i,t){let e;t?e=i.map(n=>`\`${n}\``).join(","):e=`\`${i}\``;let s=e;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),t){let o=`return [${s}]`;return new Function("data",o)}else{let o=`return ${s}`;return new Function("data",o)}}static compileMedia(i){let t=this._processBaseBlocks(i),e={};for(let[s,o]of Object.entries(t)){let n=this._processMediaBlocks(o);e[s]={};for(let[a,r]of Object.entries(n))if(r.caption){let d=this._processVariables(this._processScriptBlocks(r.caption)),l=this._compileToFunction(d,!1);e[s][a]=c=>({...r,caption:l(c)})}else e[s][a]=()=>r}return e}static compileMessages(i){let t=this._processBaseBlocks(i),e={};for(let[s,o]of Object.entries(t)){let n=this._processMessageBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){let d=this._processVariables(this._processScriptBlocks(r));e[s][a]=this._compileToFunction(d,!1)}}return e}static compileKeyboards(i){let t=this._processBaseBlocks(i),e={};for(let[s,o]of Object.entries(t)){let n=this._processKeyboardBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){e[s][a]={};for(let[d,l]of Object.entries(r)){let u=l.split(/(?<!\\),\s*/).map(m=>m.replace(/\\,/g,",").trim()).map(m=>this._processVariables(this._processScriptBlocks(m)));e[s][a][d]=this._compileToFunction(u,!0)}}}return e}};var f=class{static{p(this,"HelperPage")}static _getPage(i,t,e=!0){let o=Object.values(i)[0];if(o===void 0)throw new Error(`File ${t} must have export (not default) class page`);return e===!0&&(o.template=void 0),o}static getPageSync(i,t=!0){let e=F(i);return this._getPage(e,i,t)}static async getPage(i,t=!0){let e=await import(`${i}?t=${Date.now()}`);return this._getPage(e,i,t)}};import{readFile as W}from"fs/promises";import{watch as j}from"chokidar";import{basename as I,join as _,extname as Q}from"path";import{readdirSync as z,readFileSync as G,existsSync as D,statSync as H,writeFileSync as U}from"fs";var P=class{static{p(this,"TemplateManager")}_map=new Map;_engine=y;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_forceLanguage;_isWatchEnabled;constructor(i){let{path:t,enableWatch:e=!1,forceLanguage:s}=i;this._path=t,this._forceLanguage=s,this._isWatchEnabled=e,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(!this._path||!Array.isArray(this._path))throw new Error("Path must be set as string array");for(let i=0;i<this._path.length;i++){let t=this._path[i];if(!D(t))throw new Error(`Template base path is not exists: ${t}`);if(!H(t).isDirectory())throw new Error(`Template base path is not a directory: ${t}`)}return!0}catch(i){throw new Error(`Failed to validate Template base path: ${i}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let i=0;i<this._path.length;i++){let t=this._path[i],e=j(t,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[i]=e,e.on("change",this._handleFileChange.bind(this)),e.on("add",this._handleFileAdd.bind(this)),e.on("unlink",this._handleFileDelete.bind(this)),e.on("error",this._handleWatchError.bind(this))}}async _handleFileChange(i){let t=I(i);this._isValidFile(t)&&await this._loadFile(t,!1)}async _handleFileAdd(i){let t=I(i);this._isValidFile(t)&&await this._loadFile(t,!1)}_handleFileDelete(i){let t=I(i),e=this._getKey(t);this._map.has(e)&&this._map.delete(e)}_handleWatchError(i){}_loadAllFiles(){for(let i=0;i<this._path.length;i++){let t=this._path[i],s=z(t,"utf8").filter(o=>this._isValidFile(o));for(let o of s)this._loadFile(o,!0)}}async _loadFile(i,t=!0){for(let e=0;e<this._path.length;e++){let s=this._path[e],o=_(s,i),n=this._getExtension(i),a=this._getKey(i);if(n==".html"){let r=t?G(o,"utf8"):await W(o,"utf8");this._compile(a,r)}else if(n==".ts"){let r=await f.getPage(o,!1);r?.template!==void 0&&this._compile(a,r.template),r.template=void 0}else throw new Error(`File ${i} is not support`)}}_getExtension(i){return Q(i).toLowerCase()}_isValidFile(i){return this._supportedExtensions.has(this._getExtension(i))}_getKey(i){return i.replace(/\.[^/.]+$/,"")}_compile(i,t,e){let s=this._map.get(i),o=s||{},n=!1;(e===void 0||e?.media===!1||s?.media===void 0)&&(o.media=y.compileMedia(t),n=!0),(e===void 0||e?.message===!1||s?.message===void 0)&&(o.message=y.compileMessages(t),n=!0),(e===void 0||e?.keyboard===!1||s?.keyboard===void 0)&&(o.keyboard=y.compileKeyboards(t),n=!0),n&&this._map.set(i,o)}getMedia(i,t="default",e="en",s){let n=this._map.get(i)?.media?.[t]?.[this._forceLanguage||e];if(!n)return{};try{return n(s)}catch{return{}}}getMessage(i,t="default",e="en",s){let n=this._map.get(i)?.message?.[t]?.[this._forceLanguage||e];if(!n)return"";try{return n(s)}catch{return""}}getKeyboard(i,t="default",e="en",s="inline",o){let a=this._map.get(i)?.keyboard?.[t]?.[this._forceLanguage||e]?.[s];if(!a)return[];try{return a(o)}catch{return[]}}async write(i,t){if(this._getExtension(i)!=".html")return null;for(let e=0;e<this._path.length;e++){let s=_(this._path[e],i);if(D(s))return U(s,t,"utf8"),await this._loadFile(i,!1),!0}return null}getAvailable(){return Array.from(this._map.keys())}has(i){return this._map.has(i)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(i,t)=>typeof t=="function"?t.toString():t).length}}async destroy(){if(this._watcher)for(let i of this._watcher)await i.close();this._map.clear()}};import{existsSync as Y,readdirSync as Z}from"fs";import{Bot as ii,webhookCallback as ti}from"grammy";var A=class{static{p(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;constructor(i){if(!i?.token||i?.token?.length==0)throw new Error("Token is not valid or empty");this.log=i.log===null?void 0:i.log===void 0?new X:i.log,this.cacheSession=i.cacheSession||new S("memory","session"),this.cacheKeyboard=i.cacheKeyboard||new Map,this.templateManager=i.templateManager||new P({path:[x(process.cwd(),"src","pages")]}),this.bot=this.createBot(i.token),this.bot.catch(this.onCatch),this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this)),this.bot.on("message:text",this.onMessageText.bind(this)),this.bot.on("message:photo",this.onMessagePhoto.bind(this)),this.bot.on("message:video",this.onMessageVideo.bind(this)),this.bot.on("message:audio",this.onMessageAudio.bind(this)),this.bot.on("message:document",this.onMessageDocument.bind(this)),this.bot.on("message:animation",this.onMessageAnimation.bind(this)),this.bot.on("message:voice",this.onMessageVoice.bind(this)),this.bot.on("message:video_note",this.onMessageVideoNote.bind(this)),this.bot.on("message:sticker",this.onMessageSticker.bind(this)),this.bot.on("message:location",this.onMessageLocation.bind(this)),this.bot.on("message:contact",this.onMessageContact.bind(this)),this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),i.deploy.startsWith("polling")?this.runPolling():i.deploy.startsWith("webhook")&&this.runWebhook(i.deploy.split("webhook:")[1])}onCatch(i){this.log?.error?.(`[Bot.catch]: ${String(i)}`)}onStart(i,t,e){let{username:s}=i;t=="polling"?this.log?.success?.(`Telegram bot polling started: ${s}`):this.log?.success?.(`Telegram bot webhook started: ${s} (${e})`)}createBot(i){return new ii(i)}createCtx(i){return new M({ct:i,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:p(async i=>{this.onStart(i,"polling",null)},"onStart")})}async runWebhook(i){let t=ti(this.bot,"bun"),e="/telegram-webhook";J({fetch(a){let{pathname:r}=new URL(a.url);if(r===e)return a.method==="POST"?t(a):new Response("OK",{status:200});if(r==="/"&&a.method==="GET"){let d=new Date().toISOString();return new Response(JSON.stringify({timestamp:d}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}});let s=await this.bot.api.getWebhookInfo(),o=i.endsWith("/")?i.slice(0,-1)+e:i+e;s.url!=o&&await this.bot.api.setWebhook(o);let n=await this.bot.api.getMe();this.onStart(n,"webhook",o)}pageBuildData(i,t){i?.data===void 0&&(i.data=i.buildData()),i.data.name=q(t).name}pageSorts(i,t){let e=i.data.name,s=i.prototype,o="Payload",n="Command",a="Caption",r="Free",d=t.dynamic,l=t.dynamicSpesific,c=p(h=>h.charAt(0).toUpperCase()+h.slice(1),"upFirst"),u=p(h=>h.replace(o,"").replace(n,"").replace(a,"").replace(r,""),"getPureFuncName"),m=p((h,g)=>s[`buildSessionMethod${c(h)}`](g),"buildSessionMethod");t.all[e]=i;for(let h=0;h<t.lenListFuncStaticSession;h++){let g=t.listFuncStaticSession[h],O=t.static[g],R=t.staticIntent[g],T=t.staticSession[g],v={name:e,func:g},k=O||R;if(k!==void 0){let K=g.includes(n)?`/${e}`:e;k[s.buildIntent(K,g.startsWith("callback"))]=v}T!==void 0&&(T[m(g,e)]=v),g.toLowerCase().endsWith("free")&&l[u(g)].push(v)}s.free&&d.push(e)}pageLoads(){this.log?.info?.("Load pages..");let i=x(process.cwd(),"src","pages");if(!Y(i))throw new Error(`Directory ${i} is not found, please make it manually`);let t=Z(i),e={},s=e,o=e,n=[],a=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],r=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],d=[...a,...r,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],l=p((u,m)=>Object.fromEntries(u.map(h=>[h,{...m}])),"makeObject"),c={all:{},dynamic:[],dynamicSpesific:{text:n,photo:n,video:n,audio:n,document:n,animation:n,voice:n,videoNote:n,sticker:n,location:n,contact:n},static:l(a,e),staticIntent:l(r,s),staticSession:l(d,o),listFuncStatic:a,listFuncStaticIntent:r,listFuncStaticSession:d,lenListFuncStatic:a.length,lenListFuncStaticIntent:r.length,lenListFuncStaticSession:d.length};for(let u of t){let m=x(i,u),h=f.getPageSync(m,!0);this.pageBuildData(h,m),this.pageSorts(h,c)}return this.log?.info?.(`Finish load pages with total (${Object.keys(c.all).length})`),c}async pageRoutes(i,t){let e,s;if(e===void 0){let n=i.callbackData,a=i.msgText,r=i.msgCaption,d=this.pages.static;for(let l=0;l<this.pages.lenListFuncStatic;l++){let c=this.pages.listFuncStatic[l];if(s=d[c][n||a||r],s)break}s!==void 0&&(e=this.pages.all[s.name])}if(e===void 0){let n=await i.sessionGet();if(n){let a=n.method,r=this.pages.staticSession;for(let d=0;d<this.pages.lenListFuncStaticSession;d++){let l=this.pages.listFuncStaticSession[d];if(s=r[l][a],s)break}s!==void 0&&(e=this.pages.all[s.name])}}if(e===void 0){let n=i.callbackDataIntent,a=i.msgTextIntent,r=i.msgCaptionIntent,d=this.pages.staticIntent;for(let l=0;l<this.pages.lenListFuncStaticIntent;l++){let c=this.pages.listFuncStaticIntent[l];if(s=d[c][n||a||r],s)break}s!==void 0&&(e=this.pages.all[s.name])}if(e!==void 0&&s!==void 0)return await new e(i)[s.func]?.();let o=this.pages.dynamicSpesific[t]||[];for(let n=0;n<o.length;n++){let a=o[n];if(a===void 0)continue;let r=this.pages.all[a.func];if(r===void 0)continue;let l=await new r(i)[a.name]?.();if(l!==null)return l}for(let n=0;n<this.pages.dynamic.length;n++){let a=this.pages.dynamic[n];if(a===void 0)continue;let r=this.pages.all[a];if(r===void 0)continue;let l=await new r(i).free?.();if(l!==null)return l}return null}async hookBeforeRoute(i,t){return!0}async hookErrorPage(i,t,e,s){}async hookErrorInputNotFoundPage(i){}async onMessage(i,t){let e=this.createCtx(i);try{if(await this.hookBeforeRoute(e,t)===!1)return;await this.pageRoutes(e,t)===null&&await this.hookErrorInputNotFoundPage(e)}catch(s){await this.hookErrorPage(e,t,s,!1)}}async onCallbackQueryData(i){let t=this.createCtx(i);try{if(await t.callbackQueryAnswer(),await this.hookBeforeRoute(t,"onCallbackQueryData")===!1)return;await this.pageRoutes(t,"callback")}catch(e){await this.hookErrorPage(t,"onCallbackQueryData",e,!0)}}async onMessageText(i){await this.onMessage(i,"onMessageText")}async onMessagePhoto(i){await this.onMessage(i,"onMessagePhoto")}async onMessageVideo(i){await this.onMessage(i,"onMessageVideo")}async onMessageAudio(i){await this.onMessage(i,"onMessageAudio")}async onMessageDocument(i){await this.onMessage(i,"onMessageDocument")}async onMessageAnimation(i){await this.onMessage(i,"onMessageAnimation")}async onMessageVoice(i){await this.onMessage(i,"onMessageVoice")}async onMessageVideoNote(i){await this.onMessage(i,"onMessageVideoNote")}async onMessageSticker(i){await this.onMessage(i,"onMessageSticker")}async onMessageLocation(i){await this.onMessage(i,"onMessageLocation")}async onMessageContact(i){await this.onMessage(i,"onMessageContact")}};export{C as BaseGeneral,S as CacheExternal,M as Ctx,A as Gramstax,y as TemplateEngine,P as TemplateManager};
1
+ var N=Object.defineProperty;var u=(m,t)=>N(m,"name",{value:t,configurable:!0}),M=(m=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(m,{get:(t,i)=>(typeof require<"u"?require:t)[i]}):m)(function(m){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+m+'" is not supported')});import{LoggingPretty as E}from"logging-pretty";var C=class{static{u(this,"BaseGeneral")}static log=new E;static logError(t,i){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${i}]: ${String(t)}`)}logError(t,i,e){this.constructor.log.error(`[${i||this.constructor.name}:${e}] ${String(t)}`)}};import{Keyv as B}from"keyv";import L from"@keyv/redis";var S=class extends B{constructor(i="memory",e,s,o){let n;i.startsWith("redis")&&(n=new L(i)),i==="memory"&&(n=new Map),o?.forceStore&&(n=o.forceStore);super({store:n,namespace:e,ttl:s});this.url=i}static{u(this,"CacheExternal")}};import{setTimeout as $}from"timers/promises";import{InlineKeyboard as w,Keyboard as V}from"grammy";var P=class extends C{static{u(this,"Ctx")}static template;static data;data=this.constructor.data;get isPremium(){return this.ct.from?.is_premium??!1}get isBot(){return this.ct.from?.is_bot??!1}get userid(){return this.ct.from?.id}get username(){return this.ct.from?.username}get fullname(){return`${this.ct.from?.first_name||""}${this.ct.from?.last_name||""}`}get firstname(){return this.ct.from?.first_name}get lastname(){return this.ct.from?.last_name}get msgText(){return this.ct.message?.text}get msgTextIntent(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ")[0]:""}get msgTextPayloads(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ").slice(1):[]}get msgTextPayload(){return this.msgTextPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionIntent(){return this.msgCaption&&this.msgCaption.indexOf(" ")!=-1?this.msgCaption.split(" ")[0]:""}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataIntent(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":")[0]:""}get callbackDataPayloads(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":").slice(1):[]}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}get callbackDataParts(){return this.callbackDataPayload&&this.callbackDataPayload.indexOf("+")!=-1?this.callbackDataPayload.split("+"):[]}get languageCode(){return this.ct.from?.language_code}set languageCode(t){this.ct.from.language_code=t}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){super(),this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp,t?.data&&(this.temp.data=t.data)}async broadcast(t,i,e,s,o,n){let r=i.map(c=>this.templateManager.getMessage(this.data.name,o,c,s));for(let c=0;c<t.length;c++){let d=t[c],l=r[c];await this.ct.api.sendMessage(d,l,{parse_mode:"HTML",reply_markup:e,...n}),c+1==30&&await $(1200)}}async reply(t,i,e,s){let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,i);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,i,e,s,o){let n=this.templateManager.getMedia(this.data.name,s,this.languageCode,e),a={parse_mode:"HTML",reply_markup:i,...o};if(t=="photo")return await this.ct.replyWithPhoto(n.src,{caption:n.caption,...a});if(t=="video")return await this.ct.replyWithVideo(n.src,{caption:n.caption,...a});if(t=="audio")return await this.ct.replyWithAudio(n.src,{caption:n.caption,...a});if(t=="document")return await this.ct.replyWithDocument(n.src,{caption:n.caption,...a});if(t=="animation")return await this.ct.replyWithAnimation(n.src,{caption:n.caption,...a});if(t=="voice")return await this.ct.replyWithVoice(n.src,a);if(t=="video_note")return await this.ct.replyWithVideoNote(n.src,a);if(t=="sticker")return await this.ct.replyWithSticker(n.src,a);if(t=="location")return await this.ct.replyWithLocation(n.latitude,n.longitude,a);if(t=="contact")return await this.ct.replyWithContact(n.phone,n.first_name,{vcard:n.vcard,...a})}async replyPhoto(t,i,e,s){return this.replyMedia("photo",t,i,e,s)}async replyVideo(t,i,e,s){return this.replyMedia("video",t,i,e,s)}async replyAudio(t,i,e,s){return this.replyMedia("audio",t,i,e,s)}async replyDocument(t,i,e,s){return this.replyMedia("document",t,i,e,s)}async replyAnimation(t,i,e,s){return this.replyMedia("animation",t,i,e,s)}async replyVoice(t,i,e,s){return this.replyMedia("voice",t,i,e,s)}async replyVideoNote(t,i,e,s){return this.replyMedia("video_note",t,i,e,s)}async replySticker(t,i,e,s){return this.replyMedia("sticker",t,i,e,s)}async replyLocation(t,i,e,s){return this.replyMedia("location",t,i,e,s)}async replyContact(t,i,e,s){return this.replyMedia("contact",t,i,e,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,i,e,s){try{let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,i);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:t,...s})}catch{await this.reply(t,i,e,s)}}async editMedia(t,i,e,s,o,n){try{let{src:a,caption:r}=this.templateManager.getMedia(this.data.name,s,this.languageCode,e);return t=="voice"?(await this.delete(),await this.replyVoice(i,e,s,o)):t=="video_note"?(await this.delete(),await this.replyVoice(i,e,s,o)):t=="sticker"?(await this.delete(),await this.replySticker(i,e,s,o)):t=="location"?(await this.delete(),await this.replyLocation(i,e,s,o)):t=="contact"?(await this.delete(),await this.replyContact(i,e,s,o)):await this.ct.editMessageMedia({media:a,caption:r,type:t,parse_mode:"HTML",...o},{reply_markup:i,...n})}catch{await this.reply(i,e,s,n)}}async editPhoto(t,i,e,s,o){return await this.editMedia("photo",t,i,e,s,o)}async editVideo(t,i,e,s,o){return await this.editMedia("video",t,i,e,s,o)}async editAudio(t,i,e,s,o){return await this.editMedia("audio",t,i,e,s,o)}async editDocument(t,i,e,s,o){return await this.editMedia("document",t,i,e,s,o)}async editAnimation(t,i,e,s,o){return await this.editMedia("animation",t,i,e,s,o)}async editVoice(t,i,e,s){return await this.editMedia("voice",t,i,e,s)}async editVideoNote(t,i,e,s){return await this.editMedia("video_note",t,i,e,s)}async editSticker(t,i,e,s){return await this.editMedia("sticker",t,i,e,s)}async editLocation(t,i,e,s){return await this.editMedia("location",t,i,e,s)}async editContact(t,i,e,s){return await this.editMedia("contact",t,i,e,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,i,e){try{let s={method:t,params:i,...e},o=await this.cacheSession.set(`${this.userid}`,s);return o&&(this.session=s),o}catch{return null}}async sessionGet(){try{let t=await this.cacheSession.get(`${this.userid}`);return t&&(this.session=t),t||null}catch{return null}}async sessionClear(){try{let t=await this.cacheSession.delete(`${this.userid}`);return t&&(this.session={}),t}catch{return null}}static buildData(t){return{name:"",callbackData:t?function(...i){let e=t(...i);return`${this.name}${e===void 0?"":`:${e}`}`}:function(){return this?.name}}}inlineKeyboard(t,i){let e=this.data.name;if(i?.cache===!0){let a=`${e}:${this.languageCode}:i`,r=this.cacheKeyboard.get(a);if(!r){let c=new w,d=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"inline",i?.data),l=t(c,d);return this.cacheKeyboard.set(a,l),l}return r}let s=new w,o=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"inline",i?.data);return t(s,o)}bottomKeyboard(t,i){let e=this.data.name;if(i?.cache===!0){let a=`${e}:${this.languageCode}:b`,r=this.cacheKeyboard.get(a);if(!r){let c=new V,d=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"bottom",i?.data),l=t(c,d);return l.resized(!0),this.cacheKeyboard.set(a,l),l}return r}let s=new V,o=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"bottom",i?.data),n=t(s,o);return n.resized(),n}validateSessionCallback(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallback(i)}validateSessionCallbackPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallbackPayload(i)}validateSessionText(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionText(i)}validateSessionTextPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextPayload(i)}validateSessionTextCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommand(i)}validateSessionTextCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommandPayload(i)}validateSessionTextFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextFree(i)}validateSessionPhotoCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaption(i)}validateSessionPhotoCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionPayload(i)}validateSessionPhotoCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommand(i)}validateSessionPhotoCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommandPayload(i)}validateSessionPhotoFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoFree(i)}validateSessionVideoCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaption(i)}validateSessionVideoCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionPayload(i)}validateSessionVideoCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommand(i)}validateSessionVideoCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommandPayload(i)}validateSessionVideoFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoFree(i)}validateSessionAudioCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaption(i)}validateSessionAudioCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionPayload(i)}validateSessionAudioCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommand(i)}validateSessionAudioCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommandPayload(i)}validateSessionAudioFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioFree(i)}validateSessionDocumentCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaption(i)}validateSessionDocumentCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionPayload(i)}validateSessionDocumentCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommand(i)}validateSessionDocumentCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommandPayload(i)}validateSessionDocumentFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentFree(i)}validateSessionAnimationCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaption(i)}validateSessionAnimationCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionPayload(i)}validateSessionAnimationCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommand(i)}validateSessionAnimationCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommandPayload(i)}validateSessionAnimationFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationFree(i)}validateSessionVoiceCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaption(i)}validateSessionVoiceCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionPayload(i)}validateSessionVoiceCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommand(i)}validateSessionVoiceCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommandPayload(i)}validateSessionVoiceFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceFree(i)}validateSessionVideoNoteCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaption(i)}validateSessionVideoNoteCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionPayload(i)}validateSessionVideoNoteCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommand(i)}validateSessionVideoNoteCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommandPayload(i)}validateSessionVideoNoteFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteFree(i)}validateSessionStickerFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionStickerFree(i)}validateSessionLocationFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionLocationFree(i)}validateSessionContactFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionContactFree(i)}sessionCallback(t,i){return this.sessionSet(this.methodSessionCallback(i),t)}sessionCallbackPayload(t,i){return this.sessionSet(this.methodSessionCallbackPayload(i),t)}sessionText(t,i){return this.sessionSet(this.methodSessionText(i),t)}sessionTextPayload(t,i){return this.sessionSet(this.methodSessionTextPayload(i),t)}sessionTextCommand(t,i){return this.sessionSet(this.methodSessionTextCommand(i),t)}sessionTextCommandPayload(t,i){return this.sessionSet(this.methodSessionTextCommandPayload(i),t)}sessionTextFree(t,i){return this.sessionSet(this.methodSessionTextFree(i),t)}sessionPhotoCaption(t,i){return this.sessionSet(this.methodSessionPhotoCaption(i),t)}sessionPhotoCaptionPayload(t,i){return this.sessionSet(this.methodSessionPhotoCaptionPayload(i),t)}sessionPhotoCaptionCommand(t,i){return this.sessionSet(this.methodSessionPhotoCaptionCommand(i),t)}sessionPhotoCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionPhotoCaptionCommandPayload(i),t)}sessionPhotoFree(t,i){return this.sessionSet(this.methodSessionPhotoFree(i),t)}sessionVideoCaption(t,i){return this.sessionSet(this.methodSessionVideoCaption(i),t)}sessionVideoCaptionPayload(t,i){return this.sessionSet(this.methodSessionVideoCaptionPayload(i),t)}sessionVideoCaptionCommand(t,i){return this.sessionSet(this.methodSessionVideoCaptionCommand(i),t)}sessionVideoCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionVideoCaptionCommandPayload(i),t)}sessionVideoFree(t,i){return this.sessionSet(this.methodSessionVideoFree(i),t)}sessionAudioCaption(t,i){return this.sessionSet(this.methodSessionAudioCaption(i),t)}sessionAudioCaptionPayload(t,i){return this.sessionSet(this.methodSessionAudioCaptionPayload(i),t)}sessionAudioCaptionCommand(t,i){return this.sessionSet(this.methodSessionAudioCaptionCommand(i),t)}sessionAudioCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionAudioCaptionCommandPayload(i),t)}sessionAudioFree(t,i){return this.sessionSet(this.methodSessionAudioFree(i),t)}sessionDocumentCaption(t,i){return this.sessionSet(this.methodSessionDocumentCaption(i),t)}sessionDocumentCaptionPayload(t,i){return this.sessionSet(this.methodSessionDocumentCaptionPayload(i),t)}sessionDocumentCaptionCommand(t,i){return this.sessionSet(this.methodSessionDocumentCaptionCommand(i),t)}sessionDocumentCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionDocumentCaptionCommandPayload(i),t)}sessionDocumentFree(t,i){return this.sessionSet(this.methodSessionDocumentFree(i),t)}sessionAnimationCaption(t,i){return this.sessionSet(this.methodSessionAnimationCaption(i),t)}sessionAnimationCaptionPayload(t,i){return this.sessionSet(this.methodSessionAnimationCaptionPayload(i),t)}sessionAnimationCaptionCommand(t,i){return this.sessionSet(this.methodSessionAnimationCaptionCommand(i),t)}sessionAnimationCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionAnimationCaptionCommandPayload(i),t)}sessionAnimationFree(t,i){return this.sessionSet(this.methodSessionAnimationFree(i),t)}sessionVoiceCaption(t,i){return this.sessionSet(this.methodSessionVoiceCaption(i),t)}sessionVoiceCaptionPayload(t,i){return this.sessionSet(this.methodSessionVoiceCaptionPayload(i),t)}sessionVoiceCaptionCommand(t,i){return this.sessionSet(this.methodSessionVoiceCaptionCommand(i),t)}sessionVoiceCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionVoiceCaptionCommandPayload(i),t)}sessionVoiceFree(t,i){return this.sessionSet(this.methodSessionVoiceFree(i),t)}sessionVideoNoteCaption(t,i){return this.sessionSet(this.methodSessionVideoNoteCaption(i),t)}sessionVideoNoteCaptionPayload(t,i){return this.sessionSet(this.methodSessionVideoNoteCaptionPayload(i),t)}sessionVideoNoteCaptionCommand(t,i){return this.sessionSet(this.methodSessionVideoNoteCaptionCommand(i),t)}sessionVideoNoteCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionVideoNoteCaptionCommandPayload(i),t)}sessionVideoNoteFree(t,i){return this.sessionSet(this.methodSessionVideoNoteFree(i),t)}sessionStickerFree(t,i){return this.sessionSet(this.methodSessionStickerFree(i),t)}sessionLocationFree(t,i){return this.sessionSet(this.methodSessionLocationFree(i),t)}sessionContactFree(t,i){return this.sessionSet(this.methodSessionContactFree(i),t)}sessionToCallback(t,i){return this.sessionCallback({...this.session.params,...t},i)}sessionToCallbackPayload(t,i){return this.sessionCallbackPayload({...this.session.params,...t},i)}sessionToText(t,i){return this.sessionText({...this.session.params,...t},i)}sessionToTextPayload(t,i){return this.sessionTextPayload({...this.session.params,...t},i)}sessionToTextCommand(t,i){return this.sessionTextCommand({...this.session.params,...t},i)}sessionToTextCommandPayload(t,i){return this.sessionTextCommandPayload({...this.session.params,...t},i)}sessionToTextFree(t,i){return this.sessionTextFree({...this.session.params,...t},i)}sessionToPhotoCaption(t,i){return this.sessionPhotoCaption({...this.session.params,...t},i)}sessionToPhotoCaptionPayload(t,i){return this.sessionPhotoCaptionPayload({...this.session.params,...t},i)}sessionToPhotoCaptionCommand(t,i){return this.sessionPhotoCaptionCommand({...this.session.params,...t},i)}sessionToPhotoCaptionCommandPayload(t,i){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...t},i)}sessionToPhotoFree(t,i){return this.sessionPhotoFree({...this.session.params,...t},i)}sessionToVideoCaption(t,i){return this.sessionVideoCaption({...this.session.params,...t},i)}sessionToVideoCaptionPayload(t,i){return this.sessionVideoCaptionPayload({...this.session.params,...t},i)}sessionToVideoCaptionCommand(t,i){return this.sessionVideoCaptionCommand({...this.session.params,...t},i)}sessionToVideoCaptionCommandPayload(t,i){return this.sessionVideoCaptionCommandPayload({...this.session.params,...t},i)}sessionToVideoFree(t,i){return this.sessionVideoFree({...this.session.params,...t},i)}sessionToAudioCaption(t,i){return this.sessionAudioCaption({...this.session.params,...t},i)}sessionToAudioCaptionPayload(t,i){return this.sessionAudioCaptionPayload({...this.session.params,...t},i)}sessionToAudioCaptionCommand(t,i){return this.sessionAudioCaptionCommand({...this.session.params,...t},i)}sessionToAudioCaptionCommandPayload(t,i){return this.sessionAudioCaptionCommandPayload({...this.session.params,...t},i)}sessionToAudioFree(t,i){return this.sessionAudioFree({...this.session.params,...t},i)}sessionToDocumentCaption(t,i){return this.sessionDocumentCaption({...this.session.params,...t},i)}sessionToDocumentCaptionPayload(t,i){return this.sessionDocumentCaptionPayload({...this.session.params,...t},i)}sessionToDocumentCaptionCommand(t,i){return this.sessionDocumentCaptionCommand({...this.session.params,...t},i)}sessionToDocumentCaptionCommandPayload(t,i){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...t},i)}sessionToDocumentFree(t,i){return this.sessionDocumentFree({...this.session.params,...t},i)}sessionToAnimationCaption(t,i){return this.sessionAnimationCaption({...this.session.params,...t},i)}sessionToAnimationCaptionPayload(t,i){return this.sessionAnimationCaptionPayload({...this.session.params,...t},i)}sessionToAnimationCaptionCommand(t,i){return this.sessionAnimationCaptionCommand({...this.session.params,...t},i)}sessionToAnimationCaptionCommandPayload(t,i){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...t},i)}sessionToAnimationFree(t,i){return this.sessionAnimationFree({...this.session.params,...t},i)}sessionToVoiceCaption(t,i){return this.sessionVoiceCaption({...this.session.params,...t},i)}sessionToVoiceCaptionPayload(t,i){return this.sessionVoiceCaptionPayload({...this.session.params,...t},i)}sessionToVoiceCaptionCommand(t,i){return this.sessionVoiceCaptionCommand({...this.session.params,...t},i)}sessionToVoiceCaptionCommandPayload(t,i){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...t},i)}sessionToVoiceFree(t,i){return this.sessionVoiceFree({...this.session.params,...t},i)}sessionToVideoNoteCaption(t,i){return this.sessionVideoNoteCaption({...this.session.params,...t},i)}sessionToVideoNoteCaptionPayload(t,i){return this.sessionVideoNoteCaptionPayload({...this.session.params,...t},i)}sessionToVideoNoteCaptionCommand(t,i){return this.sessionVideoNoteCaptionCommand({...this.session.params,...t},i)}sessionToVideoNoteCaptionCommandPayload(t,i){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...t},i)}sessionToVideoNoteFree(t,i){return this.sessionVideoNoteFree({...this.session.params,...t},i)}sessionToStickerFree(t,i){return this.sessionStickerFree({...this.session.params,...t},i)}sessionToLocationFree(t,i){return this.sessionLocationFree({...this.session.params,...t},i)}sessionToContactFree(t,i){return this.sessionContactFree({...this.session.params,...t},i)}buildIntent(t,i=!0){t||(t=i?this.data.callbackData():this.data.name);let e=i?":":" ";return t?.indexOf?.(e)!=-1?t?.split?.(e)?.[0]:t}methodSession(t,i){return`${t}-${i||this.data.name}`}methodSessionCallback(t){return this.methodSession("1",t)}methodSessionCallbackPayload(t){return this.methodSession("2",t)}methodSessionText(t){return this.methodSession("3",t)}methodSessionTextPayload(t){return this.methodSession("4",t)}methodSessionTextCommand(t){return this.methodSession("5",t)}methodSessionTextCommandPayload(t){return this.methodSession("6",t)}methodSessionTextFree(t){return this.methodSession("7",t)}methodSessionPhotoCaption(t){return this.methodSession("8",t)}methodSessionPhotoCaptionPayload(t){return this.methodSession("9",t)}methodSessionPhotoCaptionCommand(t){return this.methodSession("10",t)}methodSessionPhotoCaptionCommandPayload(t){return this.methodSession("11",t)}methodSessionPhotoFree(t){return this.methodSession("12",t)}methodSessionVideoCaption(t){return this.methodSession("13",t)}methodSessionVideoCaptionPayload(t){return this.methodSession("14",t)}methodSessionVideoCaptionCommand(t){return this.methodSession("15",t)}methodSessionVideoCaptionCommandPayload(t){return this.methodSession("16",t)}methodSessionVideoFree(t){return this.methodSession("17",t)}methodSessionAudioCaption(t){return this.methodSession("18",t)}methodSessionAudioCaptionPayload(t){return this.methodSession("19",t)}methodSessionAudioCaptionCommand(t){return this.methodSession("20",t)}methodSessionAudioCaptionCommandPayload(t){return this.methodSession("21",t)}methodSessionAudioFree(t){return this.methodSession("22",t)}methodSessionDocumentCaption(t){return this.methodSession("23",t)}methodSessionDocumentCaptionPayload(t){return this.methodSession("24",t)}methodSessionDocumentCaptionCommand(t){return this.methodSession("25",t)}methodSessionDocumentCaptionCommandPayload(t){return this.methodSession("26",t)}methodSessionDocumentFree(t){return this.methodSession("27",t)}methodSessionAnimationCaption(t){return this.methodSession("28",t)}methodSessionAnimationCaptionPayload(t){return this.methodSession("29",t)}methodSessionAnimationCaptionCommand(t){return this.methodSession("30",t)}methodSessionAnimationCaptionCommandPayload(t){return this.methodSession("31",t)}methodSessionAnimationFree(t){return this.methodSession("32",t)}methodSessionVoiceCaption(t){return this.methodSession("33",t)}methodSessionVoiceCaptionPayload(t){return this.methodSession("34",t)}methodSessionVoiceCaptionCommand(t){return this.methodSession("35",t)}methodSessionVoiceCaptionCommandPayload(t){return this.methodSession("36",t)}methodSessionVoiceFree(t){return this.methodSession("37",t)}methodSessionVideoNoteCaption(t){return this.methodSession("38",t)}methodSessionVideoNoteCaptionPayload(t){return this.methodSession("39",t)}methodSessionVideoNoteCaptionCommand(t){return this.methodSession("40",t)}methodSessionVideoNoteCaptionCommandPayload(t){return this.methodSession("41",t)}methodSessionVideoNoteFree(t){return this.methodSession("42",t)}methodSessionStickerFree(t){return this.methodSession("43",t)}methodSessionLocationFree(t){return this.methodSession("44",t)}methodSessionContactFree(t){return this.methodSession("45",t)}};import{serve as J}from"bun";import{join as T,parse as q}from"path";import{LoggingPretty as X}from"logging-pretty";var b=class{static{u(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(i,e)=>`\${(data && data["${e}"]) ?? ""}`)}static _processBaseBlocks(t){let i=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,e={};for(let s of t.matchAll(i)){let o=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[o]=a}return e}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(i,e)=>{let s=e.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(t){return t.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(t){return t.replace(/<div>([\s\S]*?)<\/div>/gi,(i,e)=>e.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(t){let i=/<media\s+([^>]+)>([\s\S]*?)<\/media>/gi,e={};for(let s of t.matchAll(i)){let o=s[1],n=s[2],a={},r=/(\w+)="([^"]*)"/g;for(let g of o.matchAll(r))a[g[1]]=g[2];if(!a.lang)continue;let c=a.lang,d=a.type,l=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),p={type:d};a.src&&(p.src=a.src),l&&d!=="video_note"&&d!=="sticker"&&(p.caption=l),d==="location"&&(a.latitude&&(p.latitude=a.latitude),a.longitude&&(p.longitude=a.longitude),l&&(p.caption=l)),d==="contact"&&(a.phone&&(p.phone=a.phone),a.first_name&&(p.first_name=a.first_name),a.last_name&&(p.last_name=a.last_name),a.vcard&&(p.vcard=a.vcard),l&&(p.caption=l)),e[c]=p}return e}static _processMessageBlocks(t){let i=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,e={};for(let[,s,o]of t.matchAll(i)){let n=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[s]=n}return e}static _processKeyboardBlocks(t){let i=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\stype="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,e={};for(let[,s,o,n]of t.matchAll(i)){let a=o==="bottom"?"bottom":"inline",r=n.trim();e[s]||(e[s]={}),e[s][a]=r}return e}static _compileToFunction(t,i){let e;i?e=t.map(n=>`\`${n}\``).join(","):e=`\`${t}\``;let s=e;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),i){let o=`return [${s}]`;return new Function("data",o)}else{let o=`return ${s}`;return new Function("data",o)}}static compileMedia(t){let i=this._processBaseBlocks(t),e={};for(let[s,o]of Object.entries(i)){let n=this._processMediaBlocks(o);e[s]={};for(let[a,r]of Object.entries(n))if(r.caption){let c=this._processVariables(this._processScriptBlocks(r.caption)),d=this._compileToFunction(c,!1);e[s][a]=l=>({...r,caption:d(l)})}else e[s][a]=()=>r}return e}static compileMessages(t){let i=this._processBaseBlocks(t),e={};for(let[s,o]of Object.entries(i)){let n=this._processMessageBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){let c=this._processVariables(this._processScriptBlocks(r));e[s][a]=this._compileToFunction(c,!1)}}return e}static compileKeyboards(t){let i=this._processBaseBlocks(t),e={};for(let[s,o]of Object.entries(i)){let n=this._processKeyboardBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){e[s][a]={};for(let[c,d]of Object.entries(r)){let p=d.split(/(?<!\\),\s*/).map(g=>g.replace(/\\,/g,",").trim()).map(g=>this._processVariables(this._processScriptBlocks(g)));e[s][a][c]=this._compileToFunction(p,!0)}}}return e}};var f=class{static{u(this,"HelperPage")}static _getPage(t,i,e=!0){let o=Object.values(t)[0];if(o===void 0)throw new Error(`File ${i} must have export (not default) class page`);return e===!0&&(o.template=void 0),o}static getPageSync(t,i=!0){let e=M(t);return this._getPage(e,t,i)}static async getPage(t,i=!0){let e=await import(`${t}?t=${Date.now()}`);return this._getPage(e,t,i)}};import{readFile as W}from"fs/promises";import{watch as j}from"chokidar";import{basename as x,join as _,extname as Q}from"path";import{readdirSync as z,readFileSync as G,existsSync as D,statSync as H,writeFileSync as U}from"fs";var v=class{static{u(this,"TemplateManager")}_map=new Map;_engine=b;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_forceLanguage;_isWatchEnabled;constructor(t){let{path:i,enableWatch:e=!1,forceLanguage:s}=t;this._path=i,this._forceLanguage=s,this._isWatchEnabled=e,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(!this._path||!Array.isArray(this._path))throw new Error("Path must be set as string array");for(let t=0;t<this._path.length;t++){let i=this._path[t];if(!D(i))throw new Error(`Template base path is not exists: ${i}`);if(!H(i).isDirectory())throw new Error(`Template base path is not a directory: ${i}`)}return!0}catch(t){throw new Error(`Failed to validate Template base path: ${t}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let t=0;t<this._path.length;t++){let i=this._path[t],e=j(i,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[t]=e,e.on("change",this._handleFileChange.bind(this)),e.on("add",this._handleFileAdd.bind(this)),e.on("unlink",this._handleFileDelete.bind(this)),e.on("error",this._handleWatchError.bind(this))}}async _handleFileChange(t){let i=x(t);this._isValidFile(i)&&await this._loadFile(i,!1)}async _handleFileAdd(t){let i=x(t);this._isValidFile(i)&&await this._loadFile(i,!1)}_handleFileDelete(t){let i=x(t),e=this._getKey(i);this._map.has(e)&&this._map.delete(e)}_handleWatchError(t){}_loadAllFiles(){for(let t=0;t<this._path.length;t++){let i=this._path[t],s=z(i,"utf8").filter(o=>this._isValidFile(o));for(let o of s)this._loadFile(o,!0)}}async _loadFile(t,i=!0){for(let e=0;e<this._path.length;e++){let s=this._path[e],o=_(s,t),n=this._getExtension(t),a=this._getKey(t);if(n==".html"){let r=i?G(o,"utf8"):await W(o,"utf8");this._compile(a,r)}else if(n==".ts"){let r=await f.getPage(o,!1);r?.template!==void 0&&this._compile(a,r.template),r.template=void 0}else throw new Error(`File ${t} is not support`)}}_getExtension(t){return Q(t).toLowerCase()}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,i,e){let s=this._map.get(t),o=s||{},n=!1;(e===void 0||e?.media===!1||s?.media===void 0)&&(o.media=b.compileMedia(i),n=!0),(e===void 0||e?.message===!1||s?.message===void 0)&&(o.message=b.compileMessages(i),n=!0),(e===void 0||e?.keyboard===!1||s?.keyboard===void 0)&&(o.keyboard=b.compileKeyboards(i),n=!0),n&&this._map.set(t,o)}getMedia(t,i="default",e="en",s){let n=this._map.get(t)?.media?.[i]?.[this._forceLanguage||e];if(!n)return{};try{return n(s)}catch{return{}}}getMessage(t,i="default",e="en",s){let n=this._map.get(t)?.message?.[i]?.[this._forceLanguage||e];if(!n)return"";try{return n(s)}catch{return""}}getKeyboard(t,i="default",e="en",s="inline",o){let a=this._map.get(t)?.keyboard?.[i]?.[this._forceLanguage||e]?.[s];if(!a)return[];try{return a(o)}catch{return[]}}async write(t,i){if(this._getExtension(t)!=".html")return null;for(let e=0;e<this._path.length;e++){let s=_(this._path[e],t);if(D(s))return U(s,i,"utf8"),await this._loadFile(t,!1),!0}return null}getAvailable(){return Array.from(this._map.keys())}has(t){return this._map.has(t)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(t,i)=>typeof i=="function"?i.toString():i).length}}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};import{existsSync as Y,readdirSync as Z}from"fs";import{Bot as tt,webhookCallback as it}from"grammy";var A=class{static{u(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");this.log=t.log===null?void 0:t.log===void 0?new X:t.log,this.cacheSession=t.cacheSession||new S("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new v({path:[T(process.cwd(),"src","pages")]}),this.bot=this.createBot(t.token),this.bot.catch(this.onCatch),this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this)),this.bot.on("message:text",this.onMessageText.bind(this)),this.bot.on("message:photo",this.onMessagePhoto.bind(this)),this.bot.on("message:video",this.onMessageVideo.bind(this)),this.bot.on("message:audio",this.onMessageAudio.bind(this)),this.bot.on("message:document",this.onMessageDocument.bind(this)),this.bot.on("message:animation",this.onMessageAnimation.bind(this)),this.bot.on("message:voice",this.onMessageVoice.bind(this)),this.bot.on("message:video_note",this.onMessageVideoNote.bind(this)),this.bot.on("message:sticker",this.onMessageSticker.bind(this)),this.bot.on("message:location",this.onMessageLocation.bind(this)),this.bot.on("message:contact",this.onMessageContact.bind(this)),this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),t.deploy.startsWith("polling")?this.runPolling():t.deploy.startsWith("webhook")&&this.runWebhook(t.deploy.split("webhook:")[1])}onCatch(t){this.log?.error?.(`[Bot.catch]: ${String(t)}`)}onStart(t,i,e){let{username:s}=t;i=="polling"?this.log?.success?.(`Telegram bot polling started: ${s}`):this.log?.success?.(`Telegram bot webhook started: ${s} (${e})`)}createBot(t){return new tt(t)}createCtx(t){return new P({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:u(async t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let i=it(this.bot,"bun"),e="/telegram-webhook";J({fetch(a){let{pathname:r}=new URL(a.url);if(r===e)return a.method==="POST"?i(a):new Response("OK",{status:200});if(r==="/"&&a.method==="GET"){let c=new Date().toISOString();return new Response(JSON.stringify({timestamp:c}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}});let s=await this.bot.api.getWebhookInfo(),o=t.endsWith("/")?t.slice(0,-1)+e:t+e;s.url!=o&&await this.bot.api.setWebhook(o);let n=await this.bot.api.getMe();this.onStart(n,"webhook",o)}pageBuildData(t,i){t?.data===void 0&&(t.data=t.buildData()),t.data.name=q(i).name}pageSorts(t,i){let e=t.data.name,s=t.prototype,o="Payload",n="Command",a="Caption",r="Free",c=i.dynamic,d=i.dynamicSpesific,l=u(h=>h.charAt(0).toUpperCase()+h.slice(1),"upFirst"),p=u(h=>h.replace(o,"").replace(n,"").replace(a,"").replace(r,""),"getPureFuncName"),g=u((h,y)=>s[`methodSession${l(h)}`](y),"methodSession");i.all[e]=t;for(let h=0;h<i.lenListFuncStaticSession;h++){let y=i.listFuncStaticSession[h],O=i.static[y],R=i.staticIntent[y],k=i.staticSession[y],I={name:e,func:y},F=O||R;if(F!==void 0){let K=y.includes(n)?`/${e}`:e;F[s.buildIntent(K,y.startsWith("callback"))]=I}k!==void 0&&(k[g(y,e)]=I),y.toLowerCase().endsWith("free")&&d[p(y)].push(I)}s.free&&c.push(e)}pageLoads(){this.log?.info?.("Load pages..");let t=T(process.cwd(),"src","pages");if(!Y(t))throw new Error(`Directory ${t} is not found, please make it manually`);let i=Z(t),e={},s=e,o=e,n=[],a=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],r=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],c=[...a,...r,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],d=u((p,g)=>Object.fromEntries(p.map(h=>[h,{...g}])),"makeObject"),l={all:{},dynamic:[],dynamicSpesific:{text:n,photo:n,video:n,audio:n,document:n,animation:n,voice:n,videoNote:n,sticker:n,location:n,contact:n},static:d(a,e),staticIntent:d(r,s),staticSession:d(c,o),listFuncStatic:a,listFuncStaticIntent:r,listFuncStaticSession:c,lenListFuncStatic:a.length,lenListFuncStaticIntent:r.length,lenListFuncStaticSession:c.length};for(let p of i){let g=T(t,p),h=f.getPageSync(g,!0);this.pageBuildData(h,g),this.pageSorts(h,l)}return this.log?.info?.(`Finish load pages with total (${Object.keys(l.all).length})`),l}async pageRoutes(t,i){let e,s;if(e===void 0){let n=t.callbackData,a=t.msgText,r=t.msgCaption,c=this.pages.static;for(let d=0;d<this.pages.lenListFuncStatic;d++){let l=this.pages.listFuncStatic[d];if(s=c[l][n||a||r],s)break}s!==void 0&&(e=this.pages.all[s.name])}if(e===void 0){let n=await t.sessionGet();if(n){let a=n.method,r=this.pages.staticSession;for(let c=0;c<this.pages.lenListFuncStaticSession;c++){let d=this.pages.listFuncStaticSession[c];if(s=r[d][a],s)break}s!==void 0&&(e=this.pages.all[s.name])}}if(e===void 0){let n=t.callbackDataIntent,a=t.msgTextIntent,r=t.msgCaptionIntent,c=this.pages.staticIntent;for(let d=0;d<this.pages.lenListFuncStaticIntent;d++){let l=this.pages.listFuncStaticIntent[d];if(s=c[l][n||a||r],s)break}s!==void 0&&(e=this.pages.all[s.name])}if(e!==void 0&&s!==void 0)return await new e(t)[s.func]?.();let o=this.pages.dynamicSpesific[i]||[];for(let n=0;n<o.length;n++){let a=o[n];if(a===void 0)continue;let r=this.pages.all[a.func];if(r===void 0)continue;let d=await new r(t)[a.name]?.();if(d!==null)return d}for(let n=0;n<this.pages.dynamic.length;n++){let a=this.pages.dynamic[n];if(a===void 0)continue;let r=this.pages.all[a];if(r===void 0)continue;let d=await new r(t).free?.();if(d!==null)return d}return null}async hookBeforeRoute(t,i){return!0}async hookErrorPage(t,i,e,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,i){let e=this.createCtx(t);try{if(await this.hookBeforeRoute(e,i)===!1)return;await this.pageRoutes(e,i)===null&&await this.hookErrorInputNotFoundPage(e)}catch(s){await this.hookErrorPage(e,i,s,!1)}}async onCallbackQueryData(t){let i=this.createCtx(t);try{if(await i.callbackQueryAnswer(),await this.hookBeforeRoute(i,"onCallbackQueryData")===!1)return;await this.pageRoutes(i,"callback")}catch(e){await this.hookErrorPage(i,"onCallbackQueryData",e,!0)}}async onMessageText(t){await this.onMessage(t,"onMessageText")}async onMessagePhoto(t){await this.onMessage(t,"onMessagePhoto")}async onMessageVideo(t){await this.onMessage(t,"onMessageVideo")}async onMessageAudio(t){await this.onMessage(t,"onMessageAudio")}async onMessageDocument(t){await this.onMessage(t,"onMessageDocument")}async onMessageAnimation(t){await this.onMessage(t,"onMessageAnimation")}async onMessageVoice(t){await this.onMessage(t,"onMessageVoice")}async onMessageVideoNote(t){await this.onMessage(t,"onMessageVideoNote")}async onMessageSticker(t){await this.onMessage(t,"onMessageSticker")}async onMessageLocation(t){await this.onMessage(t,"onMessageLocation")}async onMessageContact(t){await this.onMessage(t,"onMessageContact")}};export{C as BaseGeneral,S as CacheExternal,P as Ctx,A as Gramstax,b as TemplateEngine,v as TemplateManager};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gramstax",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "private": false,
5
5
  "description": "A powerful Telegram bot framework with page-based routing and template system",
6
6
  "keywords": [