@@ -31,7 +31,7 @@ public async Task Help(CommandContext ctx, [Description("Command to provide help
31
31
32
32
Command ? cmd = null ;
33
33
IEnumerable < Command > ? searchIn = cmds ;
34
- foreach ( string c in commandSplit )
34
+ for ( int i = 0 ; i < commandSplit . Length ; i ++ )
35
35
{
36
36
if ( searchIn is null )
37
37
{
@@ -41,35 +41,41 @@ public async Task Help(CommandContext ctx, [Description("Command to provide help
41
41
42
42
StringComparison comparison = StringComparison . InvariantCultureIgnoreCase ;
43
43
StringComparer comparer = StringComparer . InvariantCultureIgnoreCase ;
44
- cmd = searchIn . FirstOrDefault ( xc => xc . Name . Equals ( c , comparison ) || ( ( xc . Attributes . FirstOrDefault ( x => x is TextAliasAttribute ) as TextAliasAttribute ) ? . Aliases . Contains ( c . Replace ( "textcmd" , "" ) , comparer ) ?? false ) ) ;
44
+ cmd = searchIn . FirstOrDefault ( xc => xc . Name . Equals ( commandSplit [ i ] , comparison ) || ( ( xc . Attributes . FirstOrDefault ( x => x is TextAliasAttribute ) as TextAliasAttribute ) ? . Aliases . Contains ( commandSplit [ i ] . Replace ( "textcmd" , "" ) , comparer ) ?? false ) ) ;
45
45
46
46
if ( cmd is null )
47
47
{
48
48
break ;
49
49
}
50
50
51
- IEnumerable < ContextCheckAttribute > failedChecks = ( await CheckPermissionsAsync ( ctx , cmd ) ) . ToList ( ) ;
52
- if ( failedChecks . Any ( ) )
51
+ // Only run checks on the last command in the chain.
52
+ // So if we are looking at a command group here, only run checks against the actual command,
53
+ // not the group(s) it's under.
54
+ if ( i == commandSplit . Length - 1 )
53
55
{
54
- if ( failedChecks . All ( x => x is RequireHomeserverPermAttribute ) )
56
+ IEnumerable < ContextCheckAttribute > failedChecks = ( await CheckPermissionsAsync ( ctx , cmd ) ) . ToList ( ) ;
57
+ if ( failedChecks . Any ( ) )
55
58
{
56
- var att = failedChecks . FirstOrDefault ( x => x is RequireHomeserverPermAttribute ) as RequireHomeserverPermAttribute ;
57
- if ( att is not null )
59
+ if ( failedChecks . All ( x => x is RequireHomeserverPermAttribute ) )
58
60
{
59
- var level = ( await GetPermLevelAsync ( ctx . Member ) ) ;
60
- var levelText = level . ToString ( ) ;
61
- if ( level == ServerPermLevel . Nothing && Program . rand . Next ( 1 , 100 ) == 69 )
62
- levelText = $ "naught but a thing, my dear human. Congratulations, you win { Program . rand . Next ( 1 , 10 ) } bonus points.";
61
+ var att = failedChecks . FirstOrDefault ( x => x is RequireHomeserverPermAttribute ) as RequireHomeserverPermAttribute ;
62
+ if ( att is not null )
63
+ {
64
+ var level = ( await GetPermLevelAsync ( ctx . Member ) ) ;
65
+ var levelText = level . ToString ( ) ;
66
+ if ( level == ServerPermLevel . Nothing && Program . rand . Next ( 1 , 100 ) == 69 )
67
+ levelText = $ "naught but a thing, my dear human. Congratulations, you win { Program . rand . Next ( 1 , 10 ) } bonus points.";
63
68
64
- await ctx . RespondAsync (
65
- $ "{ Program . cfgjson . Emoji . NoPermissions } Invalid permissions to use command **{ cmd . Name . Replace ( "textcmd" , "" ) } **!\n " +
66
- $ "Required: `{ att . TargetLvl } `\n You have: `{ levelText } `") ;
69
+ await ctx . RespondAsync (
70
+ $ "{ Program . cfgjson . Emoji . NoPermissions } Invalid permissions to use command **{ command . Replace ( "textcmd" , "" ) } **!\n " +
71
+ $ "Required: `{ att . TargetLvl } `\n You have: `{ levelText } `") ;
67
72
68
- return ;
73
+ return ;
74
+ }
69
75
}
70
- }
71
76
72
- return ;
77
+ return ;
78
+ }
73
79
}
74
80
75
81
searchIn = cmd . Subcommands . Any ( ) ? cmd . Subcommands : null ;
@@ -322,22 +328,23 @@ private async Task<IEnumerable<ContextCheckAttribute>> CheckPermissionsAsync(Com
322
328
323
329
if ( check is RequireHomeserverPermAttribute requireHomeserverPermAttribute )
324
330
{
331
+ // Fail if guild member is null but this cmd does not work outside of the home server
325
332
if ( ctx . Member is null && ! requireHomeserverPermAttribute . WorkOutside )
326
333
{
327
334
failedChecks . Add ( requireHomeserverPermAttribute ) ;
328
335
}
329
336
else
330
337
{
331
- if ( ! requireHomeserverPermAttribute . WorkOutside )
338
+ var level = await GetPermLevelAsync ( ctx . Member ) ;
339
+ if ( level < requireHomeserverPermAttribute . TargetLvl )
332
340
{
333
- var level = await GetPermLevelAsync ( ctx . Member ) ;
334
- if ( level < requireHomeserverPermAttribute . TargetLvl )
341
+ if ( requireHomeserverPermAttribute . OwnerOverride && ! Program . cfgjson . BotOwners . Contains ( ctx . User . Id )
342
+ || ! requireHomeserverPermAttribute . OwnerOverride )
335
343
{
336
344
failedChecks . Add ( requireHomeserverPermAttribute ) ;
337
345
}
338
346
}
339
347
}
340
-
341
348
}
342
349
343
350
if ( check is RequirePermissionsAttribute requirePermissionsAttribute )
0 commit comments