Skip to content

Commit

Permalink
Merge pull request #8 from Kingsman0530/main
Browse files Browse the repository at this point in the history
Fixed IDE warnings
  • Loading branch information
Pythonic-Rainbow authored Jan 16, 2024
2 parents fbaf0e2 + 2afb302 commit 051f4cc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 36 deletions.
67 changes: 33 additions & 34 deletions Bot/Coc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,48 @@ internal class Coc
{
private class ClanUtil

Check warning on line 8 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / build

Type 'ClanUtil' can be sealed because it has no subtypes in its containing assembly and is not externally visible (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852)

Check warning on line 8 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[CA1852] Type 'ClanUtil' can be sealed because it has no subtypes in its containing assembly and is not externally visible" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(8,112)
{
internal readonly Clan Clan;
internal readonly Dictionary<string, ClanMember> Members = [];
internal readonly Dictionary<string, ClanMember> ExistingMembers = [];
internal readonly Dictionary<string, ClanMember> JoiningMembers = [];
internal readonly Dictionary<string, ClanMember> LeavingMembers;
internal readonly Clan _clan;

Check warning on line 10 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[NotAccessedField.Local] Field '_clan' is assigned but its value is never used" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(10,158)
internal readonly Dictionary<string, ClanMember> _members = [];
internal readonly Dictionary<string, ClanMember> _existingMembers = [];
internal readonly Dictionary<string, ClanMember> _joiningMembers = [];

Check notice on line 13 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[MemberCanBePrivate.Local] Field '_joiningMembers' can be made private" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(13,325)

Check warning on line 13 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[CollectionNeverQueried.Local] Content of collection '_joiningMembers' is only updated but never used" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(13,374)
internal readonly Dictionary<string, ClanMember> _leavingMembers;

Check notice on line 14 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[MemberCanBePrivate.Local] Field '_leavingMembers' can be made private" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(14,404)

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)

Check warning on line 35 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[UnusedParameter.Local] Parameter 'init' is never used" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(35,1103)
{
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);

Check notice on line 45 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[MemberCanBePrivate.Local] Method 'HasMember' can be made private" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(45,1333)

Check notice on line 45 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[SuggestBaseTypeForParameter] Parameter can be of type 'ClashOfClans.Models.Identity'" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(45,1357)
}

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";
Expand All @@ -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<Clan> GetClanAsync()
{
return await s_client.Clans.GetClanAsync(ClanId);
}
private static async Task<Clan> 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)

Check warning on line 66 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract] Expression is always false according to nullable reference types' annotations" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(66,2254)
{
return;
}

if (clan.MemberList == null)
{
return;
}

ClanUtil clanUtil = new(clan);
await CheckDonations(clanUtil);
s_prevClan = clanUtil;
Expand All @@ -79,10 +81,10 @@ private static async Task PollAsync()
private static async Task CheckDonations(ClanUtil clan)
{
Dictionary<string, DonationTuple> 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);

Check notice on line 90 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[ArrangeObjectCreationWhenTypeNotEvident] Missing type specification" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(90,2990)
Expand All @@ -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);

Check notice on line 99 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[ArrangeObjectCreationWhenTypeNotEvident] Missing type specification" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(99,3304)

internal static async Task BotReadyAsync()
{
Expand Down
4 changes: 2 additions & 2 deletions Bot/Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal static async Task DonationsChangedAsync(Dictionary<string, DonationTupl
List<string> items = new(donationsDelta.Count / 2);
foreach (string name in donationsDelta.Keys)

Check notice on line 45 in Bot/Discord.cs

View workflow job for this annotation

GitHub Actions / inspect

"[ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator] Loop can be converted into LINQ-expression but another 'GetEnumerator' method will be used" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Discord.cs(45,1374)
{
int donated = donationsDelta[name].Donated;
int donated = donationsDelta[name]._donated;
if (donated > 0)
{
items.Add($"{name}: {donated}");
Expand All @@ -55,7 +55,7 @@ internal static async Task DonationsChangedAsync(Dictionary<string, DonationTupl
items.Clear();
foreach (string name in donationsDelta.Keys)
{
int received = donationsDelta[name].Received;
int received = donationsDelta[name]._received;
if (received > 0)
{
items.Add($"{name}: {received}");
Expand Down

0 comments on commit 051f4cc

Please sign in to comment.