Hide forbidden channels in /listopen and /listunassigned
This commit is contained in:
parent
e51afd0b47
commit
78994a6263
3 changed files with 55 additions and 5 deletions
|
@ -16,7 +16,7 @@ public class ListCommand
|
|||
[Command("list")]
|
||||
[Description("Lists tickets opened by a user.")]
|
||||
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;
|
||||
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.Commands;
|
||||
using DSharpPlus.Commands.ContextChecks;
|
||||
using DSharpPlus.Commands.Processors.SlashCommands;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.Exceptions;
|
||||
using DSharpPlus.Interactivity;
|
||||
using DSharpPlus.Interactivity.Extensions;
|
||||
|
||||
|
@ -27,10 +30,32 @@ public class ListOpen
|
|||
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>();
|
||||
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>();
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.Commands;
|
||||
using DSharpPlus.Commands.ContextChecks;
|
||||
using DSharpPlus.Commands.Processors.SlashCommands;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.Exceptions;
|
||||
using DSharpPlus.Interactivity;
|
||||
using DSharpPlus.Interactivity.Extensions;
|
||||
|
||||
|
@ -27,10 +30,32 @@ public class ListUnassignedCommand
|
|||
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>();
|
||||
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>();
|
||||
|
|
Loading…
Reference in a new issue