From d76e02b33f10235a6b8dfe8e7f80d60c4ec1880a Mon Sep 17 00:00:00 2001 From: AntoXa PRO Date: Wed, 27 Nov 2024 15:43:39 +0300 Subject: [PATCH] init commit --- .gitignore | 4 ++++ .prettierrc | 9 +++++++++ package.json | 19 +++++++++++++++++++ src/index.ts | 33 +++++++++++++++++++++++++++++++++ tsconfig.json | 16 ++++++++++++++++ vite.config.ts | 16 ++++++++++++++++ 6 files changed, 97 insertions(+) create mode 100644 .gitignore create mode 100644 .prettierrc create mode 100644 package.json create mode 100644 src/index.ts create mode 100644 tsconfig.json create mode 100644 vite.config.ts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0bab527 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.env +dist +node_modules +package-lock.json diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..cdda34f --- /dev/null +++ b/.prettierrc @@ -0,0 +1,9 @@ +{ + "useTabs": true, + "tabWidth": 2, + "singleQuote": true, + "semi": false, + "trailingComma": "none", + "arrowParens": "avoid", + "printWidth": 79 +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..8e7e413 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "tg-bot", + "version": "1.0.0", + "module": "./dist/index.mjs", + "main": "./dist/index.umd.js", + "scripts": { + "start": "node .", + "build": "vite build" + }, + "dependencies": { + "dotenv": "^16.4.5", + "telegraf": "^4.16.3" + }, + "devDependencies": { + "@types/node": "^22.10.0", + "prettier": "^3.4.1", + "vite": "^6.0.1" + } +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..3be39a7 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,33 @@ +// Импорт сторонних библиотек. +import * as dotenv from 'dotenv' +import { Telegraf } from 'telegraf' + +// Главная функция приложения (Точка входа). +const main = () => { + try { + // Инициализируем библиотеку для переменных окружения + // Что бы мы могли их читать из файла .env + dotenv.config() + + // Токен. + const token = process.env.TELEGRAM_TOKEN + if (!token) throw new Error('Токен не найден!') + + // Создание экземпляра бота + const bot = new Telegraf(token) + + // Обработчик команды /start + bot.start(async ctx => { + await ctx.reply('Привет!') + }) + + // Запуск бота + bot.launch() + } catch (e) { + // Обработка ошибок. + console.log('Ошибка:', e) + } +} + +// Старт приложения. +main() diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..9721a88 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + + "paths": { + "~/*": [ + "./src/*" + ] + }, + + "strict": true, + "moduleResolution": "node" + }, + "include": ["src/**/*.ts"] +} diff --git a/vite.config.ts b/vite.config.ts new file mode 100644 index 0000000..e19cc2c --- /dev/null +++ b/vite.config.ts @@ -0,0 +1,16 @@ +import { resolve } from 'node:path' +import { defineConfig } from 'vite' + +export default defineConfig({ + resolve: { alias: { '~': resolve(__dirname, './src') } }, + build: { + lib: { + name: 'tg-bot', + fileName: 'index', + entry: resolve(__dirname, 'src', 'index.ts') + }, + rollupOptions: { + external: ['telegraf', 'dotenv'] + } + } +})