create-gramstax 0.6.1 → 0.7.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.
@@ -35,7 +35,7 @@
35
35
  "lint:fix": "eslint . --fix"
36
36
  },
37
37
  "dependencies": {
38
- "gramstax": "^0.6.0",
38
+ "gramstax": "^0.7.0",
39
39
  "dayjs": "^1.11.13"
40
40
  },
41
41
  "peerDependencies": {
@@ -17,11 +17,11 @@ export class GeneralStatusPage extends PageBase {
17
17
  async toError(funcName: string, error: any, edit = true) {
18
18
  log.errorMake(error, this.constructorName, funcName)
19
19
 
20
- await this.sessionClear()
20
+ await this.clearSession()
21
21
  const kb = this.kb()
22
- const data = {isNotFound: false}
23
- if (edit) await this.edit(kb, data)
24
- else await this.reply(kb, data)
22
+ const da = {isNotFound: false}
23
+ if (edit) await this.edit(kb, da)
24
+ else await this.reply(kb, da)
25
25
  }
26
26
 
27
27
  async toErrorInputNotFound() {
@@ -8,11 +8,11 @@ export class HelpPage extends PageBase {
8
8
  else await this.reply(kb)
9
9
  }
10
10
 
11
- async callback() {
11
+ async handleCallbackData() {
12
12
  await this.show(true)
13
13
  }
14
14
 
15
- async textCommand() {
15
+ async handleCommandText() {
16
16
  await this.show(false)
17
17
  }
18
18
 
@@ -2,6 +2,14 @@ import {PageBase} from "~/base/page"
2
2
  import {StartPage} from "./start"
3
3
 
4
4
  export class RandomNumberPage extends PageBase {
5
+ async handleCallbackData() {
6
+ await this.show(true)
7
+ }
8
+
9
+ async handleCommandText() {
10
+ await this.show(false)
11
+ }
12
+
5
13
  async show(edit = true) {
6
14
  const kb = this.inlineKeyboardT([this, StartPage])
7
15
  const da = {result: Math.random() * 10 ** 18}
@@ -9,14 +17,6 @@ export class RandomNumberPage extends PageBase {
9
17
  else await this.reply(kb, da)
10
18
  }
11
19
 
12
- async callback() {
13
- await this.show(true)
14
- }
15
-
16
- async textCommand() {
17
- await this.show(false)
18
- }
19
-
20
20
  static template = `
21
21
  <base>
22
22
  <keyboard>🎲 Shake, ${this.kbl.back.default}</keyboard>
@@ -4,22 +4,22 @@ import {RandomNumberPage} from "./random-number"
4
4
  import {SumNumberPage} from "./sum-number"
5
5
 
6
6
  export class StartPage extends PageBase {
7
+ async handleCallbackData() {
8
+ await this.show(true)
9
+ }
10
+
11
+ async handleCommandText() {
12
+ await this.show(false)
13
+ }
14
+
7
15
  async show(edit = true) {
8
- await this.sessionClear()
16
+ await this.clearSession()
9
17
  const kb = this.inlineKeyboardT([RandomNumberPage, SumNumberPage, HelpPage], `2`)
10
18
  const data = {userName: this.userName}
11
19
  if (edit) await this.edit(kb, data)
12
20
  else await this.reply(kb, data)
13
21
  }
14
22
 
15
- async callback() {
16
- await this.show(true)
17
- }
18
-
19
- async textCommand() {
20
- await this.show(false)
21
- }
22
-
23
23
  static template = `
24
24
  <base>
25
25
  <keyboard>🎰 Random Number, ➕ Sum Number, 🆘 Help</keyboard>
@@ -4,52 +4,55 @@ import {StartPage} from "./start"
4
4
  export class SumNumberPage extends PageBase {
5
5
  static BASE = {pleft: `pleft`, pright: `pright`, result: `result`}
6
6
 
7
- async callback() {
7
+ async handleCallbackData() {
8
8
  await this.first(true)
9
9
  }
10
10
 
11
- async textCommand() {
11
+ async handleCommandText() {
12
12
  await this.first(false)
13
13
  }
14
14
 
15
- async textFree() {
16
- if (!this.validateSessionTextFree()) return null
15
+ async handleFreeText() {
16
+ if (!this.isSessionFreeText()) return null
17
+ const {BASE} = SumNumberPage
17
18
  const {step, left} = this.getSessionParams()
18
19
  const input = this.msgText?.trim()
19
20
  const value = input ? Number(input) : NaN
20
21
 
21
22
  if (step === `left`) {
22
23
  if (!Number.isFinite(value)) {
23
- await this.sessionTextFree({step: `left`})
24
- return await this.reply(this.kb(SumNumberPage.BASE.pleft), {}, SumNumberPage.BASE.pleft)
24
+ await this.sessionFreeText({step: `left`})
25
+ return await this.reply(this.kb(BASE.pleft), {}, BASE.pleft)
25
26
  }
26
27
 
27
- await this.sessionTextFree({step: `right`, left: value})
28
- return await this.reply(this.kb(SumNumberPage.BASE.pright), {}, SumNumberPage.BASE.pright)
28
+ await this.sessionFreeText({step: `right`, left: value})
29
+ return await this.reply(this.kb(BASE.pright), {}, BASE.pright)
29
30
  }
30
31
 
31
32
  if (step === `right`) {
32
33
  if (!Number.isFinite(value)) {
33
- await this.sessionTextFree({step: `right`, left})
34
- return await this.reply(this.kb(SumNumberPage.BASE.pright), {}, SumNumberPage.BASE.pright)
34
+ await this.sessionFreeText({step: `right`, left})
35
+ return await this.reply(this.kb(BASE.pright), {}, BASE.pright)
35
36
  }
36
37
 
37
38
  if (!Number.isFinite(left ?? NaN)) {
38
- await this.sessionClear()
39
+ await this.clearSession()
39
40
  return await this.first(false)
40
41
  }
41
42
 
42
43
  const result = left! + value
43
- await this.sessionClear()
44
- return await this.reply(this.kb(SumNumberPage.BASE.result), {result}, SumNumberPage.BASE.result)
44
+ await this.clearSession()
45
+ return await this.reply(this.kb(BASE.result), {result}, BASE.result)
45
46
  }
46
47
  }
47
48
 
48
49
  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)
50
+ await this.sessionFreeText({step: `left`})
51
+ const {BASE} = SumNumberPage
52
+ const kb = this.kb(BASE.pleft)
53
+
54
+ if (edit) await this.edit(kb, {}, BASE.pleft)
55
+ else await this.reply(kb, {}, BASE.pleft)
53
56
  }
54
57
 
55
58
  private kb(baseId: string) {
@@ -57,7 +60,7 @@ export class SumNumberPage extends PageBase {
57
60
  }
58
61
 
59
62
  private getSessionParams() {
60
- return (this.session?.params as {step?: `left` | `right`; left?: number} | undefined) ?? {}
63
+ return (this.temp.session?.params as {step?: `left` | `right`; left?: number} | undefined) ?? {}
61
64
  }
62
65
 
63
66
  static template = `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-gramstax",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",