create-gramstax 0.5.17 → 0.5.19

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.
@@ -35,7 +35,7 @@
35
35
  "lint:fix": "eslint . --fix"
36
36
  },
37
37
  "dependencies": {
38
- "gramstax": "^0.5.16",
38
+ "gramstax": "^0.5.18",
39
39
  "dayjs": "^1.11.13"
40
40
  },
41
41
  "peerDependencies": {
@@ -4,9 +4,11 @@ export class KeyboardBlock extends BlockKeyboard {
4
4
  static label = class extends LabelKeyboard {
5
5
  static home = {default: `🏠 Home`, id: `🏠 Beranda`}
6
6
  static back = {default: `⬅️ Back`, id: `⬅️ Kembali`}
7
+ static cancel = {default: `✖️ Cancel`, id: `✖️ Batal`}
7
8
  static backHome = {default: `${this.back.default}, ${this.home.default}`, id: `${this.back.id}, ${this.home.id}`}
8
9
  }
9
10
  static home = (lang?: string, type?: string) => this._build(`home`, lang, type)
10
11
  static back = (lang?: string, type?: string) => this._build(`back`, lang, type)
12
+ static cancel = (lang?: string, type?: string) => this._build(`cancel`, lang, type)
11
13
  static backHome = (lang?: string, type?: string) => this._build(`backHome`, lang, type)
12
14
  }
@@ -23,11 +23,17 @@ export class HelpPage extends PageBase {
23
23
  <b>🆘 Help Message</b>
24
24
 
25
25
  Use this command to get help and instructions.
26
+
27
+ <b>🎰 Random Number</b> - Generate a random number
28
+ <b>➕ Sum Number</b> - Add two numbers together
26
29
  </message>
27
30
  <message lang="id">
28
31
  <b>🆘 Pesan Bantuan</b>
29
32
 
30
33
  Gunakan perintah ini untuk melihat bantuan dan petunjuk.
34
+
35
+ <b>🎰 Angka Acak</b> - Menghasilkan angka secara acak
36
+ <b>➕ Jumlah Angka</b> - Menjumlahkan dua angka
31
37
  </message>
32
38
  </base>
33
39
  `
@@ -1,11 +1,12 @@
1
1
  import {HelpPage} from "./help"
2
2
  import {PageBase} from "~/base/page"
3
3
  import {RandomNumberPage} from "./random-number"
4
+ import {SumNumberPage} from "./sum-number"
4
5
 
5
6
  export class StartPage extends PageBase {
6
7
  async show(edit = true) {
7
8
  await this.sessionClear()
8
- const kb = this.inlineKeyboardT([RandomNumberPage, HelpPage], `1`)
9
+ const kb = this.inlineKeyboardT([RandomNumberPage, SumNumberPage, HelpPage], `2`)
9
10
  const data = {userName: this.userName}
10
11
  if (edit) await this.edit(kb, data)
11
12
  else await this.reply(kb, data)
@@ -21,14 +22,15 @@ export class StartPage extends PageBase {
21
22
 
22
23
  static template = `
23
24
  <base>
24
- <keyboard>🎰 Random Number, 🆘 Help</keyboard>
25
- <keyboard lang="id">🎰 Angka Acak, 🆘 Bantuan</keyboard>
25
+ <keyboard>🎰 Random Number, ➕ Sum Number, 🆘 Help</keyboard>
26
+ <keyboard lang="id">🎰 Angka Acak, ➕ Jumlah Angka, 🆘 Bantuan</keyboard>
26
27
  <message>
27
28
  <b>👋 Welcome to the bot {{userName}}</b>
28
29
 
29
30
  This bot was initially generated using Gramstax as the base setup and starting structure. It provides a clean foundation that can be extended with custom features, commands, and integrations as needed.
30
31
 
31
32
  <b>🎰 Random Number</b> - Generate a random number
33
+ <b>➕ Sum Number</b> - Add two numbers together
32
34
  <b>❓ Help</b> - View help and available commands
33
35
  </message>
34
36
  <message lang="id">
@@ -37,6 +39,7 @@ export class StartPage extends PageBase {
37
39
  Bot ini dibuat menggunakan Gramstax sebagai generator awal dan struktur dasar. Dari sini, bot dapat dikembangkan lebih lanjut dengan fitur, perintah, dan integrasi sesuai kebutuhan.
38
40
 
39
41
  <b>🎰 Angka Acak</b> - Menghasilkan angka secara acak
42
+ <b>➕ Jumlah Angka</b> - Menjumlahkan dua angka
40
43
  <b>❓ Bantuan</b> - Lihat bantuan dan daftar perintah
41
44
  </message>
42
45
  </base>
@@ -0,0 +1,104 @@
1
+ import {PageBase} from "~/base/page"
2
+ import {StartPage} from "./start"
3
+
4
+ export class SumNumberPage extends PageBase {
5
+ static BASE = {pleft: `pleft`, pright: `pright`, result: `result`}
6
+
7
+ async callback() {
8
+ await this.first(true)
9
+ }
10
+
11
+ async textCommand() {
12
+ await this.first(false)
13
+ }
14
+
15
+ async textFree() {
16
+ if (!this.validateSessionTextFree()) return null
17
+ const {step, left} = this.getSessionParams()
18
+ const input = this.msgText?.trim()
19
+ const value = input ? Number(input) : NaN
20
+
21
+ if (step === `left`) {
22
+ if (!Number.isFinite(value)) {
23
+ await this.sessionTextFree({step: `left`})
24
+ return await this.reply(this.kb(SumNumberPage.BASE.pleft), {}, SumNumberPage.BASE.pleft)
25
+ }
26
+
27
+ await this.sessionTextFree({step: `right`, left: value})
28
+ return await this.reply(this.kb(SumNumberPage.BASE.pright), {}, SumNumberPage.BASE.pright)
29
+ }
30
+
31
+ if (step === `right`) {
32
+ if (!Number.isFinite(value)) {
33
+ await this.sessionTextFree({step: `right`, left})
34
+ return await this.reply(this.kb(SumNumberPage.BASE.pright), {}, SumNumberPage.BASE.pright)
35
+ }
36
+
37
+ if (!Number.isFinite(left ?? NaN)) {
38
+ await this.sessionClear()
39
+ return await this.first(false)
40
+ }
41
+
42
+ const result = left! + value
43
+ await this.sessionClear()
44
+ return await this.reply(this.kb(SumNumberPage.BASE.result), {result}, SumNumberPage.BASE.result)
45
+ }
46
+ }
47
+
48
+ private async first(edit: boolean) {
49
+ await this.sessionTextFree({step: `left`})
50
+ const kb = this.kb(SumNumberPage.BASE.pleft)
51
+ if (edit) await this.edit(kb, {}, SumNumberPage.BASE.pleft)
52
+ else await this.reply(kb, {}, SumNumberPage.BASE.pleft)
53
+ }
54
+
55
+ private kb(baseId: string) {
56
+ return this.inlineKeyboardT([StartPage], `1`, baseId)
57
+ }
58
+
59
+ private getSessionParams() {
60
+ return (this.session?.params as {step?: `left` | `right`; left?: number} | undefined) ?? {}
61
+ }
62
+
63
+ static template = `
64
+ <base id="${this.BASE.pleft}">
65
+ ${this.kbk.cancel()}
66
+ <message>
67
+ <b>📚 Input Left Number</b>
68
+
69
+ Example: 23
70
+ </message>
71
+ <message lang="id">
72
+ <b>📚 Masukan Angka Kiri</b>
73
+
74
+ Contoh: 23
75
+ </message>
76
+ </base>
77
+ <base id="${this.BASE.pright}">
78
+ ${this.kbk.cancel()}
79
+ <message>
80
+ <b>📚 Input Right Number</b>
81
+
82
+ Example: 10
83
+ </message>
84
+ <message lang="id">
85
+ <b>📚 Masukan Angka Kanan</b>
86
+
87
+ Contoh: 10
88
+ </message>
89
+ </base>
90
+ <base id="${this.BASE.result}">
91
+ ${this.kbk.home()}
92
+ <message>
93
+ <b>📚 Result Sum</b>
94
+
95
+ {{result}}
96
+ </message>
97
+ <message lang="id">
98
+ <b>📚 Hasil Sum</b>
99
+
100
+ {{result}}
101
+ </message>
102
+ </base>
103
+ `
104
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-gramstax",
3
- "version": "0.5.17",
3
+ "version": "0.5.19",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -9,6 +9,7 @@
9
9
  "description": "",
10
10
  "keywords": [],
11
11
  "scripts": {
12
+ "build": "tsup",
12
13
  "nx-release-publish": "npm publish --access public"
13
14
  },
14
15
  "repository": {