create-gramstax 0.8.6 → 0.8.7
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/core/bot.ts +2 -2
- package/dist/src/templates/src/guards/user.ts +2 -2
- package/dist/src/templates/src/pages/blank.ts +1 -7
- package/dist/src/templates/src/pages/general-status.ts +19 -11
- package/dist/src/templates/src/pages/help.ts +13 -7
- package/dist/src/templates/src/pages/random-number.ts +14 -9
- package/dist/src/templates/src/pages/start.ts +14 -9
- package/dist/src/templates/src/pages/sum-number.ts +13 -14
- package/dist/src/templates/src/pages/username-notfound.ts +13 -7
- package/package.json +1 -1
|
@@ -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).
|
|
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).
|
|
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).
|
|
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).
|
|
14
|
+
await new UserNameNotFoundPage(this).showIndex(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
|
|
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 index = `-`
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
class Helper {
|
|
6
10
|
static kb(ctx: GeneralStatusPage) {
|
|
7
|
-
|
|
11
|
+
const bi = Base.index
|
|
12
|
+
const kb = ctx.inlineKeyboardT([StartPage], `1`, bi)
|
|
13
|
+
return kb
|
|
8
14
|
}
|
|
9
15
|
}
|
|
10
16
|
|
|
11
17
|
class Alert {
|
|
12
|
-
static async
|
|
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.index
|
|
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
|
|
32
|
+
static async showErrorInputNotFound(ctx: GeneralStatusPage) {
|
|
33
|
+
const bi = Base.index
|
|
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
|
|
41
|
-
await Alert.
|
|
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
|
|
45
|
-
await Alert.
|
|
52
|
+
async showErrorInputNotFound() {
|
|
53
|
+
await Alert.showErrorInputNotFound(this)
|
|
46
54
|
}
|
|
47
55
|
|
|
48
56
|
static template = `
|
|
49
|
-
<base>
|
|
57
|
+
<base id="${Base.index}">
|
|
50
58
|
${this.kbk.home()}
|
|
51
59
|
<message>
|
|
52
60
|
<b>{~isNotFound ? "🔎 Route Not Found" : "❌ Error Occurred"~}</b>
|
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
import {PageBase} from "~/base/page"
|
|
2
2
|
import {StartPage} from "./start"
|
|
3
3
|
|
|
4
|
+
class Base {
|
|
5
|
+
static index = `-`
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
class Main {
|
|
5
|
-
static async
|
|
6
|
-
const
|
|
9
|
+
static async showIndex(ctx: HelpPage, edit = true) {
|
|
10
|
+
const bi = Base.index
|
|
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
|
}
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
export class HelpPage extends PageBase {
|
|
16
22
|
async handleCallbackData() {
|
|
17
|
-
await Main.
|
|
23
|
+
await Main.showIndex(this, true)
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
async handleCommandText() {
|
|
21
|
-
await Main.
|
|
27
|
+
await Main.showIndex(this, false)
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
static template = `
|
|
25
|
-
<base>
|
|
31
|
+
<base id="${Base.index}">
|
|
26
32
|
${this.kbk.back()}
|
|
27
33
|
<message>
|
|
28
34
|
<b>🆘 Help Message</b>
|
|
@@ -1,33 +1,38 @@
|
|
|
1
1
|
import {PageBase} from "~/base/page"
|
|
2
2
|
import {StartPage} from "./start"
|
|
3
3
|
|
|
4
|
+
class Base {
|
|
5
|
+
static index = `-`
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
class Main {
|
|
5
|
-
static async
|
|
6
|
-
const
|
|
9
|
+
static async showIndex(ctx: RandomNumberPage, edit = true) {
|
|
10
|
+
const bi = Base.index
|
|
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
|
}
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
export class RandomNumberPage extends PageBase {
|
|
17
22
|
async handleCallbackData() {
|
|
18
|
-
await Main.
|
|
23
|
+
await Main.showIndex(this, true)
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
async handleCommandText() {
|
|
22
|
-
await Main.
|
|
27
|
+
await Main.showIndex(this, false)
|
|
23
28
|
}
|
|
24
29
|
|
|
25
|
-
async
|
|
26
|
-
await Main.
|
|
30
|
+
async showIndex(edit = true) {
|
|
31
|
+
await Main.showIndex(this, edit)
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
static template = `
|
|
30
|
-
<base>
|
|
35
|
+
<base id="${Base.index}">
|
|
31
36
|
<keyboard>🎲 Shake, ${this.kbl.back.default}</keyboard>
|
|
32
37
|
<keyboard lang="id">🎲 Kocok, ${this.kbl.back.id}</keyboard>
|
|
33
38
|
<message>
|
|
@@ -3,34 +3,39 @@ 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 index = `-`
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
class Main {
|
|
7
|
-
static async
|
|
11
|
+
static async showIndex(ctx: StartPage, edit = true) {
|
|
8
12
|
await ctx.clearSession()
|
|
9
|
-
const
|
|
13
|
+
const bi = Base.index
|
|
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
|
}
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
export class StartPage extends PageBase {
|
|
20
25
|
async handleCallbackData() {
|
|
21
|
-
await Main.
|
|
26
|
+
await Main.showIndex(this, true)
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
async handleCommandText() {
|
|
25
|
-
await Main.
|
|
30
|
+
await Main.showIndex(this, false)
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
async
|
|
29
|
-
await Main.
|
|
33
|
+
async showIndex(edit = true) {
|
|
34
|
+
await Main.showIndex(this, edit)
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
static template = `
|
|
33
|
-
<base>
|
|
38
|
+
<base id="${Base.index}">
|
|
34
39
|
<keyboard>🎰 Random Number, ➕ Sum Number, 🆘 Help</keyboard>
|
|
35
40
|
<keyboard lang="id">🎰 Angka Acak, ➕ Jumlah Angka, 🆘 Bantuan</keyboard>
|
|
36
41
|
<message>
|
|
@@ -2,14 +2,14 @@ import {PageBase} from "~/base/page"
|
|
|
2
2
|
import {StartPage} from "./start"
|
|
3
3
|
|
|
4
4
|
class Base {
|
|
5
|
-
static
|
|
6
|
-
static
|
|
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?:
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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 ===
|
|
86
|
+
if (step === Base.step1) {
|
|
88
87
|
await Main.processStep1Answer(this, value)
|
|
89
|
-
} else if (step ===
|
|
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.
|
|
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.
|
|
108
|
+
<base id="${Base.step2}">
|
|
110
109
|
${this.kbk.cancel()}
|
|
111
110
|
<message>
|
|
112
111
|
<b>📚 Input Right Number</b>
|
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
import {HelpPage} from "./help"
|
|
2
2
|
import {PageBase} from "~/base/page"
|
|
3
3
|
|
|
4
|
+
class Base {
|
|
5
|
+
static index = `-`
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
class Main {
|
|
5
|
-
static async
|
|
6
|
-
const
|
|
9
|
+
static async showIndex(ctx: UserNameNotFoundPage, edit = true) {
|
|
10
|
+
const bi = Base.index
|
|
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
|
}
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
export class UserNameNotFoundPage extends PageBase {
|
|
16
|
-
async
|
|
17
|
-
await Main.
|
|
22
|
+
async showIndex(edit = true) {
|
|
23
|
+
await Main.showIndex(this, edit)
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
static template = `
|
|
21
|
-
<base>
|
|
27
|
+
<base id="${Base.index}">
|
|
22
28
|
${this.kbk.home()}
|
|
23
29
|
<message>
|
|
24
30
|
<b>⚠️ Username Required</b>
|