From a4f1ca232145bdab65ab01d50c0171ec69c9a206 Mon Sep 17 00:00:00 2001 From: Pythonic-Rainbow Date: Wed, 7 Feb 2024 05:26:24 +0000 Subject: [PATCH] [Bot] Resolve most CA suggestions --- Bot/.editorconfig | 1 + Bot/Clash/ClanUtil.cs | 19 +++++++------------ Bot/Clash/Coc.cs | 6 ++---- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Bot/.editorconfig b/Bot/.editorconfig index 5a53323..619e4ba 100644 --- a/Bot/.editorconfig +++ b/Bot/.editorconfig @@ -33,6 +33,7 @@ dotnet_diagnostic.CA1852.severity = suggestion [*.cs] # ReSharper resharper_function_never_returns_highlighting = none +resharper_arrange_object_creation_when_type_not_evident_highlighting = none # New line preferences csharp_new_line_before_open_brace = all diff --git a/Bot/Clash/ClanUtil.cs b/Bot/Clash/ClanUtil.cs index 69160cc..e91ec59 100644 --- a/Bot/Clash/ClanUtil.cs +++ b/Bot/Clash/ClanUtil.cs @@ -23,20 +23,15 @@ internal static ClanUtil FromInit(Clan clan) IEnumerable existingMembers = Db.GetMembers().Select(m => m.CocId); foreach (string dbMember in existingMembers) { - bool stillExists = false; - foreach (ClanMember clanMember in clan.MemberList!) + ClanMember? clanMember = clan.MemberList!.FirstOrDefault(m => m.Tag == dbMember); + if (clanMember == null) { - if (clanMember.Tag.Equals(dbMember)) - { - c._members[dbMember] = clanMember; - clan.MemberList.Remove(clanMember); - stillExists = true; - break; - } + c._members[dbMember] = new(); // Fake a member } - if (!stillExists) + else { - c._members[dbMember] = new(); // Fake a member + c._members[dbMember] = clanMember; + clan.MemberList!.Remove(clanMember); } } return c; @@ -61,6 +56,6 @@ internal static ClanUtil FromPoll(Clan clan) return c; } - internal bool HasMember(ClanMember member) => _members.ContainsKey(member.Tag); + private bool HasMember(ClanMember member) => _members.ContainsKey(member.Tag); } diff --git a/Bot/Clash/Coc.cs b/Bot/Clash/Coc.cs index 8708a99..399240d 100644 --- a/Bot/Clash/Coc.cs +++ b/Bot/Clash/Coc.cs @@ -91,7 +91,7 @@ private static async Task PollAsync() CheckMembersJoined(clanUtil); CheckMembersLeft(clanUtil); await Task.WhenAll([ - CheckDonationsAsync(clanUtil), + CheckDonationsAsync(clanUtil) ]); Clan = clanUtil; } @@ -141,10 +141,8 @@ private static async Task CheckDonationsAsync(ClanUtil clan) } // Everyone is main now, begin processing Donate25 - foreach (KeyValuePair delta in foldedDelta) + foreach ((string tag, DonationTuple dt) in foldedDelta) { - string tag = delta.Key; - DonationTuple dt = delta.Value; int donated = dt._donated; int received = dt._received;