From c27d1097c33d4485948f0103211c358ded54de2a Mon Sep 17 00:00:00 2001 From: Pouria Ezzati Date: Mon, 25 Sep 2017 21:06:03 +0330 Subject: [PATCH] checks if group already has link before exporting one --- handlers/middlewares/addedToGroup.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/handlers/middlewares/addedToGroup.js b/handlers/middlewares/addedToGroup.js index d1f03f1..5db0f6f 100644 --- a/handlers/middlewares/addedToGroup.js +++ b/handlers/middlewares/addedToGroup.js @@ -4,7 +4,7 @@ const bot = require('../../bot'); const { replyOptions } = require('../../bot/options'); -const { addGroup } = require('../../stores/group'); +const { addGroup, managesGroup } = require('../../stores/group'); const { masterID } = require('../../config.json'); const addedToGroupHandler = async (ctx, next) => { @@ -13,9 +13,11 @@ const addedToGroupHandler = async (ctx, next) => { const wasAdded = msg.new_chat_members.some(user => user.username === ctx.me); if (wasAdded && ctx.from.id === masterID) { - const link = await bot.telegram.exportChatInviteLink(ctx.chat.id); - ctx.chat.link = link ? link : ''; - addGroup(ctx.chat); + if (!await managesGroup(ctx.chat)) { + const link = await bot.telegram.exportChatInviteLink(ctx.chat.id); + ctx.chat.link = link ? link : ''; + await addGroup(ctx.chat); + } ctx.reply('🛠 Ok, I\'ll help you manage this group from now.', replyOptions); }