From 1fc8938ed4bd16039e82b4d63e2fd6fd2bd74772 Mon Sep 17 00:00:00 2001 From: Wojciech Pawlik Date: Sat, 4 Apr 2020 14:01:03 +0200 Subject: [PATCH] Misc --- .eslintrc.json | 3 ++- handlers/commands/leave.js | 13 ++++++------- handlers/middlewares/addedToGroup.js | 7 ++++--- tsconfig.json | 1 + 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 4b988e7..d87bd03 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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", diff --git a/handlers/commands/leave.js b/handlers/commands/leave.js index 03f2703..ffe9b81 100644 --- a/handlers/commands/leave.js +++ b/handlers/commands/leave.js @@ -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( 'ℹ️ Couldn\'t find a group with that ID/name.' - // eslint-disable-next-line function-paren-newline ); } await Promise.all([ removeGroup(isGroup), - telegram.leaveChat(isGroup.id) + telegram.leaveChat(isGroup.id), ]); return replyWithHTML('✅ I no longer manage that group.'); } diff --git a/handlers/middlewares/addedToGroup.js b/handlers/middlewares/addedToGroup.js index fd3945f..7864e95 100644 --- a/handlers/middlewares/addedToGroup.js +++ b/handlers/middlewares/addedToGroup.js @@ -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( '⚠️ Failed to export chat invite link.\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 }); diff --git a/tsconfig.json b/tsconfig.json index ea8d250..1f93c71 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "noImplicitAny": false, "noEmit": true, "resolveJsonModule": true, + "strictNullChecks": false, "strict": true, "target": "ES2020" }