Skip to content

Commit 8590b58

Browse files
committed
Print a message and leave if couldn't obtain invite link
Closes #25
1 parent b46edc8 commit 8590b58

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

handlers/middlewares/addedToGroup.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
// Bot
4-
const bot = require('../../bot');
54
const { replyOptions } = require('../../bot/options');
65

76
const { admin } = require('../../stores/user');
@@ -10,14 +9,23 @@ const { masterID } = require('../../config.json');
109

1110
const addedToGroupHandler = async (ctx, next) => {
1211
const msg = ctx.message;
12+
const { telegram } = ctx;
1313

1414
const wasAdded = msg.new_chat_members.some(user =>
1515
user.username === ctx.me);
1616
if (wasAdded && ctx.from.id === masterID) {
1717
await admin(ctx.from);
1818
if (!await managesGroup(ctx.chat)) {
19-
const link = await bot.telegram.exportChatInviteLink(ctx.chat.id);
20-
ctx.chat.link = link ? link : '';
19+
try {
20+
const link = await telegram.exportChatInviteLink(ctx.chat.id);
21+
ctx.chat.link = link ? link : '';
22+
} catch (err) {
23+
await ctx.replyWithHTML(
24+
'⚠️ <b>Please re-add me with admin permissions.</b>' +
25+
'\n\n' +
26+
`<code>${err}</code>`);
27+
return telegram.leaveChat(ctx.chat.id);
28+
}
2129
await addGroup(ctx.chat);
2230
}
2331
ctx.reply('🛠 <b>Ok, I\'ll help you manage this group from now.</b>',

0 commit comments

Comments
 (0)