@@ -3,33 +3,53 @@ import { Message } from "../../types/message";
33import log from "../components/utils/log" ;
44import sleep from "../components/utils/sleep" ;
55import { helloMessage } from "../components/utils/data" ;
6+ import client from "../components/client" ;
67
78export const info = {
89 command : "everyone" ,
9- description : "Mentions everyone in the group." ,
10- usage : "everyone" ,
11- example : "everyone" ,
10+ description : "Mentions everyone or only admins in the group." ,
11+ usage : "everyone [--admin] " ,
12+ example : "everyone --admin " ,
1213 role : "admin" ,
1314 cooldown : 5000 ,
1415} ;
1516
1617export default async function ( msg : Message ) {
17- if ( ! / ^ e v e r y o n e $ / i. test ( msg . body ) ) return ;
18+ const match = / ^ e v e r y o n e (?: \s + - - a d m i n ) ? $ / i. exec ( msg . body . trim ( ) ) ;
19+ if ( ! match ) return ;
1820
19- const chat = await msg . getChat ( ) ;
21+ const onlyAdmins = msg . body . includes ( "--admin" ) ;
2022
23+ const chat = await msg . getChat ( ) ;
2124 if ( ! chat . isGroup ) {
2225 await msg . reply ( "This only works in group chats." ) ;
2326 return ;
2427 }
2528
2629 const groupChat = chat as GroupChat ;
2730 const participants = groupChat . participants ;
28- const mentions = participants . map ( ( p ) => p . id . _serialized ) ;
29- const total = mentions . length ;
3031
32+ const self = ( await client ( ) ) . info . wid . _serialized
33+ const filteredParticipants = participants . filter ( ( p ) => {
34+ if ( p . id . _serialized === self ) return false ;
35+ if ( onlyAdmins && ! p . isAdmin && ! p . isSuperAdmin ) return false ;
36+ return true ;
37+ } ) ;
38+
39+ if ( filteredParticipants . length === 0 ) {
40+ await msg . reply (
41+ onlyAdmins
42+ ? "No other admins found to mention (except me, myself and i)."
43+ : "No other participants found to mention (except me, myself and i)." ,
44+ ) ;
45+ return ;
46+ }
47+
48+ const mentions = filteredParticipants . map ( ( p ) => p . id . _serialized ) ;
49+ const total = mentions . length ;
3150 const baseText =
3251 helloMessage [ Math . floor ( Math . random ( ) * helloMessage . length ) ] ;
52+ // i made it per batch to prevent rate limiting and possibly issues
3353 const batchSize = 30 ;
3454
3555 for ( let i = 0 ; i < total ; i += batchSize ) {
@@ -41,10 +61,10 @@ export default async function (msg: Message) {
4161 const messageText = i === 0 ? `${ baseText } \n\n${ mentionText } ` : mentionText ;
4262
4363 await msg . reply ( messageText , undefined , { mentions : batchMentions } ) ;
64+
4465 const min = 2000 ;
4566 const max = 6000 ;
4667 const randomMs = Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ;
47-
4868 await sleep ( randomMs ) ;
4969 }
5070}
0 commit comments