@@ -2,6 +2,7 @@ import { Message } from "../types/message";
22import {
33 addBlockUser ,
44 deductUserPoints ,
5+ getBlockUser ,
56 isAdmin ,
67} from "../components/services/user" ;
78import client from "../components/client" ;
@@ -21,17 +22,26 @@ export default async function (msg: Message): Promise<void> {
2122 return ;
2223 }
2324
25+ const jid = msg . mentionedIds [ 0 ] ;
26+ const lid = jid . split ( "@" ) [ 0 ] ;
27+
2428 const botId = ( await client ( ) ) . info . wid . _serialized ;
29+ const isUserAdmin = await isAdmin ( lid ) ;
30+
31+ if ( ! msg . fromMe && ( isUserAdmin || lid === botId . split ( "@" ) [ 0 ] ) ) {
32+ await msg . reply ( `Unable block an ${ isUserAdmin ? "Admin" : "Super Admin" } ` ) ;
33+ return ;
34+ }
2535
26- for ( const userId of msg . mentionedIds ) {
27- const lid = userId . split ( "@" ) [ 0 ] ;
28- const isUserAdmin = await isAdmin ( lid ) ;
29- if ( isUserAdmin || lid === botId . split ( "@" ) [ 0 ] ) {
30- await msg . reply (
31- `Unable to block ${ isUserAdmin ? "Admin" : "Super Admin" } .` ,
32- ) ;
33- continue ;
34- }
35- await Promise . allSettled ( [ addBlockUser ( lid ) , deductUserPoints ( lid , 30 ) ] ) ;
36+ const isBlocked = await getBlockUser ( lid ) ;
37+ if ( isBlocked ) {
38+ await msg . reply ( "The user is already blocked." ) ;
39+ return ;
3640 }
41+
42+ await Promise . allSettled ( [
43+ addBlockUser ( lid ) ,
44+ deductUserPoints ( lid , 30 ) ,
45+ msg . reply ( "The user has been blocked." ) ,
46+ ] ) ;
3747}
0 commit comments