Skip to content

Commit

Permalink
Refactor condition checks and remove deconstruct handle
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
patrickklaeren committed Jul 7, 2023
1 parent 51aa03f commit 3f5a544
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/Accord.Bot/Responders/MemberUpdateResponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public partial class MemberUpdateResponder : IResponder<IGuildMemberUpdate>
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);
}
Expand Down
8 changes: 1 addition & 7 deletions src/Accord.Services/Helpers/DiscordHandleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}

0 comments on commit 3f5a544

Please sign in to comment.