@@ -7,8 +7,10 @@ public class RulesInteractions : ApplicationCommandModule
7
7
internal class RulesSlashCommands
8
8
{
9
9
[ 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 )
11
11
{
12
+ var publicResponse = await DeterminePublicResponse ( ctx . Member , ctx . Channel , isPublic ) ;
13
+
12
14
List < string > rules = default ;
13
15
14
16
try
@@ -19,7 +21,7 @@ public async Task RulesAllCommand(InteractionContext ctx)
19
21
catch
20
22
{
21
23
// 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 ) ;
23
25
return ;
24
26
}
25
27
@@ -30,13 +32,15 @@ public async Task RulesAllCommand(InteractionContext ctx)
30
32
embed . AddField ( $ "Rule { rules . IndexOf ( rule ) + 1 } ", rule ) ;
31
33
}
32
34
33
- await ctx . RespondAsync ( embed : embed ) ;
35
+ await ctx . RespondAsync ( embed : embed , ephemeral : ! publicResponse ) ;
34
36
35
37
}
36
38
37
39
[ 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 )
39
41
{
42
+ var publicResponse = await DeterminePublicResponse ( ctx . Member , ctx . Channel , isPublic ) ;
43
+
40
44
IReadOnlyList < string > rules = default ;
41
45
42
46
try
@@ -47,24 +51,26 @@ public async Task RuleCommand(InteractionContext ctx, [Option("rule_number", "Th
47
51
catch
48
52
{
49
53
// 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 ) ;
51
55
return ;
52
56
}
53
57
54
58
if ( ruleNumber < 1 || ruleNumber > rules . Count )
55
59
{
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 ) ;
57
61
return ;
58
62
}
59
63
60
64
var embed = new DiscordEmbedBuilder ( ) . WithTitle ( $ "Rule { ruleNumber } ") . WithDescription ( rules [ ( int ) ruleNumber - 1 ] ) . WithColor ( new DiscordColor ( 0xe4717b ) ) ;
61
65
62
- await ctx . RespondAsync ( embed : embed ) ;
66
+ await ctx . RespondAsync ( embed : embed , ephemeral : ! publicResponse ) ;
63
67
}
64
68
65
69
[ 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 )
67
71
{
72
+ var publicResponse = await DeterminePublicResponse ( ctx . Member , ctx . Channel , isPublic ) ;
73
+
68
74
List < string > rules = default ;
69
75
70
76
try
@@ -75,7 +81,7 @@ public async Task RuleSearchCommand(InteractionContext ctx, [Option("keyword", "
75
81
catch
76
82
{
77
83
// 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 ) ;
79
85
return ;
80
86
}
81
87
@@ -94,7 +100,29 @@ public async Task RuleSearchCommand(InteractionContext ctx, [Option("keyword", "
94
100
embed . AddField ( $ "Rule { rules . IndexOf ( rule ) + 1 } ", rule ) ;
95
101
}
96
102
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 ;
98
126
}
99
127
}
100
128
}
0 commit comments