mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-08-30 13:47:54 +00:00
Misc
This commit is contained in:
@@ -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",
|
||||||
|
@@ -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>');
|
||||||
}
|
}
|
||||||
|
@@ -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 });
|
||||||
|
@@ -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"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user