initial
This commit is contained in:
commit
512a10ca29
3
.env.example
Normal file
3
.env.example
Normal file
@ -0,0 +1,3 @@
|
||||
NODE_ENV=development
|
||||
LOG_LEVEL=trace
|
||||
TOKEN=
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
dist
|
||||
.env
|
10
README.md
Normal file
10
README.md
Normal file
@ -0,0 +1,10 @@
|
||||
# remove-keyboard-bot
|
||||
|
||||
## Run bot
|
||||
1) install NodeJS
|
||||
2) clone this repo: `git clone https://git.zeldon.ru/zeldon/remove-keyboard-bot.git`
|
||||
3) cd to dir with bot
|
||||
4) write `npm i`
|
||||
5) cp env: `cp .env.example .env`
|
||||
6) edit `.env` (add token)
|
||||
7) start in dev mode: `npm run dev` and prod: `npm run build && node dist/index.js`
|
19
index.ts
Normal file
19
index.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { env } from "#root/env.js";
|
||||
import { removeKeyboardFeature } from "#root/features/remove-keyboard.js";
|
||||
import { welcomeFeature } from "#root/features/welcome.js";
|
||||
import { logger } from "#root/logger.js";
|
||||
import { Bot } from "grammy";
|
||||
|
||||
const bot = new Bot(env.TOKEN);
|
||||
|
||||
bot.use(welcomeFeature);
|
||||
bot.use(removeKeyboardFeature);
|
||||
|
||||
bot.start({
|
||||
onStart: ({ username }) =>
|
||||
logger.info({
|
||||
msg: "bot running...",
|
||||
username,
|
||||
}),
|
||||
drop_pending_updates: true
|
||||
});
|
1699
package-lock.json
generated
Normal file
1699
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
27
package.json
Normal file
27
package.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "remove-keyboard-bot",
|
||||
"main": "dist/index.js",
|
||||
"type": "module",
|
||||
"imports": {
|
||||
"#root/*": "./dist/src/*"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "npm run clean && tsc-watch --onSuccess \"tsx index.ts\"",
|
||||
"build": "npm run clean && tsc --noEmit false",
|
||||
"clean": "rimraf dist"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.9.0",
|
||||
"rimraf": "^5.0.5",
|
||||
"tsc-watch": "^6.0.4",
|
||||
"tsx": "^3.14.0",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"dotenv": "^16.3.1",
|
||||
"envalid": "^7.3.1",
|
||||
"grammy": "^1.19.2",
|
||||
"pino": "^8.16.1",
|
||||
"pino-pretty": "^10.2.3"
|
||||
}
|
||||
}
|
10
src/env.ts
Normal file
10
src/env.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import 'dotenv/config';
|
||||
import { cleanEnv, str } from 'envalid';
|
||||
|
||||
export const env = cleanEnv(process.env, {
|
||||
NODE_ENV: str({ choices: ["development", "production"] }),
|
||||
LOG_LEVEL: str({
|
||||
choices: ["trace", "debug", "info", "warn", "error", "fatal", "silent"],
|
||||
}),
|
||||
TOKEN: str()
|
||||
});
|
14
src/features/remove-keyboard.ts
Normal file
14
src/features/remove-keyboard.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { Composer, Context } from "grammy";
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
const feature = composer.chatType(['group', 'supergroup']);
|
||||
|
||||
feature.command('remove', async (ctx) => {
|
||||
await ctx.reply('keboard removed', {
|
||||
reply_markup: { remove_keyboard: true }
|
||||
});
|
||||
|
||||
ctx.editMessageReplyMarkup();
|
||||
});
|
||||
|
||||
export { composer as removeKeyboardFeature };
|
10
src/features/welcome.ts
Normal file
10
src/features/welcome.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { Composer, Context } from "grammy";
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
const feature = composer.chatType('private');
|
||||
|
||||
feature.command(['help', 'start'], async (ctx) => {
|
||||
ctx.reply('Add this bot to chat and type /remove command');
|
||||
});
|
||||
|
||||
export { composer as welcomeFeature };
|
20
src/logger.ts
Normal file
20
src/logger.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { env } from "#root/env.js";
|
||||
import { LoggerOptions, pino } from "pino";
|
||||
import PinoPretty, { PrettyOptions } from "pino-pretty";
|
||||
|
||||
const options: LoggerOptions = {
|
||||
level: env.LOG_LEVEL
|
||||
};
|
||||
|
||||
const prettyOptions: PrettyOptions = {
|
||||
ignore: 'pid,hostname',
|
||||
colorize: env.isDev ? true : false,
|
||||
translateTime: 'SYS:dd.mm.yyyy, HH:MM:ss'
|
||||
};
|
||||
|
||||
export let logger = pino(options);
|
||||
|
||||
if (env.isDev) {
|
||||
// @ts-ignore
|
||||
logger = pino(options, PinoPretty(prettyOptions));
|
||||
}
|
24
tsconfig.json
Normal file
24
tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"preserveWatchOutput": true,
|
||||
"noEmit": true,
|
||||
"module": "NodeNext",
|
||||
"target": "ES2021",
|
||||
"moduleResolution": "NodeNext",
|
||||
"sourceMap": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": ".",
|
||||
"paths": {
|
||||
"#root/*": [
|
||||
"./src/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"src/**/*",
|
||||
"index.ts"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user