Initial commit
This commit is contained in:
commit
05a1bf047d
12 changed files with 4053 additions and 0 deletions
2
.env.example
Normal file
2
.env.example
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
API_ID=
|
||||
API_HASH=
|
||||
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
node_modules/
|
||||
dist/
|
||||
.nyc_output/
|
||||
**/.DS_Store
|
||||
.idea
|
||||
.vscode
|
||||
*.log
|
||||
*.tsbuildinfo
|
||||
.env
|
||||
14
Dockerfile
Normal file
14
Dockerfile
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
FROM node:20-alpine
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk add python3 make g++ && \
|
||||
corepack enable && \
|
||||
corepack prepare pnpm@8.7.1 --activate
|
||||
|
||||
COPY package*.json pnpm*.yaml tsconfig.json ./
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
COPY src /app/src
|
||||
RUN pnpm run build
|
||||
|
||||
CMD [ "node", "/app/dist/main.js" ]
|
||||
14
README.md
Normal file
14
README.md
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# mtproto_exporter
|
||||
|
||||
mtcute powered Telegram bot
|
||||
|
||||
## Development
|
||||
|
||||
```bash
|
||||
pnpm install --frozen-lockfile
|
||||
cp .env.example .env
|
||||
# edit .env
|
||||
pnpm start
|
||||
```
|
||||
|
||||
*generated with @mtcute/create-bot*
|
||||
2
bot-data/.gitignore
vendored
Normal file
2
bot-data/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
*
|
||||
!.gitignore
|
||||
10
docker-compose.yaml
Normal file
10
docker-compose.yaml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
version: "3.9"
|
||||
services:
|
||||
bot:
|
||||
build:
|
||||
context: .
|
||||
restart: always
|
||||
env_file:
|
||||
- .env
|
||||
volumes:
|
||||
- ./bot-data:/app/bot-data
|
||||
19
eslint.config.js
Normal file
19
eslint.config.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import antfu from '@antfu/eslint-config'
|
||||
|
||||
export default antfu({
|
||||
stylistic: {
|
||||
indent: 4,
|
||||
},
|
||||
typescript: true,
|
||||
yaml: false,
|
||||
rules: {
|
||||
'curly': ['error', 'multi-line'],
|
||||
'style/brace-style': ['error', '1tbs', { allowSingleLine: true }],
|
||||
'style/quotes': ['error', 'single', { avoidEscape: true }],
|
||||
'import/order': ['error', { 'newlines-between': 'always' }],
|
||||
'antfu/if-newline': 'off',
|
||||
'style/max-statements-per-line': ['error', { max: 2 }],
|
||||
'no-console': 'off',
|
||||
'antfu/no-top-level-await': 'off',
|
||||
},
|
||||
})
|
||||
29
package.json
Normal file
29
package.json
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "mtproto_exporter",
|
||||
"type": "module",
|
||||
"version": "0.0.1",
|
||||
"packageManager": "pnpm@10.6.5",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint --fix .",
|
||||
"start": "dotenv tsx ./src/main.ts",
|
||||
"build": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mtcute/dispatcher": "^0.22.2",
|
||||
"@mtcute/node": "^0.22.3",
|
||||
"dotenv-cli": "^8.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "^4.11.0",
|
||||
"@types/node": "^22.14.0",
|
||||
"tsx": "^4.19.3",
|
||||
"typescript": "^5.8.3"
|
||||
},
|
||||
"pnpm": {
|
||||
"onlyBuiltDependencies": [
|
||||
"better-sqlite3"
|
||||
]
|
||||
}
|
||||
}
|
||||
3903
pnpm-lock.yaml
generated
Normal file
3903
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load diff
10
src/env.ts
Normal file
10
src/env.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import process from 'node:process'
|
||||
|
||||
const API_ID = Number.parseInt(process.env.API_ID!)
|
||||
const API_HASH = process.env.API_HASH!
|
||||
|
||||
if (Number.isNaN(API_ID) || !API_HASH) {
|
||||
throw new Error('API_ID or API_HASH not set!')
|
||||
}
|
||||
|
||||
export { API_HASH, API_ID }
|
||||
19
src/main.ts
Normal file
19
src/main.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { Dispatcher, filters } from '@mtcute/dispatcher'
|
||||
import { TelegramClient } from '@mtcute/node'
|
||||
|
||||
import * as env from './env.js'
|
||||
|
||||
const tg = new TelegramClient({
|
||||
apiId: env.API_ID,
|
||||
apiHash: env.API_HASH,
|
||||
storage: 'bot-data/session',
|
||||
})
|
||||
|
||||
const dp = Dispatcher.for(tg)
|
||||
|
||||
dp.onNewMessage(filters.start, async (msg) => {
|
||||
await msg.answerText('Hello, world!')
|
||||
})
|
||||
|
||||
const user = await tg.start()
|
||||
console.log('Logged in as', user.username)
|
||||
22
tsconfig.json
Normal file
22
tsconfig.json
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"incremental": true,
|
||||
"target": "es2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"allowJs": true,
|
||||
"strict": true,
|
||||
"inlineSources": true,
|
||||
"outDir": "./dist",
|
||||
"sourceMap": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": [
|
||||
"./src"
|
||||
],
|
||||
"exclude": [
|
||||
"**/node_modules"
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue