mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
More target-typed new and redundant paranthesis cleanup
This commit is contained in:
@@ -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())
|
||||
{
|
||||
|
@@ -60,7 +60,7 @@ public sealed class AcrophobiaGame : IDisposable
|
||||
public AcrophobiaGame(Options options)
|
||||
{
|
||||
Opts = options;
|
||||
_rng = new NadekoRandom();
|
||||
_rng = new();
|
||||
InitializeStartingLetters();
|
||||
}
|
||||
|
||||
|
@@ -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()
|
||||
|
@@ -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();
|
||||
|
@@ -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
|
||||
|
@@ -43,7 +43,7 @@ public class PollRunner
|
||||
if (usr is null)
|
||||
return false;
|
||||
|
||||
voteObj = new PollVote()
|
||||
voteObj = new()
|
||||
{
|
||||
UserId = msg.Author.Id,
|
||||
VoteIndex = vote,
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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",
|
||||
|
@@ -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);
|
||||
|
@@ -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]
|
||||
|
@@ -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)));
|
||||
|
@@ -31,7 +31,7 @@ public sealed class GamesConfigService : ConfigServiceBase<GamesConfig>
|
||||
ModifyConfig(c =>
|
||||
{
|
||||
c.Version = 1;
|
||||
c.Hangman = new HangmanConfig()
|
||||
c.Hangman = new()
|
||||
{
|
||||
CurrencyReward = 0
|
||||
};
|
||||
|
@@ -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}.",
|
||||
|
@@ -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()
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user