More target-typed new and redundant paranthesis cleanup

This commit is contained in:
Kwoth
2021-12-20 00:33:11 +01:00
parent 345a9e9524
commit 1b2017024c
152 changed files with 573 additions and 580 deletions

View File

@@ -41,7 +41,7 @@ public partial class Games
return;
}
_service.ChatterBotGuilds.TryAdd(channel.Guild.Id, new Lazy<IChatterBotSession>(() => _service.CreateSession(), true));
_service.ChatterBotGuilds.TryAdd(channel.Guild.Id, new(() => _service.CreateSession(), true));
using (var uow = _db.GetDbContext())
{

View File

@@ -60,7 +60,7 @@ public sealed class AcrophobiaGame : IDisposable
public AcrophobiaGame(Options options)
{
Opts = options;
_rng = new NadekoRandom();
_rng = new();
InitializeStartingLetters();
}

View File

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

View File

@@ -30,7 +30,7 @@ public class GirlRating
Advice = advice; // convenient to have it here, even though atm there are only few different ones.
_httpFactory = factory;
Stream = new AsyncLazy<Stream>(() =>
Stream = new(() =>
{
try
{
@@ -45,7 +45,7 @@ public class GirlRating
using (var pointImg = Image.Load(_images.RategirlDot))
{
img.Mutate(x => x.DrawImage(pointImg, new Point(pointx - 10, pointy - 10), new GraphicsOptions()));
img.Mutate(x => x.DrawImage(pointImg, new(pointx - 10, pointy - 10), new GraphicsOptions()));
}
var imgStream = new MemoryStream();

View File

@@ -67,7 +67,7 @@ public sealed class NunchiGame : IDisposable
return false;
}
_killTimer = new Timer(async state =>
_killTimer = new(async state =>
{
await _locker.WaitAsync().ConfigureAwait(false);
try

View File

@@ -43,7 +43,7 @@ public class PollRunner
if (usr is null)
return false;
voteObj = new PollVote()
voteObj = new()
{
UserId = msg.Author.Id,
VoteIndex = vote,

View File

@@ -68,7 +68,7 @@ public class TicTacToe
};
_phase = Phase.Starting;
_moveLock = new SemaphoreSlim(1, 1);
_moveLock = new(1, 1);
}
private string GetText(LocStr key)
@@ -149,7 +149,7 @@ public class TicTacToe
_phase = Phase.Started;
_timeoutTimer = new Timer(async (_) =>
_timeoutTimer = new(async _ =>
{
await _moveLock.WaitAsync().ConfigureAwait(false);
try

View File

@@ -43,7 +43,7 @@ public class TriviaGame
TriviaOptions options, string quitCommand, IEmbedBuilderService eb)
{
_cache = cache;
_questionPool = new TriviaQuestionPool(_cache);
_questionPool = new(_cache);
_strings = strings;
_client = client;
_config = config;
@@ -65,7 +65,7 @@ public class TriviaGame
while (!ShouldStopGame)
{
// reset the cancellation source
_triviaCancelSource = new CancellationTokenSource();
_triviaCancelSource = new();
showHowToQuit = !showHowToQuit;
// load question

View File

@@ -28,7 +28,7 @@ public class TriviaQuestionPool
if (isPokemon)
{
var num = _rng.Next(1, maxPokemonId + 1);
return new TriviaQuestion("Who's That Pokémon?",
return new("Who's That Pokémon?",
Map[num].ToTitleCase(),
"Pokemon",
$@"https://nadeko.bot/images/pokemon/shadows/{num}.png",

View File

@@ -47,8 +47,8 @@ public class TypingGame
this.Channel = channel;
IsActive = false;
sw = new Stopwatch();
finishedUserIds = new List<ulong>();
sw = new();
finishedUserIds = new();
}
public async Task<bool> Stop()
@@ -85,7 +85,7 @@ public class TypingGame
var time = _options.StartTime;
var msg = await Channel.SendMessageAsync($"Starting new typing contest in **{time}**...", options: new RequestOptions()
var msg = await Channel.SendMessageAsync($"Starting new typing contest in **{time}**...", options: new()
{
RetryMode = RetryMode.AlwaysRetry
}).ConfigureAwait(false);

View File

@@ -145,7 +145,7 @@ public partial class Games : NadekoModule<GamesService>
advice = ratings.Uni;
}
return new GirlRating(_images, _httpFactory, crazy, hot, roll, advice);
return new(_images, _httpFactory, crazy, hot, roll, advice);
}
[NadekoCommand, Aliases]

View File

@@ -38,7 +38,7 @@ public class ChatterBotService : IEarlyBehavior
_eb = eb;
_httpFactory = factory;
ChatterBotGuilds = new ConcurrentDictionary<ulong, Lazy<IChatterBotSession>>(
ChatterBotGuilds = new(
bot.AllGuildConfigs
.Where(gc => gc.CleverbotEnabled)
.ToDictionary(gc => gc.GuildId, gc => new Lazy<IChatterBotSession>(() => CreateSession(), true)));

View File

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

View File

@@ -62,11 +62,11 @@ public class GamesService : INService
SizeLimit = 500_000
});
Ratings = new AsyncLazy<RatingTexts>(GetRatingTexts);
Ratings = new(GetRatingTexts);
_rng = new NadekoRandom();
//girl ratings
_t = new Timer((_) =>
_t = new(_ =>
{
GirlRatings.Clear();
@@ -79,7 +79,7 @@ public class GamesService : INService
catch (Exception ex)
{
Log.Warning("Error while loading typing articles {0}", ex.ToString());
TypingArticles = new List<TypingArticle>();
TypingArticles = new();
}
}
@@ -94,7 +94,7 @@ public class GamesService : INService
public void AddTypingArticle(IUser user, string text)
{
TypingArticles.Add(new TypingArticle
TypingArticles.Add(new()
{
Source = user.ToString(),
Extra = $"Text added on {DateTime.UtcNow} by {user}.",

View File

@@ -51,13 +51,13 @@ public class PollService : IEarlyBehavior
var col = new IndexedCollection<PollAnswer>(data.Skip(1)
.Select(x => new PollAnswer() { Text = x }));
return new Poll()
return new()
{
Answers = col,
Question = data[0],
ChannelId = channelId,
GuildId = guildId,
Votes = new System.Collections.Generic.HashSet<PollVote>()
Votes = new()
};
}

View File

@@ -32,7 +32,7 @@ public partial class Games
var (options, _) = OptionsParser.ParseFrom(new TypingGame.Options(), args);
var channel = (ITextChannel)ctx.Channel;
var game = _service.RunningContests.GetOrAdd(ctx.Guild.Id, id => new TypingGame(_games, _client, channel, Prefix, options, _eb));
var game = _service.RunningContests.GetOrAdd(ctx.Guild.Id, id => new(_games, _client, channel, Prefix, options, _eb));
if (game.IsActive)
{

View File

@@ -42,11 +42,11 @@ public partial class Games
});
return;
}
game = new TicTacToe(base.Strings, this._client, channel, (IGuildUser)ctx.User, options, _eb);
game = new(base.Strings, this._client, channel, (IGuildUser)ctx.User, options, _eb);
_service.TicTacToeGames.Add(channel.Id, game);
await ReplyConfirmLocalizedAsync(strs.ttt_created).ConfigureAwait(false);
game.OnEnded += (g) =>
game.OnEnded += g =>
{
_service.TicTacToeGames.Remove(channel.Id);
_sem.Dispose();