Skip to content

Commit

Permalink
[Bot] Resolve some CA warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythonic-Rainbow committed Jan 22, 2024
1 parent 73a2152 commit 228e061
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 31 deletions.
3 changes: 3 additions & 0 deletions Bot/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ dotnet_style_prefer_conditional_expression_over_assignment = true:silent

# C# files
[*.cs]
# ReSharper
resharper_function_never_returns_highlighting = none

# New line preferences
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
Expand Down
56 changes: 30 additions & 26 deletions Bot/Coc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ internal static class Coc
{
private sealed class ClanUtil
{
internal Clan _clan;
internal readonly Clan _clan;
internal readonly Dictionary<string, ClanMember> _members = [];
internal readonly Dictionary<string, ClanMember> _existingMembers = [];
internal readonly Dictionary<string, ClanMember> _joiningMembers = [];
internal Dictionary<string, ClanMember> _leavingMembers;
internal readonly Dictionary<string, ClanMember> _leavingMembers;

private ClanUtil(Clan clan, Dictionary<string, ClanMember> leavingMembers)
{
Expand Down Expand Up @@ -82,37 +82,41 @@ internal readonly struct DonationTuple(int donated, int received)

private static void CheckMembersJoined(ClanUtil clan)
{
if (clan._joiningMembers.Count > 0)
if (clan._joiningMembers.Count == 0)
{
string[] members = [.. clan._joiningMembers.Keys];
bool isSuccess = Db.AddMembers(members);
string membersMsg = string.Join(", ", members);
if (isSuccess)
{
Console.WriteLine($"{membersMsg} joined");
}
else
{
Console.Error.WriteLine($"ERROR MembersJoined {membersMsg}");
}
return;
}

string[] members = [.. clan._joiningMembers.Keys];
bool isSuccess = Db.AddMembers(members);
string membersMsg = string.Join(", ", members);
if (isSuccess)
{
Console.WriteLine($"{membersMsg} joined");
}
else
{
Console.Error.WriteLine($"ERROR MembersJoined {membersMsg}");
}
}

private static void CheckMembersLeft(ClanUtil clan)
{
if (clan._leavingMembers.Count > 0)
if (clan._leavingMembers.Count == 0)
{
string[] members = [.. clan._leavingMembers.Keys];
bool isSuccess = Db.RemoveMembers(members);
string membersMsg = string.Join(", ", members);
if (isSuccess)
{
Console.WriteLine($"{membersMsg} left");
}
else
{
Console.Error.WriteLine($"ERROR MembersLeft {membersMsg}");
}
return;
}

string[] members = [.. clan._leavingMembers.Keys];
bool isSuccess = Db.RemoveMembers(members);
string membersMsg = string.Join(", ", members);
if (isSuccess)
{
Console.WriteLine($"{membersMsg} left");
}
else
{
Console.Error.WriteLine($"ERROR MembersLeft {membersMsg}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion Bot/Dc/Attr/RequireAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Hyperstellar.Dc.Attr;

internal class RequireAdmin : PreconditionAttribute
internal sealed class RequireAdmin : PreconditionAttribute
{
public override Task<PreconditionResult> CheckRequirementsAsync(IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services) => Db.s_admins.Contains(context.User.Id)
? Task.FromResult(PreconditionResult.FromSuccess())
Expand Down
5 changes: 2 additions & 3 deletions Bot/Dc/MemberConverter.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using ClashOfClans.Models;
using Discord;
using Discord;
using Discord.Interactions;
using Hyperstellar.Sql;

namespace Hyperstellar.Dc;

internal class MemberConverter : TypeConverter
internal sealed class MemberConverter : TypeConverter
{
public override bool CanConvertTo(System.Type type) => typeof(Member).IsAssignableFrom(type);

Check warning on line 9 in Bot/Dc/MemberConverter.cs

View workflow job for this annotation

GitHub Actions / inspect

"[RedundantNameQualifier] Qualifier is redundant" on /home/runner/work/coc-clan/coc-clan/Bot/Dc/MemberConverter.cs(9,190)
public override ApplicationCommandOptionType GetDiscordType() => ApplicationCommandOptionType.String;
Expand Down
2 changes: 2 additions & 0 deletions Bot/Secrets.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Newtonsoft.Json;

namespace Hyperstellar;

internal sealed class Secrets
{
internal static readonly string s_discord; // Your Discord bot token
Expand Down
2 changes: 1 addition & 1 deletion Bot/Sql/Donation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Hyperstellar.Sql;

internal class Donation(string id)
internal sealed class Donation(string id)
{
[PrimaryKey, NotNull]
public string Id { get; set; } = id;
Expand Down

0 comments on commit 228e061

Please sign in to comment.