mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 09:18:27 -04:00
Changed all .GetService to .GetRequiredService because no service should be ever missing. However most of these should be removed in one of the future patches.
This commit is contained in:
@@ -21,7 +21,7 @@ namespace NadekoBot.Coordinator
|
||||
services.AddGrpc();
|
||||
services.AddSingleton<CoordinatorRunner>();
|
||||
services.AddSingleton<IHostedService, CoordinatorRunner>(
|
||||
serviceProvider => serviceProvider.GetService<CoordinatorRunner>());
|
||||
serviceProvider => serviceProvider.GetRequiredService<CoordinatorRunner>());
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
|
@@ -177,7 +177,7 @@ namespace NadekoBot
|
||||
}
|
||||
}
|
||||
|
||||
// todo isn't there a built in for loading type readers?
|
||||
// todo di typereaders
|
||||
private IEnumerable<object> LoadTypeReaders(Assembly assembly)
|
||||
{
|
||||
Type[] allTypes;
|
||||
|
@@ -24,7 +24,7 @@ namespace NadekoBot.Common.Attributes
|
||||
if (Seconds == 0)
|
||||
return Task.FromResult(PreconditionResult.FromSuccess());
|
||||
|
||||
var cache = services.GetService<IDataCache>();
|
||||
var cache = services.GetRequiredService<IDataCache>();
|
||||
var rem = cache.TryAddRatelimit(context.User.Id, command.Name, Seconds);
|
||||
|
||||
if(rem is null)
|
||||
|
@@ -23,7 +23,7 @@ namespace Discord
|
||||
|
||||
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
|
||||
{
|
||||
var permService = services.GetService<DiscordPermOverrideService>();
|
||||
var permService = services.GetRequiredService<DiscordPermOverrideService>();
|
||||
if (permService.TryGetOverrides(context.Guild?.Id ?? 0, command.Name.ToUpperInvariant(), out var _))
|
||||
return Task.FromResult(PreconditionResult.FromSuccess());
|
||||
|
||||
|
@@ -49,7 +49,7 @@ namespace NadekoBot.Extensions
|
||||
.AddSingleton<IRadioResolver, RadioResolver>()
|
||||
.AddSingleton<ITrackCacher, RedisTrackCacher>()
|
||||
.AddSingleton<YtLoader>()
|
||||
.AddSingleton<IPlaceholderProvider>(svc => svc.GetService<IMusicService>());
|
||||
.AddSingleton<IPlaceholderProvider>(svc => svc.GetRequiredService<IMusicService>());
|
||||
|
||||
// consider using scrutor, because slightly different versions
|
||||
// of this might be needed in several different places
|
||||
|
@@ -50,9 +50,9 @@ namespace NadekoBot.Common.TypeReaders
|
||||
{
|
||||
input = input.ToUpperInvariant();
|
||||
|
||||
var _crs = services.GetService<CustomReactionsService>();
|
||||
var crs = services.GetRequiredService<CustomReactionsService>();
|
||||
|
||||
if (_crs.ReactionExists(context.Guild?.Id, input))
|
||||
if (crs.ReactionExists(context.Guild?.Id, input))
|
||||
{
|
||||
return TypeReaderResult.FromSuccess(new CommandOrCrInfo(input, CommandOrCrInfo.Type.Custom));
|
||||
}
|
||||
|
@@ -25,11 +25,11 @@ namespace NadekoBot.Common.TypeReaders
|
||||
|
||||
public static GuildDateTime Parse(IServiceProvider services, ulong guildId, string input)
|
||||
{
|
||||
var _gts = services.GetService<GuildTimezoneService>();
|
||||
var gts = services.GetRequiredService<GuildTimezoneService>();
|
||||
if (!DateTime.TryParse(input, out var dt))
|
||||
return null;
|
||||
|
||||
var tz = _gts.GetTimeZoneOrUtc(guildId);
|
||||
var tz = gts.GetTimeZoneOrUtc(guildId);
|
||||
|
||||
return new GuildDateTime(tz, dt);
|
||||
}
|
||||
|
@@ -73,9 +73,9 @@ namespace NadekoBot.Common.TypeReaders
|
||||
|
||||
private static long Cur(IServiceProvider services, ICommandContext ctx)
|
||||
{
|
||||
var _db = services.GetService<DbService>();
|
||||
var db = services.GetRequiredService<DbService>();
|
||||
long cur;
|
||||
using (var uow = _db.GetDbContext())
|
||||
using (var uow = db.GetDbContext())
|
||||
{
|
||||
cur = uow.DiscordUser.GetUserCurrency(ctx.User.Id);
|
||||
uow.SaveChanges();
|
||||
@@ -85,7 +85,7 @@ namespace NadekoBot.Common.TypeReaders
|
||||
|
||||
private static long Max(IServiceProvider services, ICommandContext ctx)
|
||||
{
|
||||
var settings = services.GetService<GamblingConfigService>().Data;
|
||||
var settings = services.GetRequiredService<GamblingConfigService>().Data;
|
||||
var max = settings.MaxBet;
|
||||
return max == 0
|
||||
? Cur(services, ctx)
|
||||
|
Reference in New Issue
Block a user