@@ -15,7 +15,8 @@ namespace Modix.Services.Moderation
1515{ 
1616    public  class  MessageContentCheckBehaviour  : 
1717        INotificationHandler < MessageReceivedNotification > , 
18-         INotificationHandler < MessageUpdatedNotification > 
18+         INotificationHandler < MessageUpdatedNotification > , 
19+         INotificationHandler < VoiceChannelStatusUpdatedNotification > 
1920    { 
2021        private  readonly  IDesignatedChannelService  _designatedChannelService ; 
2122        private  readonly  IAuthorizationService  _authorizationService ; 
@@ -43,6 +44,29 @@ public Task HandleNotificationAsync(MessageReceivedNotification notification,
4344        public  Task  HandleNotificationAsync ( MessageUpdatedNotification  notification , 
4445            CancellationToken  cancellationToken  =  default ) 
4546            =>  TryCheckMessageAsync ( notification . NewMessage ) ; 
47+         public  async  Task  HandleNotificationAsync ( VoiceChannelStatusUpdatedNotification  notification , 
48+             CancellationToken  cancellationToken  =  default ) 
49+         { 
50+             var  channel  =  await  notification . Channel . GetOrDownloadAsync ( ) ; 
51+             var  newStatus  =  notification . NewStatus ; 
52+             var  isBlocked  =  await  IsContentBlocked ( channel ,  newStatus ) ; 
53+ 
54+             if  ( ! isBlocked ) 
55+             { 
56+                 return ; 
57+             } 
58+ 
59+             Log . Debug ( "Status {newStatus} from voice channel {channelId} is going to be deleted" ,  newStatus ,  channel . Id ) ; 
60+ 
61+             //Setting to old status seems risky as there is a race condition 
62+             //between two consecutive edits being moderated in parallel. 
63+             //May client events being fired in parallel? 
64+             await  channel . SetStatusAsync ( string . Empty ) ; 
65+ 
66+             Log . Debug ( "Status {newStatus} from voice channel {channelId} was deleted because it contains blocked content" ,  newStatus ,  channel . Id ) ; 
67+ 
68+             await  channel . SendMessageAsync ( "Sorry, the new status contained blocked content and has been removed!" ) ; 
69+         } 
4670
4771        private  async  Task  TryCheckMessageAsync ( IMessage  message ) 
4872        { 
@@ -91,16 +115,20 @@ await message.Channel.SendMessageAsync(
91115                $ "Sorry { author . Mention }  your message contained blocked content and has been removed!") ; 
92116        } 
93117
94-         private  async  Task < bool >  IsContentBlocked ( IGuildChannel  channel ,  IMessage  message ) 
118+         private  Task < bool >  IsContentBlocked ( SocketVoiceChannel  channel ,  string  status )  => 
119+             IsContentBlocked ( channel . Guild . Id ,  status ) ; 
120+         private  Task < bool >  IsContentBlocked ( IGuildChannel  channel ,  IMessage  message )  => 
121+             IsContentBlocked ( channel . GuildId ,  message . Content ) ; 
122+         private  async  Task < bool >  IsContentBlocked ( ulong  guildId ,  string  messageContent ) 
95123        { 
96-             var  patterns  =  await  _messageContentPatternService . GetPatterns ( channel . GuildId ) ; 
124+             var  patterns  =  await  _messageContentPatternService . GetPatterns ( guildId ) ; 
97125
98126            foreach  ( var  patternToCheck  in  patterns . Where ( x =>  x . Type  ==  MessageContentPatternType . Blocked ) ) 
99127            { 
100128                // If the content is not blocked, we can just continue to check the next 
101129                // blocked pattern 
102130
103-                 var  ( containsBlockedPattern ,  blockedMatches )  =  GetContentMatches ( message . Content ,  patternToCheck ) ; 
131+                 var  ( containsBlockedPattern ,  blockedMatches )  =  GetContentMatches ( messageContent ,  patternToCheck ) ; 
104132
105133                if  ( ! containsBlockedPattern ) 
106134                { 
0 commit comments