Kotz's editorconfig styles slightly modified. Target typed new usage. Brackets in expressions used for clarity.

This commit is contained in:
Kwoth
2021-12-26 02:52:09 +01:00
parent 68741ec484
commit d18f9429c6
172 changed files with 921 additions and 494 deletions

View File

@@ -41,8 +41,8 @@ public sealed class AcrophobiaGame : IDisposable
public Phase CurrentPhase { get; private set; } = Phase.Submission;
public ImmutableArray<char> StartingLetters { get; private set; }
private readonly Dictionary<AcrophobiaUser, int> submissions = new Dictionary<AcrophobiaUser, int>();
private readonly SemaphoreSlim locker = new SemaphoreSlim(1, 1);
private readonly Dictionary<AcrophobiaUser, int> submissions = new();
private readonly SemaphoreSlim locker = new(1, 1);
public Options Opts { get; }
private readonly NadekoRandom _rng;
@@ -51,7 +51,7 @@ public sealed class AcrophobiaGame : IDisposable
public event Func<string, Task> OnUserVoted = delegate { return Task.CompletedTask; };
public event Func<AcrophobiaGame, ImmutableArray<KeyValuePair<AcrophobiaUser, int>>, Task> OnEnded = delegate { return Task.CompletedTask; };
private readonly HashSet<ulong> _usersWhoVoted = new HashSet<ulong>();
private readonly HashSet<ulong> _usersWhoVoted = new();
public AcrophobiaGame(Options options)
{

View File

@@ -4,7 +4,7 @@ namespace NadekoBot.Modules.Games.Common.ChatterBot;
public class ChatterBotSession : IChatterBotSession
{
private static NadekoRandom Rng { get; } = new NadekoRandom();
private static NadekoRandom Rng { get; } = new();
private readonly string _chatterBotId;
private readonly IHttpClientFactory _httpFactory;

View File

@@ -57,7 +57,7 @@ public class CleverbotIOSession : IChatterBotSession
this._user = user;
this._httpFactory = factory;
_nick = new((Func<Task<string>>)GetNick);
_nick = new(GetNick);
}
private async Task<string> GetNick()

View File

@@ -10,20 +10,20 @@ public sealed partial class GamesConfig : ICloneable<GamesConfig>
public int Version { get; set; }
[Comment("Hangman related settings (.hangman command)")]
public HangmanConfig Hangman { get; set; } = new HangmanConfig()
public HangmanConfig Hangman { get; set; } = new()
{
CurrencyReward = 0
};
[Comment("Trivia related settings (.t command)")]
public TriviaConfig Trivia { get; set; } = new TriviaConfig()
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 List<string>()
public List<string> EightBallResponses { get; set; } = new()
{
"Most definitely yes.",
"For sure.",
@@ -51,16 +51,16 @@ 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 List<RaceAnimal>()
public List<RaceAnimal> RaceAnimals { get; set; } = new()
{
new RaceAnimal { Icon = "🐼", Name = "Panda" },
new RaceAnimal { Icon = "🐻", Name = "Bear" },
new RaceAnimal { Icon = "🐧", Name = "Pengu" },
new RaceAnimal { Icon = "🐨", Name = "Koala" },
new RaceAnimal { Icon = "🐬", Name = "Dolphin" },
new RaceAnimal { Icon = "🐞", Name = "Ladybird" },
new RaceAnimal { Icon = "🦀", Name = "Crab" },
new RaceAnimal { 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

@@ -36,8 +36,8 @@ public class GirlRating
const int miny = 385;
const int length = 345;
var pointx = (int)(minx + length * (Hot / 10));
var pointy = (int)(miny - length * ((Crazy - 4) / 6));
var pointx = (int)(minx + (length * (Hot / 10)));
var pointy = (int)(miny - (length * ((Crazy - 4) / 6)));
using (var pointImg = Image.Load(_images.RategirlDot))
{

View File

@@ -40,7 +40,7 @@ public sealed class HangmanGame
}
public State GetState(GuessResult guessResult = GuessResult.NoAction)
=> new State(_incorrect.Count,
=> new(_incorrect.Count,
CurrentPhase,
CurrentPhase == Phase.Ended
? _word
@@ -64,7 +64,7 @@ public sealed class HangmanGame
else
output[i*2] = '_';
output[i * 2 + 1] = ' ';
output[(i * 2) + 1] = ' ';
}
return new(output);

View File

@@ -21,10 +21,10 @@ public sealed class NunchiGame : IDisposable
public event Func<NunchiGame, (ulong Id, string Name)?, Task> OnRoundEnded; // tuple of the user who failed
public event Func<NunchiGame, string, Task> OnGameEnded; // name of the user who won
private readonly SemaphoreSlim _locker = new SemaphoreSlim(1, 1);
private readonly SemaphoreSlim _locker = new(1, 1);
private HashSet<(ulong Id, string Name)> _participants = new HashSet<(ulong Id, string Name)>();
private HashSet<(ulong Id, string Name)> _passed = new HashSet<(ulong Id, string Name)>();
private HashSet<(ulong Id, string Name)> _participants = new();
private readonly HashSet<(ulong Id, string Name)> _passed = new();
public ImmutableArray<(ulong Id, string Name)> Participants => _participants.ToImmutableArray();
public int ParticipantCount => _participants.Count;

View File

@@ -9,7 +9,7 @@ public class PollRunner
public event Func<IUserMessage, IGuildUser, Task> OnVoted;
private readonly SemaphoreSlim _locker = new SemaphoreSlim(1, 1);
private readonly SemaphoreSlim _locker = new(1, 1);
public PollRunner(DbService db, Poll poll)
{

View File

@@ -74,7 +74,7 @@ public class TicTacToe
{
for (var j = 0; j < _state.GetLength(1); j++)
{
sb.Append(_state[i, j] is null ? _numbers[i * 3 + j] : GetIcon(_state[i, j]));
sb.Append(_state[i, j] is null ? _numbers[(i * 3) + j] : GetIcon(_state[i, j]));
if (j < _state.GetLength(1) - 1)
sb.Append("┃");
}

View File

@@ -4,7 +4,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia;
public class TriviaGame
{
private readonly SemaphoreSlim _guessLock = new SemaphoreSlim(1, 1);
private readonly SemaphoreSlim _guessLock = new(1, 1);
private readonly IDataCache _cache;
private readonly IBotStrings _strings;
private readonly DiscordSocketClient _client;
@@ -18,9 +18,9 @@ public class TriviaGame
private CancellationTokenSource _triviaCancelSource;
public TriviaQuestion CurrentQuestion { get; private set; }
public HashSet<TriviaQuestion> OldQuestions { get; } = new HashSet<TriviaQuestion>();
public HashSet<TriviaQuestion> OldQuestions { get; } = new();
public ConcurrentDictionary<IGuildUser, int> Users { get; } = new ConcurrentDictionary<IGuildUser, int>();
public ConcurrentDictionary<IGuildUser, int> Users { get; } = new();
public bool GameActive { get; private set; }
public bool ShouldStopGame { get; private set; }

View File

@@ -6,11 +6,12 @@ namespace NadekoBot.Modules.Games.Common.Trivia;
public class TriviaQuestion
{
//represents the min size to judge levDistance with
private static readonly HashSet<Tuple<int, int>> strictness = new HashSet<Tuple<int, int>> {
new Tuple<int, int>(9, 0),
new Tuple<int, int>(14, 1),
new Tuple<int, int>(19, 2),
new Tuple<int, int>(22, 3),
private static readonly HashSet<Tuple<int, int>> strictness = new()
{
new(9, 0),
new(14, 1),
new(19, 2),
new(22, 3),
};
public const int maxStringLength = 22;

View File

@@ -5,7 +5,7 @@ public class TriviaQuestionPool
private readonly IDataCache _cache;
private readonly int maxPokemonId;
private readonly NadekoRandom _rng = new NadekoRandom();
private readonly NadekoRandom _rng = new();
private TriviaQuestion[] Pool => _cache.LocalData.TriviaQuestions;
private IReadOnlyDictionary<int, string> Map => _cache.LocalData.PokemonMap;

View File

@@ -11,7 +11,7 @@ public partial class Games : NadekoModule<GamesService>
{
private readonly IImageCache _images;
private readonly IHttpClientFactory _httpFactory;
private readonly Random _rng = new Random();
private readonly Random _rng = new();
public Games(IDataCache data, IHttpClientFactory factory)
{
@@ -79,7 +79,7 @@ public partial class Games : NadekoModule<GamesService>
private double NextDouble(double x, double y)
{
return _rng.NextDouble() * (y - x) + x;
return (_rng.NextDouble() * (y - x)) + x;
}
private GirlRating GetGirl(ulong uid)
@@ -102,19 +102,19 @@ public partial class Games : NadekoModule<GamesService>
else if (roll < 750)
{
hot = NextDouble(5, 8);
crazy = NextDouble(4, .6 * hot + 4);
crazy = NextDouble(4, (.6 * hot) + 4);
advice = ratings.Fun;
}
else if (roll < 900)
{
hot = NextDouble(5, 10);
crazy = NextDouble(.61 * hot + 4, 10);
crazy = NextDouble((.61 * hot) + 4, 10);
advice = ratings.Dan;
}
else if (roll < 951)
{
hot = NextDouble(8, 10);
crazy = NextDouble(7, .6 * hot + 4);
crazy = NextDouble(7, (.6 * hot) + 4);
advice = ratings.Dat;
}
else if (roll < 990)

View File

@@ -96,7 +96,7 @@ public class ChatterBotService : IEarlyBehavior
public async Task<bool> RunBehavior(IGuild guild, IUserMessage usrMsg)
{
if (!(guild is SocketGuild sg))
if (guild is not SocketGuild sg)
return false;
try
{
@@ -113,7 +113,7 @@ public class ChatterBotService : IEarlyBehavior
if (pc.Verbose)
{
var returnMsg = _strings.GetText(strs.perm_prevent(index + 1,
Format.Bold(pc.Permissions[index].GetCommand(_cmd.GetPrefix(guild), (SocketGuild)guild))));
Format.Bold(pc.Permissions[index].GetCommand(_cmd.GetPrefix(sg), sg))));
try { await usrMsg.Channel.SendErrorAsync(_eb, returnMsg).ConfigureAwait(false); } catch { }
Log.Information(returnMsg);

View File

@@ -7,7 +7,7 @@ public sealed class GamesConfigService : ConfigServiceBase<GamesConfig>
{
public override string Name { get; } = "games";
private const string FilePath = "data/games.yml";
private static TypedKey<GamesConfig> changeKey = new TypedKey<GamesConfig>("config.games.updated");
private static readonly TypedKey<GamesConfig> changeKey = new("config.games.updated");
public GamesConfigService(IConfigSeria serializer, IPubSub pubSub)
: base(FilePath, serializer, pubSub, changeKey)

View File

@@ -11,7 +11,7 @@ public class GamesService : INService
{
private readonly GamesConfigService _gamesConfig;
public ConcurrentDictionary<ulong, GirlRating> GirlRatings { get; } = new ConcurrentDictionary<ulong, GirlRating>();
public ConcurrentDictionary<ulong, GirlRating> GirlRatings { get; } = new();
public IReadOnlyList<string> EightBallResponses => _gamesConfig.Data.EightBallResponses;
@@ -22,14 +22,14 @@ public class GamesService : INService
private const string TypingArticlesPath = "data/typing_articles3.json";
public List<TypingArticle> TypingArticles { get; } = new List<TypingArticle>();
public List<TypingArticle> TypingArticles { get; } = new();
//channelId, game
public ConcurrentDictionary<ulong, AcrophobiaGame> AcrophobiaGames { get; } = new ConcurrentDictionary<ulong, AcrophobiaGame>();
public ConcurrentDictionary<ulong, TriviaGame> RunningTrivias { get; } = new ConcurrentDictionary<ulong, TriviaGame>();
public Dictionary<ulong, TicTacToe> TicTacToeGames { get; } = new Dictionary<ulong, TicTacToe>();
public ConcurrentDictionary<ulong, TypingGame> RunningContests { get; } = new ConcurrentDictionary<ulong, TypingGame>();
public ConcurrentDictionary<ulong, NunchiGame> NunchiGames { get; } = new ConcurrentDictionary<ulong, NunchiGame>();
public ConcurrentDictionary<ulong, AcrophobiaGame> AcrophobiaGames { get; } = new();
public ConcurrentDictionary<ulong, TriviaGame> RunningTrivias { get; } = new();
public Dictionary<ulong, TicTacToe> TicTacToeGames { get; } = new();
public ConcurrentDictionary<ulong, TypingGame> RunningContests { get; } = new();
public ConcurrentDictionary<ulong, NunchiGame> NunchiGames { get; } = new();
public AsyncLazy<RatingTexts> Ratings { get; }

View File

@@ -8,7 +8,7 @@ namespace NadekoBot.Modules.Games.Services;
public class PollService : IEarlyBehavior
{
public ConcurrentDictionary<ulong, PollRunner> ActivePolls { get; } = new ConcurrentDictionary<ulong, PollRunner>();
public ConcurrentDictionary<ulong, PollRunner> ActivePolls { get; } = new();
public int Priority => 5;

View File

@@ -8,7 +8,7 @@ public partial class Games
[Group]
public class TicTacToeCommands : NadekoSubmodule<GamesService>
{
private readonly SemaphoreSlim _sem = new SemaphoreSlim(1, 1);
private readonly SemaphoreSlim _sem = new(1, 1);
private readonly DiscordSocketClient _client;
public TicTacToeCommands(DiscordSocketClient client)