gramstax 0.0.27 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +25 -25
- package/dist/src/index.cjs +1 -1
- package/dist/src/index.d.cts +194 -203
- package/dist/src/index.d.ts +194 -203
- package/dist/src/index.js +1 -1
- package/package.json +9 -1
package/LICENSE
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
MIT License (with Fair Donation Clause)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Gramstax
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following condition:
|
|
11
|
-
|
|
12
|
-
If this Software is used in any commercial, revenue-generating, or
|
|
13
|
-
client-based project (including freelance, agency, or product development),
|
|
14
|
-
users are encouraged—but not legally required—to make a fair donation
|
|
15
|
-
to support the ongoing development and maintenance of this Software.
|
|
16
|
-
|
|
17
|
-
Donations can be made through: [your donation link here]
|
|
18
|
-
|
|
19
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
-
THE SOFTWARE.
|
|
1
|
+
MIT License (with Fair Donation Clause)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Gramstax
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following condition:
|
|
11
|
+
|
|
12
|
+
If this Software is used in any commercial, revenue-generating, or
|
|
13
|
+
client-based project (including freelance, agency, or product development),
|
|
14
|
+
users are encouraged—but not legally required—to make a fair donation
|
|
15
|
+
to support the ongoing development and maintenance of this Software.
|
|
16
|
+
|
|
17
|
+
Donations can be made through: [your donation link here]
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
THE SOFTWARE.
|
package/dist/src/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var G=Object.create;var v=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,X=Object.prototype.hasOwnProperty;var m=(p,t)=>v(p,"name",{value:t,configurable:!0});var Y=(p,t)=>{for(var e in t)v(p,e,{get:t[e],enumerable:!0})},R=(p,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of J(t))!X.call(p,s)&&s!==e&&v(p,s,{get:()=>t[s],enumerable:!(i=H(t,s))||i.enumerable});return p};var Z=(p,t,e)=>(e=p!=null?G(q(p)):{},R(t||!p||!p.__esModule?v(e,"default",{value:p,enumerable:!0}):e,p)),tt=p=>R(v({},"__esModule",{value:!0}),p);var et={};Y(et,{BaseGeneral:()=>I,CacheExternal:()=>x,Ctx:()=>M,Gramstax:()=>D,TemplateEngine:()=>f,TemplateManager:()=>k});module.exports=tt(et);var N=require("logging-pretty");var I=class{static{m(this,"BaseGeneral")}static log=new N.LoggingPretty;static logError(t,e){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${e}]: ${String(t)}`)}logError(t,e,i){this.constructor.log.error(`[${e||this.constructor.name}:${i}] ${String(t)}`)}};var K=require("keyv"),B=Z(require("@keyv/redis"),1);var x=class extends K.Keyv{constructor(e="memory",i,s,n){let o;e.startsWith("redis")&&(o=new B.default(e)),e==="memory"&&(o=new Map),n?.forceStore&&(o=n.forceStore);super({store:o,namespace:i,ttl:s});this.url=e}static{m(this,"CacheExternal")}};var E=require("timers/promises");var S=require("grammy");var M=class extends I{static{m(this,"Ctx")}static template;static data;data=this.constructor.data;get isPremium(){return this.ct.from?.is_premium??!1}get isBot(){return this.ct.from?.is_bot??!1}get userid(){return this.ct.from?.id}get username(){return this.ct.from?.username}get fullname(){return`${this.ct.from?.first_name||""}${this.ct.from?.last_name||""}`}get firstname(){return this.ct.from?.first_name}get lastname(){return this.ct.from?.last_name}get msgText(){return this.ct.message?.text}get msgTextIntent(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ")[0]:""}get msgTextPayloads(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ").slice(1):[]}get msgTextPayload(){return this.msgTextPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionIntent(){return this.msgCaption&&this.msgCaption.indexOf(" ")!=-1?this.msgCaption.split(" ")[0]:""}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataIntent(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":")[0]:""}get callbackDataPayloads(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":").slice(1):[]}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}get callbackDataParts(){return this.callbackDataPayload&&this.callbackDataPayload.indexOf("+")!=-1?this.callbackDataPayload.split("+"):[]}get languageCode(){return this.ct.from?.language_code}set languageCode(t){this.ct.from.language_code=t}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){super(),this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp}async broadcast(t,e,i,s,n,o){let r=e.map(c=>this.templateManager.getMessage(this.data.name,n,c,s));for(let c=0;c<t.length;c++){let d=t[c],l=r[c];await this.ct.api.sendMessage(d,l,{parse_mode:"HTML",reply_markup:i,...o}),c+1==30&&await(0,E.setTimeout)(1200)}}async reply(t,e,i,s){let n=this.templateManager.getMessage(this.data.name,i,this.languageCode,e);return await this.ct.reply(n,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,e,i,s,n){let o=this.templateManager.getMedia(this.data.name,s,this.languageCode,i),a={parse_mode:"HTML",reply_markup:e,...n};if(t=="photo")return await this.ct.replyWithPhoto(o.src,{caption:o.caption,...a});if(t=="video")return await this.ct.replyWithVideo(o.src,{caption:o.caption,...a});if(t=="audio")return await this.ct.replyWithAudio(o.src,{caption:o.caption,...a});if(t=="document")return await this.ct.replyWithDocument(o.src,{caption:o.caption,...a});if(t=="animation")return await this.ct.replyWithAnimation(o.src,{caption:o.caption,...a});if(t=="voice")return await this.ct.replyWithVoice(o.src,a);if(t=="video_note")return await this.ct.replyWithVideoNote(o.src,a);if(t=="sticker")return await this.ct.replyWithSticker(o.src,a);if(t=="location")return await this.ct.replyWithLocation(o.latitude,o.longitude,a);if(t=="contact")return await this.ct.replyWithContact(o.phone,o.first_name,{vcard:o.vcard,...a})}async replyPhoto(t,e,i,s){return this.replyMedia("photo",t,e,i,s)}async replyVideo(t,e,i,s){return this.replyMedia("video",t,e,i,s)}async replyAudio(t,e,i,s){return this.replyMedia("audio",t,e,i,s)}async replyDocument(t,e,i,s){return this.replyMedia("document",t,e,i,s)}async replyAnimation(t,e,i,s){return this.replyMedia("animation",t,e,i,s)}async replyVoice(t,e,i,s){return this.replyMedia("voice",t,e,i,s)}async replyVideoNote(t,e,i,s){return this.replyMedia("video_note",t,e,i,s)}async replySticker(t,e,i,s){return this.replyMedia("sticker",t,e,i,s)}async replyLocation(t,e,i,s){return this.replyMedia("location",t,e,i,s)}async replyContact(t,e,i,s){return this.replyMedia("contact",t,e,i,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,e,i,s,n=!0){try{let o=this.templateManager.getMessage(this.data.name,i,this.languageCode,e);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:t,...s})}catch(o){if(n)await this.reply(t,e,i,s);else throw o}}async editMedia(t,e,i,s,n,o,a=!0){try{let{src:r,caption:c}=this.templateManager.getMedia(this.data.name,s,this.languageCode,i);return t=="voice"?(await this.delete(),await this.replyVoice(e,i,s,n)):t=="video_note"?(await this.delete(),await this.replyVoice(e,i,s,n)):t=="sticker"?(await this.delete(),await this.replySticker(e,i,s,n)):t=="location"?(await this.delete(),await this.replyLocation(e,i,s,n)):t=="contact"?(await this.delete(),await this.replyContact(e,i,s,n)):await this.ct.editMessageMedia({media:r,caption:c,type:t,parse_mode:"HTML",...n},{reply_markup:e,...o})}catch(r){if(a===!0)await this.reply(e,i,s,o);else throw r}}async editPhoto(t,e,i,s,n){return await this.editMedia("photo",t,e,i,s,n)}async editVideo(t,e,i,s,n){return await this.editMedia("video",t,e,i,s,n)}async editAudio(t,e,i,s,n){return await this.editMedia("audio",t,e,i,s,n)}async editDocument(t,e,i,s,n){return await this.editMedia("document",t,e,i,s,n)}async editAnimation(t,e,i,s,n){return await this.editMedia("animation",t,e,i,s,n)}async editVoice(t,e,i,s){return await this.editMedia("voice",t,e,i,s)}async editVideoNote(t,e,i,s){return await this.editMedia("video_note",t,e,i,s)}async editSticker(t,e,i,s){return await this.editMedia("sticker",t,e,i,s)}async editLocation(t,e,i,s){return await this.editMedia("location",t,e,i,s)}async editContact(t,e,i,s){return await this.editMedia("contact",t,e,i,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,e,i){try{let s={method:t,params:e,...i},n=await this.cacheSession.set(`${this.userid}`,s);return n&&(this.session=s),n}catch{return null}}async sessionGet(){try{let t=await this.cacheSession.get(`${this.userid}`);return t&&(this.session=t),t||null}catch{return null}}async sessionClear(){try{let t=await this.cacheSession.delete(`${this.userid}`);return t&&(this.session={}),t}catch{return null}}static buildData(t){return{name:"",callbackData:t?function(...e){let i=t(...e);return`${this.name}${i===void 0?"":`:${i}`}`}:function(){return this?.name}}}inlineKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.languageCode}:i`,r=this.cacheKeyboard.get(a);if(!r){let c=new S.InlineKeyboard,d=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"inline",e?.data),l=t(c,d);return this.cacheKeyboard.set(a,l),l}return r}let s=new S.InlineKeyboard,n=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"inline",e?.data);return t(s,n)}bottomKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.languageCode}:b`,r=this.cacheKeyboard.get(a);if(!r){let c=new S.Keyboard,d=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"bottom",e?.data),l=t(c,d);return l.resized(!0),this.cacheKeyboard.set(a,l),l}return r}let s=new S.Keyboard,n=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"bottom",e?.data),o=t(s,n);return o.resized(),o}validateSessionCallback(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallback(e)}validateSessionCallbackPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallbackPayload(e)}validateSessionText(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionText(e)}validateSessionTextPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextPayload(e)}validateSessionTextCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommand(e)}validateSessionTextCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommandPayload(e)}validateSessionTextFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextFree(e)}validateSessionPhotoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaption(e)}validateSessionPhotoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionPayload(e)}validateSessionPhotoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommand(e)}validateSessionPhotoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommandPayload(e)}validateSessionPhotoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoFree(e)}validateSessionVideoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaption(e)}validateSessionVideoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionPayload(e)}validateSessionVideoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommand(e)}validateSessionVideoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommandPayload(e)}validateSessionVideoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoFree(e)}validateSessionAudioCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaption(e)}validateSessionAudioCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionPayload(e)}validateSessionAudioCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommand(e)}validateSessionAudioCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommandPayload(e)}validateSessionAudioFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioFree(e)}validateSessionDocumentCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaption(e)}validateSessionDocumentCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionPayload(e)}validateSessionDocumentCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommand(e)}validateSessionDocumentCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommandPayload(e)}validateSessionDocumentFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentFree(e)}validateSessionAnimationCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaption(e)}validateSessionAnimationCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionPayload(e)}validateSessionAnimationCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommand(e)}validateSessionAnimationCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommandPayload(e)}validateSessionAnimationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationFree(e)}validateSessionVoiceCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaption(e)}validateSessionVoiceCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionPayload(e)}validateSessionVoiceCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommand(e)}validateSessionVoiceCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommandPayload(e)}validateSessionVoiceFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceFree(e)}validateSessionVideoNoteCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaption(e)}validateSessionVideoNoteCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionPayload(e)}validateSessionVideoNoteCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommand(e)}validateSessionVideoNoteCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommandPayload(e)}validateSessionVideoNoteFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteFree(e)}validateSessionStickerFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionStickerFree(e)}validateSessionLocationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionLocationFree(e)}validateSessionContactFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionContactFree(e)}sessionCallback(t,e){return this.sessionSet(this.methodSessionCallback(e),t)}sessionCallbackPayload(t,e){return this.sessionSet(this.methodSessionCallbackPayload(e),t)}sessionText(t,e){return this.sessionSet(this.methodSessionText(e),t)}sessionTextPayload(t,e){return this.sessionSet(this.methodSessionTextPayload(e),t)}sessionTextCommand(t,e){return this.sessionSet(this.methodSessionTextCommand(e),t)}sessionTextCommandPayload(t,e){return this.sessionSet(this.methodSessionTextCommandPayload(e),t)}sessionTextFree(t,e){return this.sessionSet(this.methodSessionTextFree(e),t)}sessionPhotoCaption(t,e){return this.sessionSet(this.methodSessionPhotoCaption(e),t)}sessionPhotoCaptionPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionPayload(e),t)}sessionPhotoCaptionCommand(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommand(e),t)}sessionPhotoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommandPayload(e),t)}sessionPhotoFree(t,e){return this.sessionSet(this.methodSessionPhotoFree(e),t)}sessionVideoCaption(t,e){return this.sessionSet(this.methodSessionVideoCaption(e),t)}sessionVideoCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionPayload(e),t)}sessionVideoCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommand(e),t)}sessionVideoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommandPayload(e),t)}sessionVideoFree(t,e){return this.sessionSet(this.methodSessionVideoFree(e),t)}sessionAudioCaption(t,e){return this.sessionSet(this.methodSessionAudioCaption(e),t)}sessionAudioCaptionPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionPayload(e),t)}sessionAudioCaptionCommand(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommand(e),t)}sessionAudioCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommandPayload(e),t)}sessionAudioFree(t,e){return this.sessionSet(this.methodSessionAudioFree(e),t)}sessionDocumentCaption(t,e){return this.sessionSet(this.methodSessionDocumentCaption(e),t)}sessionDocumentCaptionPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionPayload(e),t)}sessionDocumentCaptionCommand(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommand(e),t)}sessionDocumentCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommandPayload(e),t)}sessionDocumentFree(t,e){return this.sessionSet(this.methodSessionDocumentFree(e),t)}sessionAnimationCaption(t,e){return this.sessionSet(this.methodSessionAnimationCaption(e),t)}sessionAnimationCaptionPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionPayload(e),t)}sessionAnimationCaptionCommand(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommand(e),t)}sessionAnimationCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommandPayload(e),t)}sessionAnimationFree(t,e){return this.sessionSet(this.methodSessionAnimationFree(e),t)}sessionVoiceCaption(t,e){return this.sessionSet(this.methodSessionVoiceCaption(e),t)}sessionVoiceCaptionPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionPayload(e),t)}sessionVoiceCaptionCommand(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommand(e),t)}sessionVoiceCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommandPayload(e),t)}sessionVoiceFree(t,e){return this.sessionSet(this.methodSessionVoiceFree(e),t)}sessionVideoNoteCaption(t,e){return this.sessionSet(this.methodSessionVideoNoteCaption(e),t)}sessionVideoNoteCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionPayload(e),t)}sessionVideoNoteCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommand(e),t)}sessionVideoNoteCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommandPayload(e),t)}sessionVideoNoteFree(t,e){return this.sessionSet(this.methodSessionVideoNoteFree(e),t)}sessionStickerFree(t,e){return this.sessionSet(this.methodSessionStickerFree(e),t)}sessionLocationFree(t,e){return this.sessionSet(this.methodSessionLocationFree(e),t)}sessionContactFree(t,e){return this.sessionSet(this.methodSessionContactFree(e),t)}sessionToCallback(t,e){return this.sessionCallback({...this.session.params,...t},e)}sessionToCallbackPayload(t,e){return this.sessionCallbackPayload({...this.session.params,...t},e)}sessionToText(t,e){return this.sessionText({...this.session.params,...t},e)}sessionToTextPayload(t,e){return this.sessionTextPayload({...this.session.params,...t},e)}sessionToTextCommand(t,e){return this.sessionTextCommand({...this.session.params,...t},e)}sessionToTextCommandPayload(t,e){return this.sessionTextCommandPayload({...this.session.params,...t},e)}sessionToTextFree(t,e){return this.sessionTextFree({...this.session.params,...t},e)}sessionToPhotoCaption(t,e){return this.sessionPhotoCaption({...this.session.params,...t},e)}sessionToPhotoCaptionPayload(t,e){return this.sessionPhotoCaptionPayload({...this.session.params,...t},e)}sessionToPhotoCaptionCommand(t,e){return this.sessionPhotoCaptionCommand({...this.session.params,...t},e)}sessionToPhotoCaptionCommandPayload(t,e){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...t},e)}sessionToPhotoFree(t,e){return this.sessionPhotoFree({...this.session.params,...t},e)}sessionToVideoCaption(t,e){return this.sessionVideoCaption({...this.session.params,...t},e)}sessionToVideoCaptionPayload(t,e){return this.sessionVideoCaptionPayload({...this.session.params,...t},e)}sessionToVideoCaptionCommand(t,e){return this.sessionVideoCaptionCommand({...this.session.params,...t},e)}sessionToVideoCaptionCommandPayload(t,e){return this.sessionVideoCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoFree(t,e){return this.sessionVideoFree({...this.session.params,...t},e)}sessionToAudioCaption(t,e){return this.sessionAudioCaption({...this.session.params,...t},e)}sessionToAudioCaptionPayload(t,e){return this.sessionAudioCaptionPayload({...this.session.params,...t},e)}sessionToAudioCaptionCommand(t,e){return this.sessionAudioCaptionCommand({...this.session.params,...t},e)}sessionToAudioCaptionCommandPayload(t,e){return this.sessionAudioCaptionCommandPayload({...this.session.params,...t},e)}sessionToAudioFree(t,e){return this.sessionAudioFree({...this.session.params,...t},e)}sessionToDocumentCaption(t,e){return this.sessionDocumentCaption({...this.session.params,...t},e)}sessionToDocumentCaptionPayload(t,e){return this.sessionDocumentCaptionPayload({...this.session.params,...t},e)}sessionToDocumentCaptionCommand(t,e){return this.sessionDocumentCaptionCommand({...this.session.params,...t},e)}sessionToDocumentCaptionCommandPayload(t,e){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...t},e)}sessionToDocumentFree(t,e){return this.sessionDocumentFree({...this.session.params,...t},e)}sessionToAnimationCaption(t,e){return this.sessionAnimationCaption({...this.session.params,...t},e)}sessionToAnimationCaptionPayload(t,e){return this.sessionAnimationCaptionPayload({...this.session.params,...t},e)}sessionToAnimationCaptionCommand(t,e){return this.sessionAnimationCaptionCommand({...this.session.params,...t},e)}sessionToAnimationCaptionCommandPayload(t,e){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...t},e)}sessionToAnimationFree(t,e){return this.sessionAnimationFree({...this.session.params,...t},e)}sessionToVoiceCaption(t,e){return this.sessionVoiceCaption({...this.session.params,...t},e)}sessionToVoiceCaptionPayload(t,e){return this.sessionVoiceCaptionPayload({...this.session.params,...t},e)}sessionToVoiceCaptionCommand(t,e){return this.sessionVoiceCaptionCommand({...this.session.params,...t},e)}sessionToVoiceCaptionCommandPayload(t,e){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...t},e)}sessionToVoiceFree(t,e){return this.sessionVoiceFree({...this.session.params,...t},e)}sessionToVideoNoteCaption(t,e){return this.sessionVideoNoteCaption({...this.session.params,...t},e)}sessionToVideoNoteCaptionPayload(t,e){return this.sessionVideoNoteCaptionPayload({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommand(t,e){return this.sessionVideoNoteCaptionCommand({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommandPayload(t,e){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoNoteFree(t,e){return this.sessionVideoNoteFree({...this.session.params,...t},e)}sessionToStickerFree(t,e){return this.sessionStickerFree({...this.session.params,...t},e)}sessionToLocationFree(t,e){return this.sessionLocationFree({...this.session.params,...t},e)}sessionToContactFree(t,e){return this.sessionContactFree({...this.session.params,...t},e)}intent(t,e=!0){t||(t=e?this.data.callbackData():this.data.name);let i=e?":":" ";return t?.indexOf?.(i)!=-1?t?.split?.(i)?.[0]:t}methodSession(t,e){return`${t}-${e||this.data.name}`}methodSessionCallback(t){return this.methodSession("1",t)}methodSessionCallbackPayload(t){return this.methodSession("2",t)}methodSessionText(t){return this.methodSession("3",t)}methodSessionTextPayload(t){return this.methodSession("4",t)}methodSessionTextCommand(t){return this.methodSession("5",t)}methodSessionTextCommandPayload(t){return this.methodSession("6",t)}methodSessionTextFree(t){return this.methodSession("7",t)}methodSessionPhotoCaption(t){return this.methodSession("8",t)}methodSessionPhotoCaptionPayload(t){return this.methodSession("9",t)}methodSessionPhotoCaptionCommand(t){return this.methodSession("10",t)}methodSessionPhotoCaptionCommandPayload(t){return this.methodSession("11",t)}methodSessionPhotoFree(t){return this.methodSession("12",t)}methodSessionVideoCaption(t){return this.methodSession("13",t)}methodSessionVideoCaptionPayload(t){return this.methodSession("14",t)}methodSessionVideoCaptionCommand(t){return this.methodSession("15",t)}methodSessionVideoCaptionCommandPayload(t){return this.methodSession("16",t)}methodSessionVideoFree(t){return this.methodSession("17",t)}methodSessionAudioCaption(t){return this.methodSession("18",t)}methodSessionAudioCaptionPayload(t){return this.methodSession("19",t)}methodSessionAudioCaptionCommand(t){return this.methodSession("20",t)}methodSessionAudioCaptionCommandPayload(t){return this.methodSession("21",t)}methodSessionAudioFree(t){return this.methodSession("22",t)}methodSessionDocumentCaption(t){return this.methodSession("23",t)}methodSessionDocumentCaptionPayload(t){return this.methodSession("24",t)}methodSessionDocumentCaptionCommand(t){return this.methodSession("25",t)}methodSessionDocumentCaptionCommandPayload(t){return this.methodSession("26",t)}methodSessionDocumentFree(t){return this.methodSession("27",t)}methodSessionAnimationCaption(t){return this.methodSession("28",t)}methodSessionAnimationCaptionPayload(t){return this.methodSession("29",t)}methodSessionAnimationCaptionCommand(t){return this.methodSession("30",t)}methodSessionAnimationCaptionCommandPayload(t){return this.methodSession("31",t)}methodSessionAnimationFree(t){return this.methodSession("32",t)}methodSessionVoiceCaption(t){return this.methodSession("33",t)}methodSessionVoiceCaptionPayload(t){return this.methodSession("34",t)}methodSessionVoiceCaptionCommand(t){return this.methodSession("35",t)}methodSessionVoiceCaptionCommandPayload(t){return this.methodSession("36",t)}methodSessionVoiceFree(t){return this.methodSession("37",t)}methodSessionVideoNoteCaption(t){return this.methodSession("38",t)}methodSessionVideoNoteCaptionPayload(t){return this.methodSession("39",t)}methodSessionVideoNoteCaptionCommand(t){return this.methodSession("40",t)}methodSessionVideoNoteCaptionCommandPayload(t){return this.methodSession("41",t)}methodSessionVideoNoteFree(t){return this.methodSession("42",t)}methodSessionStickerFree(t){return this.methodSession("43",t)}methodSessionLocationFree(t){return this.methodSession("44",t)}methodSessionContactFree(t){return this.methodSession("45",t)}};var W=require("bun");var _=require("path"),w=require("fs");var P=class{static{m(this,"HelperPage")}static getPath(){return(0,_.join)(process.cwd(),"src","pages")}static _getPage(t,e,i=!0){let n=Object.values(t)[0];if(n===void 0)throw new Error(`File ${e} must have export (not default) class page`);return i===!0&&(n.template=void 0),n}static getPageSync(t,e=!0){t||(t=this.getPath());let i=require(t);return this._getPage(i,t,e)}static async getPage(t,e=!0){t||(t=this.getPath());let i=await import(`${t}?t=${Date.now()}`);return this._getPage(i,t,e)}static getPagesSync(t,e=!0){if(t||(t=this.getPath()),!(0,w.existsSync)(t))throw new Error(`Directory ${t} is not found, please make it manually`);return(0,w.readdirSync)(t).map(s=>{let n=(0,_.join)(t,s);return{path:n,page:this.getPageSync(n,e)}})}};var F=require("path");var j=require("logging-pretty");var f=class{static{m(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(e,i)=>`\${(data && data["${i}"]) ?? ""}`)}static _processBaseBlocks(t){let e=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,i={};for(let s of t.matchAll(e)){let n=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[n]=a}return i}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(e,i)=>{let s=i.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(t){return t.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(t){return t.replace(/<div>([\s\S]*?)<\/div>/gi,(e,i)=>i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(t){let e=/<media(?:\s+([^>]*))?>([\s\S]*?)<\/media>/gi,i={};for(let s of t.matchAll(e)){let n=s[1],o=s[2],a={},r=/(\w+)="([^"]*)"/g;if(n)for(let h of n.matchAll(r))a[h[1]]=h[2];let c=a.lang||"default",d=a.type,l=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),u={type:d};a.src&&(u.src=a.src),l&&d!=="video_note"&&d!=="sticker"&&(u.caption=l),d==="location"&&(a.latitude&&(u.latitude=a.latitude),a.longitude&&(u.longitude=a.longitude),l&&(u.caption=l)),d==="contact"&&(a.phone&&(u.phone=a.phone),a.first_name&&(u.first_name=a.first_name),a.last_name&&(u.last_name=a.last_name),a.vcard&&(u.vcard=a.vcard),l&&(u.caption=l)),i[c]=u}return i}static _processMessageBlocks(t){let e=/<message(?:\s+([^>]*))?>([\s\S]*?)<\/message>/gi,i={};for(let[,s,n]of t.matchAll(e)){let o={},a=/(\w+)="([^"]*)"/g;if(s)for(let d of s.matchAll(a))o[d[1]]=d[2];let r=o.lang||"default",c=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[r]=c}return i}static _processDescriptionBlocks(t){let e=/<description(?:\s+([^>]*))?>([\s\S]*?)<\/description>/gi,i={};for(let[,s,n]of t.matchAll(e)){let o={},a=/(\w+)="([^"]*)"/g;if(s)for(let l of s.matchAll(a))o[l[1]]=l[2];let r=o.lang||"default",c=o.scope||"default",d=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[r]||(i[r]={}),i[r][c]=d}return i}static _processKeyboardBlocks(t){let e=/<keyboard(?:\s+([^>]*))?>([\s\S]*?)<\/keyboard>/gi,i={};for(let[,s,n]of t.matchAll(e)){let o={},a=/(\w+)="([^"]*)"/g;if(s)for(let l of s.matchAll(a))o[l[1]]=l[2];let r=o.lang||"default",c=o.type==="bottom"?"bottom":"inline",d=n.trim();i[r]||(i[r]={}),i[r][c]=d}return i}static _compileToFunction(t,e){let i;e?i=t.map(o=>`\`${o}\``).join(","):i=`\`${t}\``;let s=i;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),e){let n=`return [${s}]`;return new Function("data",n)}else{let n=`return ${s}`;return new Function("data",n)}}static compileMedia(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processMediaBlocks(n);i[s]={};for(let[a,r]of Object.entries(o))if(r.caption){let c=this._processVariables(this._processScriptBlocks(r.caption)),d=this._compileToFunction(c,!1);i[s][a]=l=>({...r,caption:d(l)})}else i[s][a]=()=>r}return i}static compileMessages(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processMessageBlocks(n);i[s]={};for(let[a,r]of Object.entries(o)){let c=this._processVariables(this._processScriptBlocks(r));i[s][a]=this._compileToFunction(c,!1)}}return i}static compileDescription(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processDescriptionBlocks(n);i[s]={};for(let[a,r]of Object.entries(o))for(let[c,d]of Object.entries(r))i[s][c]||(i[s][c]={}),i[s][c][a]=this._compileToFunction(d,!1)}return i}static compileKeyboards(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processKeyboardBlocks(n);i[s]={};for(let[a,r]of Object.entries(o)){i[s][a]={};for(let[c,d]of Object.entries(r)){let u=d.split(/(?<!\\),\s*/).map(h=>h.replace(/\\,/g,",").trim()).map(h=>this._processVariables(this._processScriptBlocks(h)));i[s][a][c]=this._compileToFunction(u,!0)}}}return i}};var $=require("fs/promises"),L=require("chokidar"),C=require("path"),b=require("fs");var k=class{static{m(this,"TemplateManager")}_map=new Map;_engine=f;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_isWatchEnabled;constructor(t){let{path:e,enableWatch:i=!1}=t;this._path=e,this._isWatchEnabled=i,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(!this._path||!Array.isArray(this._path))throw new Error("Path must be set as string array");for(let t=0;t<this._path.length;t++){let e=this._path[t];if(!(0,b.existsSync)(e))throw new Error(`Template base path is not exists: ${e}`);if(!(0,b.statSync)(e).isDirectory())throw new Error(`Template base path is not a directory: ${e}`)}return!0}catch(t){throw new Error(`Failed to validate Template base path: ${t}`)}}_initializeWatcher(){if(this._isWatchEnabled){if(this._watcher.length>0)throw new Error("Watcher already enabled");for(let t=0;t<this._path.length;t++){let e=this._path[t],i=(0,L.watch)(e,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[t]=i,i.on("change",this._handleFileChange.bind(this)),i.on("add",this._handleFileAdd.bind(this)),i.on("unlink",this._handleFileDelete.bind(this)),i.on("error",this._handleWatchError.bind(this))}}}async _handleFileChange(t){let e=(0,C.basename)(t);this._isValidFile(e)&&await this._loadFile(e,!1)}async _handleFileAdd(t){let e=(0,C.basename)(t);this._isValidFile(e)&&await this._loadFile(e,!1)}_handleFileDelete(t){let e=(0,C.basename)(t),i=this._getKey(e);this._map.has(i)&&this._map.delete(i)}_handleWatchError(t){}_loadAllFiles(){for(let t=0;t<this._path.length;t++){let e=this._path[t],s=(0,b.readdirSync)(e,"utf8").filter(n=>this._isValidFile(n));for(let n of s)this._loadFile(n,!0)}}async _loadFile(t,e=!0){for(let i=0;i<this._path.length;i++){let s=this._path[i],n=(0,C.join)(s,t),o=this._getExtension(t),a=this._getKey(t);if(o==".html"){let r=e?(0,b.readFileSync)(n,"utf8"):await(0,$.readFile)(n,"utf8");this._compile(a,r)}else if(o==".ts"){let r=await P.getPage(n,!1);r?.template!==void 0&&this._compile(a,r.template),r.template=void 0}else throw new Error(`File ${t} is not support`)}}_getExtension(t){return(0,C.extname)(t).toLowerCase()}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,e,i){let s=this._map.get(t),n=s||{},o=!1;(i===void 0||i?.media===!1||s?.media===void 0)&&(n.media=f.compileMedia(e),o=!0),(i===void 0||i?.message===!1||s?.message===void 0)&&(n.message=f.compileMessages(e),o=!0),(i===void 0||i?.keyboard===!1||s?.keyboard===void 0)&&(n.keyboard=f.compileKeyboards(e),o=!0),(i===void 0||i?.description===!1||s?.description===void 0)&&(n.description=f.compileDescription(e),o=!0),o&&this._map.set(t,n)}getMedia(t,e="default",i="default",s){let o=this._map.get(t)?.media?.[e],a=o?.[i]||o?.default;if(!a)return{};try{return a(s)}catch{return{}}}getMessage(t,e="default",i="default",s){let o=this._map.get(t)?.message?.[e],a=o?.[i]||o?.default;if(!a)return"";try{return a(s)}catch{return""}}getDescription(t,e="default",i="default",s="default",n){let a=this._map.get(t)?.description?.[e]?.[s],r=a?.[i]||a?.default;if(!r)return"";try{return r(n)}catch{return""}}getDescriptionLanguage(t,e="default",i="default"){let n=this._map.get(t)?.description?.[e]?.[i];return n?Object.keys(n):[]}getDescriptionScopes(t,e="default"){let s=this._map.get(t)?.description?.[e];return s?Object.keys(s):[]}getKeyboard(t,e="default",i="default",s="inline",n){let a=this._map.get(t)?.keyboard?.[e],r=a?.[i]?.[s]||a?.default?.[s];if(!r)return[];try{return r(n)}catch{return[]}}async write(t,e){if(this._getExtension(t)!=".html")return null;for(let i=0;i<this._path.length;i++){let s=(0,C.join)(this._path[i],t);if((0,b.existsSync)(s))return(0,b.writeFileSync)(s,e,"utf8"),await this._loadFile(t,!1),!0}return null}has(t){return this._map.has(t)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(t,e)=>typeof e=="function"?e.toString():e).length}}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};var T=require("grammy");var D=class{static{m(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;handlerBotUpdate;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");this.log=t.log===!0?new j.LoggingPretty:t.log?t.log:void 0,this.cacheSession=t.cacheSession||new x("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new k({path:[(0,F.join)(process.cwd(),"src","pages")]}),this.bot=this.createBot(t.token),this.bot.catch(this.onCatch),this.registerOnCallbackQueryData(),this.registerOnMessageText(),this.registerOnMessagePhoto(),this.registerOnMessageVideo(),this.registerOnMessageAudio(),this.registerOnMessageDocument(),this.registerOnMessageAnimation(),this.registerOnMessageVoice(),this.registerOnMessageVideoNote(),this.registerOnMessageSticker(),this.registerOnMessageLocation(),this.registerOnMessageContact(),this.handlerBotUpdate=this.bot.handleUpdate,this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),t.deploy.startsWith("polling")?this.runPolling():t.deploy.startsWith("webhook:")?this.runWebhook(t.deploy.split("webhook:")[1]):t.deploy.startsWith("serverless:")&&this.runServerless(t.deploy.split("serverless:")[1])}onCatch(t){this.log?.error?.(`[Bot.catch]: ${String(t)}`)}onStart(t,e,i){let{username:s}=t;this.log?.success?.(`Telegram bot polling started: ${s} ${e=="webhook"||e=="serverless"?`(${i})`:""}`)}createBot(t){return new T.Bot(t)}createCtx(t){return new M({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:m(async t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let e=(0,T.webhookCallback)(this.bot,"bun"),i="/telegram-webhook";this.handlerBotUpdate=e,(0,W.serve)({fetch(a){let{pathname:r}=new URL(a.url);if(r===i)return a.method==="POST"?e(a):new Response("OK",{status:200});if(r==="/"&&a.method==="GET"){let c=new Date().toISOString();return new Response(JSON.stringify({timestamp:c}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}});let s=await this.bot.api.getWebhookInfo(),n=t.endsWith("/")?t.slice(0,-1)+i:t+i;s.url!=n&&await this.bot.api.setWebhook(n);let o=await this.bot.api.getMe();this.onStart(o,"webhook",n)}async runServerless(t){this.handlerBotUpdate=(0,T.webhookCallback)(this.bot,t);let e=await this.bot.api.getMe();this.onStart(e,"serverless",t)}pageBuildData(t,e){t?.data===void 0&&(t.data=t.buildData()),t.data.name=(0,F.parse)(e).name}pageSorts(t,e){let i=t.data.name,s=t.prototype,n="Payload",o="Command",a="Caption",r="Free",c=e.dynamic,d=e.dynamicSpesific,l=m(g=>g.charAt(0).toUpperCase()+g.slice(1),"upFirst"),u=m(g=>g.replace(n,"").replace(o,"").replace(a,"").replace(r,""),"getPureFuncName"),h=m((g,y)=>s[`methodSession${l(g)}`](y),"methodSession");e.all[i]=t;for(let g=0;g<e.lenListFuncStaticSession;g++){let y=e.listFuncStaticSession[g],Q=e.static[y],U=e.staticIntent[y],O=e.staticSession[y],V={name:i,func:y},A=Q||U;if(A!==void 0){let z=y.includes(o)?`/${i}`:i;A[s.intent(z,y.startsWith("callback"))]=V}O!==void 0&&(O[h(y,i)]=V),y.toLowerCase().endsWith("free")&&d[u(y)].push(V)}s.free&&c.push(i)}async pageSyncDescription(t){let e=new Map,i=t.static.textCommand;for(let[,s]of Object.entries(i)){let n=s.name,o=this.templateManager.getDescriptionScopes(n);for(let a of o){e.has(a)||e.set(a,new Set);let r=this.templateManager.getDescriptionLanguage(n,"default",a);for(let c of r)e.get(a).add(c)}}for(let[s,n]of e)for(let o of n){let a=[];for(let[,d]of Object.entries(i)){let l=d.name,u=this.templateManager.getDescription(l,"default",o,s);u&&a.push({command:l,description:u})}if(a.length===0)continue;let r={type:s},c=o==="default"?void 0:o;try{let d=await this.bot.api.getMyCommands({scope:r,language_code:c}),l=JSON.stringify(d.map(h=>({command:h.command,description:h.description})).sort((h,g)=>h.command.localeCompare(g.command))),u=JSON.stringify(a.sort((h,g)=>h.command.localeCompare(g.command)));l!==u&&(await this.bot.api.setMyCommands(a,{scope:r,language_code:c}),this.log?.info?.(`Synced descriptions for scope: ${s},${c?` lang: ${c}`:""} (Total: ${a.length})`))}catch(d){this.log?.error?.(`Failed to sync descriptions for scope: ${s},${c?` lang: ${c}`:""}. ${String(d)}`)}}}pageLoads(){this.log?.info?.("Load pages..");let t={},e=t,i=t,s=[],n=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],o=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],a=[...n,...o,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],r=m((d,l)=>Object.fromEntries(d.map(u=>[u,{...l}])),"makeObject"),c={all:{},dynamic:[],dynamicSpesific:{text:s,photo:s,video:s,audio:s,document:s,animation:s,voice:s,videoNote:s,sticker:s,location:s,contact:s},static:r(n,t),staticIntent:r(o,e),staticSession:r(a,i),listFuncStatic:n,listFuncStaticIntent:o,listFuncStaticSession:a,lenListFuncStatic:n.length,lenListFuncStaticIntent:o.length,lenListFuncStaticSession:a.length};return P.getPagesSync(void 0,!0).forEach(({path:d,page:l})=>{this.pageBuildData(l,d),this.pageSorts(l,c)}),this.log?.info?.(`Finish load pages with total (${Object.keys(c.all).length})`),this.pageSyncDescription(c),c}async pageRoutes(t,e){let i,s;if(i===void 0){let o=t.callbackData,a=t.msgText,r=t.msgCaption,c=this.pages.static;for(let d=0;d<this.pages.lenListFuncStatic;d++){let l=this.pages.listFuncStatic[d];if(s=c[l][o||a||r],s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i===void 0){let o=await t.sessionGet();if(o){let a=o.method,r=this.pages.staticSession;for(let c=0;c<this.pages.lenListFuncStaticSession;c++){let d=this.pages.listFuncStaticSession[c];if(s=r[d][a],s)break}s!==void 0&&(i=this.pages.all[s.name])}}if(i===void 0){let o=t.callbackDataIntent,a=t.msgTextIntent,r=t.msgCaptionIntent,c=this.pages.staticIntent;for(let d=0;d<this.pages.lenListFuncStaticIntent;d++){let l=this.pages.listFuncStaticIntent[d];if(s=c[l][o||a||r],s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i!==void 0&&s!==void 0)return await new i(t)[s.func]?.();let n=this.pages.dynamicSpesific[e]||[];for(let o=0;o<n.length;o++){let a=n[o];if(a===void 0)continue;let r=this.pages.all[a.func];if(r===void 0)continue;let d=await new r(t)[a.name]?.();if(d!==null)return d}for(let o=0;o<this.pages.dynamic.length;o++){let a=this.pages.dynamic[o];if(a===void 0)continue;let r=this.pages.all[a];if(r===void 0)continue;let d=await new r(t).free?.();if(d!==null)return d}return null}async hookBeforeRoute(t,e){return!0}async hookErrorPage(t,e,i,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,e){let i=this.createCtx(t);try{if(await this.hookBeforeRoute(i,e)===!1)return;await this.pageRoutes(i,e)===null&&await this.hookErrorInputNotFoundPage(i)}catch(s){await this.hookErrorPage(i,e,s,!1)}}async onCallbackQueryData(t){let e=this.createCtx(t);try{if(await e.callbackQueryAnswer(),await this.hookBeforeRoute(e,"onCallbackQueryData")===!1)return;await this.pageRoutes(e,"callback")}catch(i){await this.hookErrorPage(e,"onCallbackQueryData",i,!0)}}async onMessageText(t){await this.onMessage(t,"onMessageText")}async onMessagePhoto(t){await this.onMessage(t,"onMessagePhoto")}async onMessageVideo(t){await this.onMessage(t,"onMessageVideo")}async onMessageAudio(t){await this.onMessage(t,"onMessageAudio")}async onMessageDocument(t){await this.onMessage(t,"onMessageDocument")}async onMessageAnimation(t){await this.onMessage(t,"onMessageAnimation")}async onMessageVoice(t){await this.onMessage(t,"onMessageVoice")}async onMessageVideoNote(t){await this.onMessage(t,"onMessageVideoNote")}async onMessageSticker(t){await this.onMessage(t,"onMessageSticker")}async onMessageLocation(t){await this.onMessage(t,"onMessageLocation")}async onMessageContact(t){await this.onMessage(t,"onMessageContact")}registerOnCallbackQueryData(){this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this))}registerOnMessageText(){this.bot.on("message:text",this.onMessageText.bind(this))}registerOnMessagePhoto(){this.bot.on("message:photo",this.onMessagePhoto.bind(this))}registerOnMessageVideo(){this.bot.on("message:video",this.onMessageVideo.bind(this))}registerOnMessageAudio(){this.bot.on("message:audio",this.onMessageAudio.bind(this))}registerOnMessageDocument(){this.bot.on("message:document",this.onMessageDocument.bind(this))}registerOnMessageAnimation(){this.bot.on("message:animation",this.onMessageAnimation.bind(this))}registerOnMessageVoice(){this.bot.on("message:voice",this.onMessageVoice.bind(this))}registerOnMessageVideoNote(){this.bot.on("message:video_note",this.onMessageVideoNote.bind(this))}registerOnMessageSticker(){this.bot.on("message:sticker",this.onMessageSticker.bind(this))}registerOnMessageLocation(){this.bot.on("message:location",this.onMessageLocation.bind(this))}registerOnMessageContact(){this.bot.on("message:contact",this.onMessageContact.bind(this))}};0&&(module.exports={BaseGeneral,CacheExternal,Ctx,Gramstax,TemplateEngine,TemplateManager});
|
|
1
|
+
"use strict";var H=Object.create;var v=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var X=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty;var m=(p,t)=>v(p,"name",{value:t,configurable:!0});var Z=(p,t)=>{for(var e in t)v(p,e,{get:t[e],enumerable:!0})},A=(p,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of q(t))!Y.call(p,s)&&s!==e&&v(p,s,{get:()=>t[s],enumerable:!(i=z(t,s))||i.enumerable});return p};var N=(p,t,e)=>(e=p!=null?H(X(p)):{},A(t||!p||!p.__esModule?v(e,"default",{value:p,enumerable:!0}):e,p)),tt=p=>A(v({},"__esModule",{value:!0}),p);var it={};Z(it,{CacheExternal:()=>I,Ctx:()=>x,Gramstax:()=>D,LoggingUtils:()=>T,TemplateEngine:()=>f,TemplateManager:()=>k,log:()=>et});module.exports=tt(it);var K=N(require("logging-pretty"),1);var T=class extends K.default{static{m(this,"LoggingUtils")}constructor(t){super(t)}errorMake(t,e,i){this.error(`[${e?.name||e}:${i}] ${String(t)}`)}},et=new T;var B=require("keyv"),E=N(require("@keyv/redis"),1);var I=class extends B.Keyv{constructor(e="memory",i,s,o){let n;e.startsWith("redis")&&(n=new E.default(e)),e==="memory"&&(n=new Map),o?.forceStore&&(n=o.forceStore);super({store:n,namespace:i,ttl:s});this.url=e}static{m(this,"CacheExternal")}};var L=require("timers/promises"),S=require("grammy");var x=class{static{m(this,"Ctx")}static template;static data;data=this.constructor.data;get userIsPremium(){return this.ct.from?.is_premium??!1}get userIsBot(){return this.ct.from?.is_bot??!1}get userId(){return this.ct.from?.id}get userName(){return this.ct.from?.username}get userFullName(){return`${this.ct.from?.first_name}${this.ct.from?.last_name}`}get userFirstName(){return this.ct.from?.first_name}get userLastName(){return this.ct.from?.last_name}get userLanguage(){return this.ct.from?.language_code}set userLanguage(t){this.ct.from.language_code=t}get msgText(){return this.ct.message?.text}get 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("+"):[]}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp}async broadcast(t,e,i,s,o,n,a=!1){try{let d=e.map(c=>this.templateManager.getMessage(this.data.name,o,c,s));for(let c=0;c<t.length;c++){let l=t[c],u=d[c];await this.ct.api.sendMessage(l,u,{parse_mode:"HTML",reply_markup:i,...n}),c+1==30&&await(0,L.setTimeout)(1200)}}catch(r){if(a)throw r}}async reply(t,e,i,s){let o=this.templateManager.getMessage(this.data.name,i,this.userLanguage,e);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,e,i,s,o){let n=this.templateManager.getMedia(this.data.name,s,this.userLanguage,i),a={parse_mode:"HTML",reply_markup:e,...o};if(t=="photo")return await this.ct.replyWithPhoto(n.src,{caption:n.caption,...a});if(t=="video")return await this.ct.replyWithVideo(n.src,{caption:n.caption,...a});if(t=="audio")return await this.ct.replyWithAudio(n.src,{caption:n.caption,...a});if(t=="document")return await this.ct.replyWithDocument(n.src,{caption:n.caption,...a});if(t=="animation")return await this.ct.replyWithAnimation(n.src,{caption:n.caption,...a});if(t=="voice")return await this.ct.replyWithVoice(n.src,a);if(t=="video_note")return await this.ct.replyWithVideoNote(n.src,a);if(t=="sticker")return await this.ct.replyWithSticker(n.src,a);if(t=="location")return await this.ct.replyWithLocation(parseInt(n.latitude),parseInt(n.longitude),a);if(t=="contact")return await this.ct.replyWithContact(n.phone,n.first_name,{vcard:n.vcard,...a})}async replyPhoto(t,e,i,s){return this.replyMedia("photo",t,e,i,s)}async replyVideo(t,e,i,s){return this.replyMedia("video",t,e,i,s)}async replyAudio(t,e,i,s){return this.replyMedia("audio",t,e,i,s)}async replyDocument(t,e,i,s){return this.replyMedia("document",t,e,i,s)}async replyAnimation(t,e,i,s){return this.replyMedia("animation",t,e,i,s)}async replyVoice(t,e,i,s){return this.replyMedia("voice",t,e,i,s)}async replyVideoNote(t,e,i,s){return this.replyMedia("video_note",t,e,i,s)}async replySticker(t,e,i,s){return this.replyMedia("sticker",t,e,i,s)}async replyLocation(t,e,i,s){return this.replyMedia("location",t,e,i,s)}async replyContact(t,e,i,s){return this.replyMedia("contact",t,e,i,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,e,i,s,o=!0){try{let n=this.templateManager.getMessage(this.data.name,i,this.userLanguage,e);return await this.ct.editMessageText(n,{parse_mode:"HTML",reply_markup:t,...s})}catch(n){if(o)await this.reply(t,e,i,s);else throw n}}async editMedia(t,e,i,s,o,n,a=!0){try{let{src:r,caption:d}=this.templateManager.getMedia(this.data.name,s,this.userLanguage,i);return t=="voice"?(await this.delete(),await this.replyVoice(e,i,s,o)):t=="video_note"?(await this.delete(),await this.replyVoice(e,i,s,o)):t=="sticker"?(await this.delete(),await this.replySticker(e,i,s,o)):t=="location"?(await this.delete(),await this.replyLocation(e,i,s,o)):t=="contact"?(await this.delete(),await this.replyContact(e,i,s,o)):await this.ct.editMessageMedia({media:r,caption:d,type:t,parse_mode:"HTML",...o},{reply_markup:e,...n})}catch(r){if(a===!0)await this.reply(e,i,s,n);else throw r}}async editPhoto(t,e,i,s,o){return await this.editMedia("photo",t,e,i,s,o)}async editVideo(t,e,i,s,o){return await this.editMedia("video",t,e,i,s,o)}async editAudio(t,e,i,s,o){return await this.editMedia("audio",t,e,i,s,o)}async editDocument(t,e,i,s,o){return await this.editMedia("document",t,e,i,s,o)}async editAnimation(t,e,i,s,o){return await this.editMedia("animation",t,e,i,s,o)}async editVoice(t,e,i,s){return await this.editMedia("voice",t,e,i,s)}async editVideoNote(t,e,i,s){return await this.editMedia("video_note",t,e,i,s)}async editSticker(t,e,i,s){return await this.editMedia("sticker",t,e,i,s)}async editLocation(t,e,i,s){return await this.editMedia("location",t,e,i,s)}async editContact(t,e,i,s){return await this.editMedia("contact",t,e,i,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,e,i){try{let s={method:t,params:e,...i},o=await this.cacheSession.set(`${this.userId}`,s);return o&&(this.session=s),o}catch{return null}}async sessionGet(){try{let t=await this.cacheSession.get(`${this.userId}`);return t&&(this.session=t),t||null}catch{return null}}async sessionClear(){try{let t=await this.cacheSession.delete(`${this.userId}`);return t&&(this.session={}),t}catch{return null}}static buildData(t){return{name:"",callbackData:t?function(...e){let i=t(...e);return`${this.name}${i==""||i===void 0?"":`:${i}`}`}:function(){return this?.name}}}inlineKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.userLanguage}:i`,r=this.cacheKeyboard.get(a);if(!r){let d=new S.InlineKeyboard,c=this.templateManager.getKeyboard(i,e?.baseId,this.userLanguage,"inline",e?.data),l=t(d,c);return this.cacheKeyboard.set(a,l),l}return r}let s=new S.InlineKeyboard,o=this.templateManager.getKeyboard(i,e?.baseId,this.userLanguage,"inline",e?.data);return t(s,o)}bottomKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.userLanguage}:b`,r=this.cacheKeyboard.get(a);if(!r){let d=new S.Keyboard,c=this.templateManager.getKeyboard(i,e?.baseId,this.userLanguage,"bottom",e?.data),l=t(d,c);return l.resized(!0),this.cacheKeyboard.set(a,l),l}return r}let s=new S.Keyboard,o=this.templateManager.getKeyboard(i,e?.baseId,this.userLanguage,"bottom",e?.data),n=t(s,o);return n.resized(),n}validateSessionCallback(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallback(e)}validateSessionCallbackPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallbackPayload(e)}validateSessionText(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionText(e)}validateSessionTextPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextPayload(e)}validateSessionTextCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommand(e)}validateSessionTextCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommandPayload(e)}validateSessionTextFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextFree(e)}validateSessionPhotoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaption(e)}validateSessionPhotoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionPayload(e)}validateSessionPhotoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommand(e)}validateSessionPhotoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommandPayload(e)}validateSessionPhotoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoFree(e)}validateSessionVideoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaption(e)}validateSessionVideoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionPayload(e)}validateSessionVideoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommand(e)}validateSessionVideoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommandPayload(e)}validateSessionVideoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoFree(e)}validateSessionAudioCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaption(e)}validateSessionAudioCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionPayload(e)}validateSessionAudioCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommand(e)}validateSessionAudioCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommandPayload(e)}validateSessionAudioFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioFree(e)}validateSessionDocumentCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaption(e)}validateSessionDocumentCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionPayload(e)}validateSessionDocumentCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommand(e)}validateSessionDocumentCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommandPayload(e)}validateSessionDocumentFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentFree(e)}validateSessionAnimationCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaption(e)}validateSessionAnimationCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionPayload(e)}validateSessionAnimationCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommand(e)}validateSessionAnimationCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommandPayload(e)}validateSessionAnimationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationFree(e)}validateSessionVoiceCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaption(e)}validateSessionVoiceCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionPayload(e)}validateSessionVoiceCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommand(e)}validateSessionVoiceCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommandPayload(e)}validateSessionVoiceFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceFree(e)}validateSessionVideoNoteCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaption(e)}validateSessionVideoNoteCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionPayload(e)}validateSessionVideoNoteCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommand(e)}validateSessionVideoNoteCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommandPayload(e)}validateSessionVideoNoteFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteFree(e)}validateSessionStickerFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionStickerFree(e)}validateSessionLocationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionLocationFree(e)}validateSessionContactFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionContactFree(e)}sessionCallback(t,e){return this.sessionSet(this.methodSessionCallback(e),t)}sessionCallbackPayload(t,e){return this.sessionSet(this.methodSessionCallbackPayload(e),t)}sessionText(t,e){return this.sessionSet(this.methodSessionText(e),t)}sessionTextPayload(t,e){return this.sessionSet(this.methodSessionTextPayload(e),t)}sessionTextCommand(t,e){return this.sessionSet(this.methodSessionTextCommand(e),t)}sessionTextCommandPayload(t,e){return this.sessionSet(this.methodSessionTextCommandPayload(e),t)}sessionTextFree(t,e){return this.sessionSet(this.methodSessionTextFree(e),t)}sessionPhotoCaption(t,e){return this.sessionSet(this.methodSessionPhotoCaption(e),t)}sessionPhotoCaptionPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionPayload(e),t)}sessionPhotoCaptionCommand(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommand(e),t)}sessionPhotoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommandPayload(e),t)}sessionPhotoFree(t,e){return this.sessionSet(this.methodSessionPhotoFree(e),t)}sessionVideoCaption(t,e){return this.sessionSet(this.methodSessionVideoCaption(e),t)}sessionVideoCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionPayload(e),t)}sessionVideoCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommand(e),t)}sessionVideoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommandPayload(e),t)}sessionVideoFree(t,e){return this.sessionSet(this.methodSessionVideoFree(e),t)}sessionAudioCaption(t,e){return this.sessionSet(this.methodSessionAudioCaption(e),t)}sessionAudioCaptionPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionPayload(e),t)}sessionAudioCaptionCommand(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommand(e),t)}sessionAudioCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommandPayload(e),t)}sessionAudioFree(t,e){return this.sessionSet(this.methodSessionAudioFree(e),t)}sessionDocumentCaption(t,e){return this.sessionSet(this.methodSessionDocumentCaption(e),t)}sessionDocumentCaptionPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionPayload(e),t)}sessionDocumentCaptionCommand(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommand(e),t)}sessionDocumentCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommandPayload(e),t)}sessionDocumentFree(t,e){return this.sessionSet(this.methodSessionDocumentFree(e),t)}sessionAnimationCaption(t,e){return this.sessionSet(this.methodSessionAnimationCaption(e),t)}sessionAnimationCaptionPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionPayload(e),t)}sessionAnimationCaptionCommand(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommand(e),t)}sessionAnimationCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommandPayload(e),t)}sessionAnimationFree(t,e){return this.sessionSet(this.methodSessionAnimationFree(e),t)}sessionVoiceCaption(t,e){return this.sessionSet(this.methodSessionVoiceCaption(e),t)}sessionVoiceCaptionPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionPayload(e),t)}sessionVoiceCaptionCommand(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommand(e),t)}sessionVoiceCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommandPayload(e),t)}sessionVoiceFree(t,e){return this.sessionSet(this.methodSessionVoiceFree(e),t)}sessionVideoNoteCaption(t,e){return this.sessionSet(this.methodSessionVideoNoteCaption(e),t)}sessionVideoNoteCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionPayload(e),t)}sessionVideoNoteCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommand(e),t)}sessionVideoNoteCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommandPayload(e),t)}sessionVideoNoteFree(t,e){return this.sessionSet(this.methodSessionVideoNoteFree(e),t)}sessionStickerFree(t,e){return this.sessionSet(this.methodSessionStickerFree(e),t)}sessionLocationFree(t,e){return this.sessionSet(this.methodSessionLocationFree(e),t)}sessionContactFree(t,e){return this.sessionSet(this.methodSessionContactFree(e),t)}sessionToCallback(t,e){return this.sessionCallback({...this.session.params,...t},e)}sessionToCallbackPayload(t,e){return this.sessionCallbackPayload({...this.session.params,...t},e)}sessionToText(t,e){return this.sessionText({...this.session.params,...t},e)}sessionToTextPayload(t,e){return this.sessionTextPayload({...this.session.params,...t},e)}sessionToTextCommand(t,e){return this.sessionTextCommand({...this.session.params,...t},e)}sessionToTextCommandPayload(t,e){return this.sessionTextCommandPayload({...this.session.params,...t},e)}sessionToTextFree(t,e){return this.sessionTextFree({...this.session.params,...t},e)}sessionToPhotoCaption(t,e){return this.sessionPhotoCaption({...this.session.params,...t},e)}sessionToPhotoCaptionPayload(t,e){return this.sessionPhotoCaptionPayload({...this.session.params,...t},e)}sessionToPhotoCaptionCommand(t,e){return this.sessionPhotoCaptionCommand({...this.session.params,...t},e)}sessionToPhotoCaptionCommandPayload(t,e){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...t},e)}sessionToPhotoFree(t,e){return this.sessionPhotoFree({...this.session.params,...t},e)}sessionToVideoCaption(t,e){return this.sessionVideoCaption({...this.session.params,...t},e)}sessionToVideoCaptionPayload(t,e){return this.sessionVideoCaptionPayload({...this.session.params,...t},e)}sessionToVideoCaptionCommand(t,e){return this.sessionVideoCaptionCommand({...this.session.params,...t},e)}sessionToVideoCaptionCommandPayload(t,e){return this.sessionVideoCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoFree(t,e){return this.sessionVideoFree({...this.session.params,...t},e)}sessionToAudioCaption(t,e){return this.sessionAudioCaption({...this.session.params,...t},e)}sessionToAudioCaptionPayload(t,e){return this.sessionAudioCaptionPayload({...this.session.params,...t},e)}sessionToAudioCaptionCommand(t,e){return this.sessionAudioCaptionCommand({...this.session.params,...t},e)}sessionToAudioCaptionCommandPayload(t,e){return this.sessionAudioCaptionCommandPayload({...this.session.params,...t},e)}sessionToAudioFree(t,e){return this.sessionAudioFree({...this.session.params,...t},e)}sessionToDocumentCaption(t,e){return this.sessionDocumentCaption({...this.session.params,...t},e)}sessionToDocumentCaptionPayload(t,e){return this.sessionDocumentCaptionPayload({...this.session.params,...t},e)}sessionToDocumentCaptionCommand(t,e){return this.sessionDocumentCaptionCommand({...this.session.params,...t},e)}sessionToDocumentCaptionCommandPayload(t,e){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...t},e)}sessionToDocumentFree(t,e){return this.sessionDocumentFree({...this.session.params,...t},e)}sessionToAnimationCaption(t,e){return this.sessionAnimationCaption({...this.session.params,...t},e)}sessionToAnimationCaptionPayload(t,e){return this.sessionAnimationCaptionPayload({...this.session.params,...t},e)}sessionToAnimationCaptionCommand(t,e){return this.sessionAnimationCaptionCommand({...this.session.params,...t},e)}sessionToAnimationCaptionCommandPayload(t,e){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...t},e)}sessionToAnimationFree(t,e){return this.sessionAnimationFree({...this.session.params,...t},e)}sessionToVoiceCaption(t,e){return this.sessionVoiceCaption({...this.session.params,...t},e)}sessionToVoiceCaptionPayload(t,e){return this.sessionVoiceCaptionPayload({...this.session.params,...t},e)}sessionToVoiceCaptionCommand(t,e){return this.sessionVoiceCaptionCommand({...this.session.params,...t},e)}sessionToVoiceCaptionCommandPayload(t,e){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...t},e)}sessionToVoiceFree(t,e){return this.sessionVoiceFree({...this.session.params,...t},e)}sessionToVideoNoteCaption(t,e){return this.sessionVideoNoteCaption({...this.session.params,...t},e)}sessionToVideoNoteCaptionPayload(t,e){return this.sessionVideoNoteCaptionPayload({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommand(t,e){return this.sessionVideoNoteCaptionCommand({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommandPayload(t,e){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoNoteFree(t,e){return this.sessionVideoNoteFree({...this.session.params,...t},e)}sessionToStickerFree(t,e){return this.sessionStickerFree({...this.session.params,...t},e)}sessionToLocationFree(t,e){return this.sessionLocationFree({...this.session.params,...t},e)}sessionToContactFree(t,e){return this.sessionContactFree({...this.session.params,...t},e)}intent(t,e=!0){t||(t=e?this.data.callbackData():this.data.name);let i=e?":":" ";return t.indexOf(i)!=-1?t.split(i)[0]:t}methodSession(t,e){return`${t}-${e||this.data.name}`}methodSessionCallback(t){return this.methodSession("1",t)}methodSessionCallbackPayload(t){return this.methodSession("2",t)}methodSessionText(t){return this.methodSession("3",t)}methodSessionTextPayload(t){return this.methodSession("4",t)}methodSessionTextCommand(t){return this.methodSession("5",t)}methodSessionTextCommandPayload(t){return this.methodSession("6",t)}methodSessionTextFree(t){return this.methodSession("7",t)}methodSessionPhotoCaption(t){return this.methodSession("8",t)}methodSessionPhotoCaptionPayload(t){return this.methodSession("9",t)}methodSessionPhotoCaptionCommand(t){return this.methodSession("10",t)}methodSessionPhotoCaptionCommandPayload(t){return this.methodSession("11",t)}methodSessionPhotoFree(t){return this.methodSession("12",t)}methodSessionVideoCaption(t){return this.methodSession("13",t)}methodSessionVideoCaptionPayload(t){return this.methodSession("14",t)}methodSessionVideoCaptionCommand(t){return this.methodSession("15",t)}methodSessionVideoCaptionCommandPayload(t){return this.methodSession("16",t)}methodSessionVideoFree(t){return this.methodSession("17",t)}methodSessionAudioCaption(t){return this.methodSession("18",t)}methodSessionAudioCaptionPayload(t){return this.methodSession("19",t)}methodSessionAudioCaptionCommand(t){return this.methodSession("20",t)}methodSessionAudioCaptionCommandPayload(t){return this.methodSession("21",t)}methodSessionAudioFree(t){return this.methodSession("22",t)}methodSessionDocumentCaption(t){return this.methodSession("23",t)}methodSessionDocumentCaptionPayload(t){return this.methodSession("24",t)}methodSessionDocumentCaptionCommand(t){return this.methodSession("25",t)}methodSessionDocumentCaptionCommandPayload(t){return this.methodSession("26",t)}methodSessionDocumentFree(t){return this.methodSession("27",t)}methodSessionAnimationCaption(t){return this.methodSession("28",t)}methodSessionAnimationCaptionPayload(t){return this.methodSession("29",t)}methodSessionAnimationCaptionCommand(t){return this.methodSession("30",t)}methodSessionAnimationCaptionCommandPayload(t){return this.methodSession("31",t)}methodSessionAnimationFree(t){return this.methodSession("32",t)}methodSessionVoiceCaption(t){return this.methodSession("33",t)}methodSessionVoiceCaptionPayload(t){return this.methodSession("34",t)}methodSessionVoiceCaptionCommand(t){return this.methodSession("35",t)}methodSessionVoiceCaptionCommandPayload(t){return this.methodSession("36",t)}methodSessionVoiceFree(t){return this.methodSession("37",t)}methodSessionVideoNoteCaption(t){return this.methodSession("38",t)}methodSessionVideoNoteCaptionPayload(t){return this.methodSession("39",t)}methodSessionVideoNoteCaptionCommand(t){return this.methodSession("40",t)}methodSessionVideoNoteCaptionCommandPayload(t){return this.methodSession("41",t)}methodSessionVideoNoteFree(t){return this.methodSession("42",t)}methodSessionStickerFree(t){return this.methodSession("43",t)}methodSessionLocationFree(t){return this.methodSession("44",t)}methodSessionContactFree(t){return this.methodSession("45",t)}};var j=require("bun"),F=require("path");var _=require("path"),w=require("fs");var P=class{static{m(this,"PageManager")}static _getFile(t,e,i=!0,s=0){let n=Object.values(t)[s];if(n===void 0)throw new Error(`File ${e} must have export (not default) class page`);return i===!0&&(n.template=void 0),n}static getFilePath(){return(0,_.join)(process.cwd(),"src","pages")}static getFileSync(t,e=!0,i=0){t||(t=this.getFilePath());let s=require(t);return this._getFile(s,t,e,i)}static async getFile(t,e=!0,i=0){t||(t=this.getFilePath());let s=await import(`${t}?t=${Date.now()}`);return this._getFile(s,t,e,i)}static getFileManySync(t,e=!0,i=0){if(t||(t=this.getFilePath()),!(0,w.existsSync)(t))throw new Error(`Directory ${t} is not found, please make it manually`);return(0,w.readdirSync)(t).map(o=>{let n=(0,_.join)(t,o);return{path:n,page:this.getFileSync(n,e,i)}})}};var Q=require("logging-pretty");var f=class{static{m(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(e,i)=>`\${(data && data["${i}"]) ?? ""}`)}static _processBaseBlocks(t){let e=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,i={};for(let s of t.matchAll(e)){let o=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[o]=a}return i}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(e,i)=>{let s=i.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(t){return t.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(t){return t.replace(/<div>([\s\S]*?)<\/div>/gi,(e,i)=>i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(t){let e=/<media(?:\s+([^>]*))?>([\s\S]*?)<\/media>/gi,i={};for(let s of t.matchAll(e)){let o=s[1],n=s[2],a={},r=/(\w+)="([^"]*)"/g;if(o)for(let h of o.matchAll(r))a[h[1]]=h[2];let d=a.lang||"default",c=a.type,l=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),u={type:c};a.src&&(u.src=a.src),l&&c!=="video_note"&&c!=="sticker"&&(u.caption=l),c==="location"&&(a.latitude&&(u.latitude=a.latitude),a.longitude&&(u.longitude=a.longitude),l&&(u.caption=l)),c==="contact"&&(a.phone&&(u.phone=a.phone),a.first_name&&(u.first_name=a.first_name),a.last_name&&(u.last_name=a.last_name),a.vcard&&(u.vcard=a.vcard),l&&(u.caption=l)),i[d]=u}return i}static _processMessageBlocks(t){let e=/<message(?:\s+([^>]*))?>([\s\S]*?)<\/message>/gi,i={};for(let[,s,o]of t.matchAll(e)){let n={},a=/(\w+)="([^"]*)"/g;if(s)for(let c of s.matchAll(a))n[c[1]]=c[2];let r=n.lang||"default",d=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[r]=d}return i}static _processDescriptionBlocks(t){let e=/<description(?:\s+([^>]*))?>([\s\S]*?)<\/description>/gi,i={};for(let[,s,o]of t.matchAll(e)){let n={},a=/(\w+)="([^"]*)"/g;if(s)for(let l of s.matchAll(a))n[l[1]]=l[2];let r=n.lang||"default",d=n.scope||"default",c=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[r]||(i[r]={}),i[r][d]=c}return i}static _processKeyboardBlocks(t){let e=/<keyboard(?:\s+([^>]*))?>([\s\S]*?)<\/keyboard>/gi,i={};for(let[,s,o]of t.matchAll(e)){let n={},a=/(\w+)="([^"]*)"/g;if(s)for(let l of s.matchAll(a))n[l[1]]=l[2];let r=n.lang||"default",d=n.type==="bottom"?"bottom":"inline",c=o.trim();i[r]||(i[r]={}),i[r][d]=c}return i}static _compileToFunction(t,e){let i;e?i=t.map(n=>`\`${n}\``).join(","):i=`\`${t}\``;let s=i;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),e){let o=`return [${s}]`;return new Function("data",o)}else{let o=`return ${s}`;return new Function("data",o)}}static compileMedia(t){let e=this._processBaseBlocks(t),i={};for(let[s,o]of Object.entries(e)){let n=this._processMediaBlocks(o);i[s]={};for(let[a,r]of Object.entries(n))if(r.caption){let d=this._processVariables(this._processScriptBlocks(r.caption)),c=this._compileToFunction(d,!1);i[s][a]=l=>({...r,caption:c(l)})}else i[s][a]=()=>r}return i}static compileMessages(t){let e=this._processBaseBlocks(t),i={};for(let[s,o]of Object.entries(e)){let n=this._processMessageBlocks(o);i[s]={};for(let[a,r]of Object.entries(n)){let d=this._processVariables(this._processScriptBlocks(r));i[s][a]=this._compileToFunction(d,!1)}}return i}static compileDescription(t){let e=this._processBaseBlocks(t),i={};for(let[s,o]of Object.entries(e)){let n=this._processDescriptionBlocks(o);i[s]={};for(let[a,r]of Object.entries(n))for(let[d,c]of Object.entries(r))i[s][d]||(i[s][d]={}),i[s][d][a]=this._compileToFunction(c,!1)}return i}static compileKeyboards(t){let e=this._processBaseBlocks(t),i={};for(let[s,o]of Object.entries(e)){let n=this._processKeyboardBlocks(o);i[s]={};for(let[a,r]of Object.entries(n)){i[s][a]={};for(let[d,c]of Object.entries(r)){let u=c.split(/(?<!\\),\s*/).map(h=>h.replace(/\\,/g,",").trim()).map(h=>this._processVariables(this._processScriptBlocks(h)));i[s][a][d]=this._compileToFunction(u,!0)}}}return i}};var $=require("fs/promises");var W=require("chokidar"),C=require("path"),b=require("fs");var k=class{static{m(this,"TemplateManager")}_map=new Map;_engine=f;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_isWatchEnabled;constructor(t){let{path:e,enableWatch:i=!1}=t;this._path=e,this._isWatchEnabled=i,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(!this._path||!Array.isArray(this._path))throw new Error("Path must be set as string array");for(let t=0;t<this._path.length;t++){let e=this._path[t];if(!(0,b.existsSync)(e))throw new Error(`Template base path is not exists: ${e}`);if(!(0,b.statSync)(e).isDirectory())throw new Error(`Template base path is not a directory: ${e}`)}return!0}catch(t){throw new Error(`Failed to validate Template base path: ${String(t)}`)}}_initializeWatcher(){if(this._isWatchEnabled){if(this._watcher.length>0)throw new Error("Watcher already enabled");for(let t=0;t<this._path.length;t++){let e=this._path[t],i=(0,W.watch)(e,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[t]=i,i.on("change",this._handleFileChange.bind(this)),i.on("add",this._handleFileAdd.bind(this)),i.on("unlink",this._handleFileDelete.bind(this)),i.on("error",this._handleWatchError.bind(this))}}}async _handleFileChange(t){let e=(0,C.basename)(t);this._isValidFile(e)&&await this._loadFile(e,!1)}async _handleFileAdd(t){let e=(0,C.basename)(t);this._isValidFile(e)&&await this._loadFile(e,!1)}_handleFileDelete(t){let e=(0,C.basename)(t),i=this._getKey(e);this._map.has(i)&&this._map.delete(i)}_handleWatchError(t){}async _loadAllFiles(){for(let t=0;t<this._path.length;t++){let e=this._path[t],s=(0,b.readdirSync)(e,"utf8").filter(o=>this._isValidFile(o));for(let o of s)await this._loadFile(o,!0)}}async _loadFile(t,e=!0){for(let i=0;i<this._path.length;i++){let s=this._path[i],o=(0,C.join)(s,t),n=this._getExtension(t),a=this._getKey(t);if(n==".html"){let r=e?(0,b.readFileSync)(o,"utf8"):await(0,$.readFile)(o,"utf8");this._compile(a,r)}else if(n==".ts"){let r=await P.getFile(o,!1);r?.template!==void 0&&this._compile(a,r.template),r.template=void 0}else throw new Error(`File ${t} is not support`)}}_getExtension(t){return(0,C.extname)(t).toLowerCase()}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,e,i){let s=this._map.get(t),o=s||{},n=!1;(i===void 0||i?.media===!1||s?.media===void 0)&&(o.media=f.compileMedia(e),n=!0),(i===void 0||i?.message===!1||s?.message===void 0)&&(o.message=f.compileMessages(e),n=!0),(i===void 0||i?.keyboard===!1||s?.keyboard===void 0)&&(o.keyboard=f.compileKeyboards(e),n=!0),(i===void 0||i?.description===!1||s?.description===void 0)&&(o.description=f.compileDescription(e),n=!0),n&&this._map.set(t,o)}getMedia(t,e="default",i="default",s){let n=this._map.get(t)?.media?.[e],a=n?.[i]||n?.default;try{if(!a)throw new Error("Media function not found, please check your template");return a(s)}catch{return{}}}getMessage(t,e="default",i="default",s){try{let n=this._map.get(t)?.message?.[e],a=n?.[i]||n?.default;if(!a)throw"";return a(s)}catch{return""}}getDescription(t,e="default",i="default",s="default",o){try{let a=this._map.get(t)?.description?.[e]?.[s],r=a?.[i]||a?.default;if(!r)throw"";return r(o)}catch{return""}}getDescriptionLanguage(t,e="default",i="default"){try{let o=this._map.get(t)?.description?.[e]?.[i];return o?Object.keys(o):[]}catch{return[]}}getDescriptionScopes(t,e="default"){try{let s=this._map.get(t)?.description?.[e];return s?Object.keys(s):[]}catch{return[]}}getKeyboard(t,e="default",i="default",s="inline",o){try{let a=this._map.get(t)?.keyboard?.[e],r=a?.[i]?.[s]||a?.default?.[s];if(!r)throw[];return r(o)}catch{return[]}}async write(t,e){if(this._getExtension(t)!=".html")return null;for(let i=0;i<this._path.length;i++){let s=(0,C.join)(this._path[i],t);if((0,b.existsSync)(s))return(0,b.writeFileSync)(s,e,"utf8"),await this._loadFile(t,!1),!0}return null}has(t){return this._map.has(t)}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};var M=require("grammy");var D=class{static{m(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;handlerBotUpdate;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");if(this.log=t.log===!0?new Q.LoggingPretty:t.log?t.log:void 0,this.cacheSession=t.cacheSession||new I("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new k({path:[(0,F.join)(process.cwd(),"src","pages")]}),this.bot=this.createBot(t.token),this.bot.catch(this.onCatch),this.registerOnCallbackQueryData(),this.registerOnMessageText(),this.registerOnMessagePhoto(),this.registerOnMessageVideo(),this.registerOnMessageAudio(),this.registerOnMessageDocument(),this.registerOnMessageAnimation(),this.registerOnMessageVoice(),this.registerOnMessageVideoNote(),this.registerOnMessageSticker(),this.registerOnMessageLocation(),this.registerOnMessageContact(),this.handlerBotUpdate=this.bot.handleUpdate,this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),t.deploy.startsWith("polling"))this.runPolling();else if(t.deploy.startsWith("webhook:"))this.runWebhook(t.deploy.split("webhook:")[1]);else if(t.deploy.startsWith("serverless:"))this.runServerless(t.deploy.split("serverless:")[1]);else if(!t.deploy.startsWith("test"))throw new Error("Params deploy is not valid, expected: polling, webhook:<public-url>, serverless:<your-adapter>")}onCatch(t){this.log?.error?.(`[Bot.catch]: ${JSON.stringify(t,null,2)}`)}onStart(t,e,i){let{username:s}=t;this.log?.success?.(`Telegram bot polling started: ${s} ${e=="webhook"||e=="serverless"?`(${i})`:""}`)}createBot(t){return new M.Bot(t)}createCtx(t){return new x({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}runPolling(){this.bot.start({onStart:m(t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let e=(0,M.webhookCallback)(this.bot,"bun");this.handlerBotUpdate=e;let i=new URL(t).pathname;(0,j.serve)({fetch(n){let{pathname:a}=new URL(n.url);if(n.method=="POST"&&a==i)return e(n);if(n.method=="GET"&&a=="/"){let r=new Date().toISOString();return new Response(JSON.stringify({status:"OK",timestamp:r}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}}),(await this.bot.api.getWebhookInfo()).url!=t&&await this.bot.api.setWebhook(t);let o=await this.bot.api.getMe();this.onStart(o,"webhook",t)}async runServerless(t){this.handlerBotUpdate=(0,M.webhookCallback)(this.bot,t);let e=await this.bot.api.getMe();this.onStart(e,"serverless",t)}pageBuildData(t,e){t?.data===void 0&&(t.data=t.buildData()),t.data.name=(0,F.parse)(e).name}pageSorts(t,e){let i=t.data.name,s=t.prototype,o="Payload",n="Command",a="Caption",r="Free",d=e.routeDynamic,c=e.routeDynamicSpesific,l=m(g=>g.charAt(0).toUpperCase()+g.slice(1),"upFirst"),u=m(g=>g.replace(o,"").replace(n,"").replace(a,"").replace(r,""),"getPureRouteName"),h=m((g,y)=>s[`methodSession${l(g)}`]?.(y),"methodSession");e.all[i]=t;for(let g=0;g<e.lenListRouteStaticSession;g++){let y=e.listRouteStaticSession[g],U=e.routeStatic[y],G=e.routeStaticIntent[y],O=e.routeStaticSession[y],V={name:i,routeName:y},R=U||G;if(R!==void 0){let J=y.includes(n)?`/${i}`:i;R[s.intent(J,y.startsWith("callback"))]=V}O!==void 0&&(O[h(y,i)]=V),y.toLowerCase().endsWith("free")&&c[u(y)].push(V)}s.free&&d.push(i)}async pageSyncDescription(t){let e=new Map,i=t.routeStatic.textCommand;for(let[,s]of Object.entries(i)){let o=s.name,n=this.templateManager.getDescriptionScopes(o);for(let a of n){e.has(a)||e.set(a,new Set);let r=this.templateManager.getDescriptionLanguage(o,"default",a);for(let d of r)e.get(a).add(d)}}for(let[s,o]of e)for(let n of o){let a=[];for(let[,c]of Object.entries(i)){let l=c.name,u=this.templateManager.getDescription(l,"default",n,s);u&&a.push({command:l,description:u})}if(a.length===0)continue;let r={type:s},d=n==="default"?void 0:n;try{let c=await this.bot.api.getMyCommands({scope:r,language_code:d}),l=JSON.stringify(c.map(h=>({command:h.command,description:h.description})).sort((h,g)=>h.command.localeCompare(g.command))),u=JSON.stringify(a.sort((h,g)=>h.command.localeCompare(g.command)));l!==u&&(await this.bot.api.setMyCommands(a,{scope:r,language_code:d}),this.log?.info?.(`Synced descriptions for scope: ${s},${d?` lang: ${d}`:""} (Total: ${a.length})`))}catch(c){this.log?.error?.(`Failed to sync descriptions for scope: ${s},${d?` lang: ${d}`:""}. ${String(c)}`)}}}pageLoads(){this.log?.info?.("Load pages..");let t=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],e=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],i=[...t,...e,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],s=m((a,r)=>Object.fromEntries(a.map(d=>[d,r()])),"makeObject"),o=m(()=>[],"initDynamicSpesific"),n={all:{},routeDynamic:[],routeDynamicSpesific:{text:o(),photo:o(),video:o(),audio:o(),document:o(),animation:o(),voice:o(),videoNote:o(),sticker:o(),location:o(),contact:o()},routeStatic:s(t,()=>({})),routeStaticIntent:s(e,()=>({})),routeStaticSession:s(i,()=>({})),listRouteStatic:t,listRouteStaticIntent:e,listRouteStaticSession:i,lenListRouteStatic:t.length,lenListRouteStaticIntent:e.length,lenListRouteStaticSession:i.length};return P.getFileManySync(void 0,!0).forEach(({path:a,page:r})=>{this.pageBuildData(r,a),this.pageSorts(r,n)}),this.log?.info?.(`Finish load pages with total (${Object.keys(n.all).length})`),n}async pageRoutes(t,e){let i,s;if(i===void 0){let n=t.callbackData,a=t.msgText,r=t.msgCaption,d=this.pages.routeStatic;for(let c=0;c<this.pages.lenListRouteStatic;c++){let l=this.pages.listRouteStatic[c];if(l.startsWith(e)&&(s=d[l][n||a||r]),s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i===void 0){let n=await t.sessionGet();if(n){let a=n.method,r=this.pages.routeStaticSession;for(let d=0;d<this.pages.lenListRouteStaticSession;d++){let c=this.pages.listRouteStaticSession[d];if(c.startsWith(e)&&(s=r[c][a]),s)break}s!==void 0&&(i=this.pages.all[s.name])}}if(i===void 0){let n=t.callbackDataIntent,a=t.msgTextIntent,r=t.msgCaptionIntent,d=this.pages.routeStaticIntent;for(let c=0;c<this.pages.lenListRouteStaticIntent;c++){let l=this.pages.listRouteStaticIntent[c];if(l.startsWith(e)&&(s=d[l][n||a||r]),s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i!==void 0&&s!==void 0)return i.prototype[s.routeName]?await new i(t)[s.routeName]?.():void 0;let o=this.pages.routeDynamicSpesific[e]||[];for(let n=0;n<o.length;n++){let a=o[n];if(a===void 0)continue;let r=this.pages.all[a.name];if(r===void 0||!r.prototype[a.routeName])continue;let c=await new r(t)[a.routeName]?.();if(c!==null)return c}for(let n=0;n<this.pages.routeDynamic.length;n++){let a=this.pages.routeDynamic[n];if(a===void 0)continue;let r=this.pages.all[a];if(r===void 0||!r.prototype.free)continue;let c=await new r(t).free?.();if(c!==null)return c}return null}async hookBeforeRoute(t,e){return!!(t||e)}async hookErrorPage(t,e,i,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,e){let i=this.createCtx(t);try{if(await this.hookBeforeRoute(i,e)===!1)return;await this.pageRoutes(i,e)===null&&await this.hookErrorInputNotFoundPage(i)}catch(s){await this.hookErrorPage(i,e,s,!1)}}async onCallbackQueryData(t){let e=this.createCtx(t);try{if(await e.callbackQueryAnswer(),await this.hookBeforeRoute(e,"onCallbackQueryData")===!1)return;await this.pageRoutes(e,"callback")}catch(i){await this.hookErrorPage(e,"onCallbackQueryData",i,!0)}}async onMessageText(t){await this.onMessage(t,"text")}async onMessagePhoto(t){await this.onMessage(t,"photo")}async onMessageVideo(t){await this.onMessage(t,"video")}async onMessageAudio(t){await this.onMessage(t,"audio")}async onMessageDocument(t){await this.onMessage(t,"document")}async onMessageAnimation(t){await this.onMessage(t,"animation")}async onMessageVoice(t){await this.onMessage(t,"voice")}async onMessageVideoNote(t){await this.onMessage(t,"videoNote")}async onMessageSticker(t){await this.onMessage(t,"sticker")}async onMessageLocation(t){await this.onMessage(t,"location")}async onMessageContact(t){await this.onMessage(t,"contact")}registerOnCallbackQueryData(){this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this))}registerOnMessageText(){this.bot.on("message:text",this.onMessageText.bind(this))}registerOnMessagePhoto(){this.bot.on("message:photo",this.onMessagePhoto.bind(this))}registerOnMessageVideo(){this.bot.on("message:video",this.onMessageVideo.bind(this))}registerOnMessageAudio(){this.bot.on("message:audio",this.onMessageAudio.bind(this))}registerOnMessageDocument(){this.bot.on("message:document",this.onMessageDocument.bind(this))}registerOnMessageAnimation(){this.bot.on("message:animation",this.onMessageAnimation.bind(this))}registerOnMessageVoice(){this.bot.on("message:voice",this.onMessageVoice.bind(this))}registerOnMessageVideoNote(){this.bot.on("message:video_note",this.onMessageVideoNote.bind(this))}registerOnMessageSticker(){this.bot.on("message:sticker",this.onMessageSticker.bind(this))}registerOnMessageLocation(){this.bot.on("message:location",this.onMessageLocation.bind(this))}registerOnMessageContact(){this.bot.on("message:contact",this.onMessageContact.bind(this))}};0&&(module.exports={CacheExternal,Ctx,Gramstax,LoggingUtils,TemplateEngine,TemplateManager,log});
|