create-gramstax 0.1.0 → 0.1.2
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/LICENSE +25 -25
- package/dist/src/index.cjs +0 -0
- package/dist/src/index.js +0 -0
- package/dist/src/templates/.env.example +14 -14
- package/dist/src/templates/.prettierrc +23 -23
- package/dist/src/templates/README.md +120 -120
- package/dist/src/templates/bunfig.toml +1 -1
- package/dist/src/templates/package.json +1 -1
- package/dist/src/templates/src/base/guard.ts +11 -11
- package/dist/src/templates/src/base/index.ts +4 -4
- package/dist/src/templates/src/base/page.ts +3 -3
- package/dist/src/templates/src/base/repository.ts +1 -1
- package/dist/src/templates/src/base/service.ts +1 -1
- package/dist/src/templates/src/core/bot.ts +23 -23
- package/dist/src/templates/src/core/ctx.ts +3 -3
- package/dist/src/templates/src/core/index.ts +2 -2
- package/dist/src/templates/src/db/index.ts +1 -1
- package/dist/src/templates/src/env.ts +5 -5
- package/dist/src/templates/src/guards/index.ts +1 -1
- package/dist/src/templates/src/guards/user.ts +19 -19
- package/dist/src/templates/src/index.ts +15 -15
- package/dist/src/templates/src/pages/general-error-input-notfound.ts +28 -28
- package/dist/src/templates/src/pages/general-error.ts +60 -60
- package/dist/src/templates/src/pages/help.ts +49 -49
- package/dist/src/templates/src/pages/start.ts +69 -69
- package/dist/src/templates/src/pages/username-notfound.ts +33 -33
- package/dist/src/templates/src/repositories/example.ts +3 -3
- package/dist/src/templates/src/repositories/index.ts +1 -1
- package/dist/src/templates/src/services/example.ts +3 -3
- package/dist/src/templates/src/services/index.ts +1 -1
- package/dist/src/templates/src/threads/index.ts +1 -1
- package/dist/src/templates/src/threads/main.ts +9 -9
- package/dist/src/templates/src/utils/index.ts +1 -1
- package/dist/src/templates/src/utils/log.ts +2 -2
- package/dist/src/templates/tsconfig.json +37 -37
- package/package.json +63 -63
package/LICENSE
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
MIT License (with Fair Donation Clause)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Gramstax
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following condition:
|
|
11
|
-
|
|
12
|
-
If this Software is used in any commercial, revenue-generating, or
|
|
13
|
-
client-based project (including freelance, agency, or product development),
|
|
14
|
-
users are encouraged—but not legally required—to make a fair donation
|
|
15
|
-
to support the ongoing development and maintenance of this Software.
|
|
16
|
-
|
|
17
|
-
Donations can be made through: [your donation link here]
|
|
18
|
-
|
|
19
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
-
THE SOFTWARE.
|
|
1
|
+
MIT License (with Fair Donation Clause)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Gramstax
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following condition:
|
|
11
|
+
|
|
12
|
+
If this Software is used in any commercial, revenue-generating, or
|
|
13
|
+
client-based project (including freelance, agency, or product development),
|
|
14
|
+
users are encouraged—but not legally required—to make a fair donation
|
|
15
|
+
to support the ongoing development and maintenance of this Software.
|
|
16
|
+
|
|
17
|
+
Donations can be made through: [your donation link here]
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
THE SOFTWARE.
|
package/dist/src/index.cjs
CHANGED
|
File without changes
|
package/dist/src/index.js
CHANGED
|
File without changes
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# Telegram Bot Token
|
|
2
|
-
BOT_TOKEN=your_bot_token_here
|
|
3
|
-
|
|
4
|
-
# Bot Deployment Mode
|
|
5
|
-
# Options:
|
|
6
|
-
# - polling
|
|
7
|
-
# - webhook:<full-public-url> | example: webhook:https://yourdomain.com/telegram-webhook
|
|
8
|
-
# - serverless:<adapter> | example: serverless:std/http
|
|
9
|
-
BOT_DEPLOY=polling
|
|
10
|
-
|
|
11
|
-
# Cache configuration for session
|
|
12
|
-
# Options:
|
|
13
|
-
# - memory
|
|
14
|
-
# - redis:<url> | example: redis://127.0.0.1:6379
|
|
1
|
+
# Telegram Bot Token
|
|
2
|
+
BOT_TOKEN=your_bot_token_here
|
|
3
|
+
|
|
4
|
+
# Bot Deployment Mode
|
|
5
|
+
# Options:
|
|
6
|
+
# - polling
|
|
7
|
+
# - webhook:<full-public-url> | example: webhook:https://yourdomain.com/telegram-webhook
|
|
8
|
+
# - serverless:<adapter> | example: serverless:std/http
|
|
9
|
+
BOT_DEPLOY=polling
|
|
10
|
+
|
|
11
|
+
# Cache configuration for session
|
|
12
|
+
# Options:
|
|
13
|
+
# - memory
|
|
14
|
+
# - redis:<url> | example: redis://127.0.0.1:6379
|
|
15
15
|
CACHE_SESSION=memory
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
{
|
|
2
|
-
"overrides": [
|
|
3
|
-
{
|
|
4
|
-
"files": "*.{json,sol}",
|
|
5
|
-
"options": {
|
|
6
|
-
"tabWidth": 2,
|
|
7
|
-
"printWidth": 200
|
|
8
|
-
}
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"files": "*.{ts,js}",
|
|
12
|
-
"options": {
|
|
13
|
-
"printWidth": 300,
|
|
14
|
-
"tabWidth": 2,
|
|
15
|
-
"useTabs": false,
|
|
16
|
-
"semi": false,
|
|
17
|
-
"arrowParens": "always",
|
|
18
|
-
"trailingComma": "none",
|
|
19
|
-
"bracketSameLine": false
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
]
|
|
23
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"overrides": [
|
|
3
|
+
{
|
|
4
|
+
"files": "*.{json,sol}",
|
|
5
|
+
"options": {
|
|
6
|
+
"tabWidth": 2,
|
|
7
|
+
"printWidth": 200
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"files": "*.{ts,js}",
|
|
12
|
+
"options": {
|
|
13
|
+
"printWidth": 300,
|
|
14
|
+
"tabWidth": 2,
|
|
15
|
+
"useTabs": false,
|
|
16
|
+
"semi": false,
|
|
17
|
+
"arrowParens": "always",
|
|
18
|
+
"trailingComma": "none",
|
|
19
|
+
"bracketSameLine": false
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -1,120 +1,120 @@
|
|
|
1
|
-
# {{projectName}}
|
|
2
|
-
|
|
3
|
-
A Telegram bot built with Gramstax framework.
|
|
4
|
-
|
|
5
|
-
## Getting Started
|
|
6
|
-
|
|
7
|
-
### Development
|
|
8
|
-
|
|
9
|
-
1. Install dependencies:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
{{installCmd}}
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
2. Set up your environment variables:
|
|
16
|
-
|
|
17
|
-
Copy `.env.example` to `.env` and add your Telegram bot token:
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
BOT_TOKEN=your_bot_token_here
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
3. Run the development server:
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
{{runDevCmd}}
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Production
|
|
30
|
-
|
|
31
|
-
#### Using PM2 (Recommended)
|
|
32
|
-
|
|
33
|
-
PM2 is a production process manager for Node.js applications with built-in load balancer.
|
|
34
|
-
|
|
35
|
-
1. Install dependencies:
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
{{installCmd}}
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
2. Set up production environment:
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
cp .env.example .env
|
|
45
|
-
# Edit .env with your production BOT_TOKEN
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
3. Start with PM2:
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
{{runPm2StartCmd}}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
4. PM2 Management Commands:
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
# View logs
|
|
58
|
-
{{runPm2LogsCmd}}
|
|
59
|
-
|
|
60
|
-
# Monitor processes
|
|
61
|
-
{{runPm2MonitCmd}}
|
|
62
|
-
|
|
63
|
-
# Restart bot
|
|
64
|
-
{{runPm2RestartCmd}}
|
|
65
|
-
|
|
66
|
-
# Stop bot
|
|
67
|
-
{{runPm2StopCmd}}
|
|
68
|
-
|
|
69
|
-
# Delete from PM2
|
|
70
|
-
{{runPm2DeleteCmd}}
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
5. Setup PM2 to start on system boot:
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
pm2 startup
|
|
77
|
-
pm2 save
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
#### Using Bun directly
|
|
81
|
-
|
|
82
|
-
```bash
|
|
83
|
-
{{runStartCmd}}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## Project Structure
|
|
87
|
-
|
|
88
|
-
- `src/base/` - Base classes for your bot components
|
|
89
|
-
- `src/core/` - Core bot configuration and hooks
|
|
90
|
-
- `src/pages/` - Bot pages/screens
|
|
91
|
-
- `src/guards/` - Route guards and middleware
|
|
92
|
-
- `src/services/` - Business logic services
|
|
93
|
-
- `src/repositories/` - Data access layer
|
|
94
|
-
- `src/templates/` - Message templates
|
|
95
|
-
- `src/utils/` - Utility functions
|
|
96
|
-
- `logs/` - Application logs (created automatically)
|
|
97
|
-
|
|
98
|
-
## Configuration
|
|
99
|
-
|
|
100
|
-
### Environment Variables
|
|
101
|
-
|
|
102
|
-
- `BOT_TOKEN` - Your Telegram bot token (required)
|
|
103
|
-
- `CACHE_SESSION` - Cache type configuration (optional)
|
|
104
|
-
|
|
105
|
-
### PM2 Configuration
|
|
106
|
-
|
|
107
|
-
The `ecosystem.config.js` file contains PM2 configuration:
|
|
108
|
-
|
|
109
|
-
- **instances**: Number of instances (default: 1)
|
|
110
|
-
- **exec_mode**: Execution mode (cluster/fork)
|
|
111
|
-
- **max_memory_restart**: Auto-restart if memory exceeds limit
|
|
112
|
-
- **autorestart**: Auto-restart on crash
|
|
113
|
-
- **error_file/out_file**: Log file locations
|
|
114
|
-
|
|
115
|
-
## Learn More
|
|
116
|
-
|
|
117
|
-
- [Gramstax Documentation](https://github.com/gramstax/gramstax)
|
|
118
|
-
- [Grammy Documentation](https://grammy.dev/)
|
|
119
|
-
- [Telegram Bot API](https://core.telegram.org/bots/api)
|
|
120
|
-
- [PM2 Documentation](https://pm2.keymetrics.io/)
|
|
1
|
+
# {{projectName}}
|
|
2
|
+
|
|
3
|
+
A Telegram bot built with Gramstax framework.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
### Development
|
|
8
|
+
|
|
9
|
+
1. Install dependencies:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
{{installCmd}}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
2. Set up your environment variables:
|
|
16
|
+
|
|
17
|
+
Copy `.env.example` to `.env` and add your Telegram bot token:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
BOT_TOKEN=your_bot_token_here
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
3. Run the development server:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
{{runDevCmd}}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Production
|
|
30
|
+
|
|
31
|
+
#### Using PM2 (Recommended)
|
|
32
|
+
|
|
33
|
+
PM2 is a production process manager for Node.js applications with built-in load balancer.
|
|
34
|
+
|
|
35
|
+
1. Install dependencies:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
{{installCmd}}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
2. Set up production environment:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
cp .env.example .env
|
|
45
|
+
# Edit .env with your production BOT_TOKEN
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
3. Start with PM2:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
{{runPm2StartCmd}}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
4. PM2 Management Commands:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# View logs
|
|
58
|
+
{{runPm2LogsCmd}}
|
|
59
|
+
|
|
60
|
+
# Monitor processes
|
|
61
|
+
{{runPm2MonitCmd}}
|
|
62
|
+
|
|
63
|
+
# Restart bot
|
|
64
|
+
{{runPm2RestartCmd}}
|
|
65
|
+
|
|
66
|
+
# Stop bot
|
|
67
|
+
{{runPm2StopCmd}}
|
|
68
|
+
|
|
69
|
+
# Delete from PM2
|
|
70
|
+
{{runPm2DeleteCmd}}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
5. Setup PM2 to start on system boot:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pm2 startup
|
|
77
|
+
pm2 save
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### Using Bun directly
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
{{runStartCmd}}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Project Structure
|
|
87
|
+
|
|
88
|
+
- `src/base/` - Base classes for your bot components
|
|
89
|
+
- `src/core/` - Core bot configuration and hooks
|
|
90
|
+
- `src/pages/` - Bot pages/screens
|
|
91
|
+
- `src/guards/` - Route guards and middleware
|
|
92
|
+
- `src/services/` - Business logic services
|
|
93
|
+
- `src/repositories/` - Data access layer
|
|
94
|
+
- `src/templates/` - Message templates
|
|
95
|
+
- `src/utils/` - Utility functions
|
|
96
|
+
- `logs/` - Application logs (created automatically)
|
|
97
|
+
|
|
98
|
+
## Configuration
|
|
99
|
+
|
|
100
|
+
### Environment Variables
|
|
101
|
+
|
|
102
|
+
- `BOT_TOKEN` - Your Telegram bot token (required)
|
|
103
|
+
- `CACHE_SESSION` - Cache type configuration (optional)
|
|
104
|
+
|
|
105
|
+
### PM2 Configuration
|
|
106
|
+
|
|
107
|
+
The `ecosystem.config.js` file contains PM2 configuration:
|
|
108
|
+
|
|
109
|
+
- **instances**: Number of instances (default: 1)
|
|
110
|
+
- **exec_mode**: Execution mode (cluster/fork)
|
|
111
|
+
- **max_memory_restart**: Auto-restart if memory exceeds limit
|
|
112
|
+
- **autorestart**: Auto-restart on crash
|
|
113
|
+
- **error_file/out_file**: Log file locations
|
|
114
|
+
|
|
115
|
+
## Learn More
|
|
116
|
+
|
|
117
|
+
- [Gramstax Documentation](https://github.com/gramstax/gramstax)
|
|
118
|
+
- [Grammy Documentation](https://grammy.dev/)
|
|
119
|
+
- [Telegram Bot API](https://core.telegram.org/bots/api)
|
|
120
|
+
- [PM2 Documentation](https://pm2.keymetrics.io/)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
[run]
|
|
1
|
+
[run]
|
|
2
2
|
console.depth = 4
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { CtxCore } from "~/core"
|
|
2
|
-
|
|
3
|
-
export abstract class GuardBase extends CtxCore {
|
|
4
|
-
public constructor(ctx: CtxCore) {
|
|
5
|
-
super(ctx)
|
|
6
|
-
if (ctx?.data) {
|
|
7
|
-
// save as temporary because guard should not save this.data or class.data because it is intended for Page only.
|
|
8
|
-
this.temp.data = ctx.data
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
}
|
|
1
|
+
import { CtxCore } from "~/core"
|
|
2
|
+
|
|
3
|
+
export abstract class GuardBase extends CtxCore {
|
|
4
|
+
public constructor(ctx: CtxCore) {
|
|
5
|
+
super(ctx)
|
|
6
|
+
if (ctx?.data) {
|
|
7
|
+
// save as temporary because guard should not save this.data or class.data because it is intended for Page only.
|
|
8
|
+
this.temp.data = ctx.data
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./guard"
|
|
2
|
-
export * from "./page"
|
|
3
|
-
export * from "./repository"
|
|
4
|
-
export * from "./service"
|
|
1
|
+
export * from "./guard"
|
|
2
|
+
export * from "./page"
|
|
3
|
+
export * from "./repository"
|
|
4
|
+
export * from "./service"
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { CtxCore } from "~/core"
|
|
2
|
-
|
|
3
|
-
export abstract class PageBase extends CtxCore {}
|
|
1
|
+
import { CtxCore } from "~/core"
|
|
2
|
+
|
|
3
|
+
export abstract class PageBase extends CtxCore {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export abstract class RepositoryBase {}
|
|
1
|
+
export abstract class RepositoryBase {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export abstract class ServiceBase {}
|
|
1
|
+
export abstract class ServiceBase {}
|
|
@@ -1,23 +1,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
|
+
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 {}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./bot"
|
|
2
|
-
export * from "./ctx"
|
|
1
|
+
export * from "./bot"
|
|
2
|
+
export * from "./ctx"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export class Db {}
|
|
1
|
+
export class Db {}
|
|
@@ -1,5 +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
|
-
CACHE_SESSION: process.env.CACHE_SESSION as string
|
|
5
|
-
}
|
|
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
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./user"
|
|
1
|
+
export * from "./user"
|
|
@@ -1,19 +1,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
|
+
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,28 +1,28 @@
|
|
|
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
|
+
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
|
+
}
|