create-gramstax 0.11.3 → 0.12.0
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/e2e/general-status.test.ts +2 -2
- package/dist/src/templates/e2e/help.test.ts +4 -4
- package/dist/src/templates/e2e/random-number.test.ts +2 -2
- package/dist/src/templates/e2e/start.test.ts +2 -2
- package/dist/src/templates/e2e/sum-number.test.ts +3 -3
- package/dist/src/templates/e2e/username-notfound.test.ts +2 -2
- package/dist/src/templates/package.json +2 -2
- package/dist/src/templates/src/core/bot.ts +2 -2
- package/dist/src/templates/src/db/db.ts +0 -1
- package/dist/src/templates/src/db/repositories/user.ts +7 -7
- package/dist/src/templates/src/guards/user.ts +3 -3
- package/dist/src/templates/src/index.ts +1 -1
- package/dist/src/templates/src/pages/blank.ts +3 -3
- package/dist/src/templates/src/pages/general-status.ts +16 -40
- package/dist/src/templates/src/pages/help.ts +15 -27
- package/dist/src/templates/src/pages/random-number.ts +12 -29
- package/dist/src/templates/src/pages/start.ts +13 -30
- package/dist/src/templates/src/pages/sum-number.ts +53 -60
- package/dist/src/templates/src/pages/username-notfound.ts +6 -24
- package/package.json +1 -1
|
@@ -22,7 +22,7 @@ describe(`E2E: GeneralStatusPage`, () => {
|
|
|
22
22
|
const replyId = responsesId[0]!
|
|
23
23
|
expect(reply).toBeDefined()
|
|
24
24
|
expect(replyId).toBeDefined()
|
|
25
|
-
expect(reply.body?.text).toBe(e2e.gmsg(intent, `
|
|
26
|
-
expect(replyId.body?.text).toBe(e2e.gmsg(intent, `
|
|
25
|
+
expect(reply.body?.text).toBe(e2e.gmsg(intent, `default`, {isNotFound: true}))
|
|
26
|
+
expect(replyId.body?.text).toBe(e2e.gmsg(intent, `default`, {isNotFound: true}, `id`))
|
|
27
27
|
})
|
|
28
28
|
})
|
|
@@ -20,9 +20,9 @@ describe(`E2E: HelpPage`, () => {
|
|
|
20
20
|
expect(responsesId.length).toBeGreaterThan(0)
|
|
21
21
|
const edit = responses[0]!
|
|
22
22
|
const editId = responsesId[0]!
|
|
23
|
-
expect(edit.body?.rich_message.html).toBe(e2e.gmsg(intent, `
|
|
24
|
-
expect(editId.body?.rich_message.html).toBe(e2e.gmsg(intent, `
|
|
25
|
-
expect(e2e.extractButtonLabels(edit)).toEqual(e2e.gkb(intent, `
|
|
26
|
-
expect(e2e.extractButtonLabels(editId)).toEqual(e2e.gkb(intent, `
|
|
23
|
+
expect(edit.body?.rich_message.html).toBe(e2e.gmsg(intent, `default`, {}))
|
|
24
|
+
expect(editId.body?.rich_message.html).toBe(e2e.gmsg(intent, `default`, {}, `id`))
|
|
25
|
+
expect(e2e.extractButtonLabels(edit)).toEqual(e2e.gkb(intent, `default`, `inline`, {}))
|
|
26
|
+
expect(e2e.extractButtonLabels(editId)).toEqual(e2e.gkb(intent, `default`, `inline`, {}, `id`))
|
|
27
27
|
})
|
|
28
28
|
})
|
|
@@ -22,7 +22,7 @@ describe(`E2E: RandomNumberPage`, () => {
|
|
|
22
22
|
const editId = responsesId[0]!
|
|
23
23
|
expect(edit.body?.text).toContain(`Random Number`)
|
|
24
24
|
expect(editId.body?.text).toContain(`Angka Acak`)
|
|
25
|
-
expect(e2e.extractButtonLabels(edit)).toEqual(e2e.gkb(intent, `
|
|
26
|
-
expect(e2e.extractButtonLabels(editId)).toEqual(e2e.gkb(intent, `
|
|
25
|
+
expect(e2e.extractButtonLabels(edit)).toEqual(e2e.gkb(intent, `default`, `inline`, {}))
|
|
26
|
+
expect(e2e.extractButtonLabels(editId)).toEqual(e2e.gkb(intent, `default`, `inline`, {}, `id`))
|
|
27
27
|
})
|
|
28
28
|
})
|
|
@@ -19,8 +19,8 @@ describe(`E2E: StartPage`, () => {
|
|
|
19
19
|
const replyId = responsesId[0]!
|
|
20
20
|
expect(reply.body?.rich_message.html).toContain(`Welcome`)
|
|
21
21
|
expect(replyId.body?.rich_message.html).toContain(`Selamat datang`)
|
|
22
|
-
expect(e2e.extractButtonLabels(reply)).toEqual(e2e.gkb(intent, `
|
|
23
|
-
expect(e2e.extractButtonLabels(replyId)).toEqual(e2e.gkb(intent, `
|
|
22
|
+
expect(e2e.extractButtonLabels(reply)).toEqual(e2e.gkb(intent, `default`, `inline`, {}))
|
|
23
|
+
expect(e2e.extractButtonLabels(replyId)).toEqual(e2e.gkb(intent, `default`, `inline`, {}, `id`))
|
|
24
24
|
})
|
|
25
25
|
|
|
26
26
|
it(`capture outbound requests in e2e.calls`, async () => {
|
|
@@ -15,13 +15,13 @@ describe(`E2E: SumNumberPage`, () => {
|
|
|
15
15
|
|
|
16
16
|
const step1 = await e2e.sendCallbackQuery(intent, asUser)
|
|
17
17
|
expect(step1.length).toBeGreaterThan(0)
|
|
18
|
-
expect(step1[0]!.body?.text).toBe(e2e.gmsg(intent, `
|
|
18
|
+
expect(step1[0]!.body?.text).toBe(e2e.gmsg(intent, `l`, {}))
|
|
19
19
|
e2e.clearCalls()
|
|
20
20
|
|
|
21
21
|
// input 1
|
|
22
22
|
const step2 = await e2e.sendText(`23`, asUser)
|
|
23
23
|
expect(step2.length).toBeGreaterThan(0)
|
|
24
|
-
expect(step2[0]!.body?.text).toBe(e2e.gmsg(intent, `
|
|
24
|
+
expect(step2[0]!.body?.text).toBe(e2e.gmsg(intent, `r`, {}))
|
|
25
25
|
e2e.clearCalls()
|
|
26
26
|
|
|
27
27
|
// input 2
|
|
@@ -41,6 +41,6 @@ describe(`E2E: SumNumberPage`, () => {
|
|
|
41
41
|
|
|
42
42
|
const retry = await e2e.sendText(`not-a-number`, asUser)
|
|
43
43
|
expect(retry.length).toBeGreaterThan(0)
|
|
44
|
-
expect(retry[0]!.body?.text).toBe(e2e.gmsg(intent, `
|
|
44
|
+
expect(retry[0]!.body?.text).toBe(e2e.gmsg(intent, `l`, {}))
|
|
45
45
|
})
|
|
46
46
|
})
|
|
@@ -17,8 +17,8 @@ describe(`E2E: UserNameNotFoundPage`, () => {
|
|
|
17
17
|
expect(responses.length).toBeGreaterThan(0)
|
|
18
18
|
const reply = responses[0]!
|
|
19
19
|
expect(reply).toBeDefined()
|
|
20
|
-
expect(reply.body?.text).toBe(e2e.gmsg(intent, `
|
|
20
|
+
expect(reply.body?.text).toBe(e2e.gmsg(intent, `default`, {}))
|
|
21
21
|
expect(reply.body?.text).toContain(`Username Required`)
|
|
22
|
-
expect(e2e.extractButtonLabels(reply)).toEqual(e2e.gkb(intent, `
|
|
22
|
+
expect(e2e.extractButtonLabels(reply)).toEqual(e2e.gkb(intent, `default`, `inline`, {}))
|
|
23
23
|
})
|
|
24
24
|
})
|
|
@@ -13,10 +13,10 @@ export class BotCore extends Gramstax {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
async hookErrorPage(ctx: CtxCore, data: NonNullable<Parameters<NonNullable<Gramstax[`hookErrorPage`]>>[1]>) {
|
|
16
|
-
await new GeneralStatusPage(ctx).
|
|
16
|
+
await new GeneralStatusPage(ctx).berror.show(`${data.listenerName}:hookErrorPage`, data.error, data.isEdit)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
async hookErrorInputNotFoundPage(ctx: CtxCore) {
|
|
20
|
-
await new GeneralStatusPage(ctx).
|
|
20
|
+
await new GeneralStatusPage(ctx).berrorNotFound.show()
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -15,25 +15,25 @@ export class UserRepo extends LmdbRepository<IVUser, IKUser> {
|
|
|
15
15
|
static dbName = `user`
|
|
16
16
|
|
|
17
17
|
async findOrCreate(tgId: number, data: {username: string; firstName: string; lastName: string; languageCode: string}): Promise<{user: IVUser; created: boolean}> {
|
|
18
|
-
return this.env.transaction(
|
|
19
|
-
const existing =
|
|
18
|
+
return this.env.transaction(() => {
|
|
19
|
+
const existing = this.get(tgId)
|
|
20
20
|
if (existing) {
|
|
21
21
|
const updated: IVUser = {...existing, ...data, updatedAt: Date.now()}
|
|
22
|
-
|
|
22
|
+
this.set(tgId, updated)
|
|
23
23
|
return {user: updated, created: false}
|
|
24
24
|
}
|
|
25
25
|
const now = Date.now()
|
|
26
26
|
const user: IVUser = {tgId, ...data, createdAt: now, updatedAt: now}
|
|
27
|
-
|
|
27
|
+
this.set(tgId, user)
|
|
28
28
|
return {user, created: true}
|
|
29
29
|
})
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
async touch(tgId: number) {
|
|
33
|
-
return this.env.transaction(
|
|
34
|
-
const user =
|
|
33
|
+
return this.env.transaction(() => {
|
|
34
|
+
const user = this.get(tgId)
|
|
35
35
|
if (user) {
|
|
36
|
-
|
|
36
|
+
this.set(tgId, {...user, updatedAt: Date.now()})
|
|
37
37
|
}
|
|
38
38
|
})
|
|
39
39
|
}
|
|
@@ -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).berror.show(func, err, isEdit)
|
|
8
8
|
return null
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
async ensureUsername(edit: boolean) {
|
|
12
12
|
try {
|
|
13
|
-
if (!this.
|
|
14
|
-
await new UserNameNotFoundPage(this).
|
|
13
|
+
if (!this.from?.username || this.from?.username.length == 0) {
|
|
14
|
+
await new UserNameNotFoundPage(this).bdefault.show(edit)
|
|
15
15
|
return null
|
|
16
16
|
}
|
|
17
17
|
return {status: true}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {PageBase} from "~/base/page"
|
|
2
2
|
|
|
3
3
|
export class BlankPage extends PageBase {
|
|
4
|
-
async
|
|
5
|
-
await this.
|
|
4
|
+
async handleCallbackQueryData() {
|
|
5
|
+
await this.answerCallbackQuery()
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
static template =
|
|
8
|
+
static template = ``
|
|
9
9
|
}
|
|
@@ -2,41 +2,6 @@ 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
|
-
|
|
9
|
-
class Helper {
|
|
10
|
-
static kb(ctx: GeneralStatusPage) {
|
|
11
|
-
const bi = Base.dynamic
|
|
12
|
-
const kb = ctx.inlineKeyboardT([StartPage], `1`, bi)
|
|
13
|
-
return kb
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class Main {
|
|
18
|
-
static async showError(ctx: GeneralStatusPage, funcName: string, error: any, edit = true) {
|
|
19
|
-
LogHe.errorMake(error, ctx.constructorName, funcName)
|
|
20
|
-
|
|
21
|
-
await ctx.clearSession()
|
|
22
|
-
const bi = Base.dynamic
|
|
23
|
-
const kb = Helper.kb(ctx)
|
|
24
|
-
const da = {isNotFound: false}
|
|
25
|
-
if (edit) {
|
|
26
|
-
await ctx.edit(kb, da, bi)
|
|
27
|
-
} else {
|
|
28
|
-
await ctx.reply(kb, da, bi)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
static async showErrorInputNotFound(ctx: GeneralStatusPage) {
|
|
33
|
-
const bi = Base.dynamic
|
|
34
|
-
const kb = Helper.kb(ctx)
|
|
35
|
-
const da = {isNotFound: true}
|
|
36
|
-
await ctx.reply(kb, da, bi)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
5
|
export class GeneralStatusPage extends PageBase {
|
|
41
6
|
constructorName?: string
|
|
42
7
|
|
|
@@ -45,16 +10,27 @@ export class GeneralStatusPage extends PageBase {
|
|
|
45
10
|
this.constructorName = p?.constructor?.name
|
|
46
11
|
}
|
|
47
12
|
|
|
48
|
-
|
|
49
|
-
|
|
13
|
+
berror = {
|
|
14
|
+
show: async (funcName: string, error: any, isEdit = true) => {
|
|
15
|
+
LogHe.errorMake(error, this.constructorName, funcName)
|
|
16
|
+
|
|
17
|
+
await this.clearSession()
|
|
18
|
+
const kb = this.inlineKeyboardT([StartPage])
|
|
19
|
+
const da = {isNotFound: false}
|
|
20
|
+
await this.renderAuto(kb, da, null, null, isEdit)
|
|
21
|
+
}
|
|
50
22
|
}
|
|
51
23
|
|
|
52
|
-
|
|
53
|
-
|
|
24
|
+
berrorNotFound = {
|
|
25
|
+
show: async () => {
|
|
26
|
+
const kb = this.inlineKeyboardT([StartPage])
|
|
27
|
+
const da = {isNotFound: true}
|
|
28
|
+
await this.render(kb, da)
|
|
29
|
+
}
|
|
54
30
|
}
|
|
55
31
|
|
|
56
32
|
static template = `
|
|
57
|
-
<g-base
|
|
33
|
+
<g-base>
|
|
58
34
|
${this.kbk.home()}
|
|
59
35
|
<g-message>
|
|
60
36
|
<b>{~isNotFound ? "🔎 Route Not Found" : "❌ Error Occurred"~}</b>
|
|
@@ -1,38 +1,24 @@
|
|
|
1
1
|
import {PageBase} from "~/base/page"
|
|
2
2
|
import {StartPage} from "./start"
|
|
3
3
|
|
|
4
|
-
class Base {
|
|
5
|
-
static step1 = `s1`
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
class Main {
|
|
9
|
-
static async showStep1Form(ctx: HelpPage, edit = true) {
|
|
10
|
-
const bi = Base.step1
|
|
11
|
-
const kb = ctx.inlineKeyboardT([StartPage], `1`, bi)
|
|
12
|
-
const da = {}
|
|
13
|
-
if (edit) {
|
|
14
|
-
await ctx.editRich(kb, da, bi)
|
|
15
|
-
} else {
|
|
16
|
-
await ctx.replyRich(kb, da, bi)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
static async processStep1Answer(ctx: HelpPage) {
|
|
21
|
-
throw ctx
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
4
|
export class HelpPage extends PageBase {
|
|
26
|
-
async
|
|
27
|
-
await
|
|
5
|
+
async handleCallbackQueryData() {
|
|
6
|
+
await this.bdefault.show(true)
|
|
28
7
|
}
|
|
29
8
|
|
|
30
9
|
async handleCommandText() {
|
|
31
|
-
await
|
|
10
|
+
await this.bdefault.show(false)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
bdefault = {
|
|
14
|
+
show: async (isEdit = true) => {
|
|
15
|
+
const kb = this.inlineKeyboardT([StartPage])
|
|
16
|
+
await this.renderAutoRich(kb, null, null, null, null, isEdit)
|
|
17
|
+
}
|
|
32
18
|
}
|
|
33
19
|
|
|
34
20
|
static template = `
|
|
35
|
-
<g-base
|
|
21
|
+
<g-base>
|
|
36
22
|
${this.kbk.back()}
|
|
37
23
|
<g-message>
|
|
38
24
|
<b>🆘 Help Message</b>
|
|
@@ -42,7 +28,8 @@ export class HelpPage extends PageBase {
|
|
|
42
28
|
<b>🎰 Random Number</b> - Generate a random number
|
|
43
29
|
<b>➕ Sum Number</b> - Add two numbers together
|
|
44
30
|
|
|
45
|
-
<details
|
|
31
|
+
<details>
|
|
32
|
+
<summary>📋 More commands</summary>
|
|
46
33
|
/start - Show welcome message
|
|
47
34
|
/help - Show this help
|
|
48
35
|
/random - Generate a random number
|
|
@@ -57,7 +44,8 @@ export class HelpPage extends PageBase {
|
|
|
57
44
|
<b>🎰 Angka Acak</b> - Menghasilkan angka secara acak
|
|
58
45
|
<b>➕ Jumlah Angka</b> - Menjumlahkan dua angka
|
|
59
46
|
|
|
60
|
-
<details
|
|
47
|
+
<details>
|
|
48
|
+
<summary>📋 Perintah lainnya</summary>
|
|
61
49
|
/start - Tampilkan pesan selamat datang
|
|
62
50
|
/help - Tampilkan bantuan ini
|
|
63
51
|
/random - Hasilkan angka acak
|
|
@@ -1,44 +1,27 @@
|
|
|
1
1
|
import {PageBase} from "~/base/page"
|
|
2
2
|
import {StartPage} from "./start"
|
|
3
3
|
|
|
4
|
-
class Base {
|
|
5
|
-
static step1 = `s1`
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
class Main {
|
|
9
|
-
static async showStep1Form(ctx: RandomNumberPage, edit = true) {
|
|
10
|
-
const bi = Base.step1
|
|
11
|
-
const kb = ctx.inlineKeyboardT([ctx, StartPage], `1`, bi)
|
|
12
|
-
const da = {result: Math.random() * 10 ** 18}
|
|
13
|
-
if (edit) {
|
|
14
|
-
await ctx.edit(kb, da, bi)
|
|
15
|
-
} else {
|
|
16
|
-
await ctx.reply(kb, da, bi)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
static async processStep1Answer(ctx: RandomNumberPage) {
|
|
21
|
-
throw ctx
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
4
|
export class RandomNumberPage extends PageBase {
|
|
26
|
-
async
|
|
27
|
-
await
|
|
5
|
+
async handleCallbackQueryData() {
|
|
6
|
+
await this.bdefault.show(true)
|
|
28
7
|
}
|
|
29
8
|
|
|
30
9
|
async handleCommandText() {
|
|
31
|
-
await
|
|
10
|
+
await this.bdefault.show(false)
|
|
32
11
|
}
|
|
33
12
|
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
bdefault = {
|
|
14
|
+
show: async (isEdit = true) => {
|
|
15
|
+
const kb = this.inlineKeyboardT([this, StartPage])
|
|
16
|
+
const da = {result: Math.random() * 10 ** 18}
|
|
17
|
+
await this.renderAuto(kb, da, null, null, isEdit)
|
|
18
|
+
}
|
|
36
19
|
}
|
|
37
20
|
|
|
38
21
|
static template = `
|
|
39
|
-
<g-base
|
|
40
|
-
<g-keyboard>🎲 Shake, ${this.kbl.back.default}</g-keyboard>
|
|
41
|
-
<g-keyboard lang="id">🎲 Kocok, ${this.kbl.back.id}</g-keyboard>
|
|
22
|
+
<g-base>
|
|
23
|
+
<g-keyboard type="inline">🎲 Shake, ${this.kbl.back.default}</g-keyboard>
|
|
24
|
+
<g-keyboard type="inline" lang="id">🎲 Kocok, ${this.kbl.back.id}</g-keyboard>
|
|
42
25
|
<g-message>
|
|
43
26
|
<b>🎰 Random Number</b>
|
|
44
27
|
|
|
@@ -3,45 +3,28 @@ 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
|
-
|
|
10
|
-
class Main {
|
|
11
|
-
static async showStep1Form(ctx: StartPage, edit = true) {
|
|
12
|
-
await ctx.clearSession()
|
|
13
|
-
const bi = Base.step1
|
|
14
|
-
const kb = ctx.inlineKeyboardT([RandomNumberPage, SumNumberPage, HelpPage], `2`, bi)
|
|
15
|
-
const da = {userName: ctx.userName}
|
|
16
|
-
if (edit) {
|
|
17
|
-
await ctx.editRich(kb, da, bi)
|
|
18
|
-
} else {
|
|
19
|
-
await ctx.replyRich(kb, da, bi)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static async processStep1Answer(ctx: StartPage) {
|
|
24
|
-
throw ctx
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
6
|
export class StartPage extends PageBase {
|
|
29
|
-
async
|
|
30
|
-
await
|
|
7
|
+
async handleCallbackQueryData() {
|
|
8
|
+
await this.bdefault.show(true)
|
|
31
9
|
}
|
|
32
10
|
|
|
33
11
|
async handleCommandText() {
|
|
34
|
-
await
|
|
12
|
+
await this.bdefault.show(false)
|
|
35
13
|
}
|
|
36
14
|
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
bdefault = {
|
|
16
|
+
show: async (isEdit = true) => {
|
|
17
|
+
await this.clearSession()
|
|
18
|
+
const kb = this.inlineKeyboardT([RandomNumberPage, SumNumberPage, HelpPage], `2`)
|
|
19
|
+
const da = {userName: this.from?.username}
|
|
20
|
+
await this.renderAutoRich(kb, da, null, null, null, isEdit)
|
|
21
|
+
}
|
|
39
22
|
}
|
|
40
23
|
|
|
41
24
|
static template = `
|
|
42
|
-
<g-base
|
|
43
|
-
<g-keyboard>🎰 Random Number, ➕ Sum Number, 🆘 Help</g-keyboard>
|
|
44
|
-
<g-keyboard lang="id">🎰 Angka Acak, ➕ Jumlah Angka, 🆘 Bantuan</g-keyboard>
|
|
25
|
+
<g-base>
|
|
26
|
+
<g-keyboard type="inline">🎰 Random Number, ➕ Sum Number, 🆘 Help</g-keyboard>
|
|
27
|
+
<g-keyboard type="inline" lang="id">🎰 Angka Acak, ➕ Jumlah Angka, 🆘 Bantuan</g-keyboard>
|
|
45
28
|
<g-message>
|
|
46
29
|
<b>👋 Welcome to the bot {{userName}}</b>
|
|
47
30
|
|
|
@@ -2,8 +2,8 @@ import {PageBase} from "~/base/page"
|
|
|
2
2
|
import {StartPage} from "./start"
|
|
3
3
|
|
|
4
4
|
class Base {
|
|
5
|
-
static
|
|
6
|
-
static
|
|
5
|
+
static left = `l`
|
|
6
|
+
static right = `r`
|
|
7
7
|
static success = `s`
|
|
8
8
|
}
|
|
9
9
|
|
|
@@ -17,76 +17,71 @@ class Helper {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
class
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const kb = Helper.kb(ctx, bi)
|
|
24
|
-
const da = {}
|
|
25
|
-
await ctx.setSessionFreeText({step: bi})
|
|
26
|
-
if (edit) {
|
|
27
|
-
await ctx.edit(kb, da, bi)
|
|
28
|
-
} else {
|
|
29
|
-
await ctx.reply(kb, da, bi)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static async processStep1Answer(ctx: SumNumberPage, left: number) {
|
|
34
|
-
if (!Number.isFinite(left)) {
|
|
35
|
-
await Main.showStep1Form(ctx, false)
|
|
36
|
-
} else {
|
|
37
|
-
await this.showStep2Form(ctx, left)
|
|
38
|
-
}
|
|
20
|
+
export class SumNumberPage extends PageBase {
|
|
21
|
+
async handleCallbackQueryData() {
|
|
22
|
+
await this.bleft.show(true)
|
|
39
23
|
}
|
|
40
24
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const kb = Helper.kb(ctx, bi)
|
|
44
|
-
const da = {}
|
|
45
|
-
await ctx.setSessionFreeText({step: bi, left})
|
|
46
|
-
await ctx.reply(kb, da, bi)
|
|
25
|
+
async handleCommandText() {
|
|
26
|
+
await this.bleft.show(false)
|
|
47
27
|
}
|
|
48
28
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
29
|
+
async handleSessionFreeText() {
|
|
30
|
+
const {step, left} = Helper.getSessionParams(this)
|
|
31
|
+
const input = this.msg!.text!.trim()
|
|
32
|
+
const value = input ? Number(input) : NaN
|
|
33
|
+
if (step === Base.left) {
|
|
34
|
+
await this.bleft.process(value)
|
|
35
|
+
} else if (step === Base.right) {
|
|
36
|
+
await this.bright.process(value, left!)
|
|
56
37
|
}
|
|
57
38
|
}
|
|
58
39
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
40
|
+
bleft = {
|
|
41
|
+
show: async (edit: boolean) => {
|
|
42
|
+
const kb = Helper.kb(this, Base.left)
|
|
43
|
+
await this.setSessionFreeText({step: Base.left})
|
|
44
|
+
if (edit) {
|
|
45
|
+
await this.renderEdit(kb, {}, Base.left)
|
|
46
|
+
} else {
|
|
47
|
+
await this.render(kb, {}, Base.left)
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
process: async (left: number) => {
|
|
51
|
+
if (!Number.isFinite(left)) {
|
|
52
|
+
await this.bleft.show(false)
|
|
53
|
+
} else {
|
|
54
|
+
await this.bright.show(left)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
71
57
|
}
|
|
72
58
|
|
|
73
|
-
|
|
74
|
-
|
|
59
|
+
bright = {
|
|
60
|
+
show: async (left: number) => {
|
|
61
|
+
const kb = Helper.kb(this, Base.right)
|
|
62
|
+
await this.setSessionFreeText({step: Base.right, left})
|
|
63
|
+
await this.render(kb, {}, Base.right)
|
|
64
|
+
},
|
|
65
|
+
process: async (value: number, left: number) => {
|
|
66
|
+
if (!Number.isFinite(value)) {
|
|
67
|
+
await this.bright.show(left)
|
|
68
|
+
} else {
|
|
69
|
+
await this.clearSession()
|
|
70
|
+
await this.bsuccess.show(left, value)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
75
73
|
}
|
|
76
74
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
await Main.processStep1Answer(this, value)
|
|
83
|
-
} else if (step === Base.step2) {
|
|
84
|
-
await Main.processStep2Answer(this, left!, value)
|
|
75
|
+
bsuccess = {
|
|
76
|
+
show: async (left: number, right: number) => {
|
|
77
|
+
const kb = Helper.kb(this, Base.success)
|
|
78
|
+
const da = {result: left + right}
|
|
79
|
+
await this.render(kb, da, Base.success)
|
|
85
80
|
}
|
|
86
81
|
}
|
|
87
82
|
|
|
88
83
|
static template = `
|
|
89
|
-
<g-base id="${Base.
|
|
84
|
+
<g-base id="${Base.left}">
|
|
90
85
|
${this.kbk.cancel()}
|
|
91
86
|
<g-message>
|
|
92
87
|
<b>📚 Input Left Number</b>
|
|
@@ -99,8 +94,7 @@ export class SumNumberPage extends PageBase {
|
|
|
99
94
|
Contoh: 23
|
|
100
95
|
</g-message>
|
|
101
96
|
</g-base>
|
|
102
|
-
|
|
103
|
-
<g-base id="${Base.step2}">
|
|
97
|
+
<g-base id="${Base.right}">
|
|
104
98
|
${this.kbk.cancel()}
|
|
105
99
|
<g-message>
|
|
106
100
|
<b>📚 Input Right Number</b>
|
|
@@ -113,7 +107,6 @@ export class SumNumberPage extends PageBase {
|
|
|
113
107
|
Contoh: 10
|
|
114
108
|
</g-message>
|
|
115
109
|
</g-base>
|
|
116
|
-
|
|
117
110
|
<g-base id="${Base.success}">
|
|
118
111
|
${this.kbk.home()}
|
|
119
112
|
<g-message>
|
|
@@ -1,34 +1,16 @@
|
|
|
1
1
|
import {HelpPage} from "./help"
|
|
2
2
|
import {PageBase} from "~/base/page"
|
|
3
3
|
|
|
4
|
-
class Base {
|
|
5
|
-
static step1 = `s1`
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
class Main {
|
|
9
|
-
static async showStep1Form(ctx: UserNameNotFoundPage, edit = true) {
|
|
10
|
-
const bi = Base.step1
|
|
11
|
-
const kb = ctx.inlineKeyboardT([HelpPage], `1`, bi)
|
|
12
|
-
const da = {}
|
|
13
|
-
if (edit) {
|
|
14
|
-
await ctx.edit(kb, da, bi)
|
|
15
|
-
} else {
|
|
16
|
-
await ctx.reply(kb, da, bi)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
static async processStep1Answer(ctx: UserNameNotFoundPage) {
|
|
21
|
-
throw ctx
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
4
|
export class UserNameNotFoundPage extends PageBase {
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
bdefault = {
|
|
6
|
+
show: async (isEdit = true) => {
|
|
7
|
+
const kb = this.inlineKeyboardT([HelpPage])
|
|
8
|
+
await this.renderAuto(kb, {}, null, null, isEdit)
|
|
9
|
+
}
|
|
28
10
|
}
|
|
29
11
|
|
|
30
12
|
static template = `
|
|
31
|
-
<g-base
|
|
13
|
+
<g-base>
|
|
32
14
|
${this.kbk.home()}
|
|
33
15
|
<g-message>
|
|
34
16
|
<b>⚠️ Username Required</b>
|