From 3f5a544213195ecd733e0363410388ea5afe8b08 Mon Sep 17 00:00:00 2001 From: Patrick Klaeren Date: Fri, 7 Jul 2023 18:42:13 +0100 Subject: [PATCH] Refactor condition checks and remove deconstruct handle Simplified and consolidated the conditional check in the MemberUpdateResponder.cs for better readability, and improved efficiency. The redundancies in DiscordHandleHelper.cs were eliminated by removing the deconstruct handle function as it was unused and not necessary. A condition check was added for when the discriminator is zero to just return the username. --- src/Accord.Bot/Responders/MemberUpdateResponder.cs | 3 +-- src/Accord.Services/Helpers/DiscordHandleHelper.cs | 8 +------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Accord.Bot/Responders/MemberUpdateResponder.cs b/src/Accord.Bot/Responders/MemberUpdateResponder.cs index 0f783a3..63f56a2 100644 --- a/src/Accord.Bot/Responders/MemberUpdateResponder.cs +++ b/src/Accord.Bot/Responders/MemberUpdateResponder.cs @@ -47,8 +47,7 @@ public partial class MemberUpdateResponder : IResponder await HandleUserDiff(user, messages, cancellationToken); } - if (gatewayEvent.CommunicationDisabledUntil.HasValue - && gatewayEvent.CommunicationDisabledUntil.Value is { } until) + if (gatewayEvent.CommunicationDisabledUntil is { HasValue: true, Value: { } until }) { await HandleTimeOut(gatewayEvent, user, until, cancellationToken); } diff --git a/src/Accord.Services/Helpers/DiscordHandleHelper.cs b/src/Accord.Services/Helpers/DiscordHandleHelper.cs index 634d172..9cd4dfc 100644 --- a/src/Accord.Services/Helpers/DiscordHandleHelper.cs +++ b/src/Accord.Services/Helpers/DiscordHandleHelper.cs @@ -9,12 +9,6 @@ public static string BuildHandle(string username, string discriminator) public static string BuildHandle(string username, ulong discriminator) { - return BuildHandle(username, discriminator.ToString("0000")); - } - - public static (string username, string discriminator) DeconstructHandle(string handle) - { - var split = handle.Split('#'); - return (split[0], split[1]); + return discriminator is 0 ? username : BuildHandle(username, discriminator.ToString("0000")); } } \ No newline at end of file