From cf229bfd1ca815b3caaf040b300dde9a0becce23 Mon Sep 17 00:00:00 2001 From: Pythonic-Rainbow Date: Tue, 6 Feb 2024 03:45:26 +0000 Subject: [PATCH] [Bot] Resolve most CA warnings (#16) * Test workflow * s_ * Try UA4 again * Resolve most CA warnings --- .github/workflows/bot.yml | 4 ++-- Bot/Clash/ClanUtil.cs | 4 ++-- Bot/Clash/Coc.cs | 16 ++++++---------- Bot/Sql/Donation.cs | 2 +- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/.github/workflows/bot.yml b/.github/workflows/bot.yml index 0b7b44d..1b9e0d4 100644 --- a/.github/workflows/bot.yml +++ b/.github/workflows/bot.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Setup .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: 8.0.x - name: Build @@ -39,7 +39,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Setup .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: '8.0.x' - name: Restore diff --git a/Bot/Clash/ClanUtil.cs b/Bot/Clash/ClanUtil.cs index 2ec83cb..69160cc 100644 --- a/Bot/Clash/ClanUtil.cs +++ b/Bot/Clash/ClanUtil.cs @@ -44,11 +44,11 @@ internal static ClanUtil FromInit(Clan clan) internal static ClanUtil FromPoll(Clan clan) { - ClanUtil c = new(clan, new(Coc.s_clan._members)); + ClanUtil c = new(clan, new(Coc.Clan._members)); foreach (ClanMember member in clan.MemberList!) { c._members[member.Tag] = member; - if (Coc.s_clan.HasMember(member)) + if (Coc.Clan.HasMember(member)) { c._existingMembers[member.Tag] = member; c._leavingMembers.Remove(member.Tag); diff --git a/Bot/Clash/Coc.cs b/Bot/Clash/Coc.cs index 6852dd9..8708a99 100644 --- a/Bot/Clash/Coc.cs +++ b/Bot/Clash/Coc.cs @@ -10,7 +10,7 @@ internal static class Coc private const string ClanId = "#2QU2UCJJC"; // 2G8LP8PVV private static readonly ClashOfClansClient s_client = new(Secrets.s_coc); #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. - internal static ClanUtil s_clan { get; private set; } + internal static ClanUtil Clan { get; private set; } #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. private static void CheckMembersJoined(ClanUtil clan) @@ -81,10 +81,6 @@ private static void CheckMembersLeft(ClanUtil clan) private static async Task PollAsync() { Clan clan = await GetClanAsync(); - if (clan == null) - { - return; - } if (clan.MemberList == null) { @@ -97,7 +93,7 @@ private static async Task PollAsync() await Task.WhenAll([ CheckDonationsAsync(clanUtil), ]); - s_clan = clanUtil; + Clan = clanUtil; } private static async Task CheckDonationsAsync(ClanUtil clan) @@ -106,7 +102,7 @@ private static async Task CheckDonationsAsync(ClanUtil clan) foreach (string tag in clan._existingMembers.Keys) { ClanMember current = clan._members[tag]; - ClanMember previous = s_clan._members[tag]; + ClanMember previous = Clan._members[tag]; if (current.Donations > previous.Donations || current.DonationsReceived > previous.DonationsReceived) { donDelta[current.Tag] = new(current.Donations - previous.Donations, current.DonationsReceived - previous.DonationsReceived); @@ -170,13 +166,13 @@ private static async Task CheckDonationsAsync(ClanUtil clan) internal static string? GetMemberId(string name) { - ClanMember? result = s_clan._clan.MemberList!.FirstOrDefault(m => m.Name == name); + ClanMember? result = Clan._clan.MemberList!.FirstOrDefault(m => m.Name == name); return result?.Tag; } - internal static ClanMember GetMember(string id) => s_clan._members[id]; + internal static ClanMember GetMember(string id) => Clan._members[id]; - internal static async Task InitAsync() => s_clan = ClanUtil.FromInit(await GetClanAsync()); + internal static async Task InitAsync() => Clan = ClanUtil.FromInit(await GetClanAsync()); internal static async Task BotReadyAsync() { diff --git a/Bot/Sql/Donation.cs b/Bot/Sql/Donation.cs index 3556046..536272d 100644 --- a/Bot/Sql/Donation.cs +++ b/Bot/Sql/Donation.cs @@ -8,7 +8,7 @@ internal sealed class Donation(string id, long checkTime) public string MainId { get; set; } = id; [NotNull] - public uint Donated { get; set; } = 0; + public uint Donated { get; set; } [NotNull] public long Checked { get; set; } = checkTime;