mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-20 00:43:36 +03:00
change: not all DI classes need to be services
This commit is contained in:
parent
f79968fdc2
commit
2b5b0422c2
11 changed files with 20 additions and 40 deletions
|
@ -33,12 +33,12 @@ public class BanCommandGroup : CommandGroup
|
||||||
private readonly IDiscordRestGuildAPI _guildApi;
|
private readonly IDiscordRestGuildAPI _guildApi;
|
||||||
private readonly GuildDataService _guildData;
|
private readonly GuildDataService _guildData;
|
||||||
private readonly IDiscordRestUserAPI _userApi;
|
private readonly IDiscordRestUserAPI _userApi;
|
||||||
private readonly UtilityService _utility;
|
private readonly Utility _utility;
|
||||||
|
|
||||||
public BanCommandGroup(
|
public BanCommandGroup(
|
||||||
ICommandContext context, IDiscordRestChannelAPI channelApi, GuildDataService guildData,
|
ICommandContext context, IDiscordRestChannelAPI channelApi, GuildDataService guildData,
|
||||||
IFeedbackService feedback, IDiscordRestGuildAPI guildApi, IDiscordRestUserAPI userApi,
|
IFeedbackService feedback, IDiscordRestGuildAPI guildApi, IDiscordRestUserAPI userApi,
|
||||||
UtilityService utility)
|
Utility utility)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_channelApi = channelApi;
|
_channelApi = channelApi;
|
||||||
|
|
|
@ -30,11 +30,11 @@ public class ClearCommandGroup : CommandGroup
|
||||||
private readonly IFeedbackService _feedback;
|
private readonly IFeedbackService _feedback;
|
||||||
private readonly GuildDataService _guildData;
|
private readonly GuildDataService _guildData;
|
||||||
private readonly IDiscordRestUserAPI _userApi;
|
private readonly IDiscordRestUserAPI _userApi;
|
||||||
private readonly UtilityService _utility;
|
private readonly Utility _utility;
|
||||||
|
|
||||||
public ClearCommandGroup(
|
public ClearCommandGroup(
|
||||||
IDiscordRestChannelAPI channelApi, ICommandContext context, GuildDataService guildData,
|
IDiscordRestChannelAPI channelApi, ICommandContext context, GuildDataService guildData,
|
||||||
IFeedbackService feedback, IDiscordRestUserAPI userApi, UtilityService utility)
|
IFeedbackService feedback, IDiscordRestUserAPI userApi, Utility utility)
|
||||||
{
|
{
|
||||||
_channelApi = channelApi;
|
_channelApi = channelApi;
|
||||||
_context = context;
|
_context = context;
|
||||||
|
|
|
@ -30,12 +30,12 @@ public class KickCommandGroup : CommandGroup
|
||||||
private readonly IDiscordRestGuildAPI _guildApi;
|
private readonly IDiscordRestGuildAPI _guildApi;
|
||||||
private readonly GuildDataService _guildData;
|
private readonly GuildDataService _guildData;
|
||||||
private readonly IDiscordRestUserAPI _userApi;
|
private readonly IDiscordRestUserAPI _userApi;
|
||||||
private readonly UtilityService _utility;
|
private readonly Utility _utility;
|
||||||
|
|
||||||
public KickCommandGroup(
|
public KickCommandGroup(
|
||||||
ICommandContext context, IDiscordRestChannelAPI channelApi, GuildDataService guildData,
|
ICommandContext context, IDiscordRestChannelAPI channelApi, GuildDataService guildData,
|
||||||
IFeedbackService feedback, IDiscordRestGuildAPI guildApi, IDiscordRestUserAPI userApi,
|
IFeedbackService feedback, IDiscordRestGuildAPI guildApi, IDiscordRestUserAPI userApi,
|
||||||
UtilityService utility)
|
Utility utility)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_channelApi = channelApi;
|
_channelApi = channelApi;
|
||||||
|
|
|
@ -32,11 +32,11 @@ public class MuteCommandGroup : CommandGroup
|
||||||
private readonly IDiscordRestGuildAPI _guildApi;
|
private readonly IDiscordRestGuildAPI _guildApi;
|
||||||
private readonly GuildDataService _guildData;
|
private readonly GuildDataService _guildData;
|
||||||
private readonly IDiscordRestUserAPI _userApi;
|
private readonly IDiscordRestUserAPI _userApi;
|
||||||
private readonly UtilityService _utility;
|
private readonly Utility _utility;
|
||||||
|
|
||||||
public MuteCommandGroup(
|
public MuteCommandGroup(
|
||||||
ICommandContext context, GuildDataService guildData, IFeedbackService feedback,
|
ICommandContext context, GuildDataService guildData, IFeedbackService feedback,
|
||||||
IDiscordRestGuildAPI guildApi, IDiscordRestUserAPI userApi, UtilityService utility)
|
IDiscordRestGuildAPI guildApi, IDiscordRestUserAPI userApi, Utility utility)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_guildData = guildData;
|
_guildData = guildData;
|
||||||
|
|
|
@ -57,11 +57,11 @@ public class SettingsCommandGroup : CommandGroup
|
||||||
private readonly IFeedbackService _feedback;
|
private readonly IFeedbackService _feedback;
|
||||||
private readonly GuildDataService _guildData;
|
private readonly GuildDataService _guildData;
|
||||||
private readonly IDiscordRestUserAPI _userApi;
|
private readonly IDiscordRestUserAPI _userApi;
|
||||||
private readonly UtilityService _utility;
|
private readonly Utility _utility;
|
||||||
|
|
||||||
public SettingsCommandGroup(
|
public SettingsCommandGroup(
|
||||||
ICommandContext context, GuildDataService guildData,
|
ICommandContext context, GuildDataService guildData,
|
||||||
IFeedbackService feedback, IDiscordRestUserAPI userApi, UtilityService utility)
|
IFeedbackService feedback, IDiscordRestUserAPI userApi, Utility utility)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_guildData = guildData;
|
_guildData = guildData;
|
||||||
|
|
|
@ -87,7 +87,7 @@ public sealed class Octobot
|
||||||
.AddPostExecutionEvent<ErrorLoggingPostExecutionEvent>()
|
.AddPostExecutionEvent<ErrorLoggingPostExecutionEvent>()
|
||||||
// Services
|
// Services
|
||||||
.AddSingleton<GuildDataService>()
|
.AddSingleton<GuildDataService>()
|
||||||
.AddSingleton<UtilityService>()
|
.AddSingleton<Utility>()
|
||||||
.AddHostedService<MemberUpdateService>()
|
.AddHostedService<MemberUpdateService>()
|
||||||
.AddHostedService<ScheduledEventUpdateService>()
|
.AddHostedService<ScheduledEventUpdateService>()
|
||||||
.AddHostedService<SongUpdateService>()
|
.AddHostedService<SongUpdateService>()
|
||||||
|
|
|
@ -25,11 +25,11 @@ public class GuildLoadedResponder : IResponder<IGuildCreate>
|
||||||
private readonly GuildDataService _guildData;
|
private readonly GuildDataService _guildData;
|
||||||
private readonly ILogger<GuildLoadedResponder> _logger;
|
private readonly ILogger<GuildLoadedResponder> _logger;
|
||||||
private readonly IDiscordRestUserAPI _userApi;
|
private readonly IDiscordRestUserAPI _userApi;
|
||||||
private readonly UtilityService _utility;
|
private readonly Utility _utility;
|
||||||
|
|
||||||
public GuildLoadedResponder(
|
public GuildLoadedResponder(
|
||||||
IDiscordRestChannelAPI channelApi, GuildDataService guildData, ILogger<GuildLoadedResponder> logger,
|
IDiscordRestChannelAPI channelApi, GuildDataService guildData, ILogger<GuildLoadedResponder> logger,
|
||||||
IDiscordRestUserAPI userApi, UtilityService utility)
|
IDiscordRestUserAPI userApi, Utility utility)
|
||||||
{
|
{
|
||||||
_channelApi = channelApi;
|
_channelApi = channelApi;
|
||||||
_guildData = guildData;
|
_guildData = guildData;
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace Octobot.Services;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles saving, loading, initializing and providing <see cref="GuildData" />.
|
/// Handles saving, loading, initializing and providing <see cref="GuildData" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class GuildDataService : IHostedService
|
public sealed class GuildDataService
|
||||||
{
|
{
|
||||||
private readonly ConcurrentDictionary<Snowflake, GuildData> _datas = new();
|
private readonly ConcurrentDictionary<Snowflake, GuildData> _datas = new();
|
||||||
private readonly ILogger<GuildDataService> _logger;
|
private readonly ILogger<GuildDataService> _logger;
|
||||||
|
@ -24,16 +24,6 @@ public sealed class GuildDataService : IHostedService
|
||||||
lifetime.ApplicationStopping.Register(ApplicationStopping);
|
lifetime.ApplicationStopping.Register(ApplicationStopping);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StartAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ApplicationStopping()
|
private void ApplicationStopping()
|
||||||
{
|
{
|
||||||
SaveAsync(CancellationToken.None).GetAwaiter().GetResult();
|
SaveAsync(CancellationToken.None).GetAwaiter().GetResult();
|
||||||
|
|
|
@ -30,10 +30,10 @@ public sealed partial class MemberUpdateService : BackgroundService
|
||||||
private readonly IDiscordRestGuildAPI _guildApi;
|
private readonly IDiscordRestGuildAPI _guildApi;
|
||||||
private readonly GuildDataService _guildData;
|
private readonly GuildDataService _guildData;
|
||||||
private readonly ILogger<MemberUpdateService> _logger;
|
private readonly ILogger<MemberUpdateService> _logger;
|
||||||
private readonly UtilityService _utility;
|
private readonly Utility _utility;
|
||||||
|
|
||||||
public MemberUpdateService(IDiscordRestChannelAPI channelApi, IDiscordRestGuildAPI guildApi,
|
public MemberUpdateService(IDiscordRestChannelAPI channelApi, IDiscordRestGuildAPI guildApi,
|
||||||
GuildDataService guildData, ILogger<MemberUpdateService> logger, UtilityService utility)
|
GuildDataService guildData, ILogger<MemberUpdateService> logger, Utility utility)
|
||||||
{
|
{
|
||||||
_channelApi = channelApi;
|
_channelApi = channelApi;
|
||||||
_guildApi = guildApi;
|
_guildApi = guildApi;
|
||||||
|
|
|
@ -19,10 +19,10 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
||||||
private readonly IDiscordRestGuildScheduledEventAPI _eventApi;
|
private readonly IDiscordRestGuildScheduledEventAPI _eventApi;
|
||||||
private readonly GuildDataService _guildData;
|
private readonly GuildDataService _guildData;
|
||||||
private readonly ILogger<ScheduledEventUpdateService> _logger;
|
private readonly ILogger<ScheduledEventUpdateService> _logger;
|
||||||
private readonly UtilityService _utility;
|
private readonly Utility _utility;
|
||||||
|
|
||||||
public ScheduledEventUpdateService(IDiscordRestChannelAPI channelApi, IDiscordRestGuildScheduledEventAPI eventApi,
|
public ScheduledEventUpdateService(IDiscordRestChannelAPI channelApi, IDiscordRestGuildScheduledEventAPI eventApi,
|
||||||
GuildDataService guildData, ILogger<ScheduledEventUpdateService> logger, UtilityService utility)
|
GuildDataService guildData, ILogger<ScheduledEventUpdateService> logger, Utility utility)
|
||||||
{
|
{
|
||||||
_channelApi = channelApi;
|
_channelApi = channelApi;
|
||||||
_eventApi = eventApi;
|
_eventApi = eventApi;
|
||||||
|
|
|
@ -17,14 +17,14 @@ namespace Octobot.Services;
|
||||||
/// Provides utility methods that cannot be transformed to extension methods because they require usage
|
/// Provides utility methods that cannot be transformed to extension methods because they require usage
|
||||||
/// of some Discord APIs.
|
/// of some Discord APIs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class UtilityService : IHostedService
|
public sealed class Utility
|
||||||
{
|
{
|
||||||
private readonly IDiscordRestChannelAPI _channelApi;
|
private readonly IDiscordRestChannelAPI _channelApi;
|
||||||
private readonly IDiscordRestGuildScheduledEventAPI _eventApi;
|
private readonly IDiscordRestGuildScheduledEventAPI _eventApi;
|
||||||
private readonly IDiscordRestGuildAPI _guildApi;
|
private readonly IDiscordRestGuildAPI _guildApi;
|
||||||
private readonly IDiscordRestUserAPI _userApi;
|
private readonly IDiscordRestUserAPI _userApi;
|
||||||
|
|
||||||
public UtilityService(
|
public Utility(
|
||||||
IDiscordRestChannelAPI channelApi, IDiscordRestGuildScheduledEventAPI eventApi, IDiscordRestGuildAPI guildApi,
|
IDiscordRestChannelAPI channelApi, IDiscordRestGuildScheduledEventAPI eventApi, IDiscordRestGuildAPI guildApi,
|
||||||
IDiscordRestUserAPI userApi)
|
IDiscordRestUserAPI userApi)
|
||||||
{
|
{
|
||||||
|
@ -34,16 +34,6 @@ public sealed class UtilityService : IHostedService
|
||||||
_userApi = userApi;
|
_userApi = userApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StartAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks whether or not a member can interact with another member
|
/// Checks whether or not a member can interact with another member
|
||||||
/// </summary>
|
/// </summary>
|
Loading…
Add table
Reference in a new issue