2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-30 13:47:54 +00:00
This commit is contained in:
Wojciech Pawlik
2020-04-04 14:01:03 +02:00
parent 1074615927
commit 1fc8938ed4
4 changed files with 13 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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