gramstax 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/index.cjs +1 -1
- package/dist/src/index.d.cts +12 -8
- package/dist/src/index.d.ts +12 -8
- package/dist/src/index.js +1 -1
- package/package.json +1 -1
package/dist/src/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var z=Object.create;var v=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var p=(u,i)=>v(u,"name",{value:i,configurable:!0});var q=(u,i)=>{for(var s in i)v(u,s,{get:i[s],enumerable:!0})},K=(u,i,s,e)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of U(i))!J.call(u,t)&&t!==s&&v(u,t,{get:()=>i[t],enumerable:!(e=G(i,t))||e.enumerable});return u};var X=(u,i,s)=>(s=u!=null?z(H(u)):{},K(i||!u||!u.__esModule?v(s,"default",{value:u,enumerable:!0}):s,u)),Y=u=>K(v({},"__esModule",{value:!0}),u);var Z={};q(Z,{BaseGeneral:()=>F,CacheExternal:()=>k,Ctx:()=>x,Gramstax:()=>D,TemplateEngine:()=>f,TemplateManager:()=>T});module.exports=Y(Z);var $=require("logging-pretty");var F=class{static{p(this,"BaseGeneral")}static log=new $.LoggingPretty;static logError(i,s){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${s}]: ${String(i)}`)}logError(i,s,e){this.constructor.log.error(`[${s||this.constructor.name}:${e}] ${String(i)}`)}};var L=require("keyv"),R=X(require("@keyv/redis"),1);var k=class extends L.Keyv{constructor(s="memory",e,t,o){let n;s.startsWith("redis")&&(n=new R.default(s)),s==="memory"&&(n=new Map),o?.forceStore&&(n=o.forceStore);super({store:n,namespace:e,ttl:t});this.url=s}static{p(this,"CacheExternal")}};var B=require("timers/promises");var P=require("grammy");var x=class extends F{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,s,e,t,o,n){let r=s.map(d=>this.templateManager.getMessage(this.data.name,o,d,t));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,B.setTimeout)(1200)}}async reply(i,s,e,t){let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,s);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:i,...t})}async replyAction(i){return await this.ct.replyWithChatAction(i)}async edit(i,s,e,t){try{let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,s);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:i,...t})}catch{await this.reply(i,s,e,t)}}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(i){try{return await this.ct.answerCallbackQuery(i)}catch{return null}}async sessionSet(i,s,...e){try{let t={method:i,params:s,...e},o=await this.cacheSession.set(`${this.userid}`,{method:i,params:s,...e});return o&&(this.session=t),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(...s){let e=i(...s);return`${this.name}${e===void 0?"":`:${e}`}`}:function(){return this?.name}}}buildInlineKeyboard(i,s){let e=this.data.name;if(s?.cache===!0){let a=`${e}:${this.languageCode}:inline`,r=this.cacheKeyboard.get(a);if(!r){let d=new P.InlineKeyboard,l=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"inline",s?.data),c=i(d,l);return this.cacheKeyboard.set(a,c),c}return r}let t=new P.InlineKeyboard,o=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"inline",s?.data);return i(t,o)}buildKeyboard(i,s){let e=this.data.name;if(s?.cache===!0){let a=`${e}:${this.languageCode}:default`,r=this.cacheKeyboard.get(a);if(!r){let d=new P.Keyboard,l=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"default",s?.data),c=i(d,l);return c.resized(!0),this.cacheKeyboard.set(a,c),c}return r}let t=new P.Keyboard,o=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"default",s?.data),n=i(t,o);return n.resized(),n}validateSessionCallback(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallback(s)}validateSessionCallbackPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallbackPayload(s)}validateSessionText(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodText(s)}validateSessionTextPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextPayload(s)}validateSessionTextCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommand(s)}validateSessionTextCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommandPayload(s)}validateSessionTextFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextFree(s)}validateSessionPhotoCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaption(s)}validateSessionPhotoCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionPayload(s)}validateSessionPhotoCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommand(s)}validateSessionPhotoCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommandPayload(s)}validateSessionPhotoFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoFree(s)}validateSessionVideoCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaption(s)}validateSessionVideoCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionPayload(s)}validateSessionVideoCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommand(s)}validateSessionVideoCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommandPayload(s)}validateSessionVideoFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoFree(s)}validateSessionAudioCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaption(s)}validateSessionAudioCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionPayload(s)}validateSessionAudioCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommand(s)}validateSessionAudioCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommandPayload(s)}validateSessionAudioFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioFree(s)}validateSessionDocumentCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaption(s)}validateSessionDocumentCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionPayload(s)}validateSessionDocumentCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommand(s)}validateSessionDocumentCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommandPayload(s)}validateSessionDocumentFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentFree(s)}validateSessionAnimationCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaption(s)}validateSessionAnimationCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionPayload(s)}validateSessionAnimationCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommand(s)}validateSessionAnimationCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommandPayload(s)}validateSessionAnimationFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationFree(s)}validateSessionVoiceCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaption(s)}validateSessionVoiceCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionPayload(s)}validateSessionVoiceCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommand(s)}validateSessionVoiceCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommandPayload(s)}validateSessionVoiceFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceFree(s)}validateSessionVideoNoteCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaption(s)}validateSessionVideoNoteCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionPayload(s)}validateSessionVideoNoteCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommand(s)}validateSessionVideoNoteCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommandPayload(s)}validateSessionVideoNoteFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteFree(s)}validateSessionStickerFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodStickerFree(s)}validateSessionLocationFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodLocationFree(s)}validateSessionContactFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodContactFree(s)}sessionCallback(i,s){return this.sessionSet(this.buildSessionMethodCallback(s),i)}sessionCallbackPayload(i,s){return this.sessionSet(this.buildSessionMethodCallbackPayload(s),i)}sessionText(i,s){return this.sessionSet(this.buildSessionMethodText(s),i)}sessionTextPayload(i,s){return this.sessionSet(this.buildSessionMethodTextPayload(s),i)}sessionTextCommand(i,s){return this.sessionSet(this.buildSessionMethodTextCommand(s),i)}sessionTextCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodTextCommandPayload(s),i)}sessionTextFree(i,s){return this.sessionSet(this.buildSessionMethodTextFree(s),i)}sessionPhotoCaption(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaption(s),i)}sessionPhotoCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaptionPayload(s),i)}sessionPhotoCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommand(s),i)}sessionPhotoCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommandPayload(s),i)}sessionPhotoFree(i,s){return this.sessionSet(this.buildSessionMethodPhotoFree(s),i)}sessionVideoCaption(i,s){return this.sessionSet(this.buildSessionMethodVideoCaption(s),i)}sessionVideoCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoCaptionPayload(s),i)}sessionVideoCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodVideoCaptionCommand(s),i)}sessionVideoCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoCaptionCommandPayload(s),i)}sessionVideoFree(i,s){return this.sessionSet(this.buildSessionMethodVideoFree(s),i)}sessionAudioCaption(i,s){return this.sessionSet(this.buildSessionMethodAudioCaption(s),i)}sessionAudioCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodAudioCaptionPayload(s),i)}sessionAudioCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodAudioCaptionCommand(s),i)}sessionAudioCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodAudioCaptionCommandPayload(s),i)}sessionAudioFree(i,s){return this.sessionSet(this.buildSessionMethodAudioFree(s),i)}sessionDocumentCaption(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaption(s),i)}sessionDocumentCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaptionPayload(s),i)}sessionDocumentCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommand(s),i)}sessionDocumentCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommandPayload(s),i)}sessionDocumentFree(i,s){return this.sessionSet(this.buildSessionMethodDocumentFree(s),i)}sessionAnimationCaption(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaption(s),i)}sessionAnimationCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaptionPayload(s),i)}sessionAnimationCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommand(s),i)}sessionAnimationCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommandPayload(s),i)}sessionAnimationFree(i,s){return this.sessionSet(this.buildSessionMethodAnimationFree(s),i)}sessionVoiceCaption(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaption(s),i)}sessionVoiceCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaptionPayload(s),i)}sessionVoiceCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommand(s),i)}sessionVoiceCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommandPayload(s),i)}sessionVoiceFree(i,s){return this.sessionSet(this.buildSessionMethodVoiceFree(s),i)}sessionVideoNoteCaption(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaption(s),i)}sessionVideoNoteCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionPayload(s),i)}sessionVideoNoteCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommand(s),i)}sessionVideoNoteCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommandPayload(s),i)}sessionVideoNoteFree(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteFree(s),i)}sessionStickerFree(i,s){return this.sessionSet(this.buildSessionMethodStickerFree(s),i)}sessionLocationFree(i,s){return this.sessionSet(this.buildSessionMethodLocationFree(s),i)}sessionContactFree(i,s){return this.sessionSet(this.buildSessionMethodContactFree(s),i)}sessionToCallback(i,s){return this.sessionCallback({...this.session.params,...i},s)}sessionToCallbackPayload(i,s){return this.sessionCallbackPayload({...this.session.params,...i},s)}sessionToText(i,s){return this.sessionText({...this.session.params,...i},s)}sessionToTextPayload(i,s){return this.sessionTextPayload({...this.session.params,...i},s)}sessionToTextCommand(i,s){return this.sessionTextCommand({...this.session.params,...i},s)}sessionToTextCommandPayload(i,s){return this.sessionTextCommandPayload({...this.session.params,...i},s)}sessionToTextFree(i,s){return this.sessionTextFree({...this.session.params,...i},s)}sessionToPhotoCaption(i,s){return this.sessionPhotoCaption({...this.session.params,...i},s)}sessionToPhotoCaptionPayload(i,s){return this.sessionPhotoCaptionPayload({...this.session.params,...i},s)}sessionToPhotoCaptionCommand(i,s){return this.sessionPhotoCaptionCommand({...this.session.params,...i},s)}sessionToPhotoCaptionCommandPayload(i,s){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...i},s)}sessionToPhotoFree(i,s){return this.sessionPhotoFree({...this.session.params,...i},s)}sessionToVideoCaption(i,s){return this.sessionVideoCaption({...this.session.params,...i},s)}sessionToVideoCaptionPayload(i,s){return this.sessionVideoCaptionPayload({...this.session.params,...i},s)}sessionToVideoCaptionCommand(i,s){return this.sessionVideoCaptionCommand({...this.session.params,...i},s)}sessionToVideoCaptionCommandPayload(i,s){return this.sessionVideoCaptionCommandPayload({...this.session.params,...i},s)}sessionToVideoFree(i,s){return this.sessionVideoFree({...this.session.params,...i},s)}sessionToAudioCaption(i,s){return this.sessionAudioCaption({...this.session.params,...i},s)}sessionToAudioCaptionPayload(i,s){return this.sessionAudioCaptionPayload({...this.session.params,...i},s)}sessionToAudioCaptionCommand(i,s){return this.sessionAudioCaptionCommand({...this.session.params,...i},s)}sessionToAudioCaptionCommandPayload(i,s){return this.sessionAudioCaptionCommandPayload({...this.session.params,...i},s)}sessionToAudioFree(i,s){return this.sessionAudioFree({...this.session.params,...i},s)}sessionToDocumentCaption(i,s){return this.sessionDocumentCaption({...this.session.params,...i},s)}sessionToDocumentCaptionPayload(i,s){return this.sessionDocumentCaptionPayload({...this.session.params,...i},s)}sessionToDocumentCaptionCommand(i,s){return this.sessionDocumentCaptionCommand({...this.session.params,...i},s)}sessionToDocumentCaptionCommandPayload(i,s){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...i},s)}sessionToDocumentFree(i,s){return this.sessionDocumentFree({...this.session.params,...i},s)}sessionToAnimationCaption(i,s){return this.sessionAnimationCaption({...this.session.params,...i},s)}sessionToAnimationCaptionPayload(i,s){return this.sessionAnimationCaptionPayload({...this.session.params,...i},s)}sessionToAnimationCaptionCommand(i,s){return this.sessionAnimationCaptionCommand({...this.session.params,...i},s)}sessionToAnimationCaptionCommandPayload(i,s){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...i},s)}sessionToAnimationFree(i,s){return this.sessionAnimationFree({...this.session.params,...i},s)}sessionToVoiceCaption(i,s){return this.sessionVoiceCaption({...this.session.params,...i},s)}sessionToVoiceCaptionPayload(i,s){return this.sessionVoiceCaptionPayload({...this.session.params,...i},s)}sessionToVoiceCaptionCommand(i,s){return this.sessionVoiceCaptionCommand({...this.session.params,...i},s)}sessionToVoiceCaptionCommandPayload(i,s){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...i},s)}sessionToVoiceFree(i,s){return this.sessionVoiceFree({...this.session.params,...i},s)}sessionToVideoNoteCaption(i,s){return this.sessionVideoNoteCaption({...this.session.params,...i},s)}sessionToVideoNoteCaptionPayload(i,s){return this.sessionVideoNoteCaptionPayload({...this.session.params,...i},s)}sessionToVideoNoteCaptionCommand(i,s){return this.sessionVideoNoteCaptionCommand({...this.session.params,...i},s)}sessionToVideoNoteCaptionCommandPayload(i,s){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...i},s)}sessionToVideoNoteFree(i,s){return this.sessionVideoNoteFree({...this.session.params,...i},s)}sessionToStickerFree(i,s){return this.sessionStickerFree({...this.session.params,...i},s)}sessionToLocationFree(i,s){return this.sessionLocationFree({...this.session.params,...i},s)}sessionToContactFree(i,s){return this.sessionContactFree({...this.session.params,...i},s)}buildIntent(i,s=!0){i||(i=s?this.data.callbackData():this.data.name);let e=s?":":" ";return i?.indexOf?.(e)!=-1?i?.split?.(e)?.[0]:i}buildSessionMethod(i,s){return`${i}-${s||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 O=require("bun"),M=require("path");var W=require("logging-pretty");var f=class{static{p(this,"TemplateEngine")}static _escape(i){return i.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(i){return i.replace(/\{\{(\w+)\}\}/g,(s,e)=>`\${(data && data["${e}"]) ?? ""}`)}static _processBaseBlocks(i){let s=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,e={};for(let t of i.matchAll(s)){let o=t[2]??"default",a=(t[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,(s,e)=>{let t=e.trim();return t?`\${(() => { if (!data) return ''; try { with(data) { ${t} } } 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,(s,e)=>e.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMessageBlocks(i){let s=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,e={};for(let[,t,o]of i.matchAll(s)){let n=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[t]=n}return e}static _processKeyboardBlocks(i){let s=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\sfor="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,e={};for(let[,t,o,n]of i.matchAll(s)){let a=o==="default"?"default":"inline",r=n.trim();e[t]||(e[t]={}),e[t][a]=r}return e}static _compileToFunction(i,s){let e;s?e=i.map(n=>`\`${n}\``).join(","):e=`\`${i}\``;let t=e;if(t=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(t))),s){let o=`return [${t}]`;return new Function("data",o)}else{let o=`return ${t}`;return new Function("data",o)}}static compileMessages(i){let s=this._processBaseBlocks(i),e={};for(let[t,o]of Object.entries(s)){let n=this._processMessageBlocks(o);e[t]={};for(let[a,r]of Object.entries(n)){let d=this._processVariables(this._processScriptBlocks(r));e[t][a]=this._compileToFunction(d,!1)}}return e}static compileKeyboards(i){let s=this._processBaseBlocks(i),e={};for(let[t,o]of Object.entries(s)){let n=this._processKeyboardBlocks(o);e[t]={};for(let[a,r]of Object.entries(n)){e[t][a]={};for(let[d,l]of Object.entries(r)){let C=l.split(/(?<!\\),\s*/).map(m=>m.replace(/\\,/g,",").trim()).map(m=>this._processVariables(this._processScriptBlocks(m)));e[t][a][d]=this._compileToFunction(C,!0)}}}return e}};var V=require("fs/promises"),E=require("chokidar"),y=require("path"),g=require("fs");var T=class{static{p(this,"TemplateManager")}_map=new Map;_engine=f;_watcher=null;_supportedExtensions=new Set([".html"]);_path;_forceLanguage;_isWatchEnabled;constructor(i={}){let{enableWatch:s=!1,path:e=null,forceLanguage:t=null}=i;this._path=e,this._forceLanguage=t,this._isWatchEnabled=s,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(this._path===null||!(0,g.existsSync)(this._path))return;if(!(0,g.statSync)(this._path).isDirectory())throw new Error(`Template path is not a directory: ${this._path}`)}catch(i){throw new Error(`Failed to validate Template path: ${i}`)}}_initializeWatcher(){this._path===null||!this._isWatchEnabled||(this._watcher=(0,E.watch)(this._path,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}}),this._watcher.on("change",this._handleFileChange.bind(this)),this._watcher.on("add",this._handleFileAdd.bind(this)),this._watcher.on("unlink",this._handleFileDelete.bind(this)),this._watcher.on("error",this._handleWatchError.bind(this)))}async _handleFileChange(i){let s=(0,y.basename)(i);this._isValidFile(s)&&await this._loadFile(s,!1)}async _handleFileAdd(i){let s=(0,y.basename)(i);this._isValidFile(s)&&await this._loadFile(s,!1)}_handleFileDelete(i){let s=(0,y.basename)(i),e=this._getKey(s);this._map.has(e)&&this._map.delete(e)}_handleWatchError(i){}_loadAllFiles(){if(this._path===null||!(0,g.existsSync)(this._path))return;let s=(0,g.readdirSync)(this._path,{encoding:"utf8"}).filter(e=>this._isValidFile(e));for(let e of s)this._loadFile(e,!0)}async _loadFile(i,s=!0){if(this._path===null)return;let e=(0,y.join)(this._path,i),t=this._getKey(i),o=s?(0,g.readFileSync)(e,{encoding:"utf8"}):await(0,V.readFile)(e,{encoding:"utf8"});this.compile(t,o)}_isValidFile(i){let s=(0,y.extname)(i).toLowerCase();return this._supportedExtensions.has(s)}_getKey(i){return i.replace(/\.[^/.]+$/,"")}compile(i,s,e){let t=this._map.get(i),o=t||{},n=!1;(e===void 0||e?.message===!1||t?.message===void 0)&&(o.message=f.compileMessages(s),n=!0),(e===void 0||e?.keyboard===!1||t?.keyboard===void 0)&&(o.keyboard=f.compileKeyboards(s),n=!0),n&&this._map.set(i,o)}getMessage(i,s="default",e="en",t){let n=this._map.get(i)?.message?.[s]?.[this._forceLanguage||e];if(!n)return"";try{return n(t)}catch{return""}}getKeyboard(i,s="default",e="en",t="inline",o){let a=this._map.get(i)?.keyboard?.[s]?.[this._forceLanguage||e]?.[t];if(!a)return[];try{return a(o)}catch{return[]}}setMessage(i,s){this.compile(i,s,{keyboard:!0})}setKeyboard(i,s){this.compile(i,s,{message:!0})}async write(i,s){if(this._path===null)return;let e=(0,y.join)(this._path,i);await(0,V.mkdir)(this._path,{recursive:!0}),(0,g.writeFileSync)(e,s,{encoding:"utf8"}),await this._loadFile(i,!1)}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,s)=>typeof s=="function"?s.toString():s).length}}async destroy(){this._watcher&&await this._watcher.close(),this._map.clear()}};var _=require("fs"),w=require("grammy");var D=class{static{p(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;constructor(i){this.log=i.log===null?void 0:i.log===void 0?new W.LoggingPretty:i.log,this.cacheSession=i.cacheSession||new k("memory","session"),this.cacheKeyboard=i.cacheKeyboard||new Map,this.templateManager=i.templateManager||new T({path:null}),this.bot=new w.Bot(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,s,e){let{username:t}=i;s=="polling"?this.log?.success?.(`Telegram bot polling started: ${t}`):this.log?.success?.(`Telegram bot webhook started: ${t} (${e})`)}initCtx(i){return new x({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 s=(0,w.webhookCallback)(this.bot,"bun"),e="/telegram-webhook";(0,O.serve)({fetch(a){let{pathname:r}=new URL(a.url);if(r===e)return a.method==="POST"?s(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 t=await this.bot.api.getWebhookInfo(),o=i.endsWith("/")?i.slice(0,-1)+e:i+e;t.url!=o&&await this.bot.api.setWebhook(o);let n=await this.bot.api.getMe();this.onStart(n,"webhook",o)}pageCompile(i,s=!0){i?.template!==void 0?(this.templateManager.compile(i.data.name,i.template),s&&(i.template=void 0)):i.template=void 0}pageBuildData(i,s){i?.data===void 0&&(i.data=i.buildData()),i.data.name=(0,M.parse)(s).name}pageSorts(i,s){let e=i.data.name,t=i.prototype,o="Payload",n="Command",a="Caption",r="Free",d=s.dynamic,l=s.dynamicSpesific,c=p(h=>h.charAt(0).toUpperCase()+h.slice(1),"upFirst"),C=p(h=>h.replace(o,"").replace(n,"").replace(a,"").replace(r,""),"getPureFuncName"),m=p((h,b)=>t[`buildSessionMethod${c(h)}`](b),"buildSessionMethod");s.all[e]=i;for(let h=0;h<s.lenListFuncStaticSession;h++){let b=s.listFuncStaticSession[h],S=s.static[b],j=s.staticIntent[b],N=s.staticSession[b],A={name:e,func:b},I=S||j;if(I!==void 0){let Q=b.includes(n)?`/${e}`:e;I[t.buildIntent(Q,b.startsWith("callback"))]=A}N!==void 0&&(N[m(b,e)]=A),b.toLowerCase().endsWith("free")&&l[C(b)].push(A)}t.free&&d.push(e)}pageLoads(){this.log?.info?.("Load pages..");let i=(0,M.join)(process.cwd(),"src","pages");if(!(0,_.existsSync)(i))throw new Error(`Folder ${i} is not found, please make it manually`);let s=(0,_.readdirSync)(i),e={},t=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((C,m)=>Object.fromEntries(C.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,t),staticSession:l(d,o),listFuncStatic:a,listFuncStaticIntent:r,listFuncStaticSession:d,lenListFuncStatic:a.length,lenListFuncStaticIntent:r.length,lenListFuncStaticSession:d.length};for(let C of s){let m=(0,M.join)(i,C),h=require(m),S=Object.values(h)[0];if(S===void 0)throw`file ${(0,M.parse)(m).name} must have export (not default) class page`;this.pageBuildData(S,m),this.pageCompile(S),this.pageSorts(S,c)}return this.log?.info?.(`Finish load pages with total (${Object.keys(c.all).length})`),c}async pageRoutes(i,s){let e,t;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(t=d[c][n||a||r],t)break}t!==void 0&&(e=this.pages.all[t.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(t=r[l][a],t)break}t!==void 0&&(e=this.pages.all[t.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(t=d[c][n||a||r],t)break}t!==void 0&&(e=this.pages.all[t.name])}if(e!==void 0&&t!==void 0)return await new e(i)[t.func]?.();let o=this.pages.dynamicSpesific[s]||[];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,s){return!0}async hookErrorPage(i,s,e,t){}async hookErrorInputNotFoundPage(i){}async onMessage(i,s){let e=this.initCtx(i);try{if(await this.hookBeforeRoute(e,s)===!1)return;await this.pageRoutes(e,s)===null&&await this.hookErrorInputNotFoundPage(e)}catch(t){await this.hookErrorPage(e,s,t,!1)}}async onCallbackQueryData(i){let s=this.initCtx(i);try{if(await s.callbackQueryAnswer(),await this.hookBeforeRoute(s,"onCallbackQueryData")===!1)return;await this.pageRoutes(s,"callback")}catch(e){await this.hookErrorPage(s,"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 z=Object.create;var v=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var p=(u,i)=>v(u,"name",{value:i,configurable:!0});var q=(u,i)=>{for(var s in i)v(u,s,{get:i[s],enumerable:!0})},K=(u,i,s,e)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of U(i))!J.call(u,t)&&t!==s&&v(u,t,{get:()=>i[t],enumerable:!(e=G(i,t))||e.enumerable});return u};var X=(u,i,s)=>(s=u!=null?z(H(u)):{},K(i||!u||!u.__esModule?v(s,"default",{value:u,enumerable:!0}):s,u)),Y=u=>K(v({},"__esModule",{value:!0}),u);var Z={};q(Z,{BaseGeneral:()=>x,CacheExternal:()=>F,Ctx:()=>k,Gramstax:()=>D,TemplateEngine:()=>f,TemplateManager:()=>T});module.exports=Y(Z);var $=require("logging-pretty");var x=class{static{p(this,"BaseGeneral")}static log=new $.LoggingPretty;static logError(i,s){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${s}]: ${String(i)}`)}logError(i,s,e){this.constructor.log.error(`[${s||this.constructor.name}:${e}] ${String(i)}`)}};var B=require("keyv"),L=X(require("@keyv/redis"),1);var F=class extends B.Keyv{constructor(s="memory",e,t,o){let n;s.startsWith("redis")&&(n=new L.default(s)),s==="memory"&&(n=new Map),o?.forceStore&&(n=o.forceStore);super({store:n,namespace:e,ttl:t});this.url=s}static{p(this,"CacheExternal")}};var R=require("timers/promises");var P=require("grammy");var k=class extends x{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,s,e,t,o,n){let r=s.map(d=>this.templateManager.getMessage(this.data.name,o,d,t));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,R.setTimeout)(1200)}}async reply(i,s,e,t){let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,s);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:i,...t})}async replyAction(i){return await this.ct.replyWithChatAction(i)}async edit(i,s,e,t){try{let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,s);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:i,...t})}catch{await this.reply(i,s,e,t)}}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(i){try{return await this.ct.answerCallbackQuery(i)}catch{return null}}async sessionSet(i,s,...e){try{let t={method:i,params:s,...e},o=await this.cacheSession.set(`${this.userid}`,{method:i,params:s,...e});return o&&(this.session=t),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(...s){let e=i(...s);return`${this.name}${e===void 0?"":`:${e}`}`}:function(){return this?.name}}}buildInlineKeyboard(i,s){let e=this.data.name;if(s?.cache===!0){let a=`${e}:${this.languageCode}:inline`,r=this.cacheKeyboard.get(a);if(!r){let d=new P.InlineKeyboard,l=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"inline",s?.data),c=i(d,l);return this.cacheKeyboard.set(a,c),c}return r}let t=new P.InlineKeyboard,o=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"inline",s?.data);return i(t,o)}buildKeyboard(i,s){let e=this.data.name;if(s?.cache===!0){let a=`${e}:${this.languageCode}:default`,r=this.cacheKeyboard.get(a);if(!r){let d=new P.Keyboard,l=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"default",s?.data),c=i(d,l);return c.resized(!0),this.cacheKeyboard.set(a,c),c}return r}let t=new P.Keyboard,o=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"default",s?.data),n=i(t,o);return n.resized(),n}validateSessionCallback(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallback(s)}validateSessionCallbackPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallbackPayload(s)}validateSessionText(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodText(s)}validateSessionTextPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextPayload(s)}validateSessionTextCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommand(s)}validateSessionTextCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommandPayload(s)}validateSessionTextFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextFree(s)}validateSessionPhotoCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaption(s)}validateSessionPhotoCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionPayload(s)}validateSessionPhotoCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommand(s)}validateSessionPhotoCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommandPayload(s)}validateSessionPhotoFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoFree(s)}validateSessionVideoCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaption(s)}validateSessionVideoCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionPayload(s)}validateSessionVideoCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommand(s)}validateSessionVideoCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommandPayload(s)}validateSessionVideoFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoFree(s)}validateSessionAudioCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaption(s)}validateSessionAudioCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionPayload(s)}validateSessionAudioCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommand(s)}validateSessionAudioCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommandPayload(s)}validateSessionAudioFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioFree(s)}validateSessionDocumentCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaption(s)}validateSessionDocumentCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionPayload(s)}validateSessionDocumentCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommand(s)}validateSessionDocumentCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommandPayload(s)}validateSessionDocumentFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentFree(s)}validateSessionAnimationCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaption(s)}validateSessionAnimationCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionPayload(s)}validateSessionAnimationCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommand(s)}validateSessionAnimationCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommandPayload(s)}validateSessionAnimationFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationFree(s)}validateSessionVoiceCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaption(s)}validateSessionVoiceCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionPayload(s)}validateSessionVoiceCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommand(s)}validateSessionVoiceCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommandPayload(s)}validateSessionVoiceFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceFree(s)}validateSessionVideoNoteCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaption(s)}validateSessionVideoNoteCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionPayload(s)}validateSessionVideoNoteCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommand(s)}validateSessionVideoNoteCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommandPayload(s)}validateSessionVideoNoteFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteFree(s)}validateSessionStickerFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodStickerFree(s)}validateSessionLocationFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodLocationFree(s)}validateSessionContactFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodContactFree(s)}sessionCallback(i,s){return this.sessionSet(this.buildSessionMethodCallback(s),i)}sessionCallbackPayload(i,s){return this.sessionSet(this.buildSessionMethodCallbackPayload(s),i)}sessionText(i,s){return this.sessionSet(this.buildSessionMethodText(s),i)}sessionTextPayload(i,s){return this.sessionSet(this.buildSessionMethodTextPayload(s),i)}sessionTextCommand(i,s){return this.sessionSet(this.buildSessionMethodTextCommand(s),i)}sessionTextCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodTextCommandPayload(s),i)}sessionTextFree(i,s){return this.sessionSet(this.buildSessionMethodTextFree(s),i)}sessionPhotoCaption(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaption(s),i)}sessionPhotoCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaptionPayload(s),i)}sessionPhotoCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommand(s),i)}sessionPhotoCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommandPayload(s),i)}sessionPhotoFree(i,s){return this.sessionSet(this.buildSessionMethodPhotoFree(s),i)}sessionVideoCaption(i,s){return this.sessionSet(this.buildSessionMethodVideoCaption(s),i)}sessionVideoCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoCaptionPayload(s),i)}sessionVideoCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodVideoCaptionCommand(s),i)}sessionVideoCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoCaptionCommandPayload(s),i)}sessionVideoFree(i,s){return this.sessionSet(this.buildSessionMethodVideoFree(s),i)}sessionAudioCaption(i,s){return this.sessionSet(this.buildSessionMethodAudioCaption(s),i)}sessionAudioCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodAudioCaptionPayload(s),i)}sessionAudioCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodAudioCaptionCommand(s),i)}sessionAudioCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodAudioCaptionCommandPayload(s),i)}sessionAudioFree(i,s){return this.sessionSet(this.buildSessionMethodAudioFree(s),i)}sessionDocumentCaption(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaption(s),i)}sessionDocumentCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaptionPayload(s),i)}sessionDocumentCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommand(s),i)}sessionDocumentCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommandPayload(s),i)}sessionDocumentFree(i,s){return this.sessionSet(this.buildSessionMethodDocumentFree(s),i)}sessionAnimationCaption(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaption(s),i)}sessionAnimationCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaptionPayload(s),i)}sessionAnimationCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommand(s),i)}sessionAnimationCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommandPayload(s),i)}sessionAnimationFree(i,s){return this.sessionSet(this.buildSessionMethodAnimationFree(s),i)}sessionVoiceCaption(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaption(s),i)}sessionVoiceCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaptionPayload(s),i)}sessionVoiceCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommand(s),i)}sessionVoiceCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommandPayload(s),i)}sessionVoiceFree(i,s){return this.sessionSet(this.buildSessionMethodVoiceFree(s),i)}sessionVideoNoteCaption(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaption(s),i)}sessionVideoNoteCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionPayload(s),i)}sessionVideoNoteCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommand(s),i)}sessionVideoNoteCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommandPayload(s),i)}sessionVideoNoteFree(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteFree(s),i)}sessionStickerFree(i,s){return this.sessionSet(this.buildSessionMethodStickerFree(s),i)}sessionLocationFree(i,s){return this.sessionSet(this.buildSessionMethodLocationFree(s),i)}sessionContactFree(i,s){return this.sessionSet(this.buildSessionMethodContactFree(s),i)}sessionToCallback(i,s){return this.sessionCallback({...this.session.params,...i},s)}sessionToCallbackPayload(i,s){return this.sessionCallbackPayload({...this.session.params,...i},s)}sessionToText(i,s){return this.sessionText({...this.session.params,...i},s)}sessionToTextPayload(i,s){return this.sessionTextPayload({...this.session.params,...i},s)}sessionToTextCommand(i,s){return this.sessionTextCommand({...this.session.params,...i},s)}sessionToTextCommandPayload(i,s){return this.sessionTextCommandPayload({...this.session.params,...i},s)}sessionToTextFree(i,s){return this.sessionTextFree({...this.session.params,...i},s)}sessionToPhotoCaption(i,s){return this.sessionPhotoCaption({...this.session.params,...i},s)}sessionToPhotoCaptionPayload(i,s){return this.sessionPhotoCaptionPayload({...this.session.params,...i},s)}sessionToPhotoCaptionCommand(i,s){return this.sessionPhotoCaptionCommand({...this.session.params,...i},s)}sessionToPhotoCaptionCommandPayload(i,s){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...i},s)}sessionToPhotoFree(i,s){return this.sessionPhotoFree({...this.session.params,...i},s)}sessionToVideoCaption(i,s){return this.sessionVideoCaption({...this.session.params,...i},s)}sessionToVideoCaptionPayload(i,s){return this.sessionVideoCaptionPayload({...this.session.params,...i},s)}sessionToVideoCaptionCommand(i,s){return this.sessionVideoCaptionCommand({...this.session.params,...i},s)}sessionToVideoCaptionCommandPayload(i,s){return this.sessionVideoCaptionCommandPayload({...this.session.params,...i},s)}sessionToVideoFree(i,s){return this.sessionVideoFree({...this.session.params,...i},s)}sessionToAudioCaption(i,s){return this.sessionAudioCaption({...this.session.params,...i},s)}sessionToAudioCaptionPayload(i,s){return this.sessionAudioCaptionPayload({...this.session.params,...i},s)}sessionToAudioCaptionCommand(i,s){return this.sessionAudioCaptionCommand({...this.session.params,...i},s)}sessionToAudioCaptionCommandPayload(i,s){return this.sessionAudioCaptionCommandPayload({...this.session.params,...i},s)}sessionToAudioFree(i,s){return this.sessionAudioFree({...this.session.params,...i},s)}sessionToDocumentCaption(i,s){return this.sessionDocumentCaption({...this.session.params,...i},s)}sessionToDocumentCaptionPayload(i,s){return this.sessionDocumentCaptionPayload({...this.session.params,...i},s)}sessionToDocumentCaptionCommand(i,s){return this.sessionDocumentCaptionCommand({...this.session.params,...i},s)}sessionToDocumentCaptionCommandPayload(i,s){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...i},s)}sessionToDocumentFree(i,s){return this.sessionDocumentFree({...this.session.params,...i},s)}sessionToAnimationCaption(i,s){return this.sessionAnimationCaption({...this.session.params,...i},s)}sessionToAnimationCaptionPayload(i,s){return this.sessionAnimationCaptionPayload({...this.session.params,...i},s)}sessionToAnimationCaptionCommand(i,s){return this.sessionAnimationCaptionCommand({...this.session.params,...i},s)}sessionToAnimationCaptionCommandPayload(i,s){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...i},s)}sessionToAnimationFree(i,s){return this.sessionAnimationFree({...this.session.params,...i},s)}sessionToVoiceCaption(i,s){return this.sessionVoiceCaption({...this.session.params,...i},s)}sessionToVoiceCaptionPayload(i,s){return this.sessionVoiceCaptionPayload({...this.session.params,...i},s)}sessionToVoiceCaptionCommand(i,s){return this.sessionVoiceCaptionCommand({...this.session.params,...i},s)}sessionToVoiceCaptionCommandPayload(i,s){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...i},s)}sessionToVoiceFree(i,s){return this.sessionVoiceFree({...this.session.params,...i},s)}sessionToVideoNoteCaption(i,s){return this.sessionVideoNoteCaption({...this.session.params,...i},s)}sessionToVideoNoteCaptionPayload(i,s){return this.sessionVideoNoteCaptionPayload({...this.session.params,...i},s)}sessionToVideoNoteCaptionCommand(i,s){return this.sessionVideoNoteCaptionCommand({...this.session.params,...i},s)}sessionToVideoNoteCaptionCommandPayload(i,s){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...i},s)}sessionToVideoNoteFree(i,s){return this.sessionVideoNoteFree({...this.session.params,...i},s)}sessionToStickerFree(i,s){return this.sessionStickerFree({...this.session.params,...i},s)}sessionToLocationFree(i,s){return this.sessionLocationFree({...this.session.params,...i},s)}sessionToContactFree(i,s){return this.sessionContactFree({...this.session.params,...i},s)}buildIntent(i,s=!0){i||(i=s?this.data.callbackData():this.data.name);let e=s?":":" ";return i?.indexOf?.(e)!=-1?i?.split?.(e)?.[0]:i}buildSessionMethod(i,s){return`${i}-${s||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 O=require("bun"),M=require("path");var W=require("logging-pretty");var f=class{static{p(this,"TemplateEngine")}static _escape(i){return i.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(i){return i.replace(/\{\{(\w+)\}\}/g,(s,e)=>`\${(data && data["${e}"]) ?? ""}`)}static _processBaseBlocks(i){let s=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,e={};for(let t of i.matchAll(s)){let o=t[2]??"default",a=(t[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,(s,e)=>{let t=e.trim();return t?`\${(() => { if (!data) return ''; try { with(data) { ${t} } } 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,(s,e)=>e.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMessageBlocks(i){let s=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,e={};for(let[,t,o]of i.matchAll(s)){let n=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[t]=n}return e}static _processKeyboardBlocks(i){let s=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\sfor="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,e={};for(let[,t,o,n]of i.matchAll(s)){let a=o==="default"?"default":"inline",r=n.trim();e[t]||(e[t]={}),e[t][a]=r}return e}static _compileToFunction(i,s){let e;s?e=i.map(n=>`\`${n}\``).join(","):e=`\`${i}\``;let t=e;if(t=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(t))),s){let o=`return [${t}]`;return new Function("data",o)}else{let o=`return ${t}`;return new Function("data",o)}}static compileMessages(i){let s=this._processBaseBlocks(i),e={};for(let[t,o]of Object.entries(s)){let n=this._processMessageBlocks(o);e[t]={};for(let[a,r]of Object.entries(n)){let d=this._processVariables(this._processScriptBlocks(r));e[t][a]=this._compileToFunction(d,!1)}}return e}static compileKeyboards(i){let s=this._processBaseBlocks(i),e={};for(let[t,o]of Object.entries(s)){let n=this._processKeyboardBlocks(o);e[t]={};for(let[a,r]of Object.entries(n)){e[t][a]={};for(let[d,l]of Object.entries(r)){let C=l.split(/(?<!\\),\s*/).map(m=>m.replace(/\\,/g,",").trim()).map(m=>this._processVariables(this._processScriptBlocks(m)));e[t][a][d]=this._compileToFunction(C,!0)}}}return e}};var V=require("fs/promises"),E=require("chokidar"),y=require("path"),g=require("fs");var T=class{static{p(this,"TemplateManager")}_map=new Map;_engine=f;_watcher=null;_supportedExtensions=new Set([".html"]);_path;_forceLanguage;_isWatchEnabled;constructor(i={}){let{enableWatch:s=!1,path:e=null,forceLanguage:t=null}=i;this._path=e,this._forceLanguage=t,this._isWatchEnabled=s,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(this._path===null||!(0,g.existsSync)(this._path))return;if(!(0,g.statSync)(this._path).isDirectory())throw new Error(`Template path is not a directory: ${this._path}`)}catch(i){throw new Error(`Failed to validate Template path: ${i}`)}}_initializeWatcher(){this._path===null||!this._isWatchEnabled||(this._watcher=(0,E.watch)(this._path,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}}),this._watcher.on("change",this._handleFileChange.bind(this)),this._watcher.on("add",this._handleFileAdd.bind(this)),this._watcher.on("unlink",this._handleFileDelete.bind(this)),this._watcher.on("error",this._handleWatchError.bind(this)))}async _handleFileChange(i){let s=(0,y.basename)(i);this._isValidFile(s)&&await this._loadFile(s,!1)}async _handleFileAdd(i){let s=(0,y.basename)(i);this._isValidFile(s)&&await this._loadFile(s,!1)}_handleFileDelete(i){let s=(0,y.basename)(i),e=this._getKey(s);this._map.has(e)&&this._map.delete(e)}_handleWatchError(i){}_loadAllFiles(){if(this._path===null||!(0,g.existsSync)(this._path))return;let s=(0,g.readdirSync)(this._path,{encoding:"utf8"}).filter(e=>this._isValidFile(e));for(let e of s)this._loadFile(e,!0)}async _loadFile(i,s=!0){if(this._path===null)return;let e=(0,y.join)(this._path,i),t=this._getKey(i),o=s?(0,g.readFileSync)(e,{encoding:"utf8"}):await(0,V.readFile)(e,{encoding:"utf8"});this.compile(t,o)}_isValidFile(i){let s=(0,y.extname)(i).toLowerCase();return this._supportedExtensions.has(s)}_getKey(i){return i.replace(/\.[^/.]+$/,"")}compile(i,s,e){let t=this._map.get(i),o=t||{},n=!1;(e===void 0||e?.message===!1||t?.message===void 0)&&(o.message=f.compileMessages(s),n=!0),(e===void 0||e?.keyboard===!1||t?.keyboard===void 0)&&(o.keyboard=f.compileKeyboards(s),n=!0),n&&this._map.set(i,o)}getMessage(i,s="default",e="en",t){let n=this._map.get(i)?.message?.[s]?.[this._forceLanguage||e];if(!n)return"";try{return n(t)}catch{return""}}getKeyboard(i,s="default",e="en",t="inline",o){let a=this._map.get(i)?.keyboard?.[s]?.[this._forceLanguage||e]?.[t];if(!a)return[];try{return a(o)}catch{return[]}}setMessage(i,s){this.compile(i,s,{keyboard:!0})}setKeyboard(i,s){this.compile(i,s,{message:!0})}async write(i,s){if(this._path===null)return;let e=(0,y.join)(this._path,i);await(0,V.mkdir)(this._path,{recursive:!0}),(0,g.writeFileSync)(e,s,{encoding:"utf8"}),await this._loadFile(i,!1)}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,s)=>typeof s=="function"?s.toString():s).length}}async destroy(){this._watcher&&await this._watcher.close(),this._map.clear()}};var _=require("fs"),w=require("grammy");var D=class{static{p(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;ctx;bot;constructor(i){this.log=i.log===null?void 0:i.log===void 0?new W.LoggingPretty:i.log,this.cacheSession=i.cacheSession||new F("memory","session"),this.cacheKeyboard=i.cacheKeyboard||new Map,this.templateManager=i.templateManager||new T({path:null}),this.ctx=this.createCtx(),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,s,e){let{username:t}=i;s=="polling"?this.log?.success?.(`Telegram bot polling started: ${t}`):this.log?.success?.(`Telegram bot webhook started: ${t} (${e})`)}createBot(i){return new w.Bot(i)}createCtx(){return new k({ct:{},cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}refreshCtx(i){return this.ctx.ct=i,this.ctx.temp={session:{},data:{}},this.ctx}async runPolling(){this.bot.start({onStart:p(async i=>{this.onStart(i,"polling",null)},"onStart")})}async runWebhook(i){let s=(0,w.webhookCallback)(this.bot,"bun"),e="/telegram-webhook";(0,O.serve)({fetch(a){let{pathname:r}=new URL(a.url);if(r===e)return a.method==="POST"?s(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 t=await this.bot.api.getWebhookInfo(),o=i.endsWith("/")?i.slice(0,-1)+e:i+e;t.url!=o&&await this.bot.api.setWebhook(o);let n=await this.bot.api.getMe();this.onStart(n,"webhook",o)}pageCompile(i,s=!0){i?.template!==void 0?(this.templateManager.compile(i.data.name,i.template),s&&(i.template=void 0)):i.template=void 0}pageBuildData(i,s){i?.data===void 0&&(i.data=i.buildData()),i.data.name=(0,M.parse)(s).name}pageSorts(i,s){let e=i.data.name,t=i.prototype,o="Payload",n="Command",a="Caption",r="Free",d=s.dynamic,l=s.dynamicSpesific,c=p(h=>h.charAt(0).toUpperCase()+h.slice(1),"upFirst"),C=p(h=>h.replace(o,"").replace(n,"").replace(a,"").replace(r,""),"getPureFuncName"),m=p((h,b)=>t[`buildSessionMethod${c(h)}`](b),"buildSessionMethod");s.all[e]=i;for(let h=0;h<s.lenListFuncStaticSession;h++){let b=s.listFuncStaticSession[h],S=s.static[b],j=s.staticIntent[b],I=s.staticSession[b],A={name:e,func:b},N=S||j;if(N!==void 0){let Q=b.includes(n)?`/${e}`:e;N[t.buildIntent(Q,b.startsWith("callback"))]=A}I!==void 0&&(I[m(b,e)]=A),b.toLowerCase().endsWith("free")&&l[C(b)].push(A)}t.free&&d.push(e)}pageLoads(){this.log?.info?.("Load pages..");let i=(0,M.join)(process.cwd(),"src","pages");if(!(0,_.existsSync)(i))throw new Error(`Folder ${i} is not found, please make it manually`);let s=(0,_.readdirSync)(i),e={},t=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((C,m)=>Object.fromEntries(C.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,t),staticSession:l(d,o),listFuncStatic:a,listFuncStaticIntent:r,listFuncStaticSession:d,lenListFuncStatic:a.length,lenListFuncStaticIntent:r.length,lenListFuncStaticSession:d.length};for(let C of s){let m=(0,M.join)(i,C),h=require(m),S=Object.values(h)[0];if(S===void 0)throw`file ${(0,M.parse)(m).name} must have export (not default) class page`;this.pageBuildData(S,m),this.pageCompile(S),this.pageSorts(S,c)}return this.log?.info?.(`Finish load pages with total (${Object.keys(c.all).length})`),c}async pageRoutes(i,s){let e,t;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(t=d[c][n||a||r],t)break}t!==void 0&&(e=this.pages.all[t.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(t=r[l][a],t)break}t!==void 0&&(e=this.pages.all[t.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(t=d[c][n||a||r],t)break}t!==void 0&&(e=this.pages.all[t.name])}if(e!==void 0&&t!==void 0)return await new e(i)[t.func]?.();let o=this.pages.dynamicSpesific[s]||[];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,s){return!0}async hookErrorPage(i,s,e,t){}async hookErrorInputNotFoundPage(i){}async onMessage(i,s){let e=this.refreshCtx(i);try{if(await this.hookBeforeRoute(e,s)===!1)return;await this.pageRoutes(e,s)===null&&await this.hookErrorInputNotFoundPage(e)}catch(t){await this.hookErrorPage(e,s,t,!1)}}async onCallbackQueryData(i){let s=this.refreshCtx(i);try{if(await s.callbackQueryAnswer(),await this.hookBeforeRoute(s,"onCallbackQueryData")===!1)return;await this.pageRoutes(s,"callback")}catch(e){await this.hookErrorPage(s,"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});
|
package/dist/src/index.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { LoggingPretty } from 'logging-pretty';
|
|
2
2
|
import { Keyv } from 'keyv';
|
|
3
|
+
import * as grammy from 'grammy';
|
|
4
|
+
import { Context, Keyboard, InlineKeyboard, Bot, BotError } from 'grammy';
|
|
3
5
|
import * as grammy_types from 'grammy/types';
|
|
4
6
|
import { UserFromGetMe } from 'grammy/types';
|
|
5
7
|
import { FSWatcher } from 'chokidar';
|
|
6
|
-
import { Context, Keyboard, InlineKeyboard, Bot, BotError } from 'grammy';
|
|
7
8
|
|
|
8
9
|
declare abstract class BaseGeneral {
|
|
9
10
|
static log: LoggingPretty;
|
|
@@ -482,13 +483,14 @@ declare class Ctx extends BaseGeneral {
|
|
|
482
483
|
buildSessionMethodContactFree(name?: string): string;
|
|
483
484
|
}
|
|
484
485
|
|
|
485
|
-
declare class Gramstax {
|
|
486
|
+
declare class Gramstax<ICtx extends Ctx = Ctx, IBot extends Bot = Bot> {
|
|
486
487
|
templateManager: TemplateManager;
|
|
487
488
|
cacheKeyboard: Map<any, any>;
|
|
488
489
|
cacheSession: CacheExternal;
|
|
489
490
|
pages: ReturnType<typeof this.pageLoads>;
|
|
490
491
|
log: LoggingPretty | undefined | null;
|
|
491
|
-
|
|
492
|
+
ctx: ICtx;
|
|
493
|
+
bot: IBot;
|
|
492
494
|
constructor(params: {
|
|
493
495
|
token: string;
|
|
494
496
|
deploy: string;
|
|
@@ -499,7 +501,9 @@ declare class Gramstax {
|
|
|
499
501
|
});
|
|
500
502
|
onCatch(error: BotError<Context>): void;
|
|
501
503
|
onStart(botInfo: UserFromGetMe, method: `polling` | `webhook`, data: string | null): void;
|
|
502
|
-
|
|
504
|
+
createBot(token: string): Bot<Context, grammy.Api<grammy.RawApi>>;
|
|
505
|
+
createCtx(): Ctx;
|
|
506
|
+
refreshCtx(ct: Context): ICtx;
|
|
503
507
|
runPolling(): Promise<void>;
|
|
504
508
|
runWebhook(baseUrl: string): Promise<void>;
|
|
505
509
|
pageCompile(Page: typeof Ctx, redacted?: boolean): void;
|
|
@@ -883,10 +887,10 @@ declare class Gramstax {
|
|
|
883
887
|
lenListFuncStaticIntent: 17;
|
|
884
888
|
lenListFuncStaticSession: 45;
|
|
885
889
|
};
|
|
886
|
-
pageRoutes(ctx:
|
|
887
|
-
hookBeforeRoute(ctx:
|
|
888
|
-
hookErrorPage(ctx:
|
|
889
|
-
hookErrorInputNotFoundPage(ctx:
|
|
890
|
+
pageRoutes(ctx: ICtx, fromListener: `callback` | keyof typeof this$1.pages.dynamicSpesific): Promise<any | null>;
|
|
891
|
+
hookBeforeRoute(ctx: ICtx, listenerName: string): Promise<boolean>;
|
|
892
|
+
hookErrorPage(ctx: ICtx, listenerName: string, error: any, isEdit: boolean): Promise<void>;
|
|
893
|
+
hookErrorInputNotFoundPage(ctx: ICtx): Promise<void>;
|
|
890
894
|
onMessage(ct: Context, listenerName: string): Promise<void>;
|
|
891
895
|
onCallbackQueryData(ct: Context): Promise<void>;
|
|
892
896
|
onMessageText(ct: Context): Promise<void>;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { LoggingPretty } from 'logging-pretty';
|
|
2
2
|
import { Keyv } from 'keyv';
|
|
3
|
+
import * as grammy from 'grammy';
|
|
4
|
+
import { Context, Keyboard, InlineKeyboard, Bot, BotError } from 'grammy';
|
|
3
5
|
import * as grammy_types from 'grammy/types';
|
|
4
6
|
import { UserFromGetMe } from 'grammy/types';
|
|
5
7
|
import { FSWatcher } from 'chokidar';
|
|
6
|
-
import { Context, Keyboard, InlineKeyboard, Bot, BotError } from 'grammy';
|
|
7
8
|
|
|
8
9
|
declare abstract class BaseGeneral {
|
|
9
10
|
static log: LoggingPretty;
|
|
@@ -482,13 +483,14 @@ declare class Ctx extends BaseGeneral {
|
|
|
482
483
|
buildSessionMethodContactFree(name?: string): string;
|
|
483
484
|
}
|
|
484
485
|
|
|
485
|
-
declare class Gramstax {
|
|
486
|
+
declare class Gramstax<ICtx extends Ctx = Ctx, IBot extends Bot = Bot> {
|
|
486
487
|
templateManager: TemplateManager;
|
|
487
488
|
cacheKeyboard: Map<any, any>;
|
|
488
489
|
cacheSession: CacheExternal;
|
|
489
490
|
pages: ReturnType<typeof this.pageLoads>;
|
|
490
491
|
log: LoggingPretty | undefined | null;
|
|
491
|
-
|
|
492
|
+
ctx: ICtx;
|
|
493
|
+
bot: IBot;
|
|
492
494
|
constructor(params: {
|
|
493
495
|
token: string;
|
|
494
496
|
deploy: string;
|
|
@@ -499,7 +501,9 @@ declare class Gramstax {
|
|
|
499
501
|
});
|
|
500
502
|
onCatch(error: BotError<Context>): void;
|
|
501
503
|
onStart(botInfo: UserFromGetMe, method: `polling` | `webhook`, data: string | null): void;
|
|
502
|
-
|
|
504
|
+
createBot(token: string): Bot<Context, grammy.Api<grammy.RawApi>>;
|
|
505
|
+
createCtx(): Ctx;
|
|
506
|
+
refreshCtx(ct: Context): ICtx;
|
|
503
507
|
runPolling(): Promise<void>;
|
|
504
508
|
runWebhook(baseUrl: string): Promise<void>;
|
|
505
509
|
pageCompile(Page: typeof Ctx, redacted?: boolean): void;
|
|
@@ -883,10 +887,10 @@ declare class Gramstax {
|
|
|
883
887
|
lenListFuncStaticIntent: 17;
|
|
884
888
|
lenListFuncStaticSession: 45;
|
|
885
889
|
};
|
|
886
|
-
pageRoutes(ctx:
|
|
887
|
-
hookBeforeRoute(ctx:
|
|
888
|
-
hookErrorPage(ctx:
|
|
889
|
-
hookErrorInputNotFoundPage(ctx:
|
|
890
|
+
pageRoutes(ctx: ICtx, fromListener: `callback` | keyof typeof this$1.pages.dynamicSpesific): Promise<any | null>;
|
|
891
|
+
hookBeforeRoute(ctx: ICtx, listenerName: string): Promise<boolean>;
|
|
892
|
+
hookErrorPage(ctx: ICtx, listenerName: string, error: any, isEdit: boolean): Promise<void>;
|
|
893
|
+
hookErrorInputNotFoundPage(ctx: ICtx): Promise<void>;
|
|
890
894
|
onMessage(ct: Context, listenerName: string): Promise<void>;
|
|
891
895
|
onCallbackQueryData(ct: Context): Promise<void>;
|
|
892
896
|
onMessageText(ct: Context): Promise<void>;
|
package/dist/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var L=Object.defineProperty;var c=(h,i)=>L(h,"name",{value:i,configurable:!0}),T=(h=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(h,{get:(i,s)=>(typeof require<"u"?require:i)[s]}):h)(function(h){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+h+'" is not supported')});import{LoggingPretty as R}from"logging-pretty";var f=class{static{c(this,"BaseGeneral")}static log=new R;static logError(i,s){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${s}]: ${String(i)}`)}logError(i,s,e){this.constructor.log.error(`[${s||this.constructor.name}:${e}] ${String(i)}`)}};import{Keyv as B}from"keyv";import E from"@keyv/redis";var S=class extends B{constructor(s="memory",e,t,o){let n;s.startsWith("redis")&&(n=new E(s)),s==="memory"&&(n=new Map),o?.forceStore&&(n=o.forceStore);super({store:n,namespace:e,ttl:t});this.url=s}static{c(this,"CacheExternal")}};import{setTimeout as O}from"timers/promises";import{InlineKeyboard as V,Keyboard as _}from"grammy";var P=class extends f{static{c(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,s,e,t,o,n){let r=s.map(d=>this.templateManager.getMessage(this.data.name,o,d,t));for(let d=0;d<i.length;d++){let l=i[d],u=r[d];await this.ct.api.sendMessage(l,u,{parse_mode:"HTML",reply_markup:e,...n}),d+1==30&&await O(1200)}}async reply(i,s,e,t){let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,s);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:i,...t})}async replyAction(i){return await this.ct.replyWithChatAction(i)}async edit(i,s,e,t){try{let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,s);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:i,...t})}catch{await this.reply(i,s,e,t)}}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(i){try{return await this.ct.answerCallbackQuery(i)}catch{return null}}async sessionSet(i,s,...e){try{let t={method:i,params:s,...e},o=await this.cacheSession.set(`${this.userid}`,{method:i,params:s,...e});return o&&(this.session=t),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(...s){let e=i(...s);return`${this.name}${e===void 0?"":`:${e}`}`}:function(){return this?.name}}}buildInlineKeyboard(i,s){let e=this.data.name;if(s?.cache===!0){let a=`${e}:${this.languageCode}:inline`,r=this.cacheKeyboard.get(a);if(!r){let d=new V,l=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"inline",s?.data),u=i(d,l);return this.cacheKeyboard.set(a,u),u}return r}let t=new V,o=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"inline",s?.data);return i(t,o)}buildKeyboard(i,s){let e=this.data.name;if(s?.cache===!0){let a=`${e}:${this.languageCode}:default`,r=this.cacheKeyboard.get(a);if(!r){let d=new _,l=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"default",s?.data),u=i(d,l);return u.resized(!0),this.cacheKeyboard.set(a,u),u}return r}let t=new _,o=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"default",s?.data),n=i(t,o);return n.resized(),n}validateSessionCallback(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallback(s)}validateSessionCallbackPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallbackPayload(s)}validateSessionText(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodText(s)}validateSessionTextPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextPayload(s)}validateSessionTextCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommand(s)}validateSessionTextCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommandPayload(s)}validateSessionTextFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextFree(s)}validateSessionPhotoCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaption(s)}validateSessionPhotoCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionPayload(s)}validateSessionPhotoCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommand(s)}validateSessionPhotoCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommandPayload(s)}validateSessionPhotoFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoFree(s)}validateSessionVideoCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaption(s)}validateSessionVideoCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionPayload(s)}validateSessionVideoCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommand(s)}validateSessionVideoCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommandPayload(s)}validateSessionVideoFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoFree(s)}validateSessionAudioCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaption(s)}validateSessionAudioCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionPayload(s)}validateSessionAudioCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommand(s)}validateSessionAudioCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommandPayload(s)}validateSessionAudioFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioFree(s)}validateSessionDocumentCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaption(s)}validateSessionDocumentCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionPayload(s)}validateSessionDocumentCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommand(s)}validateSessionDocumentCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommandPayload(s)}validateSessionDocumentFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentFree(s)}validateSessionAnimationCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaption(s)}validateSessionAnimationCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionPayload(s)}validateSessionAnimationCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommand(s)}validateSessionAnimationCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommandPayload(s)}validateSessionAnimationFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationFree(s)}validateSessionVoiceCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaption(s)}validateSessionVoiceCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionPayload(s)}validateSessionVoiceCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommand(s)}validateSessionVoiceCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommandPayload(s)}validateSessionVoiceFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceFree(s)}validateSessionVideoNoteCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaption(s)}validateSessionVideoNoteCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionPayload(s)}validateSessionVideoNoteCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommand(s)}validateSessionVideoNoteCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommandPayload(s)}validateSessionVideoNoteFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteFree(s)}validateSessionStickerFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodStickerFree(s)}validateSessionLocationFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodLocationFree(s)}validateSessionContactFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodContactFree(s)}sessionCallback(i,s){return this.sessionSet(this.buildSessionMethodCallback(s),i)}sessionCallbackPayload(i,s){return this.sessionSet(this.buildSessionMethodCallbackPayload(s),i)}sessionText(i,s){return this.sessionSet(this.buildSessionMethodText(s),i)}sessionTextPayload(i,s){return this.sessionSet(this.buildSessionMethodTextPayload(s),i)}sessionTextCommand(i,s){return this.sessionSet(this.buildSessionMethodTextCommand(s),i)}sessionTextCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodTextCommandPayload(s),i)}sessionTextFree(i,s){return this.sessionSet(this.buildSessionMethodTextFree(s),i)}sessionPhotoCaption(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaption(s),i)}sessionPhotoCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaptionPayload(s),i)}sessionPhotoCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommand(s),i)}sessionPhotoCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommandPayload(s),i)}sessionPhotoFree(i,s){return this.sessionSet(this.buildSessionMethodPhotoFree(s),i)}sessionVideoCaption(i,s){return this.sessionSet(this.buildSessionMethodVideoCaption(s),i)}sessionVideoCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoCaptionPayload(s),i)}sessionVideoCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodVideoCaptionCommand(s),i)}sessionVideoCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoCaptionCommandPayload(s),i)}sessionVideoFree(i,s){return this.sessionSet(this.buildSessionMethodVideoFree(s),i)}sessionAudioCaption(i,s){return this.sessionSet(this.buildSessionMethodAudioCaption(s),i)}sessionAudioCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodAudioCaptionPayload(s),i)}sessionAudioCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodAudioCaptionCommand(s),i)}sessionAudioCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodAudioCaptionCommandPayload(s),i)}sessionAudioFree(i,s){return this.sessionSet(this.buildSessionMethodAudioFree(s),i)}sessionDocumentCaption(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaption(s),i)}sessionDocumentCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaptionPayload(s),i)}sessionDocumentCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommand(s),i)}sessionDocumentCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommandPayload(s),i)}sessionDocumentFree(i,s){return this.sessionSet(this.buildSessionMethodDocumentFree(s),i)}sessionAnimationCaption(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaption(s),i)}sessionAnimationCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaptionPayload(s),i)}sessionAnimationCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommand(s),i)}sessionAnimationCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommandPayload(s),i)}sessionAnimationFree(i,s){return this.sessionSet(this.buildSessionMethodAnimationFree(s),i)}sessionVoiceCaption(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaption(s),i)}sessionVoiceCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaptionPayload(s),i)}sessionVoiceCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommand(s),i)}sessionVoiceCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommandPayload(s),i)}sessionVoiceFree(i,s){return this.sessionSet(this.buildSessionMethodVoiceFree(s),i)}sessionVideoNoteCaption(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaption(s),i)}sessionVideoNoteCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionPayload(s),i)}sessionVideoNoteCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommand(s),i)}sessionVideoNoteCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommandPayload(s),i)}sessionVideoNoteFree(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteFree(s),i)}sessionStickerFree(i,s){return this.sessionSet(this.buildSessionMethodStickerFree(s),i)}sessionLocationFree(i,s){return this.sessionSet(this.buildSessionMethodLocationFree(s),i)}sessionContactFree(i,s){return this.sessionSet(this.buildSessionMethodContactFree(s),i)}sessionToCallback(i,s){return this.sessionCallback({...this.session.params,...i},s)}sessionToCallbackPayload(i,s){return this.sessionCallbackPayload({...this.session.params,...i},s)}sessionToText(i,s){return this.sessionText({...this.session.params,...i},s)}sessionToTextPayload(i,s){return this.sessionTextPayload({...this.session.params,...i},s)}sessionToTextCommand(i,s){return this.sessionTextCommand({...this.session.params,...i},s)}sessionToTextCommandPayload(i,s){return this.sessionTextCommandPayload({...this.session.params,...i},s)}sessionToTextFree(i,s){return this.sessionTextFree({...this.session.params,...i},s)}sessionToPhotoCaption(i,s){return this.sessionPhotoCaption({...this.session.params,...i},s)}sessionToPhotoCaptionPayload(i,s){return this.sessionPhotoCaptionPayload({...this.session.params,...i},s)}sessionToPhotoCaptionCommand(i,s){return this.sessionPhotoCaptionCommand({...this.session.params,...i},s)}sessionToPhotoCaptionCommandPayload(i,s){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...i},s)}sessionToPhotoFree(i,s){return this.sessionPhotoFree({...this.session.params,...i},s)}sessionToVideoCaption(i,s){return this.sessionVideoCaption({...this.session.params,...i},s)}sessionToVideoCaptionPayload(i,s){return this.sessionVideoCaptionPayload({...this.session.params,...i},s)}sessionToVideoCaptionCommand(i,s){return this.sessionVideoCaptionCommand({...this.session.params,...i},s)}sessionToVideoCaptionCommandPayload(i,s){return this.sessionVideoCaptionCommandPayload({...this.session.params,...i},s)}sessionToVideoFree(i,s){return this.sessionVideoFree({...this.session.params,...i},s)}sessionToAudioCaption(i,s){return this.sessionAudioCaption({...this.session.params,...i},s)}sessionToAudioCaptionPayload(i,s){return this.sessionAudioCaptionPayload({...this.session.params,...i},s)}sessionToAudioCaptionCommand(i,s){return this.sessionAudioCaptionCommand({...this.session.params,...i},s)}sessionToAudioCaptionCommandPayload(i,s){return this.sessionAudioCaptionCommandPayload({...this.session.params,...i},s)}sessionToAudioFree(i,s){return this.sessionAudioFree({...this.session.params,...i},s)}sessionToDocumentCaption(i,s){return this.sessionDocumentCaption({...this.session.params,...i},s)}sessionToDocumentCaptionPayload(i,s){return this.sessionDocumentCaptionPayload({...this.session.params,...i},s)}sessionToDocumentCaptionCommand(i,s){return this.sessionDocumentCaptionCommand({...this.session.params,...i},s)}sessionToDocumentCaptionCommandPayload(i,s){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...i},s)}sessionToDocumentFree(i,s){return this.sessionDocumentFree({...this.session.params,...i},s)}sessionToAnimationCaption(i,s){return this.sessionAnimationCaption({...this.session.params,...i},s)}sessionToAnimationCaptionPayload(i,s){return this.sessionAnimationCaptionPayload({...this.session.params,...i},s)}sessionToAnimationCaptionCommand(i,s){return this.sessionAnimationCaptionCommand({...this.session.params,...i},s)}sessionToAnimationCaptionCommandPayload(i,s){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...i},s)}sessionToAnimationFree(i,s){return this.sessionAnimationFree({...this.session.params,...i},s)}sessionToVoiceCaption(i,s){return this.sessionVoiceCaption({...this.session.params,...i},s)}sessionToVoiceCaptionPayload(i,s){return this.sessionVoiceCaptionPayload({...this.session.params,...i},s)}sessionToVoiceCaptionCommand(i,s){return this.sessionVoiceCaptionCommand({...this.session.params,...i},s)}sessionToVoiceCaptionCommandPayload(i,s){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...i},s)}sessionToVoiceFree(i,s){return this.sessionVoiceFree({...this.session.params,...i},s)}sessionToVideoNoteCaption(i,s){return this.sessionVideoNoteCaption({...this.session.params,...i},s)}sessionToVideoNoteCaptionPayload(i,s){return this.sessionVideoNoteCaptionPayload({...this.session.params,...i},s)}sessionToVideoNoteCaptionCommand(i,s){return this.sessionVideoNoteCaptionCommand({...this.session.params,...i},s)}sessionToVideoNoteCaptionCommandPayload(i,s){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...i},s)}sessionToVideoNoteFree(i,s){return this.sessionVideoNoteFree({...this.session.params,...i},s)}sessionToStickerFree(i,s){return this.sessionStickerFree({...this.session.params,...i},s)}sessionToLocationFree(i,s){return this.sessionLocationFree({...this.session.params,...i},s)}sessionToContactFree(i,s){return this.sessionContactFree({...this.session.params,...i},s)}buildIntent(i,s=!0){i||(i=s?this.data.callbackData():this.data.name);let e=s?":":" ";return i?.indexOf?.(e)!=-1?i?.split?.(e)?.[0]:i}buildSessionMethod(i,s){return`${i}-${s||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 q}from"bun";import{join as D,parse as N}from"path";import{LoggingPretty as X}from"logging-pretty";var C=class{static{c(this,"TemplateEngine")}static _escape(i){return i.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(i){return i.replace(/\{\{(\w+)\}\}/g,(s,e)=>`\${(data && data["${e}"]) ?? ""}`)}static _processBaseBlocks(i){let s=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,e={};for(let t of i.matchAll(s)){let o=t[2]??"default",a=(t[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,(s,e)=>{let t=e.trim();return t?`\${(() => { if (!data) return ''; try { with(data) { ${t} } } 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,(s,e)=>e.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMessageBlocks(i){let s=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,e={};for(let[,t,o]of i.matchAll(s)){let n=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[t]=n}return e}static _processKeyboardBlocks(i){let s=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\sfor="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,e={};for(let[,t,o,n]of i.matchAll(s)){let a=o==="default"?"default":"inline",r=n.trim();e[t]||(e[t]={}),e[t][a]=r}return e}static _compileToFunction(i,s){let e;s?e=i.map(n=>`\`${n}\``).join(","):e=`\`${i}\``;let t=e;if(t=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(t))),s){let o=`return [${t}]`;return new Function("data",o)}else{let o=`return ${t}`;return new Function("data",o)}}static compileMessages(i){let s=this._processBaseBlocks(i),e={};for(let[t,o]of Object.entries(s)){let n=this._processMessageBlocks(o);e[t]={};for(let[a,r]of Object.entries(n)){let d=this._processVariables(this._processScriptBlocks(r));e[t][a]=this._compileToFunction(d,!1)}}return e}static compileKeyboards(i){let s=this._processBaseBlocks(i),e={};for(let[t,o]of Object.entries(s)){let n=this._processKeyboardBlocks(o);e[t]={};for(let[a,r]of Object.entries(n)){e[t][a]={};for(let[d,l]of Object.entries(r)){let g=l.split(/(?<!\\),\s*/).map(m=>m.replace(/\\,/g,",").trim()).map(m=>this._processVariables(this._processScriptBlocks(m)));e[t][a][d]=this._compileToFunction(g,!0)}}}return e}};import{readFile as W,mkdir as j}from"fs/promises";import{watch as Q}from"chokidar";import{basename as F,join as w,extname as z}from"path";import{readdirSync as G,readFileSync as U,existsSync as A,statSync as H,writeFileSync as J}from"fs";var M=class{static{c(this,"TemplateManager")}_map=new Map;_engine=C;_watcher=null;_supportedExtensions=new Set([".html"]);_path;_forceLanguage;_isWatchEnabled;constructor(i={}){let{enableWatch:s=!1,path:e=null,forceLanguage:t=null}=i;this._path=e,this._forceLanguage=t,this._isWatchEnabled=s,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(this._path===null||!A(this._path))return;if(!H(this._path).isDirectory())throw new Error(`Template path is not a directory: ${this._path}`)}catch(i){throw new Error(`Failed to validate Template path: ${i}`)}}_initializeWatcher(){this._path===null||!this._isWatchEnabled||(this._watcher=Q(this._path,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}}),this._watcher.on("change",this._handleFileChange.bind(this)),this._watcher.on("add",this._handleFileAdd.bind(this)),this._watcher.on("unlink",this._handleFileDelete.bind(this)),this._watcher.on("error",this._handleWatchError.bind(this)))}async _handleFileChange(i){let s=F(i);this._isValidFile(s)&&await this._loadFile(s,!1)}async _handleFileAdd(i){let s=F(i);this._isValidFile(s)&&await this._loadFile(s,!1)}_handleFileDelete(i){let s=F(i),e=this._getKey(s);this._map.has(e)&&this._map.delete(e)}_handleWatchError(i){}_loadAllFiles(){if(this._path===null||!A(this._path))return;let s=G(this._path,{encoding:"utf8"}).filter(e=>this._isValidFile(e));for(let e of s)this._loadFile(e,!0)}async _loadFile(i,s=!0){if(this._path===null)return;let e=w(this._path,i),t=this._getKey(i),o=s?U(e,{encoding:"utf8"}):await W(e,{encoding:"utf8"});this.compile(t,o)}_isValidFile(i){let s=z(i).toLowerCase();return this._supportedExtensions.has(s)}_getKey(i){return i.replace(/\.[^/.]+$/,"")}compile(i,s,e){let t=this._map.get(i),o=t||{},n=!1;(e===void 0||e?.message===!1||t?.message===void 0)&&(o.message=C.compileMessages(s),n=!0),(e===void 0||e?.keyboard===!1||t?.keyboard===void 0)&&(o.keyboard=C.compileKeyboards(s),n=!0),n&&this._map.set(i,o)}getMessage(i,s="default",e="en",t){let n=this._map.get(i)?.message?.[s]?.[this._forceLanguage||e];if(!n)return"";try{return n(t)}catch{return""}}getKeyboard(i,s="default",e="en",t="inline",o){let a=this._map.get(i)?.keyboard?.[s]?.[this._forceLanguage||e]?.[t];if(!a)return[];try{return a(o)}catch{return[]}}setMessage(i,s){this.compile(i,s,{keyboard:!0})}setKeyboard(i,s){this.compile(i,s,{message:!0})}async write(i,s){if(this._path===null)return;let e=w(this._path,i);await j(this._path,{recursive:!0}),J(e,s,{encoding:"utf8"}),await this._loadFile(i,!1)}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,s)=>typeof s=="function"?s.toString():s).length}}async destroy(){this._watcher&&await this._watcher.close(),this._map.clear()}};import{existsSync as Y,readdirSync as Z}from"fs";import{Bot as ii,webhookCallback as si}from"grammy";var I=class{static{c(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;constructor(i){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 M({path:null}),this.bot=new ii(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,s,e){let{username:t}=i;s=="polling"?this.log?.success?.(`Telegram bot polling started: ${t}`):this.log?.success?.(`Telegram bot webhook started: ${t} (${e})`)}initCtx(i){return new P({ct:i,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:c(async i=>{this.onStart(i,"polling",null)},"onStart")})}async runWebhook(i){let s=si(this.bot,"bun"),e="/telegram-webhook";q({fetch(a){let{pathname:r}=new URL(a.url);if(r===e)return a.method==="POST"?s(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 t=await this.bot.api.getWebhookInfo(),o=i.endsWith("/")?i.slice(0,-1)+e:i+e;t.url!=o&&await this.bot.api.setWebhook(o);let n=await this.bot.api.getMe();this.onStart(n,"webhook",o)}pageCompile(i,s=!0){i?.template!==void 0?(this.templateManager.compile(i.data.name,i.template),s&&(i.template=void 0)):i.template=void 0}pageBuildData(i,s){i?.data===void 0&&(i.data=i.buildData()),i.data.name=N(s).name}pageSorts(i,s){let e=i.data.name,t=i.prototype,o="Payload",n="Command",a="Caption",r="Free",d=s.dynamic,l=s.dynamicSpesific,u=c(p=>p.charAt(0).toUpperCase()+p.slice(1),"upFirst"),g=c(p=>p.replace(o,"").replace(n,"").replace(a,"").replace(r,""),"getPureFuncName"),m=c((p,b)=>t[`buildSessionMethod${u(p)}`](b),"buildSessionMethod");s.all[e]=i;for(let p=0;p<s.lenListFuncStaticSession;p++){let b=s.listFuncStaticSession[p],y=s.static[b],K=s.staticIntent[b],k=s.staticSession[b],v={name:e,func:b},x=y||K;if(x!==void 0){let $=b.includes(n)?`/${e}`:e;x[t.buildIntent($,b.startsWith("callback"))]=v}k!==void 0&&(k[m(b,e)]=v),b.toLowerCase().endsWith("free")&&l[g(b)].push(v)}t.free&&d.push(e)}pageLoads(){this.log?.info?.("Load pages..");let i=D(process.cwd(),"src","pages");if(!Y(i))throw new Error(`Folder ${i} is not found, please make it manually`);let s=Z(i),e={},t=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=c((g,m)=>Object.fromEntries(g.map(p=>[p,{...m}])),"makeObject"),u={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,t),staticSession:l(d,o),listFuncStatic:a,listFuncStaticIntent:r,listFuncStaticSession:d,lenListFuncStatic:a.length,lenListFuncStaticIntent:r.length,lenListFuncStaticSession:d.length};for(let g of s){let m=D(i,g),p=T(m),y=Object.values(p)[0];if(y===void 0)throw`file ${N(m).name} must have export (not default) class page`;this.pageBuildData(y,m),this.pageCompile(y),this.pageSorts(y,u)}return this.log?.info?.(`Finish load pages with total (${Object.keys(u.all).length})`),u}async pageRoutes(i,s){let e,t;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 u=this.pages.listFuncStatic[l];if(t=d[u][n||a||r],t)break}t!==void 0&&(e=this.pages.all[t.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(t=r[l][a],t)break}t!==void 0&&(e=this.pages.all[t.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 u=this.pages.listFuncStaticIntent[l];if(t=d[u][n||a||r],t)break}t!==void 0&&(e=this.pages.all[t.name])}if(e!==void 0&&t!==void 0)return await new e(i)[t.func]?.();let o=this.pages.dynamicSpesific[s]||[];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,s){return!0}async hookErrorPage(i,s,e,t){}async hookErrorInputNotFoundPage(i){}async onMessage(i,s){let e=this.initCtx(i);try{if(await this.hookBeforeRoute(e,s)===!1)return;await this.pageRoutes(e,s)===null&&await this.hookErrorInputNotFoundPage(e)}catch(t){await this.hookErrorPage(e,s,t,!1)}}async onCallbackQueryData(i){let s=this.initCtx(i);try{if(await s.callbackQueryAnswer(),await this.hookBeforeRoute(s,"onCallbackQueryData")===!1)return;await this.pageRoutes(s,"callback")}catch(e){await this.hookErrorPage(s,"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{f as BaseGeneral,S as CacheExternal,P as Ctx,I as Gramstax,C as TemplateEngine,M as TemplateManager};
|
|
1
|
+
var B=Object.defineProperty;var c=(h,i)=>B(h,"name",{value:i,configurable:!0}),T=(h=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(h,{get:(i,s)=>(typeof require<"u"?require:i)[s]}):h)(function(h){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+h+'" is not supported')});import{LoggingPretty as L}from"logging-pretty";var f=class{static{c(this,"BaseGeneral")}static log=new L;static logError(i,s){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${s}]: ${String(i)}`)}logError(i,s,e){this.constructor.log.error(`[${s||this.constructor.name}:${e}] ${String(i)}`)}};import{Keyv as R}from"keyv";import E from"@keyv/redis";var S=class extends R{constructor(s="memory",e,t,o){let n;s.startsWith("redis")&&(n=new E(s)),s==="memory"&&(n=new Map),o?.forceStore&&(n=o.forceStore);super({store:n,namespace:e,ttl:t});this.url=s}static{c(this,"CacheExternal")}};import{setTimeout as O}from"timers/promises";import{InlineKeyboard as V,Keyboard as _}from"grammy";var P=class extends f{static{c(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,s,e,t,o,n){let r=s.map(d=>this.templateManager.getMessage(this.data.name,o,d,t));for(let d=0;d<i.length;d++){let l=i[d],u=r[d];await this.ct.api.sendMessage(l,u,{parse_mode:"HTML",reply_markup:e,...n}),d+1==30&&await O(1200)}}async reply(i,s,e,t){let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,s);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:i,...t})}async replyAction(i){return await this.ct.replyWithChatAction(i)}async edit(i,s,e,t){try{let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,s);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:i,...t})}catch{await this.reply(i,s,e,t)}}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(i){try{return await this.ct.answerCallbackQuery(i)}catch{return null}}async sessionSet(i,s,...e){try{let t={method:i,params:s,...e},o=await this.cacheSession.set(`${this.userid}`,{method:i,params:s,...e});return o&&(this.session=t),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(...s){let e=i(...s);return`${this.name}${e===void 0?"":`:${e}`}`}:function(){return this?.name}}}buildInlineKeyboard(i,s){let e=this.data.name;if(s?.cache===!0){let a=`${e}:${this.languageCode}:inline`,r=this.cacheKeyboard.get(a);if(!r){let d=new V,l=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"inline",s?.data),u=i(d,l);return this.cacheKeyboard.set(a,u),u}return r}let t=new V,o=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"inline",s?.data);return i(t,o)}buildKeyboard(i,s){let e=this.data.name;if(s?.cache===!0){let a=`${e}:${this.languageCode}:default`,r=this.cacheKeyboard.get(a);if(!r){let d=new _,l=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"default",s?.data),u=i(d,l);return u.resized(!0),this.cacheKeyboard.set(a,u),u}return r}let t=new _,o=this.templateManager.getKeyboard(e,s?.baseId,this.languageCode,"default",s?.data),n=i(t,o);return n.resized(),n}validateSessionCallback(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallback(s)}validateSessionCallbackPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallbackPayload(s)}validateSessionText(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodText(s)}validateSessionTextPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextPayload(s)}validateSessionTextCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommand(s)}validateSessionTextCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommandPayload(s)}validateSessionTextFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextFree(s)}validateSessionPhotoCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaption(s)}validateSessionPhotoCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionPayload(s)}validateSessionPhotoCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommand(s)}validateSessionPhotoCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommandPayload(s)}validateSessionPhotoFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoFree(s)}validateSessionVideoCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaption(s)}validateSessionVideoCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionPayload(s)}validateSessionVideoCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommand(s)}validateSessionVideoCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommandPayload(s)}validateSessionVideoFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoFree(s)}validateSessionAudioCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaption(s)}validateSessionAudioCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionPayload(s)}validateSessionAudioCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommand(s)}validateSessionAudioCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommandPayload(s)}validateSessionAudioFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioFree(s)}validateSessionDocumentCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaption(s)}validateSessionDocumentCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionPayload(s)}validateSessionDocumentCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommand(s)}validateSessionDocumentCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommandPayload(s)}validateSessionDocumentFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentFree(s)}validateSessionAnimationCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaption(s)}validateSessionAnimationCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionPayload(s)}validateSessionAnimationCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommand(s)}validateSessionAnimationCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommandPayload(s)}validateSessionAnimationFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationFree(s)}validateSessionVoiceCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaption(s)}validateSessionVoiceCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionPayload(s)}validateSessionVoiceCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommand(s)}validateSessionVoiceCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommandPayload(s)}validateSessionVoiceFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceFree(s)}validateSessionVideoNoteCaption(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaption(s)}validateSessionVideoNoteCaptionPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionPayload(s)}validateSessionVideoNoteCaptionCommand(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommand(s)}validateSessionVideoNoteCaptionCommandPayload(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommandPayload(s)}validateSessionVideoNoteFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteFree(s)}validateSessionStickerFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodStickerFree(s)}validateSessionLocationFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodLocationFree(s)}validateSessionContactFree(i,s){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodContactFree(s)}sessionCallback(i,s){return this.sessionSet(this.buildSessionMethodCallback(s),i)}sessionCallbackPayload(i,s){return this.sessionSet(this.buildSessionMethodCallbackPayload(s),i)}sessionText(i,s){return this.sessionSet(this.buildSessionMethodText(s),i)}sessionTextPayload(i,s){return this.sessionSet(this.buildSessionMethodTextPayload(s),i)}sessionTextCommand(i,s){return this.sessionSet(this.buildSessionMethodTextCommand(s),i)}sessionTextCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodTextCommandPayload(s),i)}sessionTextFree(i,s){return this.sessionSet(this.buildSessionMethodTextFree(s),i)}sessionPhotoCaption(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaption(s),i)}sessionPhotoCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaptionPayload(s),i)}sessionPhotoCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommand(s),i)}sessionPhotoCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommandPayload(s),i)}sessionPhotoFree(i,s){return this.sessionSet(this.buildSessionMethodPhotoFree(s),i)}sessionVideoCaption(i,s){return this.sessionSet(this.buildSessionMethodVideoCaption(s),i)}sessionVideoCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoCaptionPayload(s),i)}sessionVideoCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodVideoCaptionCommand(s),i)}sessionVideoCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoCaptionCommandPayload(s),i)}sessionVideoFree(i,s){return this.sessionSet(this.buildSessionMethodVideoFree(s),i)}sessionAudioCaption(i,s){return this.sessionSet(this.buildSessionMethodAudioCaption(s),i)}sessionAudioCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodAudioCaptionPayload(s),i)}sessionAudioCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodAudioCaptionCommand(s),i)}sessionAudioCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodAudioCaptionCommandPayload(s),i)}sessionAudioFree(i,s){return this.sessionSet(this.buildSessionMethodAudioFree(s),i)}sessionDocumentCaption(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaption(s),i)}sessionDocumentCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaptionPayload(s),i)}sessionDocumentCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommand(s),i)}sessionDocumentCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommandPayload(s),i)}sessionDocumentFree(i,s){return this.sessionSet(this.buildSessionMethodDocumentFree(s),i)}sessionAnimationCaption(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaption(s),i)}sessionAnimationCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaptionPayload(s),i)}sessionAnimationCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommand(s),i)}sessionAnimationCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommandPayload(s),i)}sessionAnimationFree(i,s){return this.sessionSet(this.buildSessionMethodAnimationFree(s),i)}sessionVoiceCaption(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaption(s),i)}sessionVoiceCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaptionPayload(s),i)}sessionVoiceCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommand(s),i)}sessionVoiceCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommandPayload(s),i)}sessionVoiceFree(i,s){return this.sessionSet(this.buildSessionMethodVoiceFree(s),i)}sessionVideoNoteCaption(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaption(s),i)}sessionVideoNoteCaptionPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionPayload(s),i)}sessionVideoNoteCaptionCommand(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommand(s),i)}sessionVideoNoteCaptionCommandPayload(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommandPayload(s),i)}sessionVideoNoteFree(i,s){return this.sessionSet(this.buildSessionMethodVideoNoteFree(s),i)}sessionStickerFree(i,s){return this.sessionSet(this.buildSessionMethodStickerFree(s),i)}sessionLocationFree(i,s){return this.sessionSet(this.buildSessionMethodLocationFree(s),i)}sessionContactFree(i,s){return this.sessionSet(this.buildSessionMethodContactFree(s),i)}sessionToCallback(i,s){return this.sessionCallback({...this.session.params,...i},s)}sessionToCallbackPayload(i,s){return this.sessionCallbackPayload({...this.session.params,...i},s)}sessionToText(i,s){return this.sessionText({...this.session.params,...i},s)}sessionToTextPayload(i,s){return this.sessionTextPayload({...this.session.params,...i},s)}sessionToTextCommand(i,s){return this.sessionTextCommand({...this.session.params,...i},s)}sessionToTextCommandPayload(i,s){return this.sessionTextCommandPayload({...this.session.params,...i},s)}sessionToTextFree(i,s){return this.sessionTextFree({...this.session.params,...i},s)}sessionToPhotoCaption(i,s){return this.sessionPhotoCaption({...this.session.params,...i},s)}sessionToPhotoCaptionPayload(i,s){return this.sessionPhotoCaptionPayload({...this.session.params,...i},s)}sessionToPhotoCaptionCommand(i,s){return this.sessionPhotoCaptionCommand({...this.session.params,...i},s)}sessionToPhotoCaptionCommandPayload(i,s){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...i},s)}sessionToPhotoFree(i,s){return this.sessionPhotoFree({...this.session.params,...i},s)}sessionToVideoCaption(i,s){return this.sessionVideoCaption({...this.session.params,...i},s)}sessionToVideoCaptionPayload(i,s){return this.sessionVideoCaptionPayload({...this.session.params,...i},s)}sessionToVideoCaptionCommand(i,s){return this.sessionVideoCaptionCommand({...this.session.params,...i},s)}sessionToVideoCaptionCommandPayload(i,s){return this.sessionVideoCaptionCommandPayload({...this.session.params,...i},s)}sessionToVideoFree(i,s){return this.sessionVideoFree({...this.session.params,...i},s)}sessionToAudioCaption(i,s){return this.sessionAudioCaption({...this.session.params,...i},s)}sessionToAudioCaptionPayload(i,s){return this.sessionAudioCaptionPayload({...this.session.params,...i},s)}sessionToAudioCaptionCommand(i,s){return this.sessionAudioCaptionCommand({...this.session.params,...i},s)}sessionToAudioCaptionCommandPayload(i,s){return this.sessionAudioCaptionCommandPayload({...this.session.params,...i},s)}sessionToAudioFree(i,s){return this.sessionAudioFree({...this.session.params,...i},s)}sessionToDocumentCaption(i,s){return this.sessionDocumentCaption({...this.session.params,...i},s)}sessionToDocumentCaptionPayload(i,s){return this.sessionDocumentCaptionPayload({...this.session.params,...i},s)}sessionToDocumentCaptionCommand(i,s){return this.sessionDocumentCaptionCommand({...this.session.params,...i},s)}sessionToDocumentCaptionCommandPayload(i,s){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...i},s)}sessionToDocumentFree(i,s){return this.sessionDocumentFree({...this.session.params,...i},s)}sessionToAnimationCaption(i,s){return this.sessionAnimationCaption({...this.session.params,...i},s)}sessionToAnimationCaptionPayload(i,s){return this.sessionAnimationCaptionPayload({...this.session.params,...i},s)}sessionToAnimationCaptionCommand(i,s){return this.sessionAnimationCaptionCommand({...this.session.params,...i},s)}sessionToAnimationCaptionCommandPayload(i,s){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...i},s)}sessionToAnimationFree(i,s){return this.sessionAnimationFree({...this.session.params,...i},s)}sessionToVoiceCaption(i,s){return this.sessionVoiceCaption({...this.session.params,...i},s)}sessionToVoiceCaptionPayload(i,s){return this.sessionVoiceCaptionPayload({...this.session.params,...i},s)}sessionToVoiceCaptionCommand(i,s){return this.sessionVoiceCaptionCommand({...this.session.params,...i},s)}sessionToVoiceCaptionCommandPayload(i,s){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...i},s)}sessionToVoiceFree(i,s){return this.sessionVoiceFree({...this.session.params,...i},s)}sessionToVideoNoteCaption(i,s){return this.sessionVideoNoteCaption({...this.session.params,...i},s)}sessionToVideoNoteCaptionPayload(i,s){return this.sessionVideoNoteCaptionPayload({...this.session.params,...i},s)}sessionToVideoNoteCaptionCommand(i,s){return this.sessionVideoNoteCaptionCommand({...this.session.params,...i},s)}sessionToVideoNoteCaptionCommandPayload(i,s){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...i},s)}sessionToVideoNoteFree(i,s){return this.sessionVideoNoteFree({...this.session.params,...i},s)}sessionToStickerFree(i,s){return this.sessionStickerFree({...this.session.params,...i},s)}sessionToLocationFree(i,s){return this.sessionLocationFree({...this.session.params,...i},s)}sessionToContactFree(i,s){return this.sessionContactFree({...this.session.params,...i},s)}buildIntent(i,s=!0){i||(i=s?this.data.callbackData():this.data.name);let e=s?":":" ";return i?.indexOf?.(e)!=-1?i?.split?.(e)?.[0]:i}buildSessionMethod(i,s){return`${i}-${s||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 q}from"bun";import{join as D,parse as I}from"path";import{LoggingPretty as X}from"logging-pretty";var C=class{static{c(this,"TemplateEngine")}static _escape(i){return i.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(i){return i.replace(/\{\{(\w+)\}\}/g,(s,e)=>`\${(data && data["${e}"]) ?? ""}`)}static _processBaseBlocks(i){let s=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,e={};for(let t of i.matchAll(s)){let o=t[2]??"default",a=(t[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,(s,e)=>{let t=e.trim();return t?`\${(() => { if (!data) return ''; try { with(data) { ${t} } } 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,(s,e)=>e.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMessageBlocks(i){let s=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,e={};for(let[,t,o]of i.matchAll(s)){let n=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[t]=n}return e}static _processKeyboardBlocks(i){let s=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\sfor="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,e={};for(let[,t,o,n]of i.matchAll(s)){let a=o==="default"?"default":"inline",r=n.trim();e[t]||(e[t]={}),e[t][a]=r}return e}static _compileToFunction(i,s){let e;s?e=i.map(n=>`\`${n}\``).join(","):e=`\`${i}\``;let t=e;if(t=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(t))),s){let o=`return [${t}]`;return new Function("data",o)}else{let o=`return ${t}`;return new Function("data",o)}}static compileMessages(i){let s=this._processBaseBlocks(i),e={};for(let[t,o]of Object.entries(s)){let n=this._processMessageBlocks(o);e[t]={};for(let[a,r]of Object.entries(n)){let d=this._processVariables(this._processScriptBlocks(r));e[t][a]=this._compileToFunction(d,!1)}}return e}static compileKeyboards(i){let s=this._processBaseBlocks(i),e={};for(let[t,o]of Object.entries(s)){let n=this._processKeyboardBlocks(o);e[t]={};for(let[a,r]of Object.entries(n)){e[t][a]={};for(let[d,l]of Object.entries(r)){let g=l.split(/(?<!\\),\s*/).map(m=>m.replace(/\\,/g,",").trim()).map(m=>this._processVariables(this._processScriptBlocks(m)));e[t][a][d]=this._compileToFunction(g,!0)}}}return e}};import{readFile as W,mkdir as j}from"fs/promises";import{watch as Q}from"chokidar";import{basename as x,join as w,extname as z}from"path";import{readdirSync as G,readFileSync as U,existsSync as A,statSync as H,writeFileSync as J}from"fs";var M=class{static{c(this,"TemplateManager")}_map=new Map;_engine=C;_watcher=null;_supportedExtensions=new Set([".html"]);_path;_forceLanguage;_isWatchEnabled;constructor(i={}){let{enableWatch:s=!1,path:e=null,forceLanguage:t=null}=i;this._path=e,this._forceLanguage=t,this._isWatchEnabled=s,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(this._path===null||!A(this._path))return;if(!H(this._path).isDirectory())throw new Error(`Template path is not a directory: ${this._path}`)}catch(i){throw new Error(`Failed to validate Template path: ${i}`)}}_initializeWatcher(){this._path===null||!this._isWatchEnabled||(this._watcher=Q(this._path,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}}),this._watcher.on("change",this._handleFileChange.bind(this)),this._watcher.on("add",this._handleFileAdd.bind(this)),this._watcher.on("unlink",this._handleFileDelete.bind(this)),this._watcher.on("error",this._handleWatchError.bind(this)))}async _handleFileChange(i){let s=x(i);this._isValidFile(s)&&await this._loadFile(s,!1)}async _handleFileAdd(i){let s=x(i);this._isValidFile(s)&&await this._loadFile(s,!1)}_handleFileDelete(i){let s=x(i),e=this._getKey(s);this._map.has(e)&&this._map.delete(e)}_handleWatchError(i){}_loadAllFiles(){if(this._path===null||!A(this._path))return;let s=G(this._path,{encoding:"utf8"}).filter(e=>this._isValidFile(e));for(let e of s)this._loadFile(e,!0)}async _loadFile(i,s=!0){if(this._path===null)return;let e=w(this._path,i),t=this._getKey(i),o=s?U(e,{encoding:"utf8"}):await W(e,{encoding:"utf8"});this.compile(t,o)}_isValidFile(i){let s=z(i).toLowerCase();return this._supportedExtensions.has(s)}_getKey(i){return i.replace(/\.[^/.]+$/,"")}compile(i,s,e){let t=this._map.get(i),o=t||{},n=!1;(e===void 0||e?.message===!1||t?.message===void 0)&&(o.message=C.compileMessages(s),n=!0),(e===void 0||e?.keyboard===!1||t?.keyboard===void 0)&&(o.keyboard=C.compileKeyboards(s),n=!0),n&&this._map.set(i,o)}getMessage(i,s="default",e="en",t){let n=this._map.get(i)?.message?.[s]?.[this._forceLanguage||e];if(!n)return"";try{return n(t)}catch{return""}}getKeyboard(i,s="default",e="en",t="inline",o){let a=this._map.get(i)?.keyboard?.[s]?.[this._forceLanguage||e]?.[t];if(!a)return[];try{return a(o)}catch{return[]}}setMessage(i,s){this.compile(i,s,{keyboard:!0})}setKeyboard(i,s){this.compile(i,s,{message:!0})}async write(i,s){if(this._path===null)return;let e=w(this._path,i);await j(this._path,{recursive:!0}),J(e,s,{encoding:"utf8"}),await this._loadFile(i,!1)}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,s)=>typeof s=="function"?s.toString():s).length}}async destroy(){this._watcher&&await this._watcher.close(),this._map.clear()}};import{existsSync as Y,readdirSync as Z}from"fs";import{Bot as ii,webhookCallback as si}from"grammy";var N=class{static{c(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;ctx;bot;constructor(i){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 M({path:null}),this.ctx=this.createCtx(),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,s,e){let{username:t}=i;s=="polling"?this.log?.success?.(`Telegram bot polling started: ${t}`):this.log?.success?.(`Telegram bot webhook started: ${t} (${e})`)}createBot(i){return new ii(i)}createCtx(){return new P({ct:{},cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}refreshCtx(i){return this.ctx.ct=i,this.ctx.temp={session:{},data:{}},this.ctx}async runPolling(){this.bot.start({onStart:c(async i=>{this.onStart(i,"polling",null)},"onStart")})}async runWebhook(i){let s=si(this.bot,"bun"),e="/telegram-webhook";q({fetch(a){let{pathname:r}=new URL(a.url);if(r===e)return a.method==="POST"?s(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 t=await this.bot.api.getWebhookInfo(),o=i.endsWith("/")?i.slice(0,-1)+e:i+e;t.url!=o&&await this.bot.api.setWebhook(o);let n=await this.bot.api.getMe();this.onStart(n,"webhook",o)}pageCompile(i,s=!0){i?.template!==void 0?(this.templateManager.compile(i.data.name,i.template),s&&(i.template=void 0)):i.template=void 0}pageBuildData(i,s){i?.data===void 0&&(i.data=i.buildData()),i.data.name=I(s).name}pageSorts(i,s){let e=i.data.name,t=i.prototype,o="Payload",n="Command",a="Caption",r="Free",d=s.dynamic,l=s.dynamicSpesific,u=c(p=>p.charAt(0).toUpperCase()+p.slice(1),"upFirst"),g=c(p=>p.replace(o,"").replace(n,"").replace(a,"").replace(r,""),"getPureFuncName"),m=c((p,b)=>t[`buildSessionMethod${u(p)}`](b),"buildSessionMethod");s.all[e]=i;for(let p=0;p<s.lenListFuncStaticSession;p++){let b=s.listFuncStaticSession[p],y=s.static[b],K=s.staticIntent[b],F=s.staticSession[b],v={name:e,func:b},k=y||K;if(k!==void 0){let $=b.includes(n)?`/${e}`:e;k[t.buildIntent($,b.startsWith("callback"))]=v}F!==void 0&&(F[m(b,e)]=v),b.toLowerCase().endsWith("free")&&l[g(b)].push(v)}t.free&&d.push(e)}pageLoads(){this.log?.info?.("Load pages..");let i=D(process.cwd(),"src","pages");if(!Y(i))throw new Error(`Folder ${i} is not found, please make it manually`);let s=Z(i),e={},t=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=c((g,m)=>Object.fromEntries(g.map(p=>[p,{...m}])),"makeObject"),u={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,t),staticSession:l(d,o),listFuncStatic:a,listFuncStaticIntent:r,listFuncStaticSession:d,lenListFuncStatic:a.length,lenListFuncStaticIntent:r.length,lenListFuncStaticSession:d.length};for(let g of s){let m=D(i,g),p=T(m),y=Object.values(p)[0];if(y===void 0)throw`file ${I(m).name} must have export (not default) class page`;this.pageBuildData(y,m),this.pageCompile(y),this.pageSorts(y,u)}return this.log?.info?.(`Finish load pages with total (${Object.keys(u.all).length})`),u}async pageRoutes(i,s){let e,t;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 u=this.pages.listFuncStatic[l];if(t=d[u][n||a||r],t)break}t!==void 0&&(e=this.pages.all[t.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(t=r[l][a],t)break}t!==void 0&&(e=this.pages.all[t.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 u=this.pages.listFuncStaticIntent[l];if(t=d[u][n||a||r],t)break}t!==void 0&&(e=this.pages.all[t.name])}if(e!==void 0&&t!==void 0)return await new e(i)[t.func]?.();let o=this.pages.dynamicSpesific[s]||[];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,s){return!0}async hookErrorPage(i,s,e,t){}async hookErrorInputNotFoundPage(i){}async onMessage(i,s){let e=this.refreshCtx(i);try{if(await this.hookBeforeRoute(e,s)===!1)return;await this.pageRoutes(e,s)===null&&await this.hookErrorInputNotFoundPage(e)}catch(t){await this.hookErrorPage(e,s,t,!1)}}async onCallbackQueryData(i){let s=this.refreshCtx(i);try{if(await s.callbackQueryAnswer(),await this.hookBeforeRoute(s,"onCallbackQueryData")===!1)return;await this.pageRoutes(s,"callback")}catch(e){await this.hookErrorPage(s,"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{f as BaseGeneral,S as CacheExternal,P as Ctx,N as Gramstax,C as TemplateEngine,M as TemplateManager};
|