NoWizarrd / TelegramGPT

0 stars 0 forks source link

NoWizarrd - защита по ID пользователя #1

Open Selmarion opened 1 year ago

Selmarion commented 1 year ago

Привет. Проет хороший. Рабочий. Есть нюанс, что при глобальном поиске твой БОТ найдут и будут пользовать любой на планете Земля, тек как у тебя нет защиты в нём на запрет пользования. Достаточно найти в поиске твоего бота и всё...

Реализуй защиту по ID пользователя в телеграм , например введи в код

const userIds = JSON.parse(fs.readFileSync('./config/userid.json'));

где в файле /config/userid.json ты будешь хранить ID

console.log(config.get('TEST_ENV'))

const bot = new Telegraf(config.get('TELEGRAM_TOKEN'),{handlerTimeout: 1800_000})

bot.use(session())

bot.command('new', initCommand)

bot.command('start', initCommand)

const userIds = JSON.parse(fs.readFileSync('./config/userid.json'));

bot.on(message('voice'), async (ctx) => { ctx.session ??= INITIAL_SESSION try { const userId = ctx.message.from.id if (userIds.includes(userId)) { await ctx.reply(code('"Ok, Please wait..."')) const link = await ctx.telegram.getFileLink(ctx.message.voice.file_id) const userId = String(ctx.message.from.id) const oggPath = await ogg.create(link.href, userId) const mp3Path = await ogg.toMp3(oggPath, userId)

removeFile(oggPath)

const text = await openai.transcription(mp3Path)
  const response = await openai.chat(text)
  await ctx.reply(code(`Ваш запрос: ${text}`))

  await processTextToChat(ctx, text)
} else {
  await ctx.reply(code('Напиши КОНТАКТ мне для доступа'))
}

} catch (e) { console.log(Error while voice message, e.message) } })

bot.on(message('text'), async (ctx) => { ctx.session ??= INITIAL_SESSION try { const userId = ctx.message.from.id if (userIds.includes(userId)) { await ctx.reply(code('"Ok, Please wait..."')) await processTextToChat(ctx, ctx.message.text) } else { await ctx.reply(code('Напиши КОНТАКТ мне для доступа')) } } catch (e) { console.log(Error while voice message, e.message) } })

bot.launch()

NoWizarrd commented 1 year ago

Спасибо, когда вернусь к этому проекту я доработаю этот момент