create-gramstax 0.3.20 → 0.3.22
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 +6 -7
- package/dist/src/templates/src/env.ts +3 -3
- package/dist/src/templates/src/guards/user.ts +7 -3
- package/dist/src/templates/src/index.ts +3 -3
- package/dist/src/templates/src/pages/{general-error.ts → general-status.ts} +25 -14
- package/dist/src/templates/src/pages/help.ts +1 -1
- package/dist/src/templates/src/pages/input-text.ts +2 -2
- package/dist/src/templates/src/pages/start.ts +1 -1
- package/dist/src/templates/src/pages/username-notfound.ts +1 -1
- package/package.json +1 -1
- package/dist/src/templates/src/pages/general-error-input-notfound.ts +0 -45
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {Gramstax} from "gramstax"
|
|
2
2
|
import {UserGuard} from "~/guards/user"
|
|
3
|
-
import {
|
|
4
|
-
import {GeneralErrorInputNotFoundPage} from "~/pages/general-error-input-notfound"
|
|
3
|
+
import {GeneralStatusPage} from "~/pages/general-status"
|
|
5
4
|
import type {CtxCore} from "./ctx"
|
|
6
5
|
|
|
7
6
|
export class BotCore extends Gramstax {
|
|
8
|
-
async hookBeforeRoute(ctx: CtxCore)
|
|
7
|
+
async hookBeforeRoute(ctx: CtxCore) {
|
|
9
8
|
const result = await new UserGuard(ctx).ensureValid(true)
|
|
10
9
|
if (result === null) {
|
|
11
10
|
return false
|
|
@@ -13,11 +12,11 @@ export class BotCore extends Gramstax {
|
|
|
13
12
|
return true
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
async hookErrorPage(ctx: CtxCore, listenerName: string, error: any, isEdit: boolean)
|
|
17
|
-
await new
|
|
15
|
+
async hookErrorPage(ctx: CtxCore, listenerName: string, error: any, isEdit: boolean) {
|
|
16
|
+
await new GeneralStatusPage(ctx).toError(`${listenerName}:hookErrorPage`, error, isEdit)
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
async hookErrorInputNotFoundPage(ctx: CtxCore)
|
|
21
|
-
await new
|
|
19
|
+
async hookErrorInputNotFoundPage(ctx: CtxCore) {
|
|
20
|
+
await new GeneralStatusPage(ctx).toErrorInputNotFound()
|
|
22
21
|
}
|
|
23
22
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const env = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
TELEGRAM_BOT_TOKEN: process.env.TELEGRAM_BOT_TOKEN as string,
|
|
3
|
+
TELEGRAM_BOT_DEPLOY: process.env.TELEGRAM_BOT_DEPLOY as string,
|
|
4
|
+
TELEGRAM_CACHE_SESSION: process.env.TELEGRAM_CACHE_SESSION as string
|
|
5
5
|
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import {GuardBase} from "~/base/guard"
|
|
2
|
-
import {
|
|
2
|
+
import {GeneralStatusPage} from "~/pages/general-status"
|
|
3
3
|
import {UserNameNotFoundPage} from "~/pages/username-notfound"
|
|
4
4
|
|
|
5
5
|
export class UserGuard extends GuardBase {
|
|
6
|
+
async _catch(err: any, func: any, isEdit: boolean) {
|
|
7
|
+
await new GeneralStatusPage(this).toError(func, err, isEdit)
|
|
8
|
+
return null
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
async ensureValid(isEdit: boolean) {
|
|
7
12
|
try {
|
|
8
13
|
if (!this.userName || this.userName.length == 0) {
|
|
@@ -11,8 +16,7 @@ export class UserGuard extends GuardBase {
|
|
|
11
16
|
}
|
|
12
17
|
return {status: true}
|
|
13
18
|
} catch (err) {
|
|
14
|
-
await
|
|
15
|
-
return null
|
|
19
|
+
return await this._catch(err, `ensureValid`, isEdit)
|
|
16
20
|
}
|
|
17
21
|
}
|
|
18
22
|
}
|
|
@@ -6,9 +6,9 @@ import {CacheExternal} from "gramstax"
|
|
|
6
6
|
logUt.success(`Bot started..`)
|
|
7
7
|
|
|
8
8
|
new BotCore({
|
|
9
|
-
token: env.
|
|
10
|
-
deploy: env.
|
|
11
|
-
cacheSession: new CacheExternal(env.
|
|
9
|
+
token: env.TELEGRAM_BOT_TOKEN,
|
|
10
|
+
deploy: env.TELEGRAM_BOT_DEPLOY,
|
|
11
|
+
cacheSession: new CacheExternal(env.TELEGRAM_CACHE_SESSION, `session`, 24 * 60 * 60 * 1000),
|
|
12
12
|
optionsPage: {
|
|
13
13
|
shortCallbackData: true
|
|
14
14
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {log} from "gramstax"
|
|
2
2
|
import {PageBase} from "~/base/page"
|
|
3
3
|
import {StartPage} from "./start"
|
|
4
4
|
|
|
5
|
-
export class
|
|
5
|
+
export class GeneralStatusPage extends PageBase {
|
|
6
6
|
constructorName?: string
|
|
7
7
|
constructor(p: any) {
|
|
8
8
|
super(p)
|
|
@@ -11,37 +11,39 @@ export class GeneralErrorPage extends PageBase {
|
|
|
11
11
|
|
|
12
12
|
kb() {
|
|
13
13
|
return this.ikb((k, a) => {
|
|
14
|
-
return k.text(a[0]!, StartPage.data.
|
|
14
|
+
return k.text(a[0]!, StartPage.data.callback())
|
|
15
15
|
})
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
async
|
|
19
|
-
|
|
20
|
-
await this.sessionClear()
|
|
18
|
+
async toError(funcName: string, error: any, isUpdate = true) {
|
|
19
|
+
log.errorMake(error, this.constructorName, funcName)
|
|
21
20
|
|
|
21
|
+
await this.sessionClear()
|
|
22
22
|
const kb = this.kb()
|
|
23
|
+
const id = `error`
|
|
23
24
|
if (isUpdate === true) {
|
|
24
|
-
await this.edit(kb)
|
|
25
|
+
await this.edit(kb, {}, id)
|
|
25
26
|
} else {
|
|
26
|
-
await this.reply(kb)
|
|
27
|
+
await this.reply(kb, {}, id)
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
async toErrorInputNotFound() {
|
|
32
|
+
await this.reply(this.kb(), {}, `error-input-notfound`)
|
|
33
|
+
}
|
|
34
|
+
|
|
30
35
|
static template = `
|
|
31
36
|
<base>
|
|
32
37
|
${this.kbc.home()}
|
|
38
|
+
</base>
|
|
39
|
+
|
|
40
|
+
<base id="error">
|
|
33
41
|
<message>
|
|
34
42
|
<b>❌ Error</b>
|
|
35
43
|
|
|
36
44
|
An unexpected error occurred.
|
|
37
45
|
Please try again later.
|
|
38
46
|
</message>
|
|
39
|
-
<message lang="it">
|
|
40
|
-
<b>❌ Errore</b>
|
|
41
|
-
|
|
42
|
-
Si è verificato un errore imprevisto.
|
|
43
|
-
Riprova più tardi.
|
|
44
|
-
</message>
|
|
45
47
|
<message lang="id">
|
|
46
48
|
<b>❌ Kesalahan</b>
|
|
47
49
|
|
|
@@ -49,5 +51,14 @@ export class GeneralErrorPage extends PageBase {
|
|
|
49
51
|
Silakan coba lagi nanti.
|
|
50
52
|
</message>
|
|
51
53
|
</base>
|
|
54
|
+
|
|
55
|
+
<base id="error-input-notfound">
|
|
56
|
+
<message>
|
|
57
|
+
<b>❌ Not Found</b>
|
|
58
|
+
</message>
|
|
59
|
+
<message lang="id">
|
|
60
|
+
<b>❌ Tidak Ditemukan</b>
|
|
61
|
+
</message>
|
|
62
|
+
</base>
|
|
52
63
|
`
|
|
53
64
|
}
|
|
@@ -4,12 +4,12 @@ import {SessionGuard} from "~/guards/session"
|
|
|
4
4
|
|
|
5
5
|
export class InputTextPage extends PageBase {
|
|
6
6
|
static data = this.buildData({
|
|
7
|
-
|
|
7
|
+
intentTextCommand: `input_text`
|
|
8
8
|
})
|
|
9
9
|
|
|
10
10
|
kb(baseId?: string) {
|
|
11
11
|
return this.ikb((k, a) => {
|
|
12
|
-
return k.text(a[0]!, StartPage.data.
|
|
12
|
+
return k.text(a[0]!, StartPage.data.callback()), {baseId}
|
|
13
13
|
})
|
|
14
14
|
}
|
|
15
15
|
|
package/package.json
CHANGED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {PageBase} from "~/base/page"
|
|
2
|
-
import {StartPage} from "./start"
|
|
3
|
-
|
|
4
|
-
export class GeneralErrorInputNotFoundPage extends PageBase {
|
|
5
|
-
kb() {
|
|
6
|
-
return this.ikb((k, a) => {
|
|
7
|
-
return k.text(a[0]!, StartPage.data.callbackData())
|
|
8
|
-
})
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async transition(session?: boolean) {
|
|
12
|
-
if (session || this.session.method) {
|
|
13
|
-
await this.reply(this.kb(), undefined, `session-error`)
|
|
14
|
-
await this.sessionClear()
|
|
15
|
-
} else {
|
|
16
|
-
await this.reply(this.kb())
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
static template = `
|
|
21
|
-
<base>
|
|
22
|
-
${this.kbc.home()}
|
|
23
|
-
<message>
|
|
24
|
-
<b>❌ Not Found</b>
|
|
25
|
-
</message>
|
|
26
|
-
<message lang="id">
|
|
27
|
-
<b>❌ Tidak Ditemukan</b>
|
|
28
|
-
</message>
|
|
29
|
-
</base>
|
|
30
|
-
<base id="session-error">
|
|
31
|
-
<message>
|
|
32
|
-
<b>❌ Session Error</b>
|
|
33
|
-
|
|
34
|
-
An error occurred while processing your request.
|
|
35
|
-
Your session has an error.
|
|
36
|
-
</message>
|
|
37
|
-
<message lang="id">
|
|
38
|
-
<b>❌ Kesalahan Sesi</b>
|
|
39
|
-
|
|
40
|
-
Terjadi kesalahan saat memproses permintaan.
|
|
41
|
-
Sesi Anda bermasalh.
|
|
42
|
-
</message>
|
|
43
|
-
</base>
|
|
44
|
-
`
|
|
45
|
-
}
|