@@ -51,50 +51,50 @@ const removeLinks = async ({ message, chat, reply, state }, next) => {
5151 ? text . match ( regexp )
5252 : [ ] ;
5353
54- await Promise . all ( usernames . map ( username => new Promise ( async ( resolve ) => {
55- // skip if already detected an ad
56- if ( isChannelAd || isGroupAd ) return resolve ( ) ;
54+ await Promise . all ( usernames
55+ ? usernames . map ( async username => {
56+ // skip if already detected an ad
57+ if ( isChannelAd || isGroupAd ) return ;
5758
58- // detect add if it's an invite link
59- if (
60- username . includes ( '/joinchat/' ) &&
61- ! knownGroups . some ( group => group . includes ( username ) )
62- ) {
63- isGroupAd = true ;
64- return resolve ( ) ;
65- }
66-
67- // detect if usernames are channels or public groups
68- // and if they are ads
69- username = username . replace ( / .* ( ( t .m e ) | ( t e l e g r a m .m e ) ) \/ / gi, '@' ) ;
70- try {
71- const { type } = await bot . telegram . getChat ( username ) ;
72- if ( ! type ) return resolve ( ) ;
73- if (
74- type === 'channel' &&
75- shouldRemoveChannels &&
76- ! excludedChannels
77- . some ( channel =>
78- channel . includes ( username . replace ( '@' , '' ) ) )
79- ) {
80- isChannelAd = true ;
81- return resolve ( ) ;
82- }
59+ // detect add if it's an invite link
8360 if (
84- type === 'supergroup' &&
85- shouldRemoveGroups &&
86- ! knownGroups
87- . some ( group =>
88- group . includes ( username . replace ( '@' , '' ) ) )
61+ username . includes ( '/joinchat/' ) &&
62+ ! knownGroups . some ( group => group . includes ( username ) )
8963 ) {
9064 isGroupAd = true ;
91- return resolve ( ) ;
65+ return ;
9266 }
93- } catch ( err ) {
94- return resolve ( ) ;
95- }
96- return resolve ( ) ;
97- } ) ) ) ;
67+
68+ // detect if usernames are channels or public groups
69+ // and if they are ads
70+ username = username . replace ( / .* ( ( t .m e ) | ( t e l e g r a m .m e ) ) \/ / gi, '@' ) ;
71+ try {
72+ const { type } = await bot . telegram . getChat ( username ) ;
73+ if ( ! type ) return ;
74+ if (
75+ type === 'channel' &&
76+ shouldRemoveChannels &&
77+ ! excludedChannels
78+ . some ( channel =>
79+ channel . includes ( username . replace ( '@' , '' ) ) )
80+ ) {
81+ isChannelAd = true ;
82+ return ;
83+ }
84+ if (
85+ type === 'supergroup' &&
86+ shouldRemoveGroups &&
87+ ! knownGroups
88+ . some ( group =>
89+ group . includes ( username . replace ( '@' , '' ) ) )
90+ ) {
91+ isGroupAd = true ;
92+ }
93+ } catch ( err ) {
94+ console . assert ( err ) ;
95+ }
96+ } )
97+ : '' ) ;
9898
9999 if (
100100 // check if is forwarded from channel
0 commit comments