Use TryGetValue instead of ContainsKey and retrieving afterwards

This commit is contained in:
Octol1ttle 2022-10-21 11:09:56 +05:00
parent 59d9423b5f
commit 7afd00bf30
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
4 changed files with 9 additions and 9 deletions

View file

@ -26,8 +26,8 @@ public sealed class MuteCommand : ICommand {
var rolesRemoved = Boyfriend.GetRemovedRoles(cmd.Context.Guild.Id);
if (rolesRemoved.ContainsKey(toMute.Id)) {
foreach (var roleId in rolesRemoved[toMute.Id]) await toMute.AddRoleAsync(roleId);
if (rolesRemoved.TryGetValue(toMute.Id, out var mutedRemovedRoles)) {
foreach (var roleId in mutedRemovedRoles) await toMute.AddRoleAsync(roleId);
rolesRemoved.Remove(toMute.Id);
cmd.ConfigWriteScheduled = true;
cmd.Reply(Messages.RolesReturned, ":warning: ");

View file

@ -23,8 +23,8 @@ public sealed class UnmuteCommand : ICommand {
if (role != null && toUnmute.Roles.Contains(role)) {
var rolesRemoved = Boyfriend.GetRemovedRoles(cmd.Context.Guild.Id);
if (rolesRemoved.ContainsKey(toUnmute.Id)) {
await toUnmute.AddRolesAsync(rolesRemoved[toUnmute.Id]);
if (rolesRemoved.TryGetValue(toUnmute.Id, out var unmutedRemovedRoles)) {
await toUnmute.AddRolesAsync(unmutedRemovedRoles);
rolesRemoved.Remove(toUnmute.Id);
cmd.ConfigWriteScheduled = true;
}