2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-09-05 00:25:19 +00:00
Files
the-guard-bot/handlers/leaveUnmanaged.js
2017-09-22 19:47:38 +02:00

42 lines
1.1 KiB
JavaScript

'use strict';
const { managesGroup } = require('../stores/groups');
const pkg = require('../package.json');
const caption = `\
Sorry, you need to set up your own instance \
to use me in your group or network of groups.
For managing single group, it'll be simpler for you \
to use @GroupButler_bot or @mattatabot instead.
`;
const inline_keyboard = [ [ {
text: 'Set up your own instance',
url: pkg.homepage,
} ] ];
const reply_markup = JSON.stringify({ inline_keyboard });
const gifs = [
'http://i.memeful.com/media/post/4wbkyXM_700wa_0.gif',
'https://media.giphy.com/media/vaAiMdHHBTqla/giphy.gif',
'https://media.giphy.com/media/StaMzjNkq5PqM/giphy.gif',
'https://media.giphy.com/media/fjYDN5flDJ756/giphy.gif',
];
const randomChoice = arr => arr[Math.floor(Math.random() * arr.length)];
const leaveUnmanagedHandler = async (ctx, next) => {
if (ctx.chat.type === 'private' || await managesGroup(ctx.chat)) {
return next();
}
await ctx.replyWithVideo(randomChoice(gifs), { caption, reply_markup });
return ctx.telegram.leaveChat(ctx.chat.id);
};
module.exports = leaveUnmanagedHandler;