diff --git a/.env.example b/.env.example index f1875dd..dda398a 100644 --- a/.env.example +++ b/.env.example @@ -1,13 +1,8 @@ -# @BotFather => /newbot -#TG API SERVICING -# http://127.0.0.1:8081 TG_APIROOT = 'https://api.telegram.org' -# @BotFather => /newbot BOT_TOKEN = '1745011940:AAAAAAAAAAAAAAAAAAAAAAAAAAAAA' -# ADMIN for report message -ADMIN_ID = 1159809878 -# Example ( BOT_CLUSTER_CORE = 2 ) or AutoScale ( BOT_CLUSTER_CORE = 0 ) -BOT_CLUSTER_CORE = 2 -# Mongoose databse -#MONGOOSE_URL = 'mongodb+srv://secven:secvennotabugsecven@cluster0.myekb.mongodb.net/secven' -MONGOOSE_URL = 'mongodb://127.0.0.1/secven' +ADMIN_ID = 1872887287 +BOT_CLUSTER_CORE = 0 +MONGOOSE_URL = 'mongodb+srv://:@cluster0.myekb.mongodb.net/secven' + +DADATA_TOKEN = '1b333051049e4edbgffffffffffffffffffffffgg' +DADATA_SECRET = '303bd4ac15aegggggggggggggggggggggggggggg' diff --git a/ecosystem.config.js b/ecosystem.config.js index d8f1330..322a145 100644 --- a/ecosystem.config.js +++ b/ecosystem.config.js @@ -1,8 +1,8 @@ module.exports = { apps: [ { - name: 'APP-BOT', - script: './index.js', + name: require('package.json').name, + script: require('package.json').main, max_memory_restart: '1000M', wait_ready: true, restart_delay: 5000, diff --git a/package.json b/package.json index 568e713..4e4d2d3 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "bot-pattern-telegraf", + "name": "bot-eye-leak", "version": "1.0.0", "main": "index.js", "author": "", @@ -9,8 +9,8 @@ "start": "cross-env NODE_ENV=development node index.js", "dev": "cross-env NODE_ENV=development nodemon index.js", "prod": "cross-env NODE_ENV=production node index.js", - "pm:stop": "cross-env NODE_ENV=production pm2 stop ecosystem.config.js", - "pm:prod": "cross-env NODE_ENV=production pm2 start ecosystem.config.js", + "pm:stop": "pm2 stop ecosystem.config.js", + "pm:prod": "pm2 start ecosystem.config.js", "pm:up": "pm2 startup" }, "dependencies": { diff --git a/src/config/config.js b/src/config/config.js index 31720a0..8261b19 100644 --- a/src/config/config.js +++ b/src/config/config.js @@ -16,11 +16,9 @@ config.consignOpts = { config.limitSecurity = { window: ms('15s'), - limit: 5, - onLimitExceeded: ({ message, replyWithHTML }) => - replyWithHTML('❗️Please wait a second (5s)', { - disable_notification: true - }) + limit: 4, + onLimitExceeded: ({ answerCbQuery }) => + answerCbQuery('❗️Please wait a second !', true) } config.i18nOpts = { diff --git a/src/config/telegraf.js b/src/config/telegraf.js index 7e3784a..5e70eae 100644 --- a/src/config/telegraf.js +++ b/src/config/telegraf.js @@ -43,6 +43,7 @@ const Route = new Router(({ callbackQuery }) => { })() bot.route = Route +bot.rateLimit = rateLimit bot.context.db = db bot.context.extra = Extra bot.context.markup = Markup diff --git a/src/handlers/eyeofgodTask.js b/src/handlers/eyeofgodTask.js index 9cd92fb..4549d81 100644 --- a/src/handlers/eyeofgodTask.js +++ b/src/handlers/eyeofgodTask.js @@ -1,15 +1,19 @@ +const { SERVICE } = require('../util/service') + class EyeofgodTask { checkLeak = async ({ db, i18n, extra, message, session, replyWithHTML }) => { try { const id = (session.eyeof = message.text.trim()) const base = await db.Eye.findOne({ id }).sort({ id: 1 }).lean() + /// const expectData = await SERVICE.getInfoOperator(base?.phone) return await replyWithHTML( i18n.t('eyeofgod', { id: base.id, - phone: base?.phone, + nPhone: base?.phone, username: base?.username, - fullName: `${base?.first_name} | ${base?.last_name}` + fullName: `${base?.first_name ?? ''} | ${base?.last_name ?? ''}` + // ...expectData }), extra .HTML() @@ -25,10 +29,9 @@ class EyeofgodTask { ) ) ) - } catch (e) { - // console.log(e.message) + } catch { return await replyWithHTML( - '💮 No in Database', + '📍 There is no database !', extra .HTML() .inReplyTo(message.message_id) diff --git a/src/handlers/jokeTask.js b/src/handlers/jokeTask.js index 369fcc2..38f47f4 100644 --- a/src/handlers/jokeTask.js +++ b/src/handlers/jokeTask.js @@ -1,7 +1,7 @@ const fetch = require('node-fetch') class JokeTask { - async getRandomAnimation(ctx) { + async getRandomAnimation({ replyWithAnimation }) { const page = Math.floor(Math.random() * 100) return Promise.resolve( await fetch(`https://developerslife.ru/top/${page}?json=true`) @@ -11,7 +11,7 @@ class JokeTask { const index = Number(Math.floor(Math.random() * data.result.length)) // eslint-disable-next-line security/detect-object-injection const { videoURL: sendGif, description: caption } = data.result[index] - return ctx.replyWithAnimation(sendGif, { + return replyWithAnimation(sendGif, { caption, parse_mode: 'HTML' }) diff --git a/src/handlers/startTask.js b/src/handlers/startTask.js index e3396c3..a5e51ab 100644 --- a/src/handlers/startTask.js +++ b/src/handlers/startTask.js @@ -1,19 +1,19 @@ class StartTask { async start({ reply, replyWithSticker, message, i18n, from, extra }) { await replyWithSticker( - 'CAACAgIAAxkBAAIBs2DeqZIZBIYgeFBsno36780WxeHsAAIQAAPDVgMednAUKnTod-sgBA' + 'CAACAgIAAxkBAAIZH2DvF-OAI9Kzy_QazXqHYR0rUD7-AAIXAAPDVgMeQjlqcLJ92EYgBA' ) const markup = extra .HTML() .inReplyTo(message.message_id) - // .webPreview(false) + .webPreview(false) .markup(m => m.inlineKeyboard( [ - m.urlButton('Subscribe', 'https://t.me/ThisOpenSource'), - m.callbackButton('Subscribe ACQ', 'startMenu|test'), + m.callbackButton('💰 Donate', 'startMenu|donate'), m.urlButton('❤️ My Notabug', 'https://notabug.org/Secven'), - m.callbackButton('❌ Delete', 'delete') + m.urlButton('😊 Subscribe', 'https://t.me/ThisOpenSource'), + m.callbackButton(i18n.t('default.closeMessage'), 'delete') ], { columns: 2 } ) @@ -21,8 +21,17 @@ class StartTask { return await reply(i18n.t('main.start', { ...from }), markup) } - subscribe = async ctx => { - return await ctx.answerCbQuery('https://t.me/ThisOpenSource', true) + donateMe = async ({ i18n, extra, editMessageText }) => { + return editMessageText( + i18n.t('main.donate'), + extra + .HTML() + .markup(m => + m.inlineKeyboard([ + m.callbackButton(i18n.t('default.closeMessage'), 'delete') + ]) + ) + ) } } diff --git a/src/locales/en.yaml b/src/locales/en.yaml index 11f2468..a5bdaca 100644 --- a/src/locales/en.yaml +++ b/src/locales/en.yaml @@ -1,22 +1,34 @@ eyeofgod: | 👁 EyeOfGod Leak: ├ 🆔 ID: ${id} - ├ 📱 Phone: ${phone} - ├ 👤 Username: ${username} + ├ 📱 Phone: +${nPhone} + ├ 👤 Username: @${username} └ ⚫️ FullName: ${fullName} main: start: | - 💰 Donete me: - ├ https://t.me/ThisOpenSource + 🆘 Bot accepts requests to search for following formats: + + 👁 Telegram + ├ 596999557 - Search by ID + └ @username - Soon + + 🤖 Bot command + ├ /joke - IT gifs Funny + └ /lang - Change language + + 🗂 Database + ├ ✅ EyeOfGod 2021 + ├ ✅ Parsing 2021 + ├ ❌ Leak base May + └ ❌ Parsing 2020 + + ❔ If you want more databases you need to help Donat + donate: | + 💰 Donate: ├ BTC - 1Ebf7gBSSD5Y8y3zLHVy1SuJxAqAgJPjhW └ XMR - 45UcKcUN8d6M5cccXZiqC1dtpMsqSazyKSLGP3utQh3MhBmeuCuHAbYBwngsa1eAFs4yza9HukiH4axjNg58YGBrJo2x2tS - 🆘 SOS: - ├ Check Database EyeOfGod: - ├ Just send me ID: 596999557 - └ /eye 596999557 - ├ Change language: - └ /lang + ❤️ Thanks you for support stackError: report: | Handler Middleware: @@ -27,7 +39,6 @@ stackError: Stack: ${stack} 🤖 BOTNAME: ${botName} - default: lang: | 🤖 Language settings diff --git a/src/locales/ru.yaml b/src/locales/ru.yaml index 802b829..7c40828 100644 --- a/src/locales/ru.yaml +++ b/src/locales/ru.yaml @@ -1,22 +1,28 @@ eyeofgod: | 👁 EyeOfGod Leak: ├ 🆔 Айди: ${id} - ├ 📱 Телефон: ${phone} - ├ 👤 Имя пользователя: ${username} + ├ 📱 Телефон: +${nPhone} + ├ 👤 Имя пользователя: @${username} └ ⚫️ Полное Имя: ${fullName} main: start: | - 💰 Поддержать меня: - ├ https://t.me/ThisOpenSource - ├ BTC - 1Ebf7gBSSD5Y8y3zLHVy1SuJxAqAgJPjhW - └ XMR - 45UcKcUN8d6M5cccXZiqC1dtpMsqSazyKSLGP3utQh3MhBmeuCuHAbYBwngsa1eAFs4yza9HukiH4axjNg58YGBrJo2x2tS + 🆘 Бот принимает запросы на поиск следующих форматов: - 🆘 SOS: - ├ Проверьте в базе EyeOfGod: - ├ Просто отправь мне ID: 596999557 - └ /eye 596999557 - ├ Изменение языка: - └ /lang + 👁 Telegram + ├ 596999557 - Поиск по ID + └ @username - Скоро + + 🤖 Bot command + ├ /joke - IT gifs Funny + └ /lang - Изменение языка + + 🗂 База данных + ├ ✅ EyeOfGod 2021 + ├ ✅ Parsing 2021 + ├ ❌ Leak base May + └ ❌ Parsing 2020 + + ❔ Если вы хотите больше баз данных, вам нужно помочь Donat stackError: report: | Обработчик Middleware: diff --git a/src/middle/updaterUser.js b/src/middle/updaterUser.js index e187ad8..ffe929f 100644 --- a/src/middle/updaterUser.js +++ b/src/middle/updaterUser.js @@ -2,7 +2,7 @@ const { escapeHtml } = require('../util/escapeHTML') module.exports = async ({ db, from, i18n, session }, next) => { // eslint-disable-next-line camelcase - const { id, first_name, username, language_code } = from + const { id, first_name, username } = from if (!id) return await next() await db.User.findOne({ user_id: id }) .then(root => { diff --git a/src/route/eyeofgod.js b/src/route/eyeofgod.js index f32e8b3..18b76b5 100644 --- a/src/route/eyeofgod.js +++ b/src/route/eyeofgod.js @@ -1,4 +1,16 @@ module.exports = bot => { const { eyeofgodTask } = bot.handlers - bot.hears(/^[0-9]{5,20}$/, eyeofgodTask.checkLeak) + + const expect = bot.rateLimit({ + window: 1000 * 20, + limit: 1, + onLimitExceeded: ({ replyWithHTML }) => + replyWithHTML( + 'I can handle from you only one request in 15 seconds.' + ) + }) + + bot.hears(/^[0-9]{5,20}$/g, expect, eyeofgodTask.checkLeak) + + // TODO: Select menu add } diff --git a/src/route/joke.js b/src/route/joke.js index 96cf206..065befc 100644 --- a/src/route/joke.js +++ b/src/route/joke.js @@ -1,5 +1,7 @@ module.exports = bot => { const { jokeTask } = bot.handlers - bot.hears(['/joke', '!joke'], jokeTask.getRandomAnimation) + bot.hears(['/joke', '!joke', '!jo'], jokeTask.getRandomAnimation) + + // TODO: add moar } diff --git a/src/route/language.js b/src/route/language.js index 785b793..1d72834 100644 --- a/src/route/language.js +++ b/src/route/language.js @@ -10,7 +10,7 @@ module.exports = bot => { answerCbQuery, editMessageText }) => { - if (String(state.value)) { + if (state.value) { await answerCbQuery(state.value).then(() => { session.root.settings.lang = state.value i18n.locale(state.value) diff --git a/src/route/start.js b/src/route/start.js index 307452a..ffa54a2 100644 --- a/src/route/start.js +++ b/src/route/start.js @@ -5,8 +5,8 @@ module.exports = bot => { const routeList = ctx => { switch (String(ctx.state.value)) { - case 'test': - return startTask.subscribe(ctx) + case 'donate': + return startTask.donateMe(ctx) } } diff --git a/src/util/service.js b/src/util/service.js new file mode 100644 index 0000000..831e9fe --- /dev/null +++ b/src/util/service.js @@ -0,0 +1,35 @@ +const fetch = require('node-fetch') + +const getInfoOperator = async (num = '79521305638') => { + // eslint-disable-next-line no-async-promise-executor + return new Promise(async resolve => { + const url = 'https://cleaner.dadata.ru/api/v1/clean/phone' + await fetch(url, { + method: 'POST', + mode: 'cors', + headers: { + Authorization: 'Token ' + process.env.DADATA_TOKEN, + 'X-Secret': process.env.DADATA_SECRET, + 'Content-Type': 'application/json' + }, + compress: true, + body: JSON.stringify([num]) + }) + .then(res => { + if (res.statusCode === 401) + throw new Error('dadata.ru:: key or secret invalid') + + if (res.statusCode === 403) + throw new Error('dadata.ru:: invalid secret key') + return res.json() + }) + .then(data => resolve(...data)) + .catch(err => console.error('end dadata.ru::', err.message)) + }) +} + +const SERVICE = { + getInfoOperator: getInfoOperator +} + +module.exports = { SERVICE }