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:
@@ -53,7 +53,7 @@ public class CommandHandler : INService
|
||||
_db = db;
|
||||
_services = services;
|
||||
|
||||
_clearUsersOnShortCooldown = new Timer(_ =>
|
||||
_clearUsersOnShortCooldown = new(_ =>
|
||||
{
|
||||
UsersOnShortCooldown.Clear();
|
||||
}, null, GlobalCommandsCooldown, GlobalCommandsCooldown);
|
||||
@@ -129,7 +129,7 @@ public class CommandHandler : INService
|
||||
|
||||
public Task StartHandling()
|
||||
{
|
||||
_client.MessageReceived += (msg) => { var _ = Task.Run(() => MessageReceivedHandler(msg)); return Task.CompletedTask; };
|
||||
_client.MessageReceived += msg => { var _ = Task.Run(() => MessageReceivedHandler(msg)); return Task.CompletedTask; };
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ public class CommandHandler : INService
|
||||
// execute the command and measure the time it took
|
||||
if (messageContent.StartsWith(prefix, StringComparison.InvariantCulture) || isPrefixCommand)
|
||||
{
|
||||
var (Success, Error, Info) = await ExecuteCommandAsync(new CommandContext(_client, usrMsg), messageContent, isPrefixCommand ? 1 : prefix.Length, _services, MultiMatchHandling.Best).ConfigureAwait(false);
|
||||
var (Success, Error, Info) = await ExecuteCommandAsync(new(_client, usrMsg), messageContent, isPrefixCommand ? 1 : prefix.Length, _services, MultiMatchHandling.Best).ConfigureAwait(false);
|
||||
startTime = Environment.TickCount - startTime;
|
||||
|
||||
if (Success)
|
||||
|
@@ -7,7 +7,7 @@ public class GreetGrouper<T>
|
||||
|
||||
public GreetGrouper()
|
||||
{
|
||||
group = new Dictionary<ulong, HashSet<T>>();
|
||||
group = new();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class GreetGrouper<T>
|
||||
return false;
|
||||
}
|
||||
|
||||
group[guildId] = new HashSet<T>();
|
||||
group[guildId] = new();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ public class DbService
|
||||
optionsBuilder.UseSqlite(builder.ToString());
|
||||
options = optionsBuilder.Options;
|
||||
|
||||
optionsBuilder = new DbContextOptionsBuilder<NadekoContext>();
|
||||
optionsBuilder = new();
|
||||
optionsBuilder.UseSqlite(builder.ToString());
|
||||
migrateOptions = optionsBuilder.Options;
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ public class GreetSettingsService : INService
|
||||
_bss = bss;
|
||||
_eb = eb;
|
||||
|
||||
GuildConfigsCache = new ConcurrentDictionary<ulong, GreetSettings>(
|
||||
GuildConfigsCache = new(
|
||||
bot.AllGuildConfigs
|
||||
.ToDictionary(g => g.GuildId, GreetSettings.Create));
|
||||
|
||||
@@ -51,8 +51,8 @@ public class GreetSettingsService : INService
|
||||
// if user is a new booster
|
||||
// or boosted again the same server
|
||||
if ((oldUser is { PremiumSince: null } && newUser is { PremiumSince: not null })
|
||||
|| (oldUser?.PremiumSince is DateTimeOffset oldDate
|
||||
&& newUser?.PremiumSince is DateTimeOffset newDate
|
||||
|| (oldUser?.PremiumSince is { } oldDate
|
||||
&& newUser?.PremiumSince is { } newDate
|
||||
&& newDate > oldDate))
|
||||
{
|
||||
var conf = GetOrAddSettingsForGuild(newUser.Guild.Id);
|
||||
|
@@ -51,7 +51,7 @@ public sealed class BotCredsProvider : IBotCredsProvider
|
||||
{
|
||||
if (Environment.OSVersion.Platform == PlatformID.Unix)
|
||||
{
|
||||
_creds.RestartCommand = new RestartConfig()
|
||||
_creds.RestartCommand = new()
|
||||
{
|
||||
Args = "dotnet",
|
||||
Cmd = "NadekoBot.dll -- {0}",
|
||||
@@ -59,7 +59,7 @@ public sealed class BotCredsProvider : IBotCredsProvider
|
||||
}
|
||||
else
|
||||
{
|
||||
_creds.RestartCommand = new RestartConfig()
|
||||
_creds.RestartCommand = new()
|
||||
{
|
||||
Args = "NadekoBot.exe",
|
||||
Cmd = "{0}",
|
||||
@@ -141,7 +141,7 @@ public sealed class BotCredsProvider : IBotCredsProvider
|
||||
OsuApiKey = oldCreds.OsuApiKey,
|
||||
CleverbotApiKey = oldCreds.CleverbotApiKey,
|
||||
TotalShards = oldCreds.TotalShards <= 1 ? 1 : oldCreds.TotalShards,
|
||||
Patreon = new Creds.PatreonSettings(oldCreds.PatreonAccessToken,
|
||||
Patreon = new(oldCreds.PatreonAccessToken,
|
||||
null,
|
||||
null,
|
||||
oldCreds.PatreonCampaignId),
|
||||
|
@@ -9,12 +9,12 @@ public class FontProvider : INService
|
||||
|
||||
public FontProvider()
|
||||
{
|
||||
_fonts = new FontCollection();
|
||||
_fonts = new();
|
||||
|
||||
NotoSans = _fonts.Install("data/fonts/NotoSans-Bold.ttf");
|
||||
UniSans = _fonts.Install("data/fonts/Uni Sans.ttf");
|
||||
|
||||
FallBackFonts = new List<FontFamily>();
|
||||
FallBackFonts = new();
|
||||
|
||||
//FallBackFonts.Add(_fonts.Install("data/fonts/OpenSansEmoji.ttf"));
|
||||
|
||||
|
@@ -33,9 +33,9 @@ public class GoogleApiService : IGoogleApiService, INService
|
||||
ApiKey = _creds.GoogleApiKey,
|
||||
};
|
||||
|
||||
yt = new YouTubeService(bcs);
|
||||
sh = new UrlshortenerService(bcs);
|
||||
cs = new CustomsearchService(bcs);
|
||||
yt = new(bcs);
|
||||
sh = new(bcs);
|
||||
cs = new(bcs);
|
||||
}
|
||||
private static readonly Regex plRegex = new Regex("(?:youtu\\.be\\/|list=)(?<id>[\\da-zA-Z\\-_]*)", RegexOptions.Compiled);
|
||||
public async Task<IEnumerable<string>> GetPlaylistIdsByKeywordsAsync(string keywords, int count = 1)
|
||||
@@ -126,7 +126,7 @@ public class GoogleApiService : IGoogleApiService, INService
|
||||
|
||||
try
|
||||
{
|
||||
var response = await sh.Url.Insert(new Url { LongUrl = url }).ExecuteAsync().ConfigureAwait(false);
|
||||
var response = await sh.Url.Insert(new() { LongUrl = url }).ExecuteAsync().ConfigureAwait(false);
|
||||
return response.Id;
|
||||
}
|
||||
catch (GoogleApiException ex) when (ex.HttpStatusCode == HttpStatusCode.Forbidden)
|
||||
@@ -219,7 +219,7 @@ public class GoogleApiService : IGoogleApiService, INService
|
||||
|
||||
var search = await req.ExecuteAsync().ConfigureAwait(false);
|
||||
|
||||
return new ImageResult(search.Items[0].Image, search.Items[0].Link);
|
||||
return new(search.Items[0].Image, search.Items[0].Link);
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<string, string> Languages { get; } = new Dictionary<string, string>() {
|
||||
|
@@ -28,14 +28,14 @@ public class Localization : ILocalization, INService
|
||||
var cultureInfoNames = bot.AllGuildConfigs
|
||||
.ToDictionary(x => x.GuildId, x => x.Locale);
|
||||
|
||||
GuildCultureInfos = new ConcurrentDictionary<ulong, CultureInfo>(cultureInfoNames.ToDictionary(x => x.Key, x =>
|
||||
GuildCultureInfos = new(cultureInfoNames.ToDictionary(x => x.Key, x =>
|
||||
{
|
||||
CultureInfo cultureInfo = null;
|
||||
try
|
||||
{
|
||||
if (x.Value is null)
|
||||
return null;
|
||||
cultureInfo = new CultureInfo(x.Value);
|
||||
cultureInfo = new(x.Value);
|
||||
}
|
||||
catch { }
|
||||
return cultureInfo;
|
||||
@@ -107,7 +107,7 @@ public class Localization : ILocalization, INService
|
||||
_commandData.TryGetValue(key, out var toReturn);
|
||||
|
||||
if (toReturn is null)
|
||||
return new CommandData
|
||||
return new()
|
||||
{
|
||||
Cmd = key,
|
||||
Desc = key,
|
||||
|
@@ -92,7 +92,7 @@ public sealed class RedisImagesCache : IImageCache, IReadyExecutor
|
||||
{
|
||||
_con = con;
|
||||
_creds = creds;
|
||||
_http = new HttpClient();
|
||||
_http = new();
|
||||
_imagesPath = Path.Combine(_basePath, "images.yml");
|
||||
|
||||
Migrate();
|
||||
@@ -115,7 +115,7 @@ public sealed class RedisImagesCache : IImageCache, IReadyExecutor
|
||||
{
|
||||
var newData = new ImageUrls()
|
||||
{
|
||||
Coins = new ImageUrls.CoinData()
|
||||
Coins = new()
|
||||
{
|
||||
Heads = oldData.Coins.Heads.Length == 1 &&
|
||||
oldData.Coins.Heads[0].ToString() == "https://nadeko-pictures.nyc3.digitaloceanspaces.com/other/coins/heads.png"
|
||||
@@ -128,19 +128,19 @@ public sealed class RedisImagesCache : IImageCache, IReadyExecutor
|
||||
},
|
||||
Dice = oldData.Dice.Map(x => x.ToNewCdn()),
|
||||
Currency = oldData.Currency.Map(x => x.ToNewCdn()),
|
||||
Rategirl = new ImageUrls.RategirlData()
|
||||
Rategirl = new()
|
||||
{
|
||||
Dot = oldData.Rategirl.Dot.ToNewCdn(),
|
||||
Matrix = oldData.Rategirl.Matrix.ToNewCdn()
|
||||
},
|
||||
Rip = new ImageUrls.RipData()
|
||||
Rip = new()
|
||||
{
|
||||
Bg = oldData.Rip.Bg.ToNewCdn(),
|
||||
Overlay = oldData.Rip.Overlay.ToNewCdn(),
|
||||
},
|
||||
Slots = new ImageUrls.SlotData()
|
||||
Slots = new()
|
||||
{
|
||||
Bg = new Uri("https://cdn.nadeko.bot/slots/slots_bg.png"),
|
||||
Bg = new("https://cdn.nadeko.bot/slots/slots_bg.png"),
|
||||
Emojis = new[]
|
||||
{
|
||||
"https://cdn.nadeko.bot/slots/0.png",
|
||||
@@ -151,7 +151,7 @@ public sealed class RedisImagesCache : IImageCache, IReadyExecutor
|
||||
"https://cdn.nadeko.bot/slots/5.png"
|
||||
}.Map(x => new Uri(x))
|
||||
},
|
||||
Xp = new ImageUrls.XpData()
|
||||
Xp = new()
|
||||
{
|
||||
Bg = oldData.Xp.Bg.ToNewCdn(),
|
||||
},
|
||||
|
@@ -26,7 +26,7 @@ public class RemoteGrpcCoordinator : ICoordinator, IReadyExecutor
|
||||
|
||||
public bool RestartBot()
|
||||
{
|
||||
_coordClient.RestartAllShards(new RestartAllRequest
|
||||
_coordClient.RestartAllShards(new()
|
||||
{
|
||||
|
||||
});
|
||||
@@ -36,7 +36,7 @@ public class RemoteGrpcCoordinator : ICoordinator, IReadyExecutor
|
||||
|
||||
public void Die(bool graceful)
|
||||
{
|
||||
_coordClient.Die(new DieRequest()
|
||||
_coordClient.Die(new()
|
||||
{
|
||||
Graceful = graceful
|
||||
});
|
||||
@@ -44,7 +44,7 @@ public class RemoteGrpcCoordinator : ICoordinator, IReadyExecutor
|
||||
|
||||
public bool RestartShard(int shardId)
|
||||
{
|
||||
_coordClient.RestartShard(new RestartShardRequest
|
||||
_coordClient.RestartShard(new()
|
||||
{
|
||||
ShardId = shardId,
|
||||
});
|
||||
@@ -54,7 +54,7 @@ public class RemoteGrpcCoordinator : ICoordinator, IReadyExecutor
|
||||
|
||||
public IList<ShardStatus> GetAllShardStatuses()
|
||||
{
|
||||
var res = _coordClient.GetAllStatuses(new GetAllStatusesRequest());
|
||||
var res = _coordClient.GetAllStatuses(new());
|
||||
|
||||
return res.Statuses
|
||||
.ToArray()
|
||||
@@ -69,7 +69,7 @@ public class RemoteGrpcCoordinator : ICoordinator, IReadyExecutor
|
||||
|
||||
public int GetGuildCount()
|
||||
{
|
||||
var res = _coordClient.GetAllStatuses(new GetAllStatusesRequest());
|
||||
var res = _coordClient.GetAllStatuses(new());
|
||||
|
||||
return res.Statuses.Sum(x => x.GuildCount);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class RemoteGrpcCoordinator : ICoordinator, IReadyExecutor
|
||||
{
|
||||
try
|
||||
{
|
||||
var reply = await _coordClient.HeartbeatAsync(new HeartbeatRequest
|
||||
var reply = await _coordClient.HeartbeatAsync(new()
|
||||
{
|
||||
State = ToCoordConnState(_client.ConnectionState),
|
||||
GuildCount = _client.ConnectionState == ConnectionState.Connected ? _client.Guilds.Count : 0,
|
||||
|
@@ -44,7 +44,7 @@ public class StatsService : IStatsService, IReadyExecutor, INService, IDisposabl
|
||||
_client.MessageReceived += _ => Task.FromResult(Interlocked.Increment(ref _messageCounter));
|
||||
cmdHandler.CommandExecuted += (_, e) => Task.FromResult(Interlocked.Increment(ref _commandsRan));
|
||||
|
||||
_client.ChannelCreated += (c) =>
|
||||
_client.ChannelCreated += c =>
|
||||
{
|
||||
var _ = Task.Run(() =>
|
||||
{
|
||||
@@ -57,7 +57,7 @@ public class StatsService : IStatsService, IReadyExecutor, INService, IDisposabl
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
_client.ChannelDestroyed += (c) =>
|
||||
_client.ChannelDestroyed += c =>
|
||||
{
|
||||
var _ = Task.Run(() =>
|
||||
{
|
||||
@@ -70,7 +70,7 @@ public class StatsService : IStatsService, IReadyExecutor, INService, IDisposabl
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
_client.GuildAvailable += (g) =>
|
||||
_client.GuildAvailable += g =>
|
||||
{
|
||||
var _ = Task.Run(() =>
|
||||
{
|
||||
@@ -82,7 +82,7 @@ public class StatsService : IStatsService, IReadyExecutor, INService, IDisposabl
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
_client.JoinedGuild += (g) =>
|
||||
_client.JoinedGuild += g =>
|
||||
{
|
||||
var _ = Task.Run(() =>
|
||||
{
|
||||
@@ -94,7 +94,7 @@ public class StatsService : IStatsService, IReadyExecutor, INService, IDisposabl
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
_client.GuildUnavailable += (g) =>
|
||||
_client.GuildUnavailable += g =>
|
||||
{
|
||||
var _ = Task.Run(() =>
|
||||
{
|
||||
@@ -107,7 +107,7 @@ public class StatsService : IStatsService, IReadyExecutor, INService, IDisposabl
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
_client.LeftGuild += (g) =>
|
||||
_client.LeftGuild += g =>
|
||||
{
|
||||
var _ = Task.Run(() =>
|
||||
{
|
||||
@@ -120,7 +120,7 @@ public class StatsService : IStatsService, IReadyExecutor, INService, IDisposabl
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
_botlistTimer = new Timer(async (state) =>
|
||||
_botlistTimer = new(async state =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_creds.BotListToken))
|
||||
return;
|
||||
|
@@ -18,9 +18,9 @@ public class YtdlOperation
|
||||
private Process CreateProcess(string[] args)
|
||||
{
|
||||
args = args.Map(arg => arg.Replace("\"", ""));
|
||||
return new Process()
|
||||
return new()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
StartInfo = new()
|
||||
{
|
||||
FileName = "youtube-dl",
|
||||
Arguments = string.Format(_baseArgString, args),
|
||||
|
@@ -21,7 +21,7 @@ public static class ConfigParsers
|
||||
{
|
||||
try
|
||||
{
|
||||
output = new CultureInfo(input);
|
||||
output = new(input);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
@@ -66,7 +66,7 @@ public abstract class ConfigServiceBase<TSettings> : IConfigService
|
||||
// if file is deleted, regenerate it with default values
|
||||
if (!File.Exists(_filePath))
|
||||
{
|
||||
_data = new TSettings();
|
||||
_data = new();
|
||||
Save();
|
||||
}
|
||||
|
||||
|
@@ -72,7 +72,7 @@ public class BotStrings : IBotStrings
|
||||
Log.Warning("'{CommandName}' doesn't exist in 'en-US' command strings. Please report this",
|
||||
commandName);
|
||||
|
||||
return new CommandStrings()
|
||||
return new()
|
||||
{
|
||||
Args = new[] {""},
|
||||
Desc = "?"
|
||||
|
@@ -43,7 +43,7 @@ public class RedisBotStringsProvider : IBotStringsProvider
|
||||
return null;
|
||||
|
||||
var args = Array.ConvertAll(argsStr.Split('&'), HttpUtility.UrlDecode);
|
||||
return new CommandStrings()
|
||||
return new()
|
||||
{
|
||||
Args = args,
|
||||
Desc = descStr
|
||||
|
Reference in New Issue
Block a user