From 2afb3022b280b37d36565494042d448f927d254f Mon Sep 17 00:00:00 2001 From: Kingsman Date: Tue, 16 Jan 2024 14:44:29 +0800 Subject: [PATCH] Fix IDE warnings --- Bot/Coc.cs | 67 +++++++++++++++++++++++++------------------------- Bot/Discord.cs | 4 +-- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/Bot/Coc.cs b/Bot/Coc.cs index da44fdf..ff7357b 100644 --- a/Bot/Coc.cs +++ b/Bot/Coc.cs @@ -7,51 +7,48 @@ internal class Coc { private class ClanUtil { - internal readonly Clan Clan; - internal readonly Dictionary Members = []; - internal readonly Dictionary ExistingMembers = []; - internal readonly Dictionary JoiningMembers = []; - internal readonly Dictionary LeavingMembers; + internal readonly Clan _clan; + internal readonly Dictionary _members = []; + internal readonly Dictionary _existingMembers = []; + internal readonly Dictionary _joiningMembers = []; + internal readonly Dictionary _leavingMembers; internal ClanUtil(Clan clan) { - LeavingMembers = s_prevClan.Members; + _leavingMembers = s_prevClan._members; foreach (ClanMember member in clan.MemberList!) { - Members[member.Tag] = member; + _members[member.Tag] = member; if (s_prevClan.HasMember(member)) { - ExistingMembers[member.Tag] = member; - LeavingMembers.Remove(member.Tag); + _existingMembers[member.Tag] = member; + _ = _leavingMembers.Remove(member.Tag); } else { - JoiningMembers[member.Tag] = member; + _joiningMembers[member.Tag] = member; } } - Clan = clan; + _clan = clan; } internal ClanUtil(Clan clan, bool init) { - LeavingMembers = []; + _leavingMembers = []; foreach (ClanMember member in clan.MemberList!) { - Members[member.Tag] = member; + _members[member.Tag] = member; } - Clan = clan; + _clan = clan; } - internal bool HasMember(ClanMember member) - { - return Members.ContainsKey(member.Tag); - } + internal bool HasMember(ClanMember member) => _members.ContainsKey(member.Tag); } internal readonly struct DonationTuple(int donated, int received) { - internal readonly int Donated = donated; - internal readonly int Received = received; + internal readonly int _donated = donated; + internal readonly int _received = received; } private const string ClanId = "#2QU2UCJJC"; @@ -61,16 +58,21 @@ internal readonly struct DonationTuple(int donated, int received) private static ClanUtil s_prevClan; #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. - private static async Task GetClanAsync() - { - return await s_client.Clans.GetClanAsync(ClanId); - } + private static async Task GetClanAsync() => await s_client.Clans.GetClanAsync(ClanId); private static async Task PollAsync() { - var clan = await GetClanAsync(); - if (clan == null) return; - if (clan.MemberList == null) return; + Clan clan = await GetClanAsync(); + if (clan == null) + { + return; + } + + if (clan.MemberList == null) + { + return; + } + ClanUtil clanUtil = new(clan); await CheckDonations(clanUtil); s_prevClan = clanUtil; @@ -79,10 +81,10 @@ private static async Task PollAsync() private static async Task CheckDonations(ClanUtil clan) { Dictionary donationsDelta = []; - foreach (string tag in clan.ExistingMembers.Keys) + foreach (string tag in clan._existingMembers.Keys) { - ClanMember current = clan.Members[tag]; - ClanMember previous = s_prevClan.Members[tag]; + ClanMember current = clan._members[tag]; + ClanMember previous = s_prevClan._members[tag]; if (current.Donations > previous.Donations || current.DonationsReceived > previous.DonationsReceived) { donationsDelta[current.Name] = new(current.Donations - previous.Donations, current.DonationsReceived - previous.DonationsReceived); @@ -94,10 +96,7 @@ private static async Task CheckDonations(ClanUtil clan) } } - internal static async Task InitAsync() - { - s_prevClan = new(await GetClanAsync(), true); - } + internal static async Task InitAsync() => s_prevClan = new(await GetClanAsync(), true); internal static async Task BotReadyAsync() { diff --git a/Bot/Discord.cs b/Bot/Discord.cs index d5073e5..3aee0ec 100644 --- a/Bot/Discord.cs +++ b/Bot/Discord.cs @@ -44,7 +44,7 @@ internal static async Task DonationsChangedAsync(Dictionary items = new(donationsDelta.Count / 2); foreach (string name in donationsDelta.Keys) { - int donated = donationsDelta[name].Donated; + int donated = donationsDelta[name]._donated; if (donated > 0) { items.Add($"{name}: {donated}"); @@ -55,7 +55,7 @@ internal static async Task DonationsChangedAsync(Dictionary 0) { items.Add($"{name}: {received}");