Hide forbidden channels in /listopen and /listunassigned

This commit is contained in:
Toastie 2024-12-27 02:16:27 +13:00
parent e51afd0b47
commit 78994a6263
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
3 changed files with 55 additions and 5 deletions

View file

@ -16,7 +16,7 @@ public class ListCommand
[Command("list")] [Command("list")]
[Description("Lists tickets opened by a user.")] [Description("Lists tickets opened by a user.")]
public async Task OnExecute(SlashCommandContext command, public async Task OnExecute(SlashCommandContext command,
[Parameter("user")][Description("(Optional) The user to get tickets by.")] DiscordUser user = null) [Parameter("user")][Description("(Optional) The user to get tickets by, yourself by default.")] DiscordUser user = null)
{ {
DiscordUser listUser = user == null ? command.User : user; DiscordUser listUser = user == null ? command.User : user;

View file

@ -1,10 +1,13 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using DSharpPlus.Commands; using DSharpPlus.Commands;
using DSharpPlus.Commands.ContextChecks; using DSharpPlus.Commands.ContextChecks;
using DSharpPlus.Commands.Processors.SlashCommands; using DSharpPlus.Commands.Processors.SlashCommands;
using DSharpPlus.Entities; using DSharpPlus.Entities;
using DSharpPlus.Exceptions;
using DSharpPlus.Interactivity; using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions; using DSharpPlus.Interactivity.Extensions;
@ -27,10 +30,32 @@ public class ListOpen
return; return;
} }
// Get all channels in all guilds the bot is part of
List<DiscordChannel> allChannels = new List<DiscordChannel>();
foreach (KeyValuePair<ulong, DiscordGuild> guild in SupportChild.client.Guilds)
{
try
{
allChannels.AddRange(await guild.Value.GetChannelsAsync());
}
catch (Exception) { /*ignored*/ }
}
List<string> listItems = new List<string>(); List<string> listItems = new List<string>();
foreach (Database.Ticket ticket in openTickets) foreach (Database.Ticket ticket in openTickets)
{ {
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n"); try
{
DiscordChannel channel = allChannels.FirstOrDefault(c => c.Id == ticket.channelID);
if (channel != null)
{
if (command.Member!.PermissionsIn(channel).HasPermission(DiscordPermissions.AccessChannels))
{
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
}
}
}
catch (NotFoundException) { /*ignored*/ }
} }
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>(); List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();

View file

@ -1,10 +1,13 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using DSharpPlus.Commands; using DSharpPlus.Commands;
using DSharpPlus.Commands.ContextChecks; using DSharpPlus.Commands.ContextChecks;
using DSharpPlus.Commands.Processors.SlashCommands; using DSharpPlus.Commands.Processors.SlashCommands;
using DSharpPlus.Entities; using DSharpPlus.Entities;
using DSharpPlus.Exceptions;
using DSharpPlus.Interactivity; using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions; using DSharpPlus.Interactivity.Extensions;
@ -27,10 +30,32 @@ public class ListUnassignedCommand
return; return;
} }
// Get all channels in all guilds the bot is part of
List<DiscordChannel> allChannels = new List<DiscordChannel>();
foreach (KeyValuePair<ulong, DiscordGuild> guild in SupportChild.client.Guilds)
{
try
{
allChannels.AddRange(await guild.Value.GetChannelsAsync());
}
catch (Exception) { /*ignored*/ }
}
List<string> listItems = new List<string>(); List<string> listItems = new List<string>();
foreach (Database.Ticket ticket in unassignedTickets) foreach (Database.Ticket ticket in unassignedTickets)
{ {
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n"); try
{
DiscordChannel channel = allChannels.FirstOrDefault(c => c.Id == ticket.channelID);
if (channel != null)
{
if (command.Member!.PermissionsIn(channel).HasPermission(DiscordPermissions.AccessChannels))
{
listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + "> by <@" + ticket.creatorID + ">\n");
}
}
}
catch (NotFoundException) { /*ignored*/ }
} }
List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>(); List<DiscordEmbedBuilder> embeds = new List<DiscordEmbedBuilder>();