From 4407968d4cf6af58628bf4d503938969181f6773 Mon Sep 17 00:00:00 2001 From: Pythonic-Rainbow Date: Tue, 16 Jan 2024 01:03:33 +0000 Subject: [PATCH] [Bot] Follow conventions for Coc.cs --- .github/workflows/compile-bot.yml | 4 +-- .github/workflows/resharper-inspect.yml | 4 +-- Bot/Coc.cs | 45 +++++++++++++++---------- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/.github/workflows/compile-bot.yml b/.github/workflows/compile-bot.yml index eb066c5..5338dbe 100644 --- a/.github/workflows/compile-bot.yml +++ b/.github/workflows/compile-bot.yml @@ -6,10 +6,10 @@ name: Compile bot on: push: branches: [ "main", "debug-workflow" ] - paths: ["*.cs"] + paths: ["**.cs"] pull_request: branches: [ "main" ] - paths: ["*.cs"] + paths: ["**.cs"] defaults: run: diff --git a/.github/workflows/resharper-inspect.yml b/.github/workflows/resharper-inspect.yml index de8b5ef..e7e2126 100644 --- a/.github/workflows/resharper-inspect.yml +++ b/.github/workflows/resharper-inspect.yml @@ -3,10 +3,10 @@ name: Inspect code on: push: branches: [ "main", "debug-workflow" ] - paths: ["*.cs"] + paths: ["**.cs"] pull_request: branches: [ "main" ] - paths: ["*.cs"] + paths: ["**.cs"] defaults: run: diff --git a/Bot/Coc.cs b/Bot/Coc.cs index 4f5ea40..4bdbc2e 100644 --- a/Bot/Coc.cs +++ b/Bot/Coc.cs @@ -20,17 +20,18 @@ private class ClanUtil internal readonly Dictionary JoiningMembers = []; internal readonly Dictionary LeavingMembers; - public ClanUtil(Clan clan) + internal ClanUtil(Clan clan) { - LeavingMembers = _prevClan.Members; - foreach (var member in clan.MemberList!) + LeavingMembers = s_prevClan.Members; + foreach (ClanMember member in clan.MemberList!) { Members[member.Tag] = member; - if (_prevClan.HasMember(member)) + if (s_prevClan.HasMember(member)) { ExistingMembers[member.Tag] = member; LeavingMembers.Remove(member.Tag); - } else + } + else { JoiningMembers[member.Tag] = member; } @@ -41,14 +42,17 @@ public ClanUtil(Clan clan) internal ClanUtil(Clan clan, bool init) { LeavingMembers = []; - foreach (var member in clan.MemberList!) + foreach (ClanMember member in clan.MemberList!) { Members[member.Tag] = member; } Clan = clan; } - internal bool HasMember(ClanMember member) => Members.ContainsKey(member.Tag); + internal bool HasMember(ClanMember member) + { + return Members.ContainsKey(member.Tag); + } } private class MemberComparer : IEqualityComparer @@ -58,14 +62,18 @@ private class MemberComparer : IEqualityComparer public int GetHashCode(ClanMember obj) => obj.Tag.GetHashCode(); } - const string CLAN_ID = "#2QU2UCJJC"; - const string DIM_ID = "#28QL0CJV2"; + private const string ClanId = "#2QU2UCJJC"; + private const string DimId = "#28QL0CJV2"; + internal static readonly ClashOfClansClient s_client = new(Secrets.Coc); + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. - private static ClanUtil _prevClan; + 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. - internal static readonly ClashOfClansClient Client = new(Secrets.Coc); - private static async Task GetClanAsync() => await Client.Clans.GetClanAsync(CLAN_ID); + private static async Task GetClanAsync() + { + return await s_client.Clans.GetClanAsync(ClanId); + } private static async Task PollAsync() { @@ -74,16 +82,16 @@ private static async Task PollAsync() if (clan.MemberList == null) return; ClanUtil clanUtil = new(clan); await CheckDonations(clanUtil); - _prevClan = clanUtil; + s_prevClan = clanUtil; } private static async Task CheckDonations(ClanUtil clan) { Dictionary donationsDelta = []; - foreach (var tag in clan.ExistingMembers.Keys) + foreach (string tag in clan.ExistingMembers.Keys) { - var current = clan.Members[tag]; - var previous = _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); @@ -95,7 +103,10 @@ private static async Task CheckDonations(ClanUtil clan) } } - internal static async Task InitAsync() => _prevClan = new(await GetClanAsync(), true); + internal static async Task InitAsync() + { + s_prevClan = new(await GetClanAsync(), true); + } internal static async Task BotReadyAsync() {