2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-30 05:37:59 +00:00
This commit is contained in:
Wojciech Pawlik 2020-04-04 14:01:03 +02:00
parent 1074615927
commit 1fc8938ed4
No known key found for this signature in database
GPG Key ID: 7D763FCB7B36ADB5
4 changed files with 13 additions and 11 deletions

View File

@ -146,7 +146,8 @@
"allowArrowFunctions": true
}
],
"function-paren-newline": ["error", "multiline"],
"function-paren-newline": ["error", "multiline-arguments"],
"comma-dangle": ["warn", "always-multiline"],
"key-spacing": "error",
"keyword-spacing": "error",
"lines-around-comment": "error",

View File

@ -1,30 +1,29 @@
// @ts-check
'use strict';
const { isMaster } = require('../../utils/config');
const { managesGroup, removeGroup } = require('../../stores/group');
/** @param { import('../../typings/context').ExtendedContext } ctx */
const leaveCommandHandler = async ctx => {
const { chat, message, telegram, state, replyWithHTML } = ctx;
const { isMaster } = state;
if (!isMaster) return null;
const { chat, message, telegram, replyWithHTML } = ctx;
if (!isMaster(ctx.from)) return null;
const groupName = message.text.split(' ').slice(1).join(' ');
if (groupName) {
const group = /^-?\d+/.test(groupName)
? { id: Number(groupName) }
: { title: groupName };
: { title: groupName };
const isGroup = await managesGroup(group);
if (!isGroup) {
// eslint-disable-next-line function-paren-newline
return replyWithHTML(
' <b>Couldn\'t find a group with that ID/name.</b>'
// eslint-disable-next-line function-paren-newline
);
}
await Promise.all([
removeGroup(isGroup),
telegram.leaveChat(isGroup.id)
telegram.leaveChat(isGroup.id),
]);
return replyWithHTML('✅ <b>I no longer manage that group.</b>');
}

View File

@ -1,3 +1,4 @@
// @ts-check
'use strict';
// Bot
@ -7,7 +8,7 @@ const { admin } = require('../../stores/user');
const { addGroup } = require('../../stores/group');
const { isMaster } = require('../../utils/config');
/** @param { import('telegraf').ContextMessageUpdate } ctx */
/** @param { import('telegraf').Context } ctx */
const addedToGroupHandler = async (ctx, next) => {
const msg = ctx.message;
@ -19,14 +20,14 @@ const addedToGroupHandler = async (ctx, next) => {
? `https://t.me/${ctx.chat.username.toLowerCase()}`
: await ctx.exportChatInviteLink().catch(() => '');
if (!link) {
// eslint-disable-next-line function-paren-newline
await ctx.replyWithHTML(
'⚠️ <b>Failed to export chat invite link.</b>\n' +
'Group won\'t be visible in /groups list.\n' +
'\n' +
'If this isn\'t your intention, ' +
'make sure I am permitted to export chat invite link, ' +
'and then run /showgroup.');
'and then run /showgroup.'
);
}
const { id, title, type } = ctx.chat;
await addGroup({ id, link, title, type });

View File

@ -5,6 +5,7 @@
"noImplicitAny": false,
"noEmit": true,
"resolveJsonModule": true,
"strictNullChecks": false,
"strict": true,
"target": "ES2020"
}