create-gramstax 0.0.27 → 0.1.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.
Files changed (39) hide show
  1. package/LICENSE +25 -25
  2. package/dist/src/index.cjs +2 -2
  3. package/dist/src/index.js +2 -2
  4. package/dist/src/templates/.env.example +15 -18
  5. package/dist/src/templates/.prettierrc +23 -23
  6. package/dist/src/templates/README.md +120 -121
  7. package/dist/src/templates/bunfig.toml +1 -1
  8. package/dist/src/templates/package.json +48 -54
  9. package/dist/src/templates/src/base/guard.ts +11 -11
  10. package/dist/src/templates/src/base/index.ts +4 -0
  11. package/dist/src/templates/src/base/page.ts +3 -3
  12. package/dist/src/templates/src/base/repository.ts +1 -1
  13. package/dist/src/templates/src/base/service.ts +1 -1
  14. package/dist/src/templates/src/core/bot.ts +23 -23
  15. package/dist/src/templates/src/core/ctx.ts +3 -3
  16. package/dist/src/templates/src/core/index.ts +2 -0
  17. package/dist/src/templates/src/db/index.ts +1 -3
  18. package/dist/src/templates/src/env.ts +5 -6
  19. package/dist/src/templates/src/guards/index.ts +1 -0
  20. package/dist/src/templates/src/guards/user.ts +19 -19
  21. package/dist/src/templates/src/index.ts +15 -15
  22. package/dist/src/templates/src/pages/general-error-input-notfound.ts +28 -39
  23. package/dist/src/templates/src/pages/general-error.ts +60 -59
  24. package/dist/src/templates/src/pages/help.ts +49 -61
  25. package/dist/src/templates/src/pages/start.ts +69 -70
  26. package/dist/src/templates/src/pages/username-notfound.ts +33 -46
  27. package/dist/src/templates/src/repositories/example.ts +3 -5
  28. package/dist/src/templates/src/repositories/index.ts +1 -0
  29. package/dist/src/templates/src/services/example.ts +3 -4
  30. package/dist/src/templates/src/services/index.ts +1 -0
  31. package/dist/src/templates/src/threads/index.ts +1 -0
  32. package/dist/src/templates/src/threads/main.ts +9 -9
  33. package/dist/src/templates/src/utils/index.ts +1 -0
  34. package/dist/src/templates/src/utils/log.ts +2 -3
  35. package/dist/src/templates/tsconfig.json +37 -37
  36. package/package.json +8 -2
  37. package/dist/src/templates/.prettierignore +0 -1
  38. package/dist/src/templates/ecosystem.config.js +0 -26
  39. package/dist/src/templates/src/base/general.ts +0 -3
@@ -1,23 +1,23 @@
1
- import { Gramstax } from "gramstax"
2
- import { UserGuard } from "../guards/user"
3
- import { GeneralErrorPage } from "../pages/general-error"
4
- import { GeneralErrorInputNotFoundPage } from "../pages/general-error-input-notfound"
5
- import type { CtxCore } from "./ctx"
6
-
7
- export class BotCore extends Gramstax {
8
- public async hookBeforeRoute(ctx: CtxCore): Promise<boolean> {
9
- const result = await new UserGuard(ctx).ensureValid(true)
10
- if (result === null) {
11
- return false
12
- }
13
- return true
14
- }
15
-
16
- public async hookErrorPage(ctx: CtxCore, listenerName: string, error: any, isEdit: boolean): Promise<void> {
17
- await new GeneralErrorPage(ctx).transition(this.constructor.name, listenerName, error, isEdit)
18
- }
19
-
20
- public async hookErrorInputNotFoundPage(ctx: CtxCore): Promise<void> {
21
- await new GeneralErrorInputNotFoundPage(ctx).transition()
22
- }
23
- }
1
+ import { Gramstax } from "gramstax"
2
+ import { UserGuard } from "~/guards"
3
+ import { GeneralErrorPage } from "~/pages/general-error"
4
+ import { GeneralErrorInputNotFoundPage } from "~/pages/general-error-input-notfound"
5
+ import type { CtxCore } from "./ctx"
6
+
7
+ export class BotCore extends Gramstax {
8
+ public async hookBeforeRoute(ctx: CtxCore): Promise<boolean> {
9
+ const result = await new UserGuard(ctx).ensureValid(true)
10
+ if (result === null) {
11
+ return false
12
+ }
13
+ return true
14
+ }
15
+
16
+ public async hookErrorPage(ctx: CtxCore, listenerName: string, error: any, isEdit: boolean): Promise<void> {
17
+ await new GeneralErrorPage(ctx).transition(this.constructor.name, listenerName, error, isEdit)
18
+ }
19
+
20
+ public async hookErrorInputNotFoundPage(ctx: CtxCore): Promise<void> {
21
+ await new GeneralErrorInputNotFoundPage(ctx).transition()
22
+ }
23
+ }
@@ -1,3 +1,3 @@
1
- import { Ctx } from "gramstax"
2
-
3
- export class CtxCore extends Ctx {}
1
+ import { Ctx } from "gramstax"
2
+
3
+ export class CtxCore extends Ctx {}
@@ -0,0 +1,2 @@
1
+ export * from "./bot"
2
+ export * from "./ctx"
@@ -1,3 +1 @@
1
- // YOU CAN DELETE THIS FILE
2
-
3
- export class Db {}
1
+ export class Db {}
@@ -1,6 +1,5 @@
1
- export const env = {
2
- BOT_TOKEN: process.env.BOT_TOKEN as string,
3
- BOT_DEPLOY: process.env.BOT_DEPLOY as string,
4
- NODE_ENV: process.env.NODE_ENV as string,
5
- CACHE_SESSION: process.env.CACHE_SESSION as string
6
- }
1
+ export const env = {
2
+ BOT_TOKEN: process.env.BOT_TOKEN as string,
3
+ BOT_DEPLOY: process.env.BOT_DEPLOY as string,
4
+ CACHE_SESSION: process.env.CACHE_SESSION as string
5
+ }
@@ -0,0 +1 @@
1
+ export * from "./user"
@@ -1,19 +1,19 @@
1
- import { GuardBase } from "~/base/guard"
2
- import { GeneralErrorPage } from "../pages/general-error"
3
- import { UserNameNotFoundPage } from "../pages/username-notfound"
4
-
5
- export class UserGuard extends GuardBase {
6
- public async ensureValid(isEdit: boolean) {
7
- try {
8
- if (!this.username || this.username.length == 0) {
9
- await new UserNameNotFoundPage(this).transition(isEdit)
10
- return null
11
- }
12
-
13
- return { status: true }
14
- } catch (err) {
15
- await new GeneralErrorPage(this).transition(this.constructor.name, `ensureValid`, err, isEdit)
16
- return null
17
- }
18
- }
19
- }
1
+ import { GuardBase } from "~/base"
2
+ import { GeneralErrorPage } from "~/pages/general-error"
3
+ import { UserNameNotFoundPage } from "~/pages/username-notfound"
4
+
5
+ export class UserGuard extends GuardBase {
6
+ public async ensureValid(isEdit: boolean) {
7
+ try {
8
+ if (!this.userName || this.userName.length == 0) {
9
+ await new UserNameNotFoundPage(this).transition(isEdit)
10
+ return null
11
+ }
12
+
13
+ return { status: true }
14
+ } catch (err) {
15
+ await new GeneralErrorPage(this).transition(this.constructor.name, `ensureValid`, err, isEdit)
16
+ return null
17
+ }
18
+ }
19
+ }
@@ -1,15 +1,15 @@
1
- import { env } from "./env"
2
- import { log } from "./utils/log"
3
- import { BotCore } from "./core/bot"
4
- import { MainThread } from "./threads/main"
5
- import { CacheExternal } from "gramstax"
6
-
7
- new MainThread(() => {
8
- log.success(`Bot started..`)
9
-
10
- new BotCore({
11
- token: env.BOT_TOKEN,
12
- deploy: env.BOT_DEPLOY,
13
- cacheSession: new CacheExternal(env.CACHE_SESSION, `session`, 24 * 60 * 60 * 1000)
14
- })
15
- })
1
+ import { env } from "./env"
2
+ import { log } from "./utils/log"
3
+ import { BotCore } from "./core/bot"
4
+ import { MainThread } from "./threads/main"
5
+ import { CacheExternal } from "gramstax"
6
+
7
+ new MainThread(() => {
8
+ log.success(`Bot started..`)
9
+
10
+ new BotCore({
11
+ token: env.BOT_TOKEN,
12
+ deploy: env.BOT_DEPLOY,
13
+ cacheSession: new CacheExternal(env.CACHE_SESSION, `session`, 24 * 60 * 60 * 1000)
14
+ })
15
+ })
@@ -1,39 +1,28 @@
1
- import { PageBase } from "~/base/page"
2
- import { StartPage } from "./start"
3
-
4
- export class GeneralErrorInputNotFoundPage extends PageBase {
5
- public kb() {
6
- return this.inlineKeyboard((kb, arr) => {
7
- return kb.text(arr[0], StartPage.data.callbackData())
8
- })
9
- }
10
-
11
- public async transition() {
12
- await this.edit(this.kb())
13
- }
14
-
15
- public static template = /*jsx*/ `
16
- <base>
17
- <keyboard type="inline">.. Home</keyboard>
18
- <keyboard lang="en" type="inline">.. Home</keyboard>
19
- <keyboard lang="it" type="inline">.. Casa</keyboard>
20
- <keyboard lang="id" type="inline">.. Beranda</keyboard>
21
-
22
- <message>
23
- <b>❌ Not Found</b>
24
- </message>
25
-
26
- <message lang="en">
27
- <b>❌ Not Found</b>
28
- </message>
29
-
30
- <message lang="it">
31
- <b>❌ Non Trovato</b>
32
- </message>
33
-
34
- <message lang="id">
35
- <b>❌ Tidak Ditemukan</b>
36
- </message>
37
- </base>
38
- `
39
- }
1
+ import { PageBase } from "~/base"
2
+ import { StartPage } from "./start"
3
+
4
+ export class GeneralErrorInputNotFoundPage extends PageBase {
5
+ public kb() {
6
+ return this.inlineKeyboard((kb, arr) => {
7
+ return kb.text(arr[0]!, StartPage.data.callbackData())
8
+ })
9
+ }
10
+
11
+ public async transition() {
12
+ await this.edit(this.kb())
13
+ }
14
+
15
+ public static template = /*jsx*/ `
16
+ <base>
17
+ <keyboard type="inline">.. Home</keyboard>
18
+ <keyboard lang="en" type="inline">.. Home</keyboard>
19
+ <keyboard lang="it" type="inline">.. Casa</keyboard>
20
+ <keyboard lang="id" type="inline">.. Beranda</keyboard>
21
+
22
+ <message><b>❌ Not Found</b></message>
23
+ <message lang="en"><b>❌ Not Found</b></message>
24
+ <message lang="it"><b>❌ Non Trovato</b></message>
25
+ <message lang="id"><b>❌ Tidak Ditemukan</b></message>
26
+ </base>
27
+ `
28
+ }
@@ -1,59 +1,60 @@
1
- import { PageBase } from "~/base/page"
2
- import { StartPage } from "./start"
3
-
4
- export class GeneralErrorPage extends PageBase {
5
- public kb() {
6
- return this.inlineKeyboard((kb, arr) => {
7
- return kb.text(arr[0], StartPage.data.callbackData())
8
- })
9
- }
10
-
11
- public async transition(constructorName: string, funcName: string, error: any, isUpdate = true) {
12
- this.logError(error, constructorName, funcName)
13
- await this.sessionClear()
14
-
15
- const kb = this.kb()
16
- if (isUpdate === true) {
17
- await this.edit(kb)
18
- } else {
19
- await this.reply(kb)
20
- }
21
- }
22
-
23
- public static template = /*jsx*/ `
24
- <base>
25
- <keyboard type="inline">.. Home</keyboard>
26
- <keyboard lang="en" type="inline">.. Home</keyboard>
27
- <keyboard lang="es" type="inline">.. Inicio</keyboard>
28
- <keyboard lang="id" type="inline">.. Beranda</keyboard>
29
-
30
- <message>
31
- <b>❌ Error</b>
32
-
33
- An unexpected error occurred.
34
- Please try again later.
35
- </message>
36
-
37
- <message lang="en">
38
- <b>❌ Error</b>
39
-
40
- An unexpected error occurred.
41
- Please try again later.
42
- </message>
43
-
44
- <message lang="it">
45
- <b>❌ Errore</b>
46
-
47
- Si è verificato un errore imprevisto.
48
- Riprova più tardi.
49
- </message>
50
-
51
- <message lang="id">
52
- <b>❌ Kesalahan</b>
53
-
54
- Terjadi kesalahan yang tidak diharapkan.
55
- Silakan coba lagi nanti.
56
- </message>
57
- </base>
58
- `
59
- }
1
+ import { log } from "~/utils"
2
+ import { PageBase } from "~/base"
3
+ import { StartPage } from "./start"
4
+
5
+ export class GeneralErrorPage extends PageBase {
6
+ public kb() {
7
+ return this.inlineKeyboard((kb, arr) => {
8
+ return kb.text(arr[0]!, StartPage.data.callbackData())
9
+ })
10
+ }
11
+
12
+ public async transition(constructorName: string, funcName: string, error: unknown, isUpdate = true) {
13
+ log.errorMake(error, constructorName, funcName)
14
+ await this.sessionClear()
15
+
16
+ const kb = this.kb()
17
+ if (isUpdate === true) {
18
+ await this.edit(kb)
19
+ } else {
20
+ await this.reply(kb)
21
+ }
22
+ }
23
+
24
+ public static template = /*jsx*/ `
25
+ <base>
26
+ <keyboard type="inline">.. Home</keyboard>
27
+ <keyboard lang="en" type="inline">.. Home</keyboard>
28
+ <keyboard lang="es" type="inline">.. Inicio</keyboard>
29
+ <keyboard lang="id" type="inline">.. Beranda</keyboard>
30
+
31
+ <message>
32
+ <b>❌ Error</b>
33
+
34
+ An unexpected error occurred.
35
+ Please try again later.
36
+ </message>
37
+
38
+ <message lang="en">
39
+ <b>❌ Error</b>
40
+
41
+ An unexpected error occurred.
42
+ Please try again later.
43
+ </message>
44
+
45
+ <message lang="it">
46
+ <b>❌ Errore</b>
47
+
48
+ Si è verificato un errore imprevisto.
49
+ Riprova più tardi.
50
+ </message>
51
+
52
+ <message lang="id">
53
+ <b>❌ Kesalahan</b>
54
+
55
+ Terjadi kesalahan yang tidak diharapkan.
56
+ Silakan coba lagi nanti.
57
+ </message>
58
+ </base>
59
+ `
60
+ }
@@ -1,61 +1,49 @@
1
- import { PageBase } from "~/base/page"
2
- import { StartPage } from "./start"
3
-
4
- export class HelpPage extends PageBase {
5
- public kb() {
6
- return this.inlineKeyboard((kb, arr) => {
7
- return kb //
8
- .text(arr[0], StartPage.data.callbackData())
9
- })
10
- }
11
-
12
- public async internal(edit = true) {
13
- const kb = this.kb()
14
- if (edit) {
15
- await this.edit(kb)
16
- } else {
17
- await this.reply(kb)
18
- }
19
- }
20
-
21
- public async callback() {
22
- await this.internal(true)
23
- }
24
-
25
- public async text() {
26
- await this.internal(false)
27
- }
28
-
29
- public async textCommand() {
30
- await this.internal(false)
31
- }
32
-
33
- public async textCommandPayload() {
34
- await this.internal(false)
35
- }
36
-
37
- public static template = /*jsx*/ `
38
- <base>
39
- <keyboard type="inline">.. Back</keyboard>
40
- <keyboard lang="en" type="inline">.. Back</keyboard>
41
- <keyboard lang="it" type="inline">.. Ritorno</keyboard>
42
- <keyboard lang="id" type="inline">.. Kembali</keyboard>
43
-
44
- <message>
45
- <b>Help message</b>
46
- </message>
47
-
48
- <message lang="en">
49
- <b>Help message</b>
50
- </message>
51
-
52
- <message lang="it">
53
- <b>Ordina aiuto</b>
54
- </message>
55
-
56
- <message lang="id">
57
- <b>Pesan bantuan</b>
58
- </message>
59
- </base>
60
- `
61
- }
1
+ import { PageBase } from "~/base"
2
+ import { StartPage } from "./start"
3
+
4
+ export class HelpPage extends PageBase {
5
+ public kb() {
6
+ return this.inlineKeyboard((kb, arr) => {
7
+ return kb.text(arr[0]!, StartPage.data.callbackData())
8
+ })
9
+ }
10
+
11
+ public async internal(edit = true) {
12
+ const kb = this.kb()
13
+ if (edit) {
14
+ await this.edit(kb)
15
+ } else {
16
+ await this.reply(kb)
17
+ }
18
+ }
19
+
20
+ public async callback() {
21
+ await this.internal(true)
22
+ }
23
+
24
+ public async text() {
25
+ await this.internal(false)
26
+ }
27
+
28
+ public async textCommand() {
29
+ await this.internal(false)
30
+ }
31
+
32
+ public async textCommandPayload() {
33
+ await this.internal(false)
34
+ }
35
+
36
+ public static template = /*jsx*/ `
37
+ <base>
38
+ <keyboard type="inline">.. Back</keyboard>
39
+ <keyboard lang="en" type="inline">.. Back</keyboard>
40
+ <keyboard lang="it" type="inline">.. Ritorno</keyboard>
41
+ <keyboard lang="id" type="inline">.. Kembali</keyboard>
42
+
43
+ <message><b>Help message</b></message>
44
+ <message lang="en"><b>Help message</b></message>
45
+ <message lang="it"><b>Ordina aiuto</b></message>
46
+ <message lang="id"><b>Pesan bantuan</b></message>
47
+ </base>
48
+ `
49
+ }
@@ -1,70 +1,69 @@
1
- import { HelpPage } from "./help"
2
- import { PageBase } from "~/base/page"
3
-
4
- export class StartPage extends PageBase {
5
- public kb() {
6
- return this.inlineKeyboard((kb, arr) => {
7
- return kb //
8
- .text(arr[0], HelpPage.data.callbackData())
9
- })
10
- }
11
-
12
- public async internal(edit = true) {
13
- const kb = this.kb()
14
- const data = { username: this.username }
15
- if (edit) {
16
- await this.edit(kb, data)
17
- } else {
18
- await this.reply(kb, data)
19
- }
20
- }
21
-
22
- public async callback() {
23
- await this.internal(true)
24
- }
25
-
26
- public async text() {
27
- await this.internal(false)
28
- }
29
-
30
- public async textCommand() {
31
- await this.internal(false)
32
- }
33
-
34
- public async textCommandPayload() {
35
- await this.internal(false)
36
- }
37
-
38
- public static template = /*jsx*/ `
39
- <base>
40
- <keyboard type="inline">❓ Help</keyboard>
41
- <keyboard lang="en" type="inline">❓ Help</keyboard>
42
- <keyboard lang="it" type="inline">❓ Aiuto</keyboard>
43
- <keyboard lang="id" type="inline">❓ Bantuan</keyboard>
44
-
45
- <message>
46
- <b>Welcome to the bot {{username}}</b>
47
-
48
- <b>❓ Help</b> - View help
49
- </message>
50
-
51
- <message lang="en">
52
- <b>Welcome to the bot {{username}}</b>
53
-
54
- <b>❓ Help</b> - View help
55
- </message>
56
-
57
- <message lang="it">
58
- <b>Benvenuto nel Bot di {{username}}</b>
59
-
60
- <b>❓ Aiuto</b> - Ottieni assistenza e informazioni
61
- </message>
62
-
63
- <message lang="id">
64
- <b>Selamat datang di bot {{username}}</b>
65
-
66
- <b>❓ Bantuan</b> - Lihat bantuan
67
- </message>
68
- </base>
69
- `
70
- }
1
+ import { HelpPage } from "./help"
2
+ import { PageBase } from "~/base"
3
+
4
+ export class StartPage extends PageBase {
5
+ public kb() {
6
+ return this.inlineKeyboard((kb, arr) => {
7
+ return kb.text(arr[0]!, HelpPage.data.callbackData())
8
+ })
9
+ }
10
+
11
+ public async internal(edit = true) {
12
+ const kb = this.kb()
13
+ const data = { userName: this.userName }
14
+ if (edit) {
15
+ await this.edit(kb, data)
16
+ } else {
17
+ await this.reply(kb, data)
18
+ }
19
+ }
20
+
21
+ public async callback() {
22
+ await this.internal(true)
23
+ }
24
+
25
+ public async text() {
26
+ await this.internal(false)
27
+ }
28
+
29
+ public async textCommand() {
30
+ await this.internal(false)
31
+ }
32
+
33
+ public async textCommandPayload() {
34
+ await this.internal(false)
35
+ }
36
+
37
+ public static template = /*jsx*/ `
38
+ <base>
39
+ <keyboard type="inline">❓ Help</keyboard>
40
+ <keyboard lang="en" type="inline">❓ Help</keyboard>
41
+ <keyboard lang="it" type="inline">❓ Aiuto</keyboard>
42
+ <keyboard lang="id" type="inline">❓ Bantuan</keyboard>
43
+
44
+ <message>
45
+ <b>Welcome to the bot {{userName}}</b>
46
+
47
+ <b>❓ Help</b> - View help
48
+ </message>
49
+
50
+ <message lang="en">
51
+ <b>Welcome to the bot {{userName}}</b>
52
+
53
+ <b>❓ Help</b> - View help
54
+ </message>
55
+
56
+ <message lang="it">
57
+ <b>Benvenuto nel Bot di {{userName}}</b>
58
+
59
+ <b>❓ Aiuto</b> - Ottieni assistenza e informazioni
60
+ </message>
61
+
62
+ <message lang="id">
63
+ <b>Selamat datang di bot {{userName}}</b>
64
+
65
+ <b>❓ Bantuan</b> - Lihat bantuan
66
+ </message>
67
+ </base>
68
+ `
69
+ }