Skip to content

Commit f6dfa08

Browse files
committed
send a message when /ban and /warn is used in private chat
1 parent 8029e27 commit f6dfa08

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

handlers/commands/ban.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,29 @@ const { listGroups } = require('../../stores/group');
1313
const { isAdmin, isBanned, ban } = require('../../stores/user');
1414

1515
const banHandler = async ({ chat, message, reply, telegram, me, state }) => {
16-
if (!state.isAdmin) return null;
17-
1816
const userToBan = message.reply_to_message
1917
? message.reply_to_message.from
2018
: message.commandMention
2119
? message.commandMention
2220
: null;
2321
const reason = message.text.split(' ').slice(1).join(' ').trim();
2422

23+
if (!state.isAdmin || userToBan.username === me) return null;
24+
25+
if (message.chat.type === 'private') {
26+
return reply(
27+
'ℹ️ <b>This command is only available in groups.</b>',
28+
replyOptions
29+
);
30+
}
31+
2532
if (!userToBan) {
2633
return reply(
2734
'ℹ️ <b>Reply to a message or mention a user.</b>',
2835
replyOptions
2936
).then(scheduleDeletion);
3037
}
3138

32-
if (message.chat.type === 'private' || userToBan.username === me) {
33-
return null;
34-
}
35-
3639
if (await isAdmin(userToBan)) {
3740
return reply('ℹ️ <b>Can\'t ban other admins.</b>', replyOptions);
3841
}

handlers/commands/warn.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,29 @@ const { isAdmin, ban, getWarns, warn } = require('../../stores/user');
2020

2121
const warnHandler = async ({ message, chat, reply, me, state }) => {
2222
const { user } = state;
23-
if (!state.isAdmin) return null;
24-
2523
const userToWarn = message.reply_to_message
2624
? message.reply_to_message.from
2725
: message.commandMention
2826
? message.commandMention
2927
: null;
3028

29+
if (!state.isAdmin || userToWarn.username === me) return null;
30+
31+
if (message.chat.type === 'private') {
32+
return reply(
33+
'ℹ️ <b>This command is only available in groups.</b>',
34+
replyOptions
35+
);
36+
}
37+
38+
3139
if (!userToWarn) {
3240
return reply(
3341
'ℹ️ <b>Reply to a message or mentoin a user.</b>',
3442
replyOptions
3543
).then(scheduleDeletion);
3644
}
3745

38-
if (message.chat.type === 'private' || userToWarn.username === me) {
39-
return null;
40-
}
41-
4246
const reason = message.text.split(' ').slice(1).join(' ').trim();
4347

4448
if (await isAdmin(userToWarn)) {

0 commit comments

Comments
 (0)