diff --git a/Commands/InteractionCommands/RulesInteractions.cs b/Commands/InteractionCommands/RulesInteractions.cs index edb6d93..0cf4aa2 100644 --- a/Commands/InteractionCommands/RulesInteractions.cs +++ b/Commands/InteractionCommands/RulesInteractions.cs @@ -7,8 +7,10 @@ public class RulesInteractions : ApplicationCommandModule internal class RulesSlashCommands { [SlashCommand("all", "Shows all of the community rules.", defaultPermission: true)] - public async Task RulesAllCommand(InteractionContext ctx) + public async Task RulesAllCommand(InteractionContext ctx, [Option("public", "Whether to show the response publicly.")] bool? isPublic = null) { + var publicResponse = await DeterminePublicResponse(ctx.Member, ctx.Channel, isPublic); + List rules = default; try @@ -19,7 +21,7 @@ public async Task RulesAllCommand(InteractionContext ctx) catch { // community must be disabled - await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} I don't see any rules set in Discord for this server!"); + await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} I don't see any rules set in Discord for this server!", ephemeral: !publicResponse); return; } @@ -30,13 +32,15 @@ public async Task RulesAllCommand(InteractionContext ctx) embed.AddField($"Rule {rules.IndexOf(rule) + 1}", rule); } - await ctx.RespondAsync(embed: embed); + await ctx.RespondAsync(embed: embed, ephemeral: !publicResponse); } [SlashCommand("rule", "Shows a specific rule.", defaultPermission: true)] - public async Task RuleCommand(InteractionContext ctx, [Option("rule_number", "The rule number to show.")] long ruleNumber) + 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) { + var publicResponse = await DeterminePublicResponse(ctx.Member, ctx.Channel, isPublic); + IReadOnlyList rules = default; try @@ -47,24 +51,26 @@ public async Task RuleCommand(InteractionContext ctx, [Option("rule_number", "Th catch { // community must be disabled - await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} I don't see any rules set in Discord for this server!"); + await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} I don't see any rules set in Discord for this server!", ephemeral: !publicResponse); return; } if (ruleNumber < 1 || ruleNumber > rules.Count) { - await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Rule number must be between 1 and {rules.Count}."); + await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Rule number must be between 1 and {rules.Count}.", ephemeral: !publicResponse); return; } var embed = new DiscordEmbedBuilder().WithTitle($"Rule {ruleNumber}").WithDescription(rules[(int)ruleNumber - 1]).WithColor(new DiscordColor(0xe4717b)); - await ctx.RespondAsync(embed: embed); + await ctx.RespondAsync(embed: embed, ephemeral: !publicResponse); } [SlashCommand("search", "Search for a rule by keyword.", defaultPermission: true)] - public async Task RuleSearchCommand(InteractionContext ctx, [Option("keyword", "The keyword to search for.")] string keyword) + 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) { + var publicResponse = await DeterminePublicResponse(ctx.Member, ctx.Channel, isPublic); + List rules = default; try @@ -75,7 +81,7 @@ public async Task RuleSearchCommand(InteractionContext ctx, [Option("keyword", " catch { // community must be disabled - await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} I don't see any rules set in Discord for this server!"); + await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} I don't see any rules set in Discord for this server!", ephemeral: !publicResponse); return; } @@ -94,7 +100,29 @@ public async Task RuleSearchCommand(InteractionContext ctx, [Option("keyword", " embed.AddField($"Rule {rules.IndexOf(rule) + 1}", rule); } - await ctx.RespondAsync(embed: embed); + await ctx.RespondAsync(embed: embed, ephemeral: !publicResponse); + } + + // Returns: true for public response, false for private + private async Task DeterminePublicResponse(DiscordMember member, DiscordChannel channel, bool? isPublic) + { + if (Program.cfgjson.RulesAllowedPublicChannels.Contains(channel.Id) || Program.cfgjson.RulesAllowedPublicChannels.Contains(channel.Parent.Id)) + { + if (isPublic is null) + return true; + + return isPublic.Value; + } + + if (await GetPermLevelAsync(member) >= ServerPermLevel.TrialModerator) + { + if (isPublic is null) + return false; + + return isPublic.Value; + } + + return false; } } } diff --git a/Structs.cs b/Structs.cs index 50cda8d..6b4fbda 100644 --- a/Structs.cs +++ b/Structs.cs @@ -301,6 +301,9 @@ public class ConfigJson [JsonProperty("forumChannelAutoWarnFallbackChannel")] public ulong ForumChannelAutoWarnFallbackChannel { get; private set; } = 0; + + [JsonProperty("rulesAllowedPublicChannels")] + public List RulesAllowedPublicChannels { get; private set; } = new(); } public enum Level { Information, Warning, Error, Debug, Verbose } diff --git a/config.json b/config.json index f19cb84..170e651 100644 --- a/config.json +++ b/config.json @@ -324,5 +324,13 @@ "lokiURL": "http://100.79.19.82:3100", "lokiServiceName": "cliptok", "voiceChannelPurge": true, - "forumChannelAutoWarnFallbackChannel": 150662382874525696 + "forumChannelAutoWarnFallbackChannel": 150662382874525696, + "rulesAllowedPublicChannels": [ + 150909451270881280, + 1006577277313744996, + 153165424358457345, + 740272437719072808, + 536572162450915340, + 355973419961155584 + ] }