- More code cleanup and codestyle updates

- Fixed some possible nullref exceptions
- Methods signatures now have up to 3 parameters before breakaing down each parameter in a separate line
- Method invocations have the same rule, except the first parameter will be in the same line as the invocation to prevent some ugliness when passing lambas as arguments
- Applied many more codestyles
- Extensions folder fully reformatted
This commit is contained in:
Kwoth
2021-12-26 17:28:39 +01:00
parent b85ba177cd
commit d5fd6aae8e
217 changed files with 1017 additions and 1494 deletions

View File

@@ -12,9 +12,7 @@ public partial class Games
private readonly DiscordSocketClient _client;
public AcropobiaCommands(DiscordSocketClient client)
{
_client = client;
}
=> _client = client;
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
@@ -80,11 +78,9 @@ public partial class Games
}
private Task Game_OnUserVoted(string user)
{
return SendConfirmAsync(
=> SendConfirmAsync(
GetText(strs.acrophobia),
GetText(strs.acro_vote_cast(Format.Bold(user))));
}
private async Task Game_OnVotingStarted(AcrophobiaGame game, ImmutableArray<KeyValuePair<AcrophobiaUser, int>> submissions)
{

View File

@@ -11,9 +11,7 @@ public partial class Games
private readonly DbService _db;
public ChatterBotCommands(DbService db)
{
_db = db;
}
=> _db = db;
[NoPublicBot]
[NadekoCommand, Aliases]

View File

@@ -15,9 +15,9 @@ public sealed class AcrophobiaGame : IDisposable
public void NormalizeOptions()
{
if (SubmissionTime < 15 || SubmissionTime > 300)
if (SubmissionTime is < 15 or > 300)
SubmissionTime = 60;
if (VoteTime < 15 || VoteTime > 120)
if (VoteTime is < 15 or > 120)
VoteTime = 30;
}
}

View File

@@ -14,14 +14,10 @@ public class AcrophobiaUser
}
public override int GetHashCode()
{
return UserId.GetHashCode();
}
=> UserId.GetHashCode();
public override bool Equals(object obj)
{
return obj is AcrophobiaUser x
=> obj is AcrophobiaUser x
? x.UserId == this.UserId
: false;
}
}

View File

