@@ -144,10 +144,8 @@ public async Task RemovePerm(string command, string[] roles, IMessageChannel cha
144
144
else
145
145
{
146
146
//Check all roles and make sure they are assigned to the command
147
- foreach ( IRole role in iRoles )
147
+ foreach ( IRole role in iRoles . Where ( role => server . GetCommandInfo ( command ) . GetRole ( role . Id ) == 0 ) )
148
148
{
149
- if ( server . GetCommandInfo ( command ) . GetRole ( role . Id ) != 0 ) continue ;
150
-
151
149
await channel . SendMessageAsync (
152
150
$ "The command `{ command } ` doesn't have the role **{ role } ** assigned to it!") ;
153
151
return ;
@@ -160,16 +158,22 @@ await channel.SendMessageAsync(
160
158
}
161
159
162
160
//There are no more roles assigned to the command so remove it entirely
163
- if ( server . GetCommandInfo ( command ) . Roles . Count == 0 )
164
- {
165
- server . CommandInfos . Remove ( server . GetCommandInfo ( command ) ) ;
166
- }
161
+ CheckAllServerRoles ( server ) ;
167
162
168
163
ServerListsManager . SaveServerList ( ) ;
169
164
await channel . SendMessageAsync ( RemovePermMessage ( roles , command , server ) ) ;
170
165
}
171
166
}
172
167
168
+ public static void CheckAllServerRoles ( ServerList server )
169
+ {
170
+ List < ServerList . CommandInfo > cmdsToRemove = server . CommandInfos . Where ( command => command . Roles . Count == 0 ) . ToList ( ) ;
171
+ foreach ( ServerList . CommandInfo command in cmdsToRemove )
172
+ {
173
+ server . CommandInfos . Remove ( command ) ;
174
+ }
175
+ }
176
+
173
177
private bool CanModifyPerm ( string command )
174
178
{
175
179
bool canModifyPerm = true ;
@@ -231,16 +235,14 @@ private static string RemovePermMessage(IReadOnlyList<string> roles, string comm
231
235
{
232
236
return $ "**{ roles [ 0 ] } ** role will not be allowed to use the command `{ command } `.";
233
237
}
234
- else //Multiple roles
235
- {
236
- StringBuilder sb = new StringBuilder ( ) ;
237
- for ( int i = 0 ; i < roles . Count ; i ++ )
238
- {
239
- sb . Append ( i == roles . Count - 1 ? roles [ i ] : $ "{ roles [ i ] } , ") ;
240
- }
241
238
242
- return $ "**{ sb } ** roles will not be allowed to use the command `{ command } `.";
239
+ StringBuilder sb = new StringBuilder ( ) ;
240
+ for ( int i = 0 ; i < roles . Count ; i ++ )
241
+ {
242
+ sb . Append ( i == roles . Count - 1 ? roles [ i ] : $ "{ roles [ i ] } , ") ;
243
243
}
244
+
245
+ return $ "**{ sb } ** roles will not be allowed to use the command `{ command } `.";
244
246
}
245
247
}
246
248
}
0 commit comments