@@ -7,8 +7,10 @@ public class RulesInteractions : ApplicationCommandModule
77 internal class RulesSlashCommands
88 {
99 [ SlashCommand ( "all" , "Shows all of the community rules." , defaultPermission : true ) ]
10- public async Task RulesAllCommand ( InteractionContext ctx )
10+ public async Task RulesAllCommand ( InteractionContext ctx , [ Option ( "public" , "Whether to show the response publicly." ) ] bool ? isPublic = null )
1111 {
12+ var publicResponse = await DeterminePublicResponse ( ctx . Member , ctx . Channel , isPublic ) ;
13+
1214 List < string > rules = default ;
1315
1416 try
@@ -19,7 +21,7 @@ public async Task RulesAllCommand(InteractionContext ctx)
1921 catch
2022 {
2123 // community must be disabled
22- await ctx . RespondAsync ( $ "{ Program . cfgjson . Emoji . Error } I don't see any rules set in Discord for this server!") ;
24+ await ctx . RespondAsync ( $ "{ Program . cfgjson . Emoji . Error } I don't see any rules set in Discord for this server!", ephemeral : ! publicResponse ) ;
2325 return ;
2426 }
2527
@@ -30,13 +32,15 @@ public async Task RulesAllCommand(InteractionContext ctx)
3032 embed . AddField ( $ "Rule { rules . IndexOf ( rule ) + 1 } ", rule ) ;
3133 }
3234
33- await ctx . RespondAsync ( embed : embed ) ;
35+ await ctx . RespondAsync ( embed : embed , ephemeral : ! publicResponse ) ;
3436
3537 }
3638
3739 [ SlashCommand ( "rule" , "Shows a specific rule." , defaultPermission : true ) ]
38- public async Task RuleCommand ( InteractionContext ctx , [ Option ( "rule_number" , "The rule number to show." ) ] long ruleNumber )
40+ public async Task RuleCommand ( InteractionContext ctx , [ Option ( "rule_number" , "The rule number to show." ) ] long ruleNumber , [ Option ( "public" , "Whether to show the response publicly." ) ] bool ? isPublic = null )
3941 {
42+ var publicResponse = await DeterminePublicResponse ( ctx . Member , ctx . Channel , isPublic ) ;
43+
4044 IReadOnlyList < string > rules = default ;
4145
4246 try
@@ -47,24 +51,26 @@ public async Task RuleCommand(InteractionContext ctx, [Option("rule_number", "Th
4751 catch
4852 {
4953 // community must be disabled
50- await ctx . RespondAsync ( $ "{ Program . cfgjson . Emoji . Error } I don't see any rules set in Discord for this server!") ;
54+ await ctx . RespondAsync ( $ "{ Program . cfgjson . Emoji . Error } I don't see any rules set in Discord for this server!", ephemeral : ! publicResponse ) ;
5155 return ;
5256 }
5357
5458 if ( ruleNumber < 1 || ruleNumber > rules . Count )
5559 {
56- await ctx . RespondAsync ( $ "{ Program . cfgjson . Emoji . Error } Rule number must be between 1 and { rules . Count } .") ;
60+ await ctx . RespondAsync ( $ "{ Program . cfgjson . Emoji . Error } Rule number must be between 1 and { rules . Count } .", ephemeral : ! publicResponse ) ;
5761 return ;
5862 }
5963
6064 var embed = new DiscordEmbedBuilder ( ) . WithTitle ( $ "Rule { ruleNumber } ") . WithDescription ( rules [ ( int ) ruleNumber - 1 ] ) . WithColor ( new DiscordColor ( 0xe4717b ) ) ;
6165
62- await ctx . RespondAsync ( embed : embed ) ;
66+ await ctx . RespondAsync ( embed : embed , ephemeral : ! publicResponse ) ;
6367 }
6468
6569 [ SlashCommand ( "search" , "Search for a rule by keyword." , defaultPermission : true ) ]
66- public async Task RuleSearchCommand ( InteractionContext ctx , [ Option ( "keyword" , "The keyword to search for." ) ] string keyword )
70+ public async Task RuleSearchCommand ( InteractionContext ctx , [ Option ( "keyword" , "The keyword to search for." ) ] string keyword , [ Option ( "public" , "Whether to show the response publicly." ) ] bool ? isPublic = null )
6771 {
72+ var publicResponse = await DeterminePublicResponse ( ctx . Member , ctx . Channel , isPublic ) ;
73+
6874 List < string > rules = default ;
6975
7076 try
@@ -75,7 +81,7 @@ public async Task RuleSearchCommand(InteractionContext ctx, [Option("keyword", "
7581 catch
7682 {
7783 // community must be disabled
78- await ctx . RespondAsync ( $ "{ Program . cfgjson . Emoji . Error } I don't see any rules set in Discord for this server!") ;
84+ await ctx . RespondAsync ( $ "{ Program . cfgjson . Emoji . Error } I don't see any rules set in Discord for this server!", ephemeral : ! publicResponse ) ;
7985 return ;
8086 }
8187
@@ -94,7 +100,29 @@ public async Task RuleSearchCommand(InteractionContext ctx, [Option("keyword", "
94100 embed . AddField ( $ "Rule { rules . IndexOf ( rule ) + 1 } ", rule ) ;
95101 }
96102
97- await ctx . RespondAsync ( embed : embed ) ;
103+ await ctx . RespondAsync ( embed : embed , ephemeral : ! publicResponse ) ;
104+ }
105+
106+ // Returns: true for public response, false for private
107+ private async Task < bool > DeterminePublicResponse ( DiscordMember member , DiscordChannel channel , bool ? isPublic )
108+ {
109+ if ( Program . cfgjson . RulesAllowedPublicChannels . Contains ( channel . Id ) || Program . cfgjson . RulesAllowedPublicChannels . Contains ( channel . Parent . Id ) )
110+ {
111+ if ( isPublic is null )
112+ return true ;
113+
114+ return isPublic . Value ;
115+ }
116+
117+ if ( await GetPermLevelAsync ( member ) >= ServerPermLevel . TrialModerator )
118+ {
119+ if ( isPublic is null )
120+ return false ;
121+
122+ return isPublic . Value ;
123+ }
124+
125+ return false ;
98126 }
99127 }
100128 }
0 commit comments