@@ -88,8 +88,7 @@ public sealed class HangmanService : IHangmanService, ILateExecutor
if (state.GuessResult == HangmanGame.GuessResult.NoAction)
return;
if (state.GuessResult == HangmanGame.GuessResult.Incorrect
|| state.GuessResult == HangmanGame.GuessResult.AlreadyTried)
if (state.GuessResult is HangmanGame.GuessResult.Incorrect or HangmanGame.GuessResult.AlreadyTried)
{
_cdCache.Set(msg.Author.Id, string.Empty, new MemoryCacheEntryOptions()
{

View File

@@ -34,9 +34,7 @@ public sealed class NunchiGame : IDisposable
private Timer _killTimer;
public NunchiGame(ulong creatorId, string creatorName)
{
_participants.Add((creatorId, creatorName));
}
=> _participants.Add((creatorId, creatorName));
public async Task<bool> Join(ulong userId, string userName)
{

View File

@@ -59,7 +59,5 @@ public class PollRunner
}
public void End()
{
OnVoted = null;
}
=> OnVoted = null;
}

View File

@@ -9,7 +9,7 @@ public class TicTacToe
{
public void NormalizeOptions()
{
if (TurnTimer < 5 || TurnTimer > 60)
if (TurnTimer is < 5 or > 60)
TurnTimer = 15;
}
@@ -127,7 +127,7 @@ public class TicTacToe
public async Task Start(IGuildUser user)
{
if (_phase == Phase.Started || _phase == Phase.Ended)
if (_phase is Phase.Started or Phase.Ended)
{
await _channel.SendErrorAsync(_eb, user.Mention + GetText(strs.ttt_already_running)).ConfigureAwait(false);
return;

View File

@@ -86,9 +86,7 @@ public class TriviaGame
questionMessage = await Channel.EmbedAsync(questionEmbed).ConfigureAwait(false);
}
catch (HttpException ex) when (ex.HttpCode == System.Net.HttpStatusCode.NotFound ||
ex.HttpCode == System.Net.HttpStatusCode.Forbidden ||
ex.HttpCode == System.Net.HttpStatusCode.BadRequest)
catch (HttpException ex) when (ex.HttpCode is System.Net.HttpStatusCode.NotFound or System.Net.HttpStatusCode.Forbidden or System.Net.HttpStatusCode.BadRequest)
{
return;
}
@@ -116,7 +114,7 @@ public class TriviaGame
await questionMessage.ModifyAsync(m => m.Embed = questionEmbed.WithFooter(CurrentQuestion.GetHint()).Build())
.ConfigureAwait(false);
}
catch (HttpException ex) when (ex.HttpCode == System.Net.HttpStatusCode.NotFound || ex.HttpCode == System.Net.HttpStatusCode.Forbidden)
catch (HttpException ex) when (ex.HttpCode is System.Net.HttpStatusCode.NotFound or System.Net.HttpStatusCode.Forbidden)
{
break;
}

View File

@@ -19,9 +19,9 @@ public class TriviaOptions : INadekoCommandOptions
{
if (WinRequirement < 0)
WinRequirement = 10;
if (QuestionTimer < 10 || QuestionTimer > 300)
if (QuestionTimer is < 10 or > 300)
QuestionTimer = 30;
if (Timeout < 0 || Timeout > 20)
if (Timeout is < 0 or > 20)
Timeout = 10;
}

View File

@@ -78,7 +78,7 @@ public class TriviaQuestion
str = Regex.Replace(str, "^\\s+", "");
str = Regex.Replace(str, "\\s+$", "");
//Trim the really long answers
str = str.Length <= maxStringLength ? str : str.Substring(0, maxStringLength);
str = str.Length <= maxStringLength ? str : str[..maxStringLength];
return str;
}

View File

@@ -13,7 +13,7 @@ public class TypingGame
public void NormalizeOptions()
{
if (StartTime < 3 || StartTime > 30)
if (StartTime is < 3 or > 30)
StartTime = 5;
}
}
@@ -123,9 +123,7 @@ public class TypingGame
}
private void HandleAnswers()
{
_client.MessageReceived += AnswerReceived;
}
=> _client.MessageReceived += AnswerReceived;
private Task AnswerReceived(SocketMessage imsg)
{

View File

@@ -76,9 +76,7 @@ public partial class Games : NadekoModule<GamesService>
}
private double NextDouble(double x, double y)
{
return (_rng.NextDouble() * (y - x)) + x;
}
=> (_rng.NextDouble() * (y - x)) + x;
private GirlRating GetGirl(ulong uid)
{
@@ -139,13 +137,11 @@ public partial class Games : NadekoModule<GamesService>
[NadekoCommand, Aliases]
public async Task Linux(string guhnoo, string loonix)
{
await SendConfirmAsync(
=> await SendConfirmAsync(
$@"I'd just like to interject for moment. What you're refering to as {loonix}, is in fact, {guhnoo}/{loonix}, or as I've recently taken to calling it, {guhnoo} plus {loonix}. {loonix} is not an operating system unto itself, but rather another free component of a fully functioning {guhnoo} system made useful by the {guhnoo} corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX.
Many computer users run a modified version of the {guhnoo} system every day, without realizing it. Through a peculiar turn of events, the version of {guhnoo} which is widely used today is often called {loonix}, and many of its users are not aware that it is basically the {guhnoo} system, developed by the {guhnoo} Project.
There really is a {loonix}, and these people are using it, but it is just a part of the system they use. {loonix} is the kernel: the program in the system that allocates the machine's resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. {loonix} is normally used in combination with the {guhnoo} operating system: the whole system is basically {guhnoo} with {loonix} added, or {guhnoo}/{loonix}. All the so-called {loonix} distributions are really distributions of {guhnoo}/{loonix}."
).ConfigureAwait(false);
}
}

View File

@@ -11,22 +11,18 @@ public partial class Games
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Hangmanlist()
{
await SendConfirmAsync(
=> await SendConfirmAsync(
GetText(strs.hangman_types(Prefix)),
_service.GetHangmanTypes().JoinWith('\n'));
}
_service.GetHangmanTypes().Join('\n'));
private static string Draw(HangmanGame.State state)
{
return $@". ┌─────┐
=> $@". ┌─────┐
.┃...............┋
.┃...............┋
.┃{(state.Errors > 0 ? ".............😲" : "")}
.{(state.Errors > 1 ? "............./" : "")} {(state.Errors > 2 ? "|" : "")} {(state.Errors > 3 ? "\\" : "")}
.{(state.Errors > 4 ? "............../" : "")} {(state.Errors > 5 ? "\\" : "")}
/-\";
}
public static IEmbedBuilder GetEmbed(IEmbedBuilderService eb, HangmanGame.State state)
{
@@ -35,21 +31,21 @@ public partial class Games
.WithOkColor()
.AddField("Hangman", Draw(state))
.AddField("Guess", Format.Code(state.Word))
.WithFooter(state.missedLetters.JoinWith(' '));
.WithFooter(state.missedLetters.Join(' '));
if (state.Phase == HangmanGame.Phase.Ended && state.Failed)
return eb.Create()
.WithErrorColor()
.AddField("Hangman", Draw(state))
.AddField("Guess", Format.Code(state.Word))
.WithFooter(state.missedLetters.JoinWith(' '));
.WithFooter(state.missedLetters.Join(' '));
else
{
return eb.Create()
.WithOkColor()
.AddField("Hangman", Draw(state))
.AddField("Guess", Format.Code(state.Word))
.WithFooter(state.missedLetters.JoinWith(' '));
.WithFooter(state.missedLetters.Join(' '));
}
}

View File

@@ -11,9 +11,7 @@ public partial class Games
private readonly DiscordSocketClient _client;
public NunchiCommands(DiscordSocketClient client)
{
_client = client;
}
=> _client = client;
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
@@ -91,16 +89,12 @@ public partial class Games
}
private Task Nunchi_OnRoundStarted(NunchiGame arg, int cur)
{
return ConfirmLocalizedAsync(strs.nunchi_round_started(
=> ConfirmLocalizedAsync(strs.nunchi_round_started(
Format.Bold(arg.ParticipantCount.ToString()),
Format.Bold(cur.ToString())));
}
private Task Nunchi_OnUserGuessed(NunchiGame arg)
{
return ConfirmLocalizedAsync(strs.nunchi_next_number(Format.Bold(arg.CurrentNumber.ToString())));
}
=> ConfirmLocalizedAsync(strs.nunchi_next_number(Format.Bold(arg.CurrentNumber.ToString())));
private Task Nunchi_OnRoundEnded(NunchiGame arg1, (ulong Id, string Name)? arg2)
{
@@ -112,8 +106,6 @@ public partial class Games
}
private Task Nunchi_OnGameStarted(NunchiGame arg)
{
return ConfirmLocalizedAsync(strs.nunchi_started(Format.Bold(arg.ParticipantCount.ToString())));
}
=> ConfirmLocalizedAsync(strs.nunchi_started(Format.Bold(arg.ParticipantCount.ToString())));
}
}

View File

@@ -12,9 +12,7 @@ public partial class Games
private readonly DiscordSocketClient _client;
public PollCommands(DiscordSocketClient client)
{
_client = client;
}
=> _client = client;
[NadekoCommand, Aliases]
[UserPerm(GuildPerm.ManageMessages)]

View File

@@ -64,11 +64,11 @@ public class ChatterBotService : IEarlyBehavior
string message;
if (msg.Content.StartsWith(normalMention, StringComparison.InvariantCulture))
{
message = msg.Content.Substring(normalMention.Length).Trim();
message = msg.Content[normalMention.Length..].Trim();
}
else if (msg.Content.StartsWith(nickMention, StringComparison.InvariantCulture))
{
message = msg.Content.Substring(nickMention.Length).Trim();
message = msg.Content[nickMention.Length..].Trim();
}
else
{

View File

@@ -94,14 +94,12 @@ public class GamesService : INService
}
public string GetEightballResponse(ulong userId, string question)
{
return _8BallCache.GetOrCreate($"8ball:{userId}:{question}", e =>
=> _8BallCache.GetOrCreate($"8ball:{userId}:{question}", e =>
{
e.Size = question.Length;
e.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(12);
return EightBallResponses[_rng.Next(0, EightBallResponses.Count)];;
});
}
public TypingArticle RemoveTypingArticle(int index)
{

View File

@@ -12,9 +12,7 @@ public partial class Games
private readonly DiscordSocketClient _client;
public TicTacToeCommands(DiscordSocketClient client)
{
_client = client;
}
=> _client = client;
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]