Updated editorconfig to (mostly?) require braces around if/else statements, and applied the new formatting rules

This commit is contained in:
Kwoth
2022-02-02 01:44:45 +01:00
parent b22cd5a81e
commit ffa2c3f119
202 changed files with 2108 additions and 920 deletions

View File

@@ -127,7 +127,7 @@ public sealed class AcrophobiaGame : IDisposable
|| !_usersWhoVoted.Add(userId))
break;
++_submissions[toVoteFor];
_= Task.Run(() => OnUserVoted(userName));
_ = Task.Run(() => OnUserVoted(userName));
return true;
}

View File

@@ -48,7 +48,7 @@ public partial class Games
if (msg.Channel.Id != ctx.Channel.Id)
return Task.CompletedTask;
_= Task.Run(async () =>
_ = Task.Run(async () =>
{
try
{

View File

@@ -137,7 +137,7 @@ Message: {Content}",
usrMsg.Author,
usrMsg.Author.Id,
usrMsg.Content);
return true;
}
}

View File

@@ -11,10 +11,17 @@ public sealed partial class GamesConfig : ICloneable<GamesConfig>
public int Version { get; set; }
[Comment("Hangman related settings (.hangman command)")]
public HangmanConfig Hangman { get; set; } = new() { CurrencyReward = 0 };
public HangmanConfig Hangman { get; set; } = new()
{
CurrencyReward = 0
};
[Comment("Trivia related settings (.t command)")]
public TriviaConfig Trivia { get; set; } = new() { CurrencyReward = 0, MinimumWinReq = 1 };
public TriviaConfig Trivia { get; set; } = new()
{
CurrencyReward = 0,
MinimumWinReq = 1
};
[Comment("List of responses for the .8ball command. A random one will be selected every time")]
public List<string> EightBallResponses { get; set; } = new()
@@ -47,14 +54,46 @@ public sealed partial class GamesConfig : ICloneable<GamesConfig>
[Comment("List of animals which will be used for the animal race game (.race)")]
public List<RaceAnimal> RaceAnimals { get; set; } = new()
{
new() { Icon = "🐼", Name = "Panda" },
new() { Icon = "🐻", Name = "Bear" },
new() { Icon = "🐧", Name = "Pengu" },
new() { Icon = "🐨", Name = "Koala" },
new() { Icon = "🐬", Name = "Dolphin" },
new() { Icon = "🐞", Name = "Ladybird" },
new() { Icon = "🦀", Name = "Crab" },
new() { Icon = "🦄", Name = "Unicorn" }
new()
{
Icon = "🐼",
Name = "Panda"
},
new()
{
Icon = "🐻",
Name = "Bear"
},
new()
{
Icon = "🐧",
Name = "Pengu"
},
new()
{
Icon = "🐨",
Name = "Koala"
},
new()
{
Icon = "🐬",
Name = "Dolphin"
},
new()
{
Icon = "🐞",
Name = "Ladybird"
},
new()
{
Icon = "🦀",
Name = "Crab"
},
new()
{
Icon = "🦄",
Name = "Unicorn"
}
};
}

View File

@@ -38,7 +38,10 @@ public sealed class GamesConfigService : ConfigServiceBase<GamesConfig>
ModifyConfig(c =>
{
c.Version = 1;
c.Hangman = new() { CurrencyReward = 0 };
c.Hangman = new()
{
CurrencyReward = 0
};
});
}
}

View File

@@ -38,7 +38,10 @@ public class GamesService : INService
{
_gamesConfig = gamesConfig;
_httpFactory = httpFactory;
_8BallCache = new MemoryCache(new MemoryCacheOptions { SizeLimit = 500_000 });
_8BallCache = new MemoryCache(new MemoryCacheOptions
{
SizeLimit = 500_000
});
Ratings = new(GetRatingTexts);
_rng = new NadekoRandom();

View File

@@ -24,6 +24,7 @@ public sealed class DefaultHangmanSource : IHangmanSource
var qs = new Dictionary<string, HangmanTerm[]>();
foreach (var file in Directory.EnumerateFiles("data/hangman/", "*.yml"))
{
try
{
var data = Yaml.Deserializer.Deserialize<HangmanTerm[]>(File.ReadAllText(file));
@@ -33,6 +34,7 @@ public sealed class DefaultHangmanSource : IHangmanSource
{
Log.Error(ex, "Loading {HangmanFile} failed", file);
}
}
termsDict = qs;

View File

@@ -62,7 +62,8 @@ public partial class Games
[RequireContext(ContextType.Guild)]
public async partial Task HangmanStop()
{
if (await _service.StopHangman(ctx.Channel.Id)) await ReplyConfirmLocalizedAsync(strs.hangman_stopped);
if (await _service.StopHangman(ctx.Channel.Id))
await ReplyConfirmLocalizedAsync(strs.hangman_stopped);
}
}
}

View File

@@ -54,7 +54,8 @@ public sealed class HangmanService : IHangmanService, ILateExecutor
{
lock (_locker)
{
if (_hangmanGames.TryRemove(channelId, out _)) return new(true);
if (_hangmanGames.TryRemove(channelId, out _))
return new(true);
}
return new(false);
@@ -88,7 +89,10 @@ public sealed class HangmanService : IHangmanService, ILateExecutor
if (state.GuessResult is HangmanGame.GuessResult.Incorrect or HangmanGame.GuessResult.AlreadyTried)
_cdCache.Set(msg.Author.Id,
string.Empty,
new MemoryCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(3) });
new MemoryCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(3)
});
if (state.Phase == HangmanGame.Phase.Ended)
if (_hangmanGames.TryRemove(msg.Channel.Id, out _))

View File

@@ -85,7 +85,7 @@ public sealed class NunchiGame : IDisposable
KILL_TIMEOUT);
CurrentPhase = Phase.Playing;
_= OnGameStarted?.Invoke(this);
_ = OnGameStarted?.Invoke(this);
_ = OnRoundStarted?.Invoke(this, CurrentNumber);
return true;
}
@@ -122,7 +122,7 @@ public sealed class NunchiGame : IDisposable
{
killTimer.Change(Timeout.Infinite, Timeout.Infinite);
CurrentPhase = Phase.Ended;
_= OnGameEnded?.Invoke(this, userTuple.Name);
_ = OnGameEnded?.Invoke(this, userTuple.Name);
}
else // else just start the new round without the user who was the last
{

View File

@@ -55,7 +55,7 @@ public partial class Games
Task ClientMessageReceived(SocketMessage arg)
{
_= Task.Run(async () =>
_ = Task.Run(async () =>
{
if (arg.Channel.Id != ctx.Channel.Id)
return;

View File

@@ -39,11 +39,15 @@ public class PollRunner
if (usr is null)
return false;
voteObj = new() { UserId = msg.Author.Id, VoteIndex = vote };
voteObj = new()
{
UserId = msg.Author.Id,
VoteIndex = vote
};
if (!Poll.Votes.Add(voteObj))
return false;
_= OnVoted?.Invoke(msg, usr);
_ = OnVoted?.Invoke(msg, usr);
}
finally { _locker.Release(); }

View File

@@ -44,7 +44,11 @@ public class PollService : IEarlyBehavior
if (data.Length < 3)
return null;
var col = new IndexedCollection<PollAnswer>(data.Skip(1).Select(x => new PollAnswer { Text = x }));
var col = new IndexedCollection<PollAnswer>(data.Skip(1)
.Select(x => new PollAnswer
{
Text = x
}));
return new()
{

View File

@@ -89,7 +89,8 @@ public partial class Games
{
var removed = _service.RemoveTypingArticle(--index);
if (removed is null) return;
if (removed is null)
return;
var embed = _eb.Create()
.WithTitle($"Removed typing article #{index + 1}")

View File

@@ -41,7 +41,8 @@ public class TypingGame
public async Task<bool> Stop()
{
if (!IsActive) return false;
if (!IsActive)
return false;
_client.MessageReceived -= AnswerReceived;
_finishedUserIds.Clear();
IsActive = false;
@@ -60,7 +61,8 @@ public class TypingGame
public async Task Start()
{
if (IsActive) return; // can't start running game
if (IsActive)
return; // can't start running game
IsActive = true;
CurrentSentence = GetRandomSentence();
var i = (int)(CurrentSentence.Length / WORD_VALUE * 1.7f);
@@ -73,7 +75,10 @@ public class TypingGame
var time = _options.StartTime;
var msg = await Channel.SendMessageAsync($"Starting new typing contest in **{time}**...",
options: new() { RetryMode = RetryMode.AlwaysRetry });
options: new()
{
RetryMode = RetryMode.AlwaysRetry
});
do
{
@@ -117,7 +122,7 @@ public class TypingGame
private Task AnswerReceived(SocketMessage imsg)
{
_= Task.Run(async () =>
_ = Task.Run(async () =>
{
try
{
@@ -126,7 +131,8 @@ public class TypingGame
if (imsg is not SocketUserMessage msg)
return;
if (Channel is null || Channel.Id != msg.Channel.Id) return;
if (Channel is null || Channel.Id != msg.Channel.Id)
return;
var guess = msg.Content;

View File

@@ -175,14 +175,17 @@ public class TicTacToe
{
for (var i = 0; i < 3; i++)
for (var j = 0; j < 3; j++)
{
if (_state[i, j] is null)
return false;
}
return true;
}
private Task Client_MessageReceived(SocketMessage msg)
{
_= Task.Run(async () =>
_ = Task.Run(async () =>
{
await _moveLock.WaitAsync();
try
@@ -266,7 +269,8 @@ public class TicTacToe
try
{
if (del2 is not null) await del2;
if (del2 is not null)
await del2;
}
catch { }
});

View File

@@ -28,7 +28,7 @@ public partial class Games
{
if (_service.TicTacToeGames.TryGetValue(channel.Id, out var game))
{
_= Task.Run(async () =>
_ = Task.Run(async () =>
{
await game.Start((IGuildUser)ctx.User);
});

View File

@@ -40,7 +40,8 @@ public partial class Games
var (opts, _) = OptionsParser.ParseFrom(new TriviaOptions(), args);
var config = _gamesConfig.Data;
if (config.Trivia.MinimumWinReq > 0 && config.Trivia.MinimumWinReq > opts.WinRequirement) return;
if (config.Trivia.MinimumWinReq > 0 && config.Trivia.MinimumWinReq > opts.WinRequirement)
return;
var trivia = new TriviaGame(Strings,
_client,

View File

@@ -198,7 +198,7 @@ public class TriviaGame
private Task PotentialGuess(SocketMessage imsg)
{
_= Task.Run(async () =>
_ = Task.Run(async () =>
{
try
{
@@ -226,7 +226,8 @@ public class TriviaGame
}
finally { _guessLock.Release(); }
if (!guess) return;
if (!guess)
return;
triviaCancelSource.Cancel();

View File

@@ -11,7 +11,10 @@ public class TriviaQuestion
//represents the min size to judge levDistance with
private static readonly HashSet<Tuple<int, int>> _strictness = new()
{
new(9, 0), new(14, 1), new(19, 2), new(22, 3)
new(9, 0),
new(14, 1),
new(19, 2),
new(22, 3)
};
public string Category { get; set; }
@@ -44,9 +47,11 @@ public class TriviaQuestion
public bool IsAnswerCorrect(string guess)
{
if (Answer.Equals(guess, StringComparison.InvariantCulture)) return true;
if (Answer.Equals(guess, StringComparison.InvariantCulture))
return true;
var cleanGuess = Clean(guess);
if (CleanAnswer.Equals(cleanGuess, StringComparison.InvariantCulture)) return true;
if (CleanAnswer.Equals(cleanGuess, StringComparison.InvariantCulture))
return true;
var levDistanceClean = CleanAnswer.LevenshteinDistance(cleanGuess);
var levDistanceNormal = Answer.LevenshteinDistance(guess);
@@ -57,12 +62,14 @@ public class TriviaQuestion
private static bool JudgeGuess(int guessLength, int answerLength, int levDistance)
{
foreach (var level in _strictness)
{
if (guessLength <= level.Item1 || answerLength <= level.Item1)
{
if (levDistance <= level.Item2)
return true;
return false;
}
}
return false;
}

View File

@@ -37,7 +37,7 @@ public class TriviaQuestionPool
TriviaQuestion randomQuestion;
while (exclude.Contains(randomQuestion = Pool[_rng.Next(0, Pool.Length)]))
{
{
// if too many questions are excluded, clear the exclusion list and start over
if (exclude.Count > Pool.Length / 10 * 9)
{