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.
- package/dist/src/templates/package.json +1 -1
- package/dist/src/templates/src/pages/general-status.ts +4 -4
- package/dist/src/templates/src/pages/help.ts +2 -2
- package/dist/src/templates/src/pages/random-number.ts +8 -8
- package/dist/src/templates/src/pages/start.ts +9 -9
- package/dist/src/templates/src/pages/sum-number.ts +21 -18
- package/package.json +1 -1
|
@@ -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.
|
|
20
|
+
await this.clearSession()
|
|
21
21
|
const kb = this.kb()
|
|
22
|
-
const
|
|
23
|
-
if (edit) await this.edit(kb,
|
|
24
|
-
else await this.reply(kb,
|
|
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
|
|
11
|
+
async handleCallbackData() {
|
|
12
12
|
await this.show(true)
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
async
|
|
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.
|
|
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
|
|
7
|
+
async handleCallbackData() {
|
|
8
8
|
await this.first(true)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
async
|
|
11
|
+
async handleCommandText() {
|
|
12
12
|
await this.first(false)
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
async
|
|
16
|
-
if (!this.
|
|
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.
|
|
24
|
-
return await this.reply(this.kb(
|
|
24
|
+
await this.sessionFreeText({step: `left`})
|
|
25
|
+
return await this.reply(this.kb(BASE.pleft), {}, BASE.pleft)
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
await this.
|
|
28
|
-
return await this.reply(this.kb(
|
|
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.
|
|
34
|
-
return await this.reply(this.kb(
|
|
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.
|
|
39
|
+
await this.clearSession()
|
|
39
40
|
return await this.first(false)
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
const result = left! + value
|
|
43
|
-
await this.
|
|
44
|
-
return await this.reply(this.kb(
|
|
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.
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
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 = `
|