create-gramstax 0.8.6 → 0.8.8

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.8.5",
38
+ "gramstax": "^0.8.7",
39
39
  "dayjs": "^1.11.13"
40
40
  },
41
41
  "peerDependencies": {
@@ -13,10 +13,10 @@ export class BotCore extends Gramstax {
13
13
  }
14
14
 
15
15
  async hookErrorPage(ctx: CtxCore, listenerName: string, error: any, isEdit: boolean) {
16
- await new GeneralStatusPage(ctx).error(`${listenerName}:hookErrorPage`, error, isEdit)
16
+ await new GeneralStatusPage(ctx).showError(`${listenerName}:hookErrorPage`, error, isEdit)
17
17
  }
18
18
 
19
19
  async hookErrorInputNotFoundPage(ctx: CtxCore) {
20
- await new GeneralStatusPage(ctx).errorInputNotFound()
20
+ await new GeneralStatusPage(ctx).showErrorInputNotFound()
21
21
  }
22
22
  }
@@ -4,14 +4,14 @@ import {UserNameNotFoundPage} from "~/pages/username-notfound"
4
4
 
5
5
  export class UserGuard extends GuardBase {
6
6
  async _catch(err: any, func: any, isEdit: boolean) {
7
- await new GeneralStatusPage(this).error(func, err, isEdit)
7
+ await new GeneralStatusPage(this).showError(func, err, isEdit)
8
8
  return null
9
9
  }
10
10
 
11
11
  async ensureUsername(edit: boolean) {
12
12
  try {
13
13
  if (!this.userName || this.userName.length == 0) {
14
- await new UserNameNotFoundPage(this).showEntryPoint(edit)
14
+ await new UserNameNotFoundPage(this).showStep1Form(edit)
15
15
  return null
16
16
  }
17
17
  return {status: true}
@@ -1,14 +1,8 @@
1
1
  import {PageBase} from "~/base/page"
2
2
 
3
- class Main {
4
- static async showEntryPoint(ctx: BlankPage) {
5
- await ctx.callbackQueryAnswer()
6
- }
7
- }
8
-
9
3
  export class BlankPage extends PageBase {
10
4
  async handleCallbackData() {
11
- await Main.showEntryPoint(this)
5
+ await this.callbackQueryAnswer()
12
6
  }
13
7
 
14
8
  static template = `<base></base>`
@@ -2,30 +2,38 @@ import {LogHe} from "~/helpers/log"
2
2
  import {PageBase} from "~/base/page"
3
3
  import {StartPage} from "./start"
4
4
 
5
+ class Base {
6
+ static dynamic = `d`
7
+ }
8
+
5
9
  class Helper {
6
10
  static kb(ctx: GeneralStatusPage) {
7
- return ctx.inlineKeyboardT([StartPage])
11
+ const bi = Base.dynamic
12
+ const kb = ctx.inlineKeyboardT([StartPage], `1`, bi)
13
+ return kb
8
14
  }
9
15
  }
10
16
 
11
17
  class Alert {
12
- static async error(ctx: GeneralStatusPage, funcName: string, error: any, edit = true) {
18
+ static async showError(ctx: GeneralStatusPage, funcName: string, error: any, edit = true) {
13
19
  LogHe.errorMake(error, ctx.constructorName, funcName)
14
20
 
15
21
  await ctx.clearSession()
22
+ const bi = Base.dynamic
16
23
  const kb = Helper.kb(ctx)
17
24
  const da = {isNotFound: false}
18
25
  if (edit) {
19
- await ctx.edit(kb, da)
26
+ await ctx.edit(kb, da, bi)
20
27
  } else {
21
- await ctx.reply(kb, da)
28
+ await ctx.reply(kb, da, bi)
22
29
  }
23
30
  }
24
31
 
25
- static async errorInputNotFound(ctx: GeneralStatusPage) {
32
+ static async showErrorInputNotFound(ctx: GeneralStatusPage) {
33
+ const bi = Base.dynamic
26
34
  const kb = Helper.kb(ctx)
27
35
  const da = {isNotFound: true}
28
- await ctx.reply(kb, da)
36
+ await ctx.reply(kb, da, bi)
29
37
  }
30
38
  }
31
39
 
@@ -37,16 +45,16 @@ export class GeneralStatusPage extends PageBase {
37
45
  this.constructorName = p?.constructor?.name
38
46
  }
39
47
 
40
- async error(...args: Parameters<typeof Alert.error> extends [any, ...infer R] ? R : []) {
41
- await Alert.error(this, ...args)
48
+ async showError(...args: Parameters<typeof Alert.showError> extends [any, ...infer R] ? R : []) {
49
+ await Alert.showError(this, ...args)
42
50
  }
43
51
 
44
- async errorInputNotFound() {
45
- await Alert.errorInputNotFound(this)
52
+ async showErrorInputNotFound() {
53
+ await Alert.showErrorInputNotFound(this)
46
54
  }
47
55
 
48
56
  static template = `
49
- <base>
57
+ <base id="${Base.dynamic}">
50
58
  ${this.kbk.home()}
51
59
  <message>
52
60
  <b>{~isNotFound ? "🔎 Route Not Found" : "❌ Error Occurred"~}</b>
@@ -1,28 +1,38 @@
1
1
  import {PageBase} from "~/base/page"
2
2
  import {StartPage} from "./start"
3
3
 
4
+ class Base {
5
+ static step1 = `s1`
6
+ }
7
+
4
8
  class Main {
5
- static async showEntryPoint(ctx: HelpPage, edit = true) {
6
- const kb = ctx.inlineKeyboardT([StartPage])
9
+ static async showStep1Form(ctx: HelpPage, edit = true) {
10
+ const bi = Base.step1
11
+ const kb = ctx.inlineKeyboardT([StartPage], `1`, bi)
12
+ const da = {}
7
13
  if (edit) {
8
- await ctx.edit(kb)
14
+ await ctx.edit(kb, da, bi)
9
15
  } else {
10
- await ctx.reply(kb)
16
+ await ctx.reply(kb, da, bi)
11
17
  }
12
18
  }
19
+
20
+ static async processStep1Answer(ctx: HelpPage) {
21
+ throw ctx
22
+ }
13
23
  }
14
24
 
15
25
  export class HelpPage extends PageBase {
16
26
  async handleCallbackData() {
17
- await Main.showEntryPoint(this, true)
27
+ await Main.showStep1Form(this, true)
18
28
  }
19
29
 
20
30
  async handleCommandText() {
21
- await Main.showEntryPoint(this, false)
31
+ await Main.showStep1Form(this, false)
22
32
  }
23
33
 
24
34
  static template = `
25
- <base>
35
+ <base id="${Base.step1}">
26
36
  ${this.kbk.back()}
27
37
  <message>
28
38
  <b>🆘 Help Message</b>
@@ -1,33 +1,42 @@
1
1
  import {PageBase} from "~/base/page"
2
2
  import {StartPage} from "./start"
3
3
 
4
+ class Base {
5
+ static step1 = `s1`
6
+ }
7
+
4
8
  class Main {
5
- static async showEntryPoint(ctx: RandomNumberPage, edit = true) {
6
- const kb = ctx.inlineKeyboardT([this, StartPage])
9
+ static async showStep1Form(ctx: RandomNumberPage, edit = true) {
10
+ const bi = Base.step1
11
+ const kb = ctx.inlineKeyboardT([ctx, StartPage], `1`, bi)
7
12
  const da = {result: Math.random() * 10 ** 18}
8
13
  if (edit) {
9
- await ctx.edit(kb, da)
14
+ await ctx.edit(kb, da, bi)
10
15
  } else {
11
- await ctx.reply(kb, da)
16
+ await ctx.reply(kb, da, bi)
12
17
  }
13
18
  }
19
+
20
+ static async processStep1Answer(ctx: RandomNumberPage) {
21
+ throw ctx
22
+ }
14
23
  }
15
24
 
16
25
  export class RandomNumberPage extends PageBase {
17
26
  async handleCallbackData() {
18
- await Main.showEntryPoint(this, true)
27
+ await Main.showStep1Form(this, true)
19
28
  }
20
29
 
21
30
  async handleCommandText() {
22
- await Main.showEntryPoint(this, false)
31
+ await Main.showStep1Form(this, false)
23
32
  }
24
33
 
25
- async entryPoint(edit = true) {
26
- await Main.showEntryPoint(this, edit)
34
+ async showStep1Form(edit = true) {
35
+ await Main.showStep1Form(this, edit)
27
36
  }
28
37
 
29
38
  static template = `
30
- <base>
39
+ <base id="${Base.step1}">
31
40
  <keyboard>🎲 Shake, ${this.kbl.back.default}</keyboard>
32
41
  <keyboard lang="id">🎲 Kocok, ${this.kbl.back.id}</keyboard>
33
42
  <message>
@@ -3,34 +3,43 @@ import {PageBase} from "~/base/page"
3
3
  import {RandomNumberPage} from "./random-number"
4
4
  import {SumNumberPage} from "./sum-number"
5
5
 
6
+ class Base {
7
+ static step1 = `s1`
8
+ }
9
+
6
10
  class Main {
7
- static async showEntryPoint(ctx: StartPage, edit = true) {
11
+ static async showStep1Form(ctx: StartPage, edit = true) {
8
12
  await ctx.clearSession()
9
- const kb = ctx.inlineKeyboardT([RandomNumberPage, SumNumberPage, HelpPage], `2`)
13
+ const bi = Base.step1
14
+ const kb = ctx.inlineKeyboardT([RandomNumberPage, SumNumberPage, HelpPage], `2`, bi)
10
15
  const da = {userName: ctx.userName}
11
16
  if (edit) {
12
- await ctx.edit(kb, da)
17
+ await ctx.edit(kb, da, bi)
13
18
  } else {
14
- await ctx.reply(kb, da)
19
+ await ctx.reply(kb, da, bi)
15
20
  }
16
21
  }
22
+
23
+ static async processStep1Answer(ctx: StartPage) {
24
+ throw ctx
25
+ }
17
26
  }
18
27
 
19
28
  export class StartPage extends PageBase {
20
29
  async handleCallbackData() {
21
- await Main.showEntryPoint(this, true)
30
+ await Main.showStep1Form(this, true)
22
31
  }
23
32
 
24
33
  async handleCommandText() {
25
- await Main.showEntryPoint(this, false)
34
+ await Main.showStep1Form(this, false)
26
35
  }
27
36
 
28
- async entryPoint(edit = true) {
29
- await Main.showEntryPoint(this, edit)
37
+ async showStep1Form(edit = true) {
38
+ await Main.showStep1Form(this, edit)
30
39
  }
31
40
 
32
41
  static template = `
33
- <base>
42
+ <base id="${Base.step1}">
34
43
  <keyboard>🎰 Random Number, ➕ Sum Number, 🆘 Help</keyboard>
35
44
  <keyboard lang="id">🎰 Angka Acak, ➕ Jumlah Angka, 🆘 Bantuan</keyboard>
36
45
  <message>
@@ -2,14 +2,14 @@ import {PageBase} from "~/base/page"
2
2
  import {StartPage} from "./start"
3
3
 
4
4
  class Base {
5
- static pleft: `pleft`
6
- static pright: `pright`
5
+ static step1: `s1`
6
+ static step2: `s2`
7
7
  static success: `success`
8
8
  }
9
9
 
10
10
  class Helper {
11
11
  static getSessionParams(ctx: SumNumberPage) {
12
- return (ctx.temp.session?.params as {step?: `left` | `right`; left?: number} | undefined) ?? {}
12
+ return (ctx.temp.session?.params as {step?: (typeof Base)[keyof typeof Base]; left?: number} | undefined) ?? {}
13
13
  }
14
14
 
15
15
  static kb(ctx: SumNumberPage, baseId: string) {
@@ -18,7 +18,7 @@ class Helper {
18
18
  }
19
19
 
20
20
  class Alert {
21
- static async success(ctx: SumNumberPage, left: number, right: number) {
21
+ static async showSuccess(ctx: SumNumberPage, left: number, right: number) {
22
22
  await ctx.clearSession()
23
23
  const bi = Base.success
24
24
  const kb = Helper.kb(ctx, bi)
@@ -29,10 +29,10 @@ class Alert {
29
29
 
30
30
  class Main {
31
31
  static async showStep1Form(ctx: SumNumberPage, edit: boolean) {
32
- await ctx.sessionFreeText({step: `left`})
33
- const bi = Base.pleft
32
+ const bi = Base.step1
34
33
  const kb = Helper.kb(ctx, bi)
35
34
  const da = {}
35
+ await ctx.sessionFreeText({step: bi})
36
36
  if (edit) {
37
37
  await ctx.edit(kb, da, bi)
38
38
  } else {
@@ -49,10 +49,10 @@ class Main {
49
49
  }
50
50
 
51
51
  static async showStep2Form(ctx: SumNumberPage, left: number) {
52
- await ctx.sessionFreeText({step: `right`, left})
53
- const bi = Base.pright
52
+ const bi = Base.step2
54
53
  const kb = Helper.kb(ctx, bi)
55
54
  const da = {}
55
+ await ctx.sessionFreeText({step: bi, left})
56
56
  await ctx.reply(kb, da, bi)
57
57
  }
58
58
 
@@ -60,10 +60,9 @@ class Main {
60
60
  if (!Number.isFinite(right)) {
61
61
  await Main.showStep2Form(ctx, right)
62
62
  } else if (!Number.isFinite(right ?? NaN)) {
63
- await ctx.clearSession()
64
63
  await Main.showStep1Form(ctx, false)
65
64
  } else {
66
- await Alert.success(ctx, left, right)
65
+ await Alert.showSuccess(ctx, left, right)
67
66
  }
68
67
  }
69
68
  }
@@ -84,15 +83,15 @@ export class SumNumberPage extends PageBase {
84
83
  const {step, left} = Helper.getSessionParams(this)
85
84
  const input = this.msgText?.trim()
86
85
  const value = input ? Number(input) : NaN
87
- if (step === `left`) {
86
+ if (step === Base.step1) {
88
87
  await Main.processStep1Answer(this, value)
89
- } else if (step === `right`) {
88
+ } else if (step === Base.step2) {
90
89
  await Main.processStep2Answer(this, left!, value)
91
90
  }
92
91
  }
93
92
 
94
93
  static template = `
95
- <base id="${Base.pleft}">
94
+ <base id="${Base.step1}">
96
95
  ${this.kbk.cancel()}
97
96
  <message>
98
97
  <b>📚 Input Left Number</b>
@@ -106,7 +105,7 @@ export class SumNumberPage extends PageBase {
106
105
  </message>
107
106
  </base>
108
107
 
109
- <base id="${Base.pright}">
108
+ <base id="${Base.step2}">
110
109
  ${this.kbk.cancel()}
111
110
  <message>
112
111
  <b>📚 Input Right Number</b>
@@ -1,24 +1,34 @@
1
1
  import {HelpPage} from "./help"
2
2
  import {PageBase} from "~/base/page"
3
3
 
4
+ class Base {
5
+ static step1 = `s1`
6
+ }
7
+
4
8
  class Main {
5
- static async showEntryPoint(ctx: UserNameNotFoundPage, edit = true) {
6
- const kb = ctx.inlineKeyboardT([HelpPage])
9
+ static async showStep1Form(ctx: UserNameNotFoundPage, edit = true) {
10
+ const bi = Base.step1
11
+ const kb = ctx.inlineKeyboardT([HelpPage], `1`, bi)
12
+ const da = {}
7
13
  if (edit) {
8
- await ctx.edit(kb)
14
+ await ctx.edit(kb, da, bi)
9
15
  } else {
10
- await ctx.reply(kb)
16
+ await ctx.reply(kb, da, bi)
11
17
  }
12
18
  }
19
+
20
+ static async processStep1Answer(ctx: UserNameNotFoundPage) {
21
+ throw ctx
22
+ }
13
23
  }
14
24
 
15
25
  export class UserNameNotFoundPage extends PageBase {
16
- async showEntryPoint(edit = true) {
17
- await Main.showEntryPoint(this, edit)
26
+ async showStep1Form(edit = true) {
27
+ await Main.showStep1Form(this, edit)
18
28
  }
19
29
 
20
30
  static template = `
21
- <base>
31
+ <base id="${Base.step1}">
22
32
  ${this.kbk.home()}
23
33
  <message>
24
34
  <b>⚠️ Username Required</b>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-gramstax",
3
- "version": "0.8.6",
3
+ "version": "0.8.8",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",