create-gramstax 0.3.10 → 0.3.12

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.
Files changed (31) hide show
  1. package/dist/src/index.cjs +2 -2
  2. package/dist/src/index.js +1 -1
  3. package/dist/src/templates/.prettierrc +2 -1
  4. package/dist/src/templates/package.json +1 -1
  5. package/dist/src/templates/src/base/guard.ts +2 -2
  6. package/dist/src/templates/src/base/page.ts +4 -4
  7. package/dist/src/templates/src/components/keyboard.ts +9 -9
  8. package/dist/src/templates/src/core/bot.ts +9 -9
  9. package/dist/src/templates/src/core/ctx.ts +1 -1
  10. package/dist/src/templates/src/data/keyboard.ts +3 -3
  11. package/dist/src/templates/src/guards/session.ts +15 -0
  12. package/dist/src/templates/src/guards/user.ts +6 -7
  13. package/dist/src/templates/src/index.ts +5 -5
  14. package/dist/src/templates/src/pages/general-error-input-notfound.ts +31 -9
  15. package/dist/src/templates/src/pages/general-error.ts +13 -8
  16. package/dist/src/templates/src/pages/help.ts +7 -7
  17. package/dist/src/templates/src/pages/input-text.ts +74 -0
  18. package/dist/src/templates/src/pages/start.ts +8 -9
  19. package/dist/src/templates/src/pages/username-notfound.ts +5 -5
  20. package/dist/src/templates/src/utils/log.ts +2 -2
  21. package/package.json +1 -1
  22. package/dist/src/templates/src/base/repository.ts +0 -1
  23. package/dist/src/templates/src/base/service.ts +0 -1
  24. package/dist/src/templates/src/cache/external.ts +0 -3
  25. package/dist/src/templates/src/db/example.ts +0 -1
  26. package/dist/src/templates/src/repositories/example.ts +0 -3
  27. package/dist/src/templates/src/services/example.ts +0 -3
  28. package/dist/src/templates/src/thread/export.ts +0 -3
  29. package/dist/src/templates/src/thread/main-pool.ts +0 -3
  30. package/dist/src/templates/src/thread/main.ts +0 -3
  31. package/dist/src/templates/src/thread/sub.ts +0 -3
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var F=Object.create;var d=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var l=(o,e)=>d(o,"name",{value:e,configurable:!0});var I=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of E(e))!T.call(o,a)&&a!==t&&d(o,a,{get:()=>e[a],enumerable:!(n=N(e,a))||n.enumerable});return o};var _=(o,e,t)=>(t=o!=null?F(L(o)):{},I(e||!o||!o.__esModule?d(t,"default",{value:o,enumerable:!0}):t,o));var U=l(()=>typeof document>"u"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"?document.currentScript.src:new URL("main.js",document.baseURI).href,"getImportMetaUrl"),u=U();var w=require("logging-pretty"),r=new w.LoggingPretty;var i=_(require("fs"),1),s=_(require("path"),1),S=require("url");var y=require("child_process"),h=_(require("enquirer"),1);var B=(0,S.fileURLToPath)(u),G=s.dirname(B),f=class{constructor(e){this.projectDirectory=e}static{l(this,"Create")}config;printBanner(){console.log(`
2
+ "use strict";var F=Object.create;var d=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var l=(o,e)=>d(o,"name",{value:e,configurable:!0});var I=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of E(e))!T.call(o,a)&&a!==t&&d(o,a,{get:()=>e[a],enumerable:!(n=N(e,a))||n.enumerable});return o};var _=(o,e,t)=>(t=o!=null?F(L(o)):{},I(e||!o||!o.__esModule?d(t,"default",{value:o,enumerable:!0}):t,o));var U=l(()=>typeof document>"u"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"?document.currentScript.src:new URL("main.js",document.baseURI).href,"getImportMetaUrl"),f=U();var w=require("logging-pretty"),r=new w.LoggingPretty;var i=_(require("fs"),1),s=_(require("path"),1),S=require("url");var y=require("child_process"),h=_(require("enquirer"),1);var B=(0,S.fileURLToPath)(f),G=s.dirname(B),g=class{constructor(e){this.projectDirectory=e}static{l(this,"Create")}config;printBanner(){console.log(`
3
3
  $$$$$$\\ $$\\
4
4
  $$ __$$\\ $$ |
5
5
  $$ / \\__| $$$$$$\\ $$$$$$\\ $$$$$$\\$$$$\\ $$$$$$$\\ $$$$$$\\ $$$$$$\\ $$\\ $$\\
@@ -9,4 +9,4 @@ $$ | $$ |$$ | $$ __$$ |$$ | $$ | $$ | \\____$$\\ $$ |$$\\ $$ __$$ | $$
9
9
  \\$$$$$$ |$$ | \\$$$$$$$ |$$ | $$ | $$ |$$$$$$$ | \\$$$$ |\\$$$$$$$ |$$ /\\$$\\
10
10
  \\______/ \\__| \\_______|\\__| \\__| \\__|\\_______/ \\____/ \\_______|\\__/ \\__|
11
11
 
12
- `)}getPackageManagerCommands(e){return{bun:{install:"bun install",dev:"bun dev",start:"bun start"},npm:{install:"npm install",dev:"npm run dev",start:"npm start"},pnpm:{install:"pnpm install",dev:"pnpm dev",start:"pnpm start"},yarn:{install:"yarn install",dev:"yarn dev",start:"yarn start"}}[e]}copyDirectorySync(e,t,n={}){i.existsSync(t)||i.mkdirSync(t,{recursive:!0});let a=i.readdirSync(e,{withFileTypes:!0});for(let c of a){let p=s.join(e,c.name),$=s.join(t,c.name);if(c.isDirectory())this.copyDirectorySync(p,$,n);else if(c.isFile()){let m=i.readFileSync(p,"utf-8");m=this.replaceTemplateVariables(m,n),i.writeFileSync($,m)}}}replaceTemplateVariables(e,t){let n=e;for(let[a,c]of Object.entries(t))n=n.replace(new RegExp(`{{${a}}}`,"g"),c);return n}async promptForProjectName(){return(await h.default.prompt({type:"input",name:"projectName",message:"What is your project named?",initial:"",validate:l(t=>t===""||/^[a-z0-9-_]+$/i.test(t)?!0:"Project name can only contain letters, numbers, hyphens, and underscores","validate")})).projectName}async promptForConfiguration(){let e=[];e.push({type:"select",name:"packageManager",message:"Which package manager would you like to use?",choices:[{name:"bun",message:"Bun (recommended)",value:"bun"},{name:"npm",message:"npm",value:"npm"},{name:"pnpm",message:"pnpm",value:"pnpm"},{name:"yarn",message:"Yarn",value:"yarn"}],initial:0}),e.push({type:"select",name:"runtime",message:"Which runtime would you like to use?",choices:[{name:"bun",message:"Bun (recommended)",value:"bun"},{name:"node",message:"Node.js",value:"node"}],initial:0}),e.push({type:"confirm",name:"eslint",message:"Would you like to use ESLint?",initial:!0});let t=await h.default.prompt(e);return{packageManager:t.packageManager,runtime:t.runtime,eslint:t.eslint}}async installDependencies(e,t){return await new Promise(n=>{let p=(0,y.spawn)(t,["install"],{cwd:e,stdio:"inherit",shell:!0});p.on("close",$=>{$===0?n(!0):(r.fail("Dependencies installation failed"),n(!1))}),p.on("error",$=>{r.fail(`Dependencies installation failed: ${$.message}`),n(!1)})})}async gatherProjectConfig(){this.printBanner();let e=this.projectDirectory,t,n=!1;e?(t=s.resolve(process.cwd(),e),n=!1):(e=await this.promptForProjectName(),e===""?(e=s.basename(process.cwd()),t=process.cwd(),n=!0):(t=s.resolve(process.cwd(),e),n=!1));let a=await this.promptForConfiguration(),c=a.packageManager,p=a.runtime,$=a.eslint;return r.info(`Project: ${e}`),r.info(`Location: ${t}`),r.info(`Package Manager: ${c}`),r.info(`Runtime: ${p}`),r.info(`ESLint: ${$?"Yes":"No"}`),n?i.readdirSync(t).length>0&&(r.error("Current directory is not empty!"),process.exit(1)):i.existsSync(t)&&(r.error(`Directory "${e}" already exists!`),process.exit(1)),{projectName:e,projectPath:t,packageManager:c,runtime:p,setupEslint:$}}async executeProjectGeneration(e){let{projectName:t,projectPath:n,packageManager:a,runtime:c,setupEslint:p}=e;r.info("Creating project directory.."),i.existsSync(n)||i.mkdirSync(n,{recursive:!0}),r.info("Copying template files..");let $=s.join(G,"templates"),m=this.getPackageManagerCommands(a),M={projectName:t,installCmd:m.install,runDevCmd:m.dev,runStartCmd:m.start};this.copyDirectorySync($,n,M),r.info("Creating logs directory.."),i.mkdirSync(s.join(n,"logs"),{recursive:!0}),i.writeFileSync(s.join(n,"logs/.gitkeep"),"");let R=s.join(n,".env"),j=s.join(n,".env.example");if(i.existsSync(j)&&(r.info("Creating .env file.."),i.renameSync(j,R)),c!=="bun"){r.info("Removing bunfig.toml for Node.js runtime..");let v=s.join(n,"bunfig.toml");i.existsSync(v)&&i.unlinkSync(v)}let P=s.join(n,"tsconfig.json"),D=i.readFileSync(P,{encoding:"utf8"}).replace("//{{types}}",c=="bun"?'"bun-types"':"");if(i.writeFileSync(P,D,{encoding:"utf8"}),r.info("Installing dependencies.."),!await this.installDependencies(n,a))return r.fail("Project created failed!"),process.exit();p&&(r.info("Setting up ESLint.."),await this.setupEslintConfig(n)),r.info("Project created successfully!"),r.info(`Next steps: ${e.projectPath!==process.cwd()?`cd ${t} && `:" "}${m.install} && ${m.dev}`),r.info("Done..")}async setupEslintConfig(e){return new Promise(t=>{let n=(0,y.spawn)("npm",["init","@eslint/config@latest"],{cwd:e,stdio:"inherit",shell:!0});n.on("close",a=>{a===0||r.fail("ESLint setup failed. You can set it up later with: npm init @eslint/config"),t()}),n.on("error",a=>{r.fail(`ESLint setup failed: ${a.message}`),r.info("You can set it up later with: npm init @eslint/config"),t()})})}async createProject(){try{this.config=await this.gatherProjectConfig(),await this.executeProjectGeneration(this.config)}catch(e){e instanceof Error?r.error(`Failed to create project: ${e.message}`):r.error(`Failed to create project: ${String(e)}`),process.exit(1)}}};var b=require("commander"),k=require("fs"),g=require("path"),C=require("url"),W=(0,C.fileURLToPath)(u),Y=(0,g.dirname)(W),O=JSON.parse((0,k.readFileSync)((0,g.join)(Y,"../../package.json"),"utf-8")).version,x=new b.Command;x.name("create-gramstax").description("CLI to create a new Gramstax Telegram bot project").version(O).argument("[project-directory]","Directory to create the project in").action(async o=>{try{await new f(o).createProject()}catch(e){r.error(`Failed to create project: ${String(e)}`),process.exit(1)}});x.parse();
12
+ `)}getPackageManagerCommands(e){return{bun:{install:"bun install",dev:"bun dev",start:"bun start"},npm:{install:"npm install",dev:"npm run dev",start:"npm start"},pnpm:{install:"pnpm install",dev:"pnpm dev",start:"pnpm start"},yarn:{install:"yarn install",dev:"yarn dev",start:"yarn start"}}[e]}copyDirectorySync(e,t,n={}){i.existsSync(t)||i.mkdirSync(t,{recursive:!0});let a=i.readdirSync(e,{withFileTypes:!0});for(let c of a){let p=s.join(e,c.name),$=s.join(t,c.name);if(c.isDirectory())this.copyDirectorySync(p,$,n);else if(c.isFile()){let m=i.readFileSync(p,"utf-8");m=this.replaceTemplateVariables(m,n),i.writeFileSync($,m)}}}replaceTemplateVariables(e,t){let n=e;for(let[a,c]of Object.entries(t))n=n.replace(new RegExp(`{{${a}}}`,"g"),c);return n}async promptForProjectName(){return(await h.default.prompt({type:"input",name:"projectName",message:"What is your project named?",initial:"",validate:l(t=>t===""||/^[a-z0-9-_]+$/i.test(t)?!0:"Project name can only contain letters, numbers, hyphens, and underscores","validate")})).projectName}async promptForConfiguration(){let e=[];e.push({type:"select",name:"packageManager",message:"Which package manager would you like to use?",choices:[{name:"bun",message:"Bun (recommended)",value:"bun"},{name:"npm",message:"npm",value:"npm"},{name:"pnpm",message:"pnpm",value:"pnpm"},{name:"yarn",message:"Yarn",value:"yarn"}],initial:0}),e.push({type:"select",name:"runtime",message:"Which runtime would you like to use?",choices:[{name:"bun",message:"Bun (recommended)",value:"bun"},{name:"node",message:"Node.js",value:"node"}],initial:0}),e.push({type:"confirm",name:"eslint",message:"Would you like to use ESLint?",initial:!0});let t=await h.default.prompt(e);return{packageManager:t.packageManager,runtime:t.runtime,eslint:t.eslint}}async installDependencies(e,t){return await new Promise(n=>{let p=(0,y.spawn)(t,["install"],{cwd:e,stdio:"inherit",shell:!0});p.on("close",$=>{$===0?n(!0):(r.fail("Dependencies installation failed"),n(!1))}),p.on("error",$=>{r.fail(`Dependencies installation failed: ${$.message}`),n(!1)})})}async gatherProjectConfig(){this.printBanner();let e=this.projectDirectory,t,n=!1;e?(t=s.resolve(process.cwd(),e),n=!1):(e=await this.promptForProjectName(),e===""?(e=s.basename(process.cwd()),t=process.cwd(),n=!0):(t=s.resolve(process.cwd(),e),n=!1));let a=await this.promptForConfiguration(),c=a.packageManager,p=a.runtime,$=a.eslint;return r.info(`Project: ${e}`),r.info(`Location: ${t}`),r.info(`Package Manager: ${c}`),r.info(`Runtime: ${p}`),r.info(`ESLint: ${$?"Yes":"No"}`),n?i.readdirSync(t).length>0&&(r.error("Current directory is not empty!"),process.exit(1)):i.existsSync(t)&&(r.error(`Directory "${e}" already exists!`),process.exit(1)),{projectName:e,projectPath:t,packageManager:c,runtime:p,setupEslint:$}}async executeProjectGeneration(e){let{projectName:t,projectPath:n,packageManager:a,runtime:c,setupEslint:p}=e;r.info("Creating project directory.."),i.existsSync(n)||i.mkdirSync(n,{recursive:!0}),r.info("Copying template files..");let $=s.join(G,"templates"),m=this.getPackageManagerCommands(a),M={projectName:t,installCmd:m.install,runDevCmd:m.dev,runStartCmd:m.start};this.copyDirectorySync($,n,M),r.info("Creating logs directory.."),i.mkdirSync(s.join(n,"logs"),{recursive:!0}),i.writeFileSync(s.join(n,"logs/.gitkeep"),"");let R=s.join(n,".env"),j=s.join(n,".env.example");if(i.existsSync(j)&&(r.info("Creating .env file.."),i.renameSync(j,R)),c!=="bun"){r.info("Removing bunfig.toml for Node.js runtime..");let v=s.join(n,"bunfig.toml");i.existsSync(v)&&i.unlinkSync(v)}let P=s.join(n,"tsconfig.json"),D=i.readFileSync(P,{encoding:"utf8"}).replace("//{{types}}",c=="bun"?'"bun-types"':"");if(i.writeFileSync(P,D,{encoding:"utf8"}),r.info("Installing dependencies.."),!await this.installDependencies(n,a))return r.fail("Project created failed!"),process.exit();p&&(r.info("Setting up ESLint.."),await this.setupEslintConfig(n)),r.info("Project created successfully!"),r.info(`Next steps: ${e.projectPath!==process.cwd()?`cd ${t} && `:" "}${m.install} && ${m.dev}`),r.info("Done..")}async setupEslintConfig(e){return new Promise(t=>{let n=(0,y.spawn)("npm",["init","@eslint/config@latest"],{cwd:e,stdio:"inherit",shell:!0});n.on("close",a=>{a===0||r.fail("ESLint setup failed. You can set it up later with: npm init @eslint/config"),t()}),n.on("error",a=>{r.fail(`ESLint setup failed: ${a.message}`),r.info("You can set it up later with: npm init @eslint/config"),t()})})}async createProject(){try{this.config=await this.gatherProjectConfig(),await this.executeProjectGeneration(this.config)}catch(e){e instanceof Error?r.error(`Failed to create project: ${e.message}`):r.error(`Failed to create project: ${String(e)}`),process.exit(1)}}};var b=require("commander"),k=require("fs"),u=require("path"),C=require("url"),W=(0,C.fileURLToPath)(f),Y=(0,u.dirname)(W),O=JSON.parse((0,k.readFileSync)((0,u.join)(Y,"../../package.json"),"utf-8")).version,x=new b.Command;x.name("create-gramstax").description("CLI to create a new Gramstax Telegram bot project").version(O).argument("[project-directory]","Directory to create the project in").action(async o=>{try{await new g(o).createProject()}catch(e){r.error(`Failed to create project: ${String(e)}`),process.exit(1)}});x.parse();
package/dist/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- var w=Object.defineProperty;var g=(l,e)=>w(l,"name",{value:e,configurable:!0});import{LoggingPretty as b}from"logging-pretty";var r=new b;import*as i from"fs";import*as a from"path";import{fileURLToPath as S}from"url";import{spawn as _}from"child_process";import y from"enquirer";var k=S(import.meta.url),C=a.dirname(k),m=class{constructor(e){this.projectDirectory=e}static{g(this,"Create")}config;printBanner(){console.log(`
2
+ var w=Object.defineProperty;var g=(l,e)=>w(l,"name",{value:e,configurable:!0});import{LoggingPretty as S}from"logging-pretty";var r=new S;import*as i from"fs";import*as a from"path";import{fileURLToPath as b}from"url";import{spawn as _}from"child_process";import y from"enquirer";var k=b(import.meta.url),C=a.dirname(k),m=class{constructor(e){this.projectDirectory=e}static{g(this,"Create")}config;printBanner(){console.log(`
3
3
  $$$$$$\\ $$\\
4
4
  $$ __$$\\ $$ |
5
5
  $$ / \\__| $$$$$$\\ $$$$$$\\ $$$$$$\\$$$$\\ $$$$$$$\\ $$$$$$\\ $$$$$$\\ $$\\ $$\\
@@ -16,7 +16,8 @@
16
16
  "semi": false,
17
17
  "arrowParens": "always",
18
18
  "trailingComma": "none",
19
- "bracketSameLine": false
19
+ "bracketSameLine": false,
20
+ "bracketSpacing": false
20
21
  }
21
22
  }
22
23
  ]
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "logging-pretty": "^3.0.0",
39
- "gramstax": "^0.3.9"
39
+ "gramstax": "^0.3.11"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "typescript": "5.9.3"
@@ -1,7 +1,7 @@
1
- import { CtxCore } from "~/core/ctx"
1
+ import {CtxCore} from "~/core/ctx"
2
2
 
3
3
  export abstract class GuardBase extends CtxCore {
4
- public constructor(ctx: CtxCore) {
4
+ constructor(ctx: CtxCore) {
5
5
  super(ctx)
6
6
  if (ctx?.data) {
7
7
  // save as temporary because guard should not save this.data or class.data because it is intended for Page only.
@@ -1,7 +1,7 @@
1
- import { KeyboardComponent } from "~/components/keyboard"
2
- import { CtxCore } from "~/core/ctx"
1
+ import {KeyboardComponent} from "~/components/keyboard"
2
+ import {CtxCore} from "~/core/ctx"
3
3
 
4
4
  export abstract class PageBase extends CtxCore {
5
- public static kbc = KeyboardComponent
6
- public static kbd = KeyboardComponent.data
5
+ static kbc = KeyboardComponent
6
+ static kbd = KeyboardComponent.data
7
7
  }
@@ -1,29 +1,29 @@
1
- import { KeyboardData } from "~/data/keyboard"
2
- import { ComponentKeyboard } from "gramstax"
1
+ import {KeyboardData} from "~/data/keyboard"
2
+ import {ComponentKeyboard} from "gramstax"
3
3
 
4
4
  export class KeyboardComponent extends ComponentKeyboard {
5
- public static data = KeyboardData
6
- public static home(lang?: string, type?: string) {
5
+ static data = KeyboardData
6
+ static home(lang?: string, type?: string) {
7
7
  return this._build(`home`, lang, type)
8
8
  }
9
9
 
10
- public static back(lang?: string, type?: string) {
10
+ static back(lang?: string, type?: string) {
11
11
  return this._build(`back`, lang, type)
12
12
  }
13
13
 
14
- public static cancel(lang?: string, type?: string) {
14
+ static cancel(lang?: string, type?: string) {
15
15
  return this._build(`cancel`, lang, type)
16
16
  }
17
17
 
18
- public static refresh(lang?: string, type?: string) {
18
+ static refresh(lang?: string, type?: string) {
19
19
  return this._build(`refresh`, lang, type)
20
20
  }
21
21
 
22
- public static refreshBack(lang?: string, type?: string) {
22
+ static refreshBack(lang?: string, type?: string) {
23
23
  return this._build(`refreshBack`, lang, type)
24
24
  }
25
25
 
26
- public static backRefresh(lang?: string, type?: string) {
26
+ static backRefresh(lang?: string, type?: string) {
27
27
  return this._build(`backRefresh`, lang, type)
28
28
  }
29
29
  }
@@ -1,11 +1,11 @@
1
- import { Gramstax } from "gramstax"
2
- import { UserGuard } from "~/guards/user"
3
- import { GeneralErrorPage } from "~/pages/general-error"
4
- import { GeneralErrorInputNotFoundPage } from "~/pages/general-error-input-notfound"
5
- import type { CtxCore } from "./ctx"
1
+ import {Gramstax} from "gramstax"
2
+ import {UserGuard} from "~/guards/user"
3
+ import {GeneralErrorPage} from "~/pages/general-error"
4
+ import {GeneralErrorInputNotFoundPage} from "~/pages/general-error-input-notfound"
5
+ import type {CtxCore} from "./ctx"
6
6
 
7
7
  export class BotCore extends Gramstax {
8
- public async hookBeforeRoute(ctx: CtxCore): Promise<boolean> {
8
+ async hookBeforeRoute(ctx: CtxCore): Promise<boolean> {
9
9
  const result = await new UserGuard(ctx).ensureValid(true)
10
10
  if (result === null) {
11
11
  return false
@@ -13,11 +13,11 @@ export class BotCore extends Gramstax {
13
13
  return true
14
14
  }
15
15
 
16
- public async hookErrorPage(ctx: CtxCore, listenerName: string, error: any, isEdit: boolean): Promise<void> {
17
- await new GeneralErrorPage(ctx).transition(this.constructor.name, listenerName, error, isEdit)
16
+ async hookErrorPage(ctx: CtxCore, listenerName: string, error: any, isEdit: boolean): Promise<void> {
17
+ await new GeneralErrorPage(ctx).transition(listenerName, error, isEdit)
18
18
  }
19
19
 
20
- public async hookErrorInputNotFoundPage(ctx: CtxCore): Promise<void> {
20
+ async hookErrorInputNotFoundPage(ctx: CtxCore): Promise<void> {
21
21
  await new GeneralErrorInputNotFoundPage(ctx).transition()
22
22
  }
23
23
  }
@@ -1,3 +1,3 @@
1
- import { Ctx } from "gramstax"
1
+ import {Ctx} from "gramstax"
2
2
 
3
3
  export class CtxCore extends Ctx {}
@@ -1,7 +1,7 @@
1
- import { DataKeyboard } from "gramstax"
1
+ import {DataKeyboard} from "gramstax"
2
2
 
3
3
  export class KeyboardData extends DataKeyboard {
4
- public static home(lang?: string) {
4
+ static home(lang?: string) {
5
5
  return this._build(lang, false, {
6
6
  default: `Home`,
7
7
  it: `Casa`,
@@ -9,7 +9,7 @@ export class KeyboardData extends DataKeyboard {
9
9
  })
10
10
  }
11
11
 
12
- public static back(lang?: string) {
12
+ static back(lang?: string) {
13
13
  return this._build(lang, false, {
14
14
  default: `.. Back`,
15
15
  it: `.. Ritorno`,
@@ -0,0 +1,15 @@
1
+ import {GuardBase} from "~/base/guard"
2
+
3
+ export class SessionGuard extends GuardBase {
4
+ async ensureTextFree() {
5
+ try {
6
+ const {method, params} = this.session
7
+ if (this.validateSessionTextFree(method, this.temp.data.name) === false) {
8
+ return null
9
+ }
10
+ return params
11
+ } catch {
12
+ return null
13
+ }
14
+ }
15
+ }
@@ -1,18 +1,17 @@
1
- import { GuardBase } from "~/base/guard"
2
- import { GeneralErrorPage } from "~/pages/general-error"
3
- import { UserNameNotFoundPage } from "~/pages/username-notfound"
1
+ import {GuardBase} from "~/base/guard"
2
+ import {GeneralErrorPage} from "~/pages/general-error"
3
+ import {UserNameNotFoundPage} from "~/pages/username-notfound"
4
4
 
5
5
  export class UserGuard extends GuardBase {
6
- public async ensureValid(isEdit: boolean) {
6
+ async ensureValid(isEdit: boolean) {
7
7
  try {
8
8
  if (!this.userName || this.userName.length == 0) {
9
9
  await new UserNameNotFoundPage(this).transition(isEdit)
10
10
  return null
11
11
  }
12
-
13
- return { status: true }
12
+ return {status: true}
14
13
  } catch (err) {
15
- await new GeneralErrorPage(this).transition(this.constructor.name, `ensureValid`, err, isEdit)
14
+ await new GeneralErrorPage(this).transition(`ensureValid`, err, isEdit)
16
15
  return null
17
16
  }
18
17
  }
@@ -1,12 +1,12 @@
1
- import { env } from "./env"
2
- import { logUt } from "./utils/log"
3
- import { BotCore } from "./core/bot"
4
- import { ExternalCache } from "./cache/external"
1
+ import {env} from "./env"
2
+ import {logUt} from "./utils/log"
3
+ import {BotCore} from "./core/bot"
4
+ import {CacheExternal} from "gramstax"
5
5
 
6
6
  logUt.success(`Bot started..`)
7
7
 
8
8
  new BotCore({
9
9
  token: env.BOT_TOKEN,
10
10
  deploy: env.BOT_DEPLOY,
11
- cacheSession: new ExternalCache(env.CACHE_SESSION, `session`, 24 * 60 * 60 * 1000)
11
+ cacheSession: new CacheExternal(env.CACHE_SESSION, `session`, 24 * 60 * 60 * 1000)
12
12
  })
@@ -1,23 +1,45 @@
1
- import { PageBase } from "~/base/page"
2
- import { StartPage } from "./start"
1
+ import {PageBase} from "~/base/page"
2
+ import {StartPage} from "./start"
3
3
 
4
4
  export class GeneralErrorInputNotFoundPage extends PageBase {
5
- public kb() {
5
+ kb() {
6
6
  return this.inlineKeyboard((kb, arr) => {
7
7
  return kb.text(arr[0]!, StartPage.data.callbackData())
8
8
  })
9
9
  }
10
10
 
11
- public async transition() {
12
- await this.edit(this.kb())
11
+ async transition(session?: boolean) {
12
+ if (session || this.session.method) {
13
+ await this.reply(this.kb(), undefined, `session-error`)
14
+ await this.sessionClear()
15
+ } else {
16
+ await this.reply(this.kb())
17
+ }
13
18
  }
14
19
 
15
- public static template = /*jsx*/ `
20
+ static template = /*jsx*/ `
16
21
  <base>
17
22
  ${this.kbc.home()}
18
- <message><b>❌ Not Found</b></message>
19
- <message lang="it"><b>❌ Non Trovato</b></message>
20
- <message lang="id"><b>❌ Tidak Ditemukan</b></message>
23
+ <message>
24
+ <b>❌ Not Found</b>
25
+ </message>
26
+ <message lang="id">
27
+ <b>❌ Tidak Ditemukan</b>
28
+ </message>
29
+ </base>
30
+ <base id="session-error">
31
+ <message>
32
+ <b>❌ Session Error</b>
33
+
34
+ An error occurred while processing your request.
35
+ Your session has an error.
36
+ </message>
37
+ <message lang="id">
38
+ <b>❌ Kesalahan Sesi</b>
39
+
40
+ Terjadi kesalahan saat memproses permintaan.
41
+ Sesi Anda bermasalh.
42
+ </message>
21
43
  </base>
22
44
  `
23
45
  }
@@ -1,16 +1,22 @@
1
- import { logUt } from "~/utils/log"
2
- import { PageBase } from "~/base/page"
3
- import { StartPage } from "./start"
1
+ import {logUt} from "~/utils/log"
2
+ import {PageBase} from "~/base/page"
3
+ import {StartPage} from "./start"
4
4
 
5
5
  export class GeneralErrorPage extends PageBase {
6
- public kb() {
6
+ constructorName?: string
7
+ constructor(p: any) {
8
+ super(p)
9
+ this.constructorName = p?.constructor?.name
10
+ }
11
+
12
+ kb() {
7
13
  return this.inlineKeyboard((kb, arr) => {
8
14
  return kb.text(arr[0]!, StartPage.data.callbackData())
9
15
  })
10
16
  }
11
17
 
12
- public async transition(constructorName: string, funcName: string, error: unknown, isUpdate = true) {
13
- logUt.errorMake(error, constructorName, funcName)
18
+ async transition(funcName: string, error: unknown, isUpdate = true) {
19
+ logUt.errorMake(error, this.constructorName, funcName)
14
20
  await this.sessionClear()
15
21
 
16
22
  const kb = this.kb()
@@ -21,10 +27,9 @@ export class GeneralErrorPage extends PageBase {
21
27
  }
22
28
  }
23
29
 
24
- public static template = /*jsx*/ `
30
+ static template = /*jsx*/ `
25
31
  <base>
26
32
  ${this.kbc.home()}
27
-
28
33
  <message>
29
34
  <b>❌ Error</b>
30
35
 
@@ -1,14 +1,14 @@
1
- import { PageBase } from "~/base/page"
2
- import { StartPage } from "./start"
1
+ import {PageBase} from "~/base/page"
2
+ import {StartPage} from "./start"
3
3
 
4
4
  export class HelpPage extends PageBase {
5
- public kb() {
5
+ kb() {
6
6
  return this.inlineKeyboard((kb, arr) => {
7
7
  return kb.text(arr[0]!, StartPage.data.callbackData())
8
8
  })
9
9
  }
10
10
 
11
- public async internal(edit = true) {
11
+ async internal(edit = true) {
12
12
  const kb = this.kb()
13
13
  if (edit) {
14
14
  await this.edit(kb)
@@ -17,15 +17,15 @@ export class HelpPage extends PageBase {
17
17
  }
18
18
  }
19
19
 
20
- public async callback() {
20
+ async callback() {
21
21
  await this.internal(true)
22
22
  }
23
23
 
24
- public async textCommand() {
24
+ async textCommand() {
25
25
  await this.internal(false)
26
26
  }
27
27
 
28
- public static template = /*jsx*/ `
28
+ static template = /*jsx*/ `
29
29
  <base>
30
30
  ${this.kbc.back()}
31
31
  <message><b>Help message</b></message>
@@ -0,0 +1,74 @@
1
+ import {PageBase} from "~/base/page"
2
+ import {StartPage} from "./start"
3
+ import {SessionGuard} from "~/guards/session"
4
+
5
+ export class InputTextPage extends PageBase {
6
+ static data = this.buildData({
7
+ textCommand: `input_text`
8
+ })
9
+
10
+ kb(baseId?: string) {
11
+ return this.inlineKeyboard(
12
+ (kb, arr) => {
13
+ return kb.text(arr[0]!, StartPage.data.callbackData())
14
+ },
15
+ {baseId}
16
+ )
17
+ }
18
+
19
+ async callback() {
20
+ await this.sessionToTextFree()
21
+ await this.edit(this.kb())
22
+ }
23
+
24
+ async textCommand() {
25
+ await this.sessionToTextFree()
26
+ await this.reply(this.kb())
27
+ }
28
+
29
+ async textFree() {
30
+ const params = await new SessionGuard(this).ensureTextFree()
31
+ if (params === null) {
32
+ /**
33
+ * Return "null" if you want the bot to continue to check for suitable route for the
34
+ * "dynamicSpecific" and "dynamic" type with the route suffix "Free" or "free" (without session), for example: textFree, animationFree, free.
35
+ *
36
+ * Return "undefined"/void if you want the bot to stop checking for "dynamicSpecific" and "dynamic" route types.
37
+ *
38
+ * Returning undefined/void indicates the success of this rule. There are only two returns allowed for all routes: null and undefined / void.
39
+ */
40
+ return null
41
+ }
42
+
43
+ const baseId = `result`
44
+ const data = {res: this.msgText}
45
+ await this.reply(this.kb(baseId), data, baseId)
46
+ }
47
+
48
+ static template = /*jsx*/ `
49
+ <base>
50
+ ${this.kbc.cancel()}
51
+ <message>Please input text you want view</message>
52
+ <message lang="it">Inserisci il testo che vuoi vedere</message>
53
+ <message lang="id">Tolong masukan text yang ingin anda liat</message>
54
+ </base>
55
+ <base id="result">
56
+ ${this.kbc.home()}
57
+ <message>
58
+ Result: {{res}}
59
+
60
+ Please input other text to see difference result
61
+ </message>
62
+ <message lang="it">
63
+ Risultato: {{res}}
64
+
65
+ Inserisci un altro testo per vedere il risultato diverso
66
+ </message>
67
+ <message lang="id">
68
+ Hasil: {{res}}
69
+
70
+ Tolong masukan text lain untuk lihat hasil yang berbeda
71
+ </message>
72
+ </base>
73
+ `
74
+ }
@@ -1,16 +1,16 @@
1
- import { HelpPage } from "./help"
2
- import { PageBase } from "~/base/page"
1
+ import {HelpPage} from "./help"
2
+ import {PageBase} from "~/base/page"
3
3
 
4
4
  export class StartPage extends PageBase {
5
- public kb() {
5
+ kb() {
6
6
  return this.inlineKeyboard((kb, arr) => {
7
7
  return kb.text(arr[0]!, HelpPage.data.callbackData())
8
8
  })
9
9
  }
10
10
 
11
- public async internal(edit = true) {
11
+ async internal(edit = true) {
12
12
  const kb = this.kb()
13
- const data = { userName: this.userName }
13
+ const data = {userName: this.userName}
14
14
  if (edit) {
15
15
  await this.edit(kb, data)
16
16
  } else {
@@ -18,21 +18,20 @@ export class StartPage extends PageBase {
18
18
  }
19
19
  }
20
20
 
21
- public async callback() {
21
+ async callback() {
22
22
  await this.internal(true)
23
23
  }
24
24
 
25
- public async textCommand() {
25
+ async textCommand() {
26
26
  await this.internal(false)
27
27
  }
28
28
 
29
- public static template = /*jsx*/ `
29
+ static template = /*jsx*/ `
30
30
  <base id="with-import-and-you-can-use-components">
31
31
  <keyboard>❓ Help</keyboard>
32
32
  <keyboard lang="it">❓ Aiuto</keyboard>
33
33
  <keyboard lang="id">❓ Bantuan</keyboard>
34
34
  </base>
35
-
36
35
  <base>
37
36
  <import src="start" base="with-import-and-you-can-use-components" />
38
37
  <message>
@@ -1,14 +1,14 @@
1
- import { HelpPage } from "./help"
2
- import { PageBase } from "~/base/page"
1
+ import {HelpPage} from "./help"
2
+ import {PageBase} from "~/base/page"
3
3
 
4
4
  export class UserNameNotFoundPage extends PageBase {
5
- public kb() {
5
+ kb() {
6
6
  return this.inlineKeyboard((kb, arr) => {
7
7
  return kb.text(arr[0]!, HelpPage.data.callbackData())
8
8
  })
9
9
  }
10
10
 
11
- public async transition(edit = true) {
11
+ async transition(edit = true) {
12
12
  const kb = this.kb()
13
13
  if (edit) {
14
14
  await this.edit(kb)
@@ -17,7 +17,7 @@ export class UserNameNotFoundPage extends PageBase {
17
17
  }
18
18
  }
19
19
 
20
- public static template = /*jsx*/ `
20
+ static template = /*jsx*/ `
21
21
  <base>
22
22
  ${this.kbc.home()}
23
23
  <message>Please set the username first before using the bot.</message>
@@ -1,2 +1,2 @@
1
- import { log } from "gramstax"
2
- export { log as logUt }
1
+ import {log} from "gramstax"
2
+ export {log as logUt}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-gramstax",
3
- "version": "0.3.10",
3
+ "version": "0.3.12",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -1 +0,0 @@
1
- export abstract class RepoBase {}
@@ -1 +0,0 @@
1
- export abstract class ServiceBase {}
@@ -1,3 +0,0 @@
1
- import { CacheExternal } from "gramstax"
2
-
3
- export class ExternalCache extends CacheExternal {}
@@ -1 +0,0 @@
1
- export class ExampleDb {}
@@ -1,3 +0,0 @@
1
- import { RepoBase } from "~/base/repository"
2
-
3
- export class ExampleRepo extends RepoBase {}
@@ -1,3 +0,0 @@
1
- import { ServiceBase } from "~/base/service"
2
-
3
- export class ExampleService extends ServiceBase {}
@@ -1,3 +0,0 @@
1
- import { ThreadExport } from "gramstax"
2
-
3
- export class ExportThread extends ThreadExport {}
@@ -1,3 +0,0 @@
1
- import { ThreadMainPool } from "gramstax"
2
-
3
- export class MainPoolThread extends ThreadMainPool {}
@@ -1,3 +0,0 @@
1
- import { ThreadMain } from "gramstax"
2
-
3
- export class MainThread extends ThreadMain {}
@@ -1,3 +0,0 @@
1
- import { ThreadSub } from "gramstax"
2
-
3
- export class SubThread extends ThreadSub {}