From 2331f6a0cec8417e7ec1fe3b5282525e1497ccc5 Mon Sep 17 00:00:00 2001 From: Karl Essinger Date: Sun, 7 Nov 2021 23:44:52 +0100 Subject: [PATCH] Fixed exception at trying to re-add user to ticket that no longer exists --- SupportBoi/EventHandler.cs | 51 ++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/SupportBoi/EventHandler.cs b/SupportBoi/EventHandler.cs index 008b8d8..60370b0 100644 --- a/SupportBoi/EventHandler.cs +++ b/SupportBoi/EventHandler.cs @@ -221,15 +221,19 @@ internal async Task OnMemberAdded(DiscordClient client, GuildMemberAddEventArgs foreach (Database.Ticket ticket in ownTickets) { - DiscordChannel channel = await client.GetChannelAsync(ticket.channelID); - if (channel?.GuildId == e.Guild.Id) + try { - await channel.AddOverwriteAsync(e.Member, Permissions.AccessChannels, Permissions.None); - DiscordEmbed message = new DiscordEmbedBuilder() - .WithColor(DiscordColor.Green) - .WithDescription("User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has rejoined the server, and has been re-added to the ticket."); - await channel.SendMessageAsync(message); + DiscordChannel channel = await client.GetChannelAsync(ticket.channelID); + if (channel?.GuildId == e.Guild.Id) + { + await channel.AddOverwriteAsync(e.Member, Permissions.AccessChannels, Permissions.None); + DiscordEmbed message = new DiscordEmbedBuilder() + .WithColor(DiscordColor.Green) + .WithDescription("User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has rejoined the server, and has been re-added to the ticket."); + await channel.SendMessageAsync(message); + } } + catch (Exception) { } } } @@ -239,14 +243,18 @@ internal async Task OnMemberRemoved(DiscordClient client, Guild​Member​Remov { foreach(Database.Ticket ticket in ownTickets) { - DiscordChannel channel = await client.GetChannelAsync(ticket.channelID); - if (channel?.GuildId == e.Guild.Id) + try { - DiscordEmbed message = new DiscordEmbedBuilder() - .WithColor(DiscordColor.Red) - .WithDescription("User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server."); - await channel.SendMessageAsync(message); + DiscordChannel channel = await client.GetChannelAsync(ticket.channelID); + if (channel?.GuildId == e.Guild.Id) + { + DiscordEmbed message = new DiscordEmbedBuilder() + .WithColor(DiscordColor.Red) + .WithDescription("User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server."); + await channel.SendMessageAsync(message); + } } + catch (Exception) { } } } @@ -255,16 +263,21 @@ internal async Task OnMemberRemoved(DiscordClient client, Guild​Member​Remov DiscordChannel logChannel = await client.GetChannelAsync(Config.logChannel); if (logChannel != null) { + foreach (Database.Ticket ticket in assignedTickets) { - DiscordChannel channel = await client.GetChannelAsync(ticket.channelID); - if (channel?.GuildId == e.Guild.Id) + try { - DiscordEmbed message = new DiscordEmbedBuilder() - .WithColor(DiscordColor.Red) - .WithDescription("Assigned staff member '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server: <#" + channel.Id + ">"); - await logChannel.SendMessageAsync(message); + DiscordChannel channel = await client.GetChannelAsync(ticket.channelID); + if (channel?.GuildId == e.Guild.Id) + { + DiscordEmbed message = new DiscordEmbedBuilder() + .WithColor(DiscordColor.Red) + .WithDescription("Assigned staff member '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server: <#" + channel.Id + ">"); + await logChannel.SendMessageAsync(message); + } } + catch (Exception) { } } } }