diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index fafd9f48..e30d1664 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -12,16 +12,14 @@ using NadekoBot.Services.Administration; namespace NadekoBot.Modules.Administration { - public partial class Administration : NadekoTopLevelModule + public partial class Administration : NadekoTopLevelModule { private IGuild _nadekoSupportServer; private readonly DbService _db; - private readonly AdministrationService _admin; - public Administration(DbService db, AdministrationService admin) + public Administration(DbService db) { _db = db; - _admin = admin; } [NadekoCommand, Usage, Description, Aliases] @@ -40,12 +38,12 @@ namespace NadekoBot.Modules.Administration } if (enabled) { - _admin.DeleteMessagesOnCommand.Add(Context.Guild.Id); + _service.DeleteMessagesOnCommand.Add(Context.Guild.Id); await ReplyConfirmLocalized("delmsg_on").ConfigureAwait(false); } else { - _admin.DeleteMessagesOnCommand.TryRemove(Context.Guild.Id); + _service.DeleteMessagesOnCommand.TryRemove(Context.Guild.Id); await ReplyConfirmLocalized("delmsg_off").ConfigureAwait(false); } } diff --git a/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs b/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs index b7930e66..18a1d367 100644 --- a/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs @@ -12,15 +12,13 @@ namespace NadekoBot.Modules.Administration public partial class Administration { [Group] - public class AutoAssignRoleCommands : NadekoSubmodule + public class AutoAssignRoleCommands : NadekoSubmodule { private readonly DbService _db; - private readonly AutoAssignRoleService _service; - public AutoAssignRoleCommands(AutoAssignRoleService service, DbService db) + public AutoAssignRoleCommands(DbService db) { _db = db; - _service = service; } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Administration/Commands/GameChannelCommands.cs b/src/NadekoBot/Modules/Administration/Commands/GameChannelCommands.cs index 46a250e1..93cbd5e7 100644 --- a/src/NadekoBot/Modules/Administration/Commands/GameChannelCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/GameChannelCommands.cs @@ -10,15 +10,13 @@ namespace NadekoBot.Modules.Administration public partial class Administration { [Group] - public class GameChannelCommands : NadekoSubmodule + public class GameChannelCommands : NadekoSubmodule { private readonly DbService _db; - private readonly GameVoiceChannelService _service; - public GameChannelCommands(GameVoiceChannelService service, DbService db) + public GameChannelCommands(DbService db) { _db = db; - _service = service; } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs index dbdb63dc..cb83822c 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -18,14 +18,12 @@ namespace NadekoBot.Modules.Administration { [Group] [NoPublicBot] - public class LogCommands : NadekoSubmodule + public class LogCommands : NadekoSubmodule { - private readonly LogCommandService _lc; private readonly DbService _db; - public LogCommands(LogCommandService lc, DbService db) + public LogCommands(DbService db) { - _lc = lc; _db = db; } @@ -46,7 +44,7 @@ namespace NadekoBot.Modules.Administration using (var uow = _db.UnitOfWork) { logSetting = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id).LogSetting; - _lc.GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting); + _service.GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting); logSetting.LogOtherId = logSetting.MessageUpdatedId = logSetting.MessageDeletedId = @@ -82,7 +80,7 @@ namespace NadekoBot.Modules.Administration using (var uow = _db.UnitOfWork) { var config = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id); - LogSetting logSetting = _lc.GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting); + LogSetting logSetting = _service.GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting); removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id); config.LogSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id); if (removed == 0) @@ -122,7 +120,7 @@ namespace NadekoBot.Modules.Administration using (var uow = _db.UnitOfWork) { var logSetting = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id).LogSetting; - _lc.GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting); + _service.GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting); switch (type) { case LogType.Other: diff --git a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs index e3ca82b9..e3673b34 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs @@ -11,14 +11,12 @@ namespace NadekoBot.Modules.Administration public partial class Administration { [Group] - public class MuteCommands : NadekoSubmodule + public class MuteCommands : NadekoSubmodule { - private readonly MuteService _service; private readonly DbService _db; - public MuteCommands(MuteService service, DbService db) + public MuteCommands(DbService db) { - _service = service; _db = db; } diff --git a/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs b/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs index 03957dfc..549230a3 100644 --- a/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs @@ -11,16 +11,14 @@ namespace NadekoBot.Modules.Administration public partial class Administration { [Group] - public class PlayingRotateCommands : NadekoSubmodule + public class PlayingRotateCommands : NadekoSubmodule { private static readonly object _locker = new object(); private readonly DbService _db; - private readonly PlayingRotateService _service; - public PlayingRotateCommands(PlayingRotateService service, DbService db) + public PlayingRotateCommands(DbService db) { _db = db; - _service = service; } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Administration/Commands/ProtectionCommands.cs b/src/NadekoBot/Modules/Administration/Commands/ProtectionCommands.cs index 73bd2de0..cf18fe63 100644 --- a/src/NadekoBot/Modules/Administration/Commands/ProtectionCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/ProtectionCommands.cs @@ -15,15 +15,13 @@ namespace NadekoBot.Modules.Administration public partial class Administration { [Group] - public class ProtectionCommands : NadekoSubmodule + public class ProtectionCommands : NadekoSubmodule { - private readonly ProtectionService _service; private readonly MuteService _mute; private readonly DbService _db; - public ProtectionCommands(ProtectionService service, MuteService mute, DbService db) + public ProtectionCommands(MuteService mute, DbService db) { - _service = service; _mute = mute; _db = db; } diff --git a/src/NadekoBot/Modules/Administration/Commands/PruneCommands.cs b/src/NadekoBot/Modules/Administration/Commands/PruneCommands.cs index 44407c19..f3a9d39c 100644 --- a/src/NadekoBot/Modules/Administration/Commands/PruneCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/PruneCommands.cs @@ -4,9 +4,6 @@ using NadekoBot.Attributes; using NadekoBot.Extensions; using NadekoBot.Services.Administration; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading.Tasks; namespace NadekoBot.Modules.Administration @@ -14,15 +11,9 @@ namespace NadekoBot.Modules.Administration public partial class Administration { [Group] - public class PruneCommands : ModuleBase + public class PruneCommands : NadekoSubmodule { private readonly TimeSpan twoWeeks = TimeSpan.FromDays(14); - private readonly PruneService _prune; - - public PruneCommands(PruneService prune) - { - _prune = prune; - } //delets her own messages, no perm required [NadekoCommand, Usage, Description, Aliases] @@ -31,7 +22,7 @@ namespace NadekoBot.Modules.Administration { var user = await Context.Guild.GetCurrentUserAsync().ConfigureAwait(false); - await _prune.PruneWhere((ITextChannel)Context.Channel, 100, (x) => x.Author.Id == user.Id).ConfigureAwait(false); + await _service.PruneWhere((ITextChannel)Context.Channel, 100, (x) => x.Author.Id == user.Id).ConfigureAwait(false); Context.Message.DeleteAfter(3); } // prune x @@ -47,7 +38,7 @@ namespace NadekoBot.Modules.Administration return; if (count > 1000) count = 1000; - await _prune.PruneWhere((ITextChannel)Context.Channel, count, x => true).ConfigureAwait(false); + await _service.PruneWhere((ITextChannel)Context.Channel, count, x => true).ConfigureAwait(false); } //prune @user [x] @@ -66,7 +57,7 @@ namespace NadekoBot.Modules.Administration if (count > 1000) count = 1000; - await _prune.PruneWhere((ITextChannel)Context.Channel, count, m => m.Author.Id == user.Id && DateTime.UtcNow - m.CreatedAt < twoWeeks); + await _service.PruneWhere((ITextChannel)Context.Channel, count, m => m.Author.Id == user.Id && DateTime.UtcNow - m.CreatedAt < twoWeeks); } } } diff --git a/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs b/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs index bf23d99b..bb829d37 100644 --- a/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs @@ -15,14 +15,12 @@ namespace NadekoBot.Modules.Administration public partial class Administration { [Group] - public class SlowModeCommands : NadekoSubmodule + public class SlowModeCommands : NadekoSubmodule { - private readonly SlowmodeService _service; private readonly DbService _db; - public SlowModeCommands(SlowmodeService service, DbService db) + public SlowModeCommands(DbService db) { - _service = service; _db = db; } diff --git a/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs b/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs index 2205a1c8..4e348f62 100644 --- a/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs @@ -14,7 +14,6 @@ using NadekoBot.Services.Database.Models; using Microsoft.EntityFrameworkCore; using NadekoBot.Services.Administration; using System.Diagnostics; -using NadekoBot.DataStructures; using NadekoBot.Services.Music; namespace NadekoBot.Modules.Administration @@ -22,21 +21,19 @@ namespace NadekoBot.Modules.Administration public partial class Administration { [Group] - public class SelfCommands : NadekoSubmodule + public class SelfCommands : NadekoSubmodule { private readonly DbService _db; private static readonly object _locker = new object(); - private readonly SelfService _service; private readonly DiscordSocketClient _client; private readonly IImagesService _images; private readonly MusicService _music; - public SelfCommands(DbService db, SelfService service, DiscordSocketClient client, + public SelfCommands(DbService db, DiscordSocketClient client, MusicService music, IImagesService images) { _db = db; - _service = service; _client = client; _images = images; _music = music; diff --git a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs index 5a2f9f98..b957a4c9 100644 --- a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommands.cs @@ -11,14 +11,12 @@ namespace NadekoBot.Modules.Administration public partial class Administration { [Group] - public class ServerGreetCommands : NadekoSubmodule + public class ServerGreetCommands : NadekoSubmodule { - private readonly GreetSettingsService _greetService; private readonly DbService _db; - public ServerGreetCommands(GreetSettingsService greetService, DbService db) + public ServerGreetCommands(DbService db) { - _greetService = greetService; _db = db; } @@ -30,7 +28,7 @@ namespace NadekoBot.Modules.Administration if (timer < 0 || timer > 600) return; - await _greetService.SetGreetDel(Context.Guild.Id, timer).ConfigureAwait(false); + await _service.SetGreetDel(Context.Guild.Id, timer).ConfigureAwait(false); if (timer > 0) await ReplyConfirmLocalized("greetdel_on", timer).ConfigureAwait(false); @@ -43,7 +41,7 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageGuild)] public async Task Greet() { - var enabled = await _greetService.SetGreet(Context.Guild.Id, Context.Channel.Id).ConfigureAwait(false); + var enabled = await _service.SetGreet(Context.Guild.Id, Context.Channel.Id).ConfigureAwait(false); if (enabled) await ReplyConfirmLocalized("greet_on").ConfigureAwait(false); @@ -67,7 +65,7 @@ namespace NadekoBot.Modules.Administration return; } - var sendGreetEnabled = _greetService.SetGreetMessage(Context.Guild.Id, ref text); + var sendGreetEnabled = _service.SetGreetMessage(Context.Guild.Id, ref text); await ReplyConfirmLocalized("greetmsg_new").ConfigureAwait(false); if (!sendGreetEnabled) @@ -79,7 +77,7 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageGuild)] public async Task GreetDm() { - var enabled = await _greetService.SetGreetDm(Context.Guild.Id).ConfigureAwait(false); + var enabled = await _service.SetGreetDm(Context.Guild.Id).ConfigureAwait(false); if (enabled) await ReplyConfirmLocalized("greetdm_on").ConfigureAwait(false); @@ -103,7 +101,7 @@ namespace NadekoBot.Modules.Administration return; } - var sendGreetEnabled = _greetService.SetGreetDmMessage(Context.Guild.Id, ref text); + var sendGreetEnabled = _service.SetGreetDmMessage(Context.Guild.Id, ref text); await ReplyConfirmLocalized("greetdmmsg_new").ConfigureAwait(false); if (!sendGreetEnabled) @@ -115,7 +113,7 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageGuild)] public async Task Bye() { - var enabled = await _greetService.SetBye(Context.Guild.Id, Context.Channel.Id).ConfigureAwait(false); + var enabled = await _service.SetBye(Context.Guild.Id, Context.Channel.Id).ConfigureAwait(false); if (enabled) await ReplyConfirmLocalized("bye_on").ConfigureAwait(false); @@ -139,7 +137,7 @@ namespace NadekoBot.Modules.Administration return; } - var sendByeEnabled = _greetService.SetByeMessage(Context.Guild.Id, ref text); + var sendByeEnabled = _service.SetByeMessage(Context.Guild.Id, ref text); await ReplyConfirmLocalized("byemsg_new").ConfigureAwait(false); if (!sendByeEnabled) @@ -151,7 +149,7 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageGuild)] public async Task ByeDel(int timer = 30) { - await _greetService.SetByeDel(Context.Guild.Id, timer).ConfigureAwait(false); + await _service.SetByeDel(Context.Guild.Id, timer).ConfigureAwait(false); if (timer > 0) await ReplyConfirmLocalized("byedel_on", timer).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Administration/Commands/TimeZoneCommands.cs b/src/NadekoBot/Modules/Administration/Commands/TimeZoneCommands.cs index c97fdbca..8f014c47 100644 --- a/src/NadekoBot/Modules/Administration/Commands/TimeZoneCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/TimeZoneCommands.cs @@ -13,15 +13,8 @@ namespace NadekoBot.Modules.Administration public partial class Administration { [Group] - public class TimeZoneCommands : NadekoSubmodule + public class TimeZoneCommands : NadekoSubmodule { - private readonly GuildTimezoneService _service; - - public TimeZoneCommands(GuildTimezoneService service) - { - _service = service; - } - [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task Timezones(int page = 1) diff --git a/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs b/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs index 363a9222..49d1fc38 100644 --- a/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs @@ -15,15 +15,13 @@ namespace NadekoBot.Modules.Administration public partial class Administration { [Group] - public class UserPunishCommands : NadekoSubmodule + public class UserPunishCommands : NadekoSubmodule { private readonly DbService _db; - private readonly UserPunishService _service; - public UserPunishCommands(UserPunishService service, DbService db, MuteService muteService) + public UserPunishCommands(DbService db, MuteService muteService) { _db = db; - _service = service; } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Administration/Commands/VcRoleCommands.cs b/src/NadekoBot/Modules/Administration/Commands/VcRoleCommands.cs index 5fe31422..5865b9a9 100644 --- a/src/NadekoBot/Modules/Administration/Commands/VcRoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/VcRoleCommands.cs @@ -16,14 +16,12 @@ namespace NadekoBot.Modules.Administration public partial class Administration { [Group] - public class VcRoleCommands : NadekoSubmodule + public class VcRoleCommands : NadekoSubmodule { - private readonly VcRoleService _service; private readonly DbService _db; - public VcRoleCommands(VcRoleService service, DbService db) + public VcRoleCommands(DbService db) { - _service = service; _db = db; } diff --git a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs index 53f85510..9f328bea 100644 --- a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs @@ -15,14 +15,12 @@ namespace NadekoBot.Modules.Administration public partial class Administration { [Group] - public class VoicePlusTextCommands : NadekoSubmodule + public class VoicePlusTextCommands : NadekoSubmodule { - private readonly VplusTService _service; private readonly DbService _db; - public VoicePlusTextCommands(VplusTService service, DbService db) + public VoicePlusTextCommands(DbService db) { - _service = service; _db = db; } diff --git a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs index b80a5921..da99f55d 100644 --- a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -12,19 +12,17 @@ using NadekoBot.Services.CustomReactions; namespace NadekoBot.Modules.CustomReactions { - public class CustomReactions : NadekoTopLevelModule + public class CustomReactions : NadekoTopLevelModule { private readonly IBotCredentials _creds; private readonly DbService _db; - private readonly CustomReactionsService _crs; private readonly DiscordSocketClient _client; - public CustomReactions(IBotCredentials creds, DbService db, CustomReactionsService crs, + public CustomReactions(IBotCredentials creds, DbService db, DiscordSocketClient client) { _creds = creds; _db = db; - _crs = crs; _client = client; } @@ -60,12 +58,12 @@ namespace NadekoBot.Modules.CustomReactions if (channel == null) { - Array.Resize(ref _crs.GlobalReactions, _crs.GlobalReactions.Length + 1); - _crs.GlobalReactions[_crs.GlobalReactions.Length - 1] = cr; + Array.Resize(ref _service.GlobalReactions, _service.GlobalReactions.Length + 1); + _service.GlobalReactions[_service.GlobalReactions.Length - 1] = cr; } else { - _crs.GuildReactions.AddOrUpdate(Context.Guild.Id, + _service.GuildReactions.AddOrUpdate(Context.Guild.Id, new CustomReaction[] { cr }, (k, old) => { @@ -91,9 +89,9 @@ namespace NadekoBot.Modules.CustomReactions return; CustomReaction[] customReactions; if (Context.Guild == null) - customReactions = _crs.GlobalReactions.Where(cr => cr != null).ToArray(); + customReactions = _service.GlobalReactions.Where(cr => cr != null).ToArray(); else - customReactions = _crs.GuildReactions.GetOrAdd(Context.Guild.Id, Array.Empty()).Where(cr => cr != null).ToArray(); + customReactions = _service.GuildReactions.GetOrAdd(Context.Guild.Id, Array.Empty()).Where(cr => cr != null).ToArray(); if (customReactions == null || !customReactions.Any()) { @@ -135,9 +133,9 @@ namespace NadekoBot.Modules.CustomReactions { CustomReaction[] customReactions; if (Context.Guild == null) - customReactions = _crs.GlobalReactions.Where(cr => cr != null).ToArray(); + customReactions = _service.GlobalReactions.Where(cr => cr != null).ToArray(); else - customReactions = _crs.GuildReactions.GetOrAdd(Context.Guild.Id, new CustomReaction[]{ }).Where(cr => cr != null).ToArray(); + customReactions = _service.GuildReactions.GetOrAdd(Context.Guild.Id, new CustomReaction[]{ }).Where(cr => cr != null).ToArray(); if (customReactions == null || !customReactions.Any()) { @@ -165,9 +163,9 @@ namespace NadekoBot.Modules.CustomReactions return; CustomReaction[] customReactions; if (Context.Guild == null) - customReactions = _crs.GlobalReactions.Where(cr => cr != null).ToArray(); + customReactions = _service.GlobalReactions.Where(cr => cr != null).ToArray(); else - customReactions = _crs.GuildReactions.GetOrAdd(Context.Guild.Id, new CustomReaction[]{ }).Where(cr => cr != null).ToArray(); + customReactions = _service.GuildReactions.GetOrAdd(Context.Guild.Id, new CustomReaction[]{ }).Where(cr => cr != null).ToArray(); if (customReactions == null || !customReactions.Any()) { @@ -197,9 +195,9 @@ namespace NadekoBot.Modules.CustomReactions { CustomReaction[] customReactions; if (Context.Guild == null) - customReactions = _crs.GlobalReactions; + customReactions = _service.GlobalReactions; else - customReactions = _crs.GuildReactions.GetOrAdd(Context.Guild.Id, new CustomReaction[]{ }); + customReactions = _service.GuildReactions.GetOrAdd(Context.Guild.Id, new CustomReaction[]{ }); var found = customReactions.FirstOrDefault(cr => cr?.Id == id); @@ -240,13 +238,13 @@ namespace NadekoBot.Modules.CustomReactions { uow.CustomReactions.Remove(toDelete); //todo 91 i can dramatically improve performance of this, if Ids are ordered. - _crs.GlobalReactions = _crs.GlobalReactions.Where(cr => cr?.Id != toDelete.Id).ToArray(); + _service.GlobalReactions = _service.GlobalReactions.Where(cr => cr?.Id != toDelete.Id).ToArray(); success = true; } else if ((toDelete.GuildId != null && toDelete.GuildId != 0) && Context.Guild.Id == toDelete.GuildId) { uow.CustomReactions.Remove(toDelete); - _crs.GuildReactions.AddOrUpdate(Context.Guild.Id, new CustomReaction[] { }, (key, old) => + _service.GuildReactions.AddOrUpdate(Context.Guild.Id, new CustomReaction[] { }, (key, old) => { return old.Where(cr => cr?.Id != toDelete.Id).ToArray(); }); @@ -284,10 +282,10 @@ namespace NadekoBot.Modules.CustomReactions CustomReaction[] reactions = new CustomReaction[0]; if (Context.Guild == null) - reactions = _crs.GlobalReactions; + reactions = _service.GlobalReactions; else { - _crs.GuildReactions.TryGetValue(Context.Guild.Id, out reactions); + _service.GuildReactions.TryGetValue(Context.Guild.Id, out reactions); } if (reactions.Any()) { @@ -335,10 +333,10 @@ namespace NadekoBot.Modules.CustomReactions CustomReaction[] reactions = new CustomReaction[0]; if (Context.Guild == null) - reactions = _crs.GlobalReactions; + reactions = _service.GlobalReactions; else { - _crs.GuildReactions.TryGetValue(Context.Guild.Id, out reactions); + _service.GuildReactions.TryGetValue(Context.Guild.Id, out reactions); } if (reactions.Any()) { @@ -379,13 +377,13 @@ namespace NadekoBot.Modules.CustomReactions { if (string.IsNullOrWhiteSpace(trigger)) { - _crs.ClearStats(); + _service.ClearStats(); await ReplyConfirmLocalized("all_stats_cleared").ConfigureAwait(false); } else { uint throwaway; - if (_crs.ReactionStats.TryRemove(trigger, out throwaway)) + if (_service.ReactionStats.TryRemove(trigger, out throwaway)) { await ReplyErrorLocalized("stats_cleared", Format.Bold(trigger)).ConfigureAwait(false); } @@ -401,7 +399,7 @@ namespace NadekoBot.Modules.CustomReactions { if (--page < 0) return; - var ordered = _crs.ReactionStats.OrderByDescending(x => x.Value).ToArray(); + var ordered = _service.ReactionStats.OrderByDescending(x => x.Value).ToArray(); if (!ordered.Any()) return; var lastPage = ordered.Length / 9; diff --git a/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs b/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs index ddf0e78d..ad0e9189 100644 --- a/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs @@ -11,15 +11,13 @@ namespace NadekoBot.Modules.Games public partial class Games { [Group] - public class CleverBotCommands : NadekoSubmodule + public class CleverBotCommands : NadekoSubmodule { private readonly DbService _db; - private readonly ChatterBotService _games; - public CleverBotCommands(DbService db, ChatterBotService games) + public CleverBotCommands(DbService db) { _db = db; - _games = games; } [NadekoCommand, Usage, Description, Aliases] @@ -29,7 +27,7 @@ namespace NadekoBot.Modules.Games { var channel = (ITextChannel)Context.Channel; - if (_games.ChatterBotGuilds.TryRemove(channel.Guild.Id, out Lazy throwaway)) + if (_service.ChatterBotGuilds.TryRemove(channel.Guild.Id, out Lazy throwaway)) { using (var uow = _db.UnitOfWork) { @@ -40,7 +38,7 @@ namespace NadekoBot.Modules.Games return; } - _games.ChatterBotGuilds.TryAdd(channel.Guild.Id, new Lazy(() => new ChatterBotSession(Context.Guild.Id), true)); + _service.ChatterBotGuilds.TryAdd(channel.Guild.Id, new Lazy(() => new ChatterBotSession(Context.Guild.Id), true)); using (var uow = _db.UnitOfWork) { diff --git a/src/NadekoBot/Modules/Games/Commands/PollCommands.cs b/src/NadekoBot/Modules/Games/Commands/PollCommands.cs index 0d6b6cb2..4679fa3e 100644 --- a/src/NadekoBot/Modules/Games/Commands/PollCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PollCommands.cs @@ -11,15 +11,13 @@ namespace NadekoBot.Modules.Games public partial class Games { [Group] - public class PollCommands : NadekoSubmodule + public class PollCommands : NadekoSubmodule { private readonly DiscordSocketClient _client; - private readonly PollService _polls; - public PollCommands(DiscordSocketClient client, PollService polls) + public PollCommands(DiscordSocketClient client) { _client = client; - _polls = polls; } [NadekoCommand, Usage, Description, Aliases] @@ -33,7 +31,7 @@ namespace NadekoBot.Modules.Games [RequireContext(ContextType.Guild)] public async Task PollStats() { - if (!_polls.ActivePolls.TryGetValue(Context.Guild.Id, out var poll)) + if (!_service.ActivePolls.TryGetValue(Context.Guild.Id, out var poll)) return; await Context.Channel.EmbedAsync(poll.GetStats(GetText("current_poll_results"))); @@ -41,7 +39,7 @@ namespace NadekoBot.Modules.Games private async Task InternalStartPoll(string arg) { - if(await _polls.StartPoll((ITextChannel)Context.Channel, Context.Message, arg) == false) + if(await _service.StartPoll((ITextChannel)Context.Channel, Context.Message, arg) == false) await ReplyErrorLocalized("poll_already_running").ConfigureAwait(false); } @@ -52,7 +50,7 @@ namespace NadekoBot.Modules.Games { var channel = (ITextChannel)Context.Channel; - _polls.ActivePolls.TryRemove(channel.Guild.Id, out var poll); + _service.ActivePolls.TryRemove(channel.Guild.Id, out var poll); await poll.StopPoll().ConfigureAwait(false); } } diff --git a/src/NadekoBot/Modules/Games/Games.cs b/src/NadekoBot/Modules/Games/Games.cs index 5c4e0f61..399f500a 100644 --- a/src/NadekoBot/Modules/Games/Games.cs +++ b/src/NadekoBot/Modules/Games/Games.cs @@ -9,14 +9,12 @@ using NadekoBot.Services.Games; namespace NadekoBot.Modules.Games { - public partial class Games : NadekoTopLevelModule + public partial class Games : NadekoTopLevelModule { - private readonly GamesService _games; private readonly IImagesService _images; - public Games(GamesService games, IImagesService images) + public Games(IImagesService images) { - _games = games; _images = images; } @@ -40,7 +38,7 @@ namespace NadekoBot.Modules.Games await Context.Channel.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor) .AddField(efb => efb.WithName("❓ " + GetText("question") ).WithValue(question).WithIsInline(false)) - .AddField(efb => efb.WithName("🎱 " + GetText("8ball")).WithValue(_games.EightBallResponses[new NadekoRandom().Next(0, _games.EightBallResponses.Length)]).WithIsInline(false))); + .AddField(efb => efb.WithName("🎱 " + GetText("8ball")).WithValue(_service.EightBallResponses[new NadekoRandom().Next(0, _service.EightBallResponses.Length)]).WithIsInline(false))); } [NadekoCommand, Usage, Description, Aliases] @@ -100,7 +98,7 @@ namespace NadekoBot.Modules.Games [RequireContext(ContextType.Guild)] public async Task RateGirl(IGuildUser usr) { - var gr = _games.GirlRatings.GetOrAdd(usr.Id, GetGirl); + var gr = _service.GirlRatings.GetOrAdd(usr.Id, GetGirl); var img = await gr.Url; await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithTitle("Girl Rating For " + usr) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 7d3162cc..c492810d 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -15,7 +15,7 @@ using NadekoBot.Services.Help; namespace NadekoBot.Modules.Help { - public class Help : NadekoTopLevelModule + public class Help : NadekoTopLevelModule { public const string PatreonUrl = "https://patreon.com/nadekobot"; public const string PaypalUrl = "https://paypal.me/Kwoth"; @@ -23,18 +23,16 @@ namespace NadekoBot.Modules.Help private readonly BotConfig _config; private readonly CommandService _cmds; private readonly GlobalPermissionService _perms; - private readonly HelpService _h; public string HelpString => String.Format(_config.HelpString, _creds.ClientId, Prefix); public string DMHelpString => _config.DMHelpString; - public Help(IBotCredentials creds, GlobalPermissionService perms, BotConfig config, CommandService cmds, HelpService h) + public Help(IBotCredentials creds, GlobalPermissionService perms, BotConfig config, CommandService cmds) { _creds = creds; _config = config; _cmds = cmds; _perms = perms; - _h = h; } [NadekoCommand, Usage, Description, Aliases] @@ -107,7 +105,7 @@ namespace NadekoBot.Modules.Help // return; //} - var embed = _h.GetCommandHelp(com, Context.Guild); + var embed = _service.GetCommandHelp(com, Context.Guild); await channel.EmbedAsync(embed).ConfigureAwait(false); } @@ -144,7 +142,7 @@ namespace NadekoBot.Modules.Help lastModule = module.Name; } helpstr.AppendLine($"{string.Join(" ", com.Aliases.Select(a => "`" + Prefix + a + "`"))} |" + - $" {string.Format(com.Summary, Prefix)} {_h.GetCommandRequirements(com, Context.Guild)} |" + + $" {string.Format(com.Summary, Prefix)} {_service.GetCommandRequirements(com, Context.Guild)} |" + $" {string.Format(com.Remarks, Prefix)}"); } File.WriteAllText("../../docs/Commands List.md", helpstr.ToString()); diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 1d84dcee..b20f1589 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -21,22 +21,20 @@ using NadekoBot.Services.Impl; namespace NadekoBot.Modules.Music { [NoPublicBot] - public class Music : NadekoTopLevelModule + public class Music : NadekoTopLevelModule { - private static MusicService _music; private readonly DiscordSocketClient _client; private readonly IBotCredentials _creds; private readonly IGoogleApiService _google; private readonly DbService _db; public Music(DiscordSocketClient client, IBotCredentials creds, IGoogleApiService google, - DbService db, MusicService music) + DbService db) { _client = client; _creds = creds; _google = google; _db = db; - _music = music; //_client.UserVoiceStateUpdated += Client_UserVoiceStateUpdated; _client.LeftGuild += _client_LeftGuild; @@ -44,7 +42,7 @@ namespace NadekoBot.Modules.Music private Task _client_LeftGuild(SocketGuild arg) { - var t = _music.DestroyPlayer(arg.Id); + var t = _service.DestroyPlayer(arg.Id); return Task.CompletedTask; } @@ -151,7 +149,7 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task Play([Remainder] string query = null) { - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); if (string.IsNullOrWhiteSpace(query)) { await Next(); @@ -176,9 +174,9 @@ namespace NadekoBot.Modules.Music public async Task Queue([Remainder] string query) { _log.Info("Getting player"); - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); _log.Info("Resolving song"); - var songInfo = await _music.ResolveSong(query, Context.User.ToString()); + var songInfo = await _service.ResolveSong(query, Context.User.ToString()); _log.Info("Queueing song"); try { await InternalQueue(mp, songInfo, false); } catch (QueueFullException) { return; } _log.Info("--------------"); @@ -229,7 +227,7 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task ListQueue(int page = 0) { - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); var (current, songs) = mp.QueueArray(); if (!songs.Any()) @@ -316,7 +314,7 @@ namespace NadekoBot.Modules.Music if (skipCount < 1) return; - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); mp.Next(skipCount); } @@ -325,7 +323,7 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task Stop() { - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); mp.Stop(); } @@ -333,14 +331,14 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task Destroy() { - await _music.DestroyPlayer(Context.Guild.Id); + await _service.DestroyPlayer(Context.Guild.Id); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task Pause() { - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); mp.TogglePause(); } @@ -348,7 +346,7 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task Volume(int val) { - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); if (val < 0 || val > 100) { await ReplyErrorLocalized("volume_input_invalid").ConfigureAwait(false); @@ -385,7 +383,7 @@ namespace NadekoBot.Modules.Music await ReplyErrorLocalized("removed_song_error").ConfigureAwait(false); return; } - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); try { var song = mp.RemoveAt(index - 1); @@ -409,7 +407,7 @@ namespace NadekoBot.Modules.Music [Priority(0)] public async Task SongRemove(All all) { - var mp = _music.GetPlayerOrDefault(Context.Guild.Id); + var mp = _service.GetPlayerOrDefault(Context.Guild.Id); if (mp == null) return; mp.Stop(true); @@ -476,7 +474,7 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task Save([Remainder] string name) { - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); var songs = mp.QueueArray().Songs .Select(s => new PlaylistSong() @@ -517,7 +515,7 @@ namespace NadekoBot.Modules.Music return; try { - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); MusicPlaylist mpl; using (var uow = _db.UnitOfWork) { @@ -537,7 +535,7 @@ namespace NadekoBot.Modules.Music { await Task.Yield(); - await Task.WhenAll(Task.Delay(1000), InternalQueue(mp, await _music.ResolveSong(item.Query, Context.User.ToString(), item.ProviderType), true)).ConfigureAwait(false); + await Task.WhenAll(Task.Delay(1000), InternalQueue(mp, await _service.ResolveSong(item.Query, Context.User.ToString(), item.ProviderType), true)).ConfigureAwait(false); } catch (SongNotFoundException) { } catch { break; } @@ -555,7 +553,7 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task Fairplay() { - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); var val = mp.FairPlay = !mp.FairPlay; if (val) @@ -572,8 +570,8 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task SoundCloudQueue([Remainder] string query) { - var mp = await _music.GetOrCreatePlayer(Context); - var song = await _music.ResolveSong(query, Context.User.ToString(), MusicType.Soundcloud); + var mp = await _service.GetOrCreatePlayer(Context); + var song = await _service.ResolveSong(query, Context.User.ToString(), MusicType.Soundcloud); await InternalQueue(mp, song, false).ConfigureAwait(false); } @@ -586,7 +584,7 @@ namespace NadekoBot.Modules.Music if (string.IsNullOrWhiteSpace(pl)) return; - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); using (var http = new HttpClient()) { @@ -617,7 +615,7 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task NowPlaying() { - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); var (_, currentSong) = mp.Current; if (currentSong == null) return; @@ -636,7 +634,7 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task ShufflePlaylist() { - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); var val = mp.ToggleShuffle(); if(val) await ReplyConfirmLocalized("songs_shuffle_enable").ConfigureAwait(false); @@ -651,7 +649,7 @@ namespace NadekoBot.Modules.Music if (string.IsNullOrWhiteSpace(playlist)) return; - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); var plId = (await _google.GetPlaylistIdsByKeywordsAsync(playlist).ConfigureAwait(false)).FirstOrDefault(); if (plId == null) @@ -676,7 +674,7 @@ namespace NadekoBot.Modules.Music if (mp.Exited) return; - await Task.WhenAll(Task.Delay(150), InternalQueue(mp, await _music.ResolveSong(song, Context.User.ToString(), MusicType.YouTube), true)); + await Task.WhenAll(Task.Delay(150), InternalQueue(mp, await _service.ResolveSong(song, Context.User.ToString(), MusicType.YouTube), true)); } catch (SongNotFoundException) { } catch { break; } @@ -690,8 +688,8 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task Radio(string radioLink) { - var mp = await _music.GetOrCreatePlayer(Context); - var song = await _music.ResolveSong(radioLink, Context.User.ToString(), MusicType.Radio); + var mp = await _service.GetOrCreatePlayer(Context); + var song = await _service.ResolveSong(radioLink, Context.User.ToString(), MusicType.Radio); await InternalQueue(mp, song, false).ConfigureAwait(false); } @@ -700,8 +698,8 @@ namespace NadekoBot.Modules.Music [OwnerOnly] public async Task Local([Remainder] string path) { - var mp = await _music.GetOrCreatePlayer(Context); - var song = await _music.ResolveSong(path, Context.User.ToString(), MusicType.Local); + var mp = await _service.GetOrCreatePlayer(Context); + var song = await _service.ResolveSong(path, Context.User.ToString(), MusicType.Local); await InternalQueue(mp, song, false).ConfigureAwait(false); } @@ -713,7 +711,7 @@ namespace NadekoBot.Modules.Music if (string.IsNullOrWhiteSpace(dirPath)) return; - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); DirectoryInfo dir; try { dir = new DirectoryInfo(dirPath); } catch { return; } @@ -724,7 +722,7 @@ namespace NadekoBot.Modules.Music try { await Task.Yield(); - var song = await _music.ResolveSong(file.FullName, Context.User.ToString(), MusicType.Local); + var song = await _service.ResolveSong(file.FullName, Context.User.ToString(), MusicType.Local); await InternalQueue(mp, song, true).ConfigureAwait(false); } catch (QueueFullException) @@ -749,7 +747,7 @@ namespace NadekoBot.Modules.Music if (vch == null) return; - var mp = _music.GetPlayerOrDefault(Context.Guild.Id); + var mp = _service.GetPlayerOrDefault(Context.Guild.Id); if (mp == null) return; @@ -764,7 +762,7 @@ namespace NadekoBot.Modules.Music if (string.IsNullOrWhiteSpace(fromto)) return; - MusicPlayer mp = _music.GetPlayerOrDefault(Context.Guild.Id); + MusicPlayer mp = _service.GetPlayerOrDefault(Context.Guild.Id); if (mp == null) return; @@ -796,7 +794,7 @@ namespace NadekoBot.Modules.Music { if (size < 0) return; - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); mp.MaxQueueSize = size; @@ -813,7 +811,7 @@ namespace NadekoBot.Modules.Music if (seconds < 15 && seconds != 0) return; - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); mp.MaxPlaytimeSeconds = seconds; if (seconds == 0) await ReplyConfirmLocalized("max_playtime_none").ConfigureAwait(false); @@ -825,7 +823,7 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task ReptCurSong() { - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); var (_, currentSong) = mp.Current; if (currentSong == null) return; @@ -846,7 +844,7 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task RepeatPl() { - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); var currentValue = mp.ToggleRepeatPlaylist(); if (currentValue) await ReplyConfirmLocalized("rpl_enabled").ConfigureAwait(false); @@ -858,7 +856,7 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task Autoplay() { - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); if (!mp.ToggleAutoplay()) await ReplyConfirmLocalized("autoplay_disabled").ConfigureAwait(false); @@ -871,7 +869,7 @@ namespace NadekoBot.Modules.Music [RequireUserPermission(GuildPermission.ManageMessages)] public async Task SetMusicChannel() { - var mp = await _music.GetOrCreatePlayer(Context); + var mp = await _service.GetOrCreatePlayer(Context); mp.OutputTextChannel = (ITextChannel)Context.Channel; diff --git a/src/NadekoBot/Modules/NSFW/NSFW.cs b/src/NadekoBot/Modules/NSFW/NSFW.cs index a5815bc6..21db0f12 100644 --- a/src/NadekoBot/Modules/NSFW/NSFW.cs +++ b/src/NadekoBot/Modules/NSFW/NSFW.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using NadekoBot.Services; using System.Net.Http; using NadekoBot.Extensions; -using System.Xml; using System.Threading; using System.Collections.Concurrent; using NadekoBot.Services.Searches; @@ -16,16 +15,10 @@ using NadekoBot.DataStructures; namespace NadekoBot.Modules.NSFW { - public class NSFW : NadekoTopLevelModule + public class NSFW : NadekoTopLevelModule { private static readonly ConcurrentDictionary _autoHentaiTimers = new ConcurrentDictionary(); private static readonly ConcurrentHashSet _hentaiBombBlacklist = new ConcurrentHashSet(); - private readonly SearchesService _service; - - public NSFW(SearchesService service) - { - _service = service; - } private async Task InternalHentai(IMessageChannel channel, string tag, bool noError) { diff --git a/src/NadekoBot/Modules/NadekoModule.cs b/src/NadekoBot/Modules/NadekoModule.cs index db7086fa..1138762b 100644 --- a/src/NadekoBot/Modules/NadekoModule.cs +++ b/src/NadekoBot/Modules/NadekoModule.cs @@ -130,8 +130,22 @@ namespace NadekoBot.Modules } } } + + public abstract class NadekoTopLevelModule : NadekoTopLevelModule where TService : INService + { + public TService _service { get; set; } + + public NadekoTopLevelModule(bool isTopLevel = true) : base(isTopLevel) + { + } + } public abstract class NadekoSubmodule : NadekoTopLevelModule + { + protected NadekoSubmodule() : base(false) { } + } + + public abstract class NadekoSubmodule : NadekoTopLevelModule where TService : INService { protected NadekoSubmodule() : base(false) { diff --git a/src/NadekoBot/Modules/Permissions/Permissions.cs b/src/NadekoBot/Modules/Permissions/Permissions.cs index 2fd612a3..0ba34b9f 100644 --- a/src/NadekoBot/Modules/Permissions/Permissions.cs +++ b/src/NadekoBot/Modules/Permissions/Permissions.cs @@ -13,15 +13,13 @@ using NadekoBot.Services.Permissions; namespace NadekoBot.Modules.Permissions { - public partial class Permissions : NadekoTopLevelModule + public partial class Permissions : NadekoTopLevelModule { private readonly DbService _db; - private readonly PermissionService _service; - public Permissions(PermissionService service, DbService db) + public Permissions(DbService db) { _db = db; - _service = service; } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Pokemon/Pokemon.cs b/src/NadekoBot/Modules/Pokemon/Pokemon.cs index 3b8d47a4..22680a29 100644 --- a/src/NadekoBot/Modules/Pokemon/Pokemon.cs +++ b/src/NadekoBot/Modules/Pokemon/Pokemon.cs @@ -12,16 +12,14 @@ using NadekoBot.Services.Pokemon; namespace NadekoBot.Modules.Pokemon { - public class Pokemon : NadekoTopLevelModule + public class Pokemon : NadekoTopLevelModule { - private readonly PokemonService _service; private readonly DbService _db; private readonly BotConfig _bc; private readonly CurrencyService _cs; - public Pokemon(PokemonService pokemonService, DbService db, BotConfig bc, CurrencyService cs) + public Pokemon(DbService db, BotConfig bc, CurrencyService cs) { - _service = pokemonService; _db = db; _bc = bc; _cs = cs; diff --git a/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs b/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs index ff41e0ca..edf392e2 100644 --- a/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/AnimeSearchCommands.cs @@ -15,15 +15,8 @@ namespace NadekoBot.Modules.Searches public partial class Searches { [Group] - public class AnimeSearchCommands : NadekoSubmodule + public class AnimeSearchCommands : NadekoSubmodule { - private readonly AnimeSearchService _service; - - public AnimeSearchCommands(AnimeSearchService service) - { - _service = service; - } - [NadekoCommand, Usage, Description, Aliases] [Priority(0)] public async Task Mal([Remainder] string name) diff --git a/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs b/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs index ec653b87..a99f77d7 100644 --- a/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs @@ -14,14 +14,8 @@ namespace NadekoBot.Modules.Searches public partial class Searches { [Group] - public class JokeCommands : NadekoSubmodule + public class JokeCommands : NadekoSubmodule { - private readonly SearchesService _searches; - - public JokeCommands(SearchesService searches) - { - _searches = searches; - } [NadekoCommand, Usage, Description, Aliases] public async Task Yomama() @@ -65,24 +59,24 @@ namespace NadekoBot.Modules.Searches [NadekoCommand, Usage, Description, Aliases] public async Task WowJoke() { - if (!_searches.WowJokes.Any()) + if (!_service.WowJokes.Any()) { await ReplyErrorLocalized("jokes_not_loaded").ConfigureAwait(false); return; } - var joke = _searches.WowJokes[new NadekoRandom().Next(0, _searches.WowJokes.Count)]; + var joke = _service.WowJokes[new NadekoRandom().Next(0, _service.WowJokes.Count)]; await Context.Channel.SendConfirmAsync(joke.Question, joke.Answer).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] public async Task MagicItem() { - if (!_searches.WowJokes.Any()) + if (!_service.WowJokes.Any()) { await ReplyErrorLocalized("magicitems_not_loaded").ConfigureAwait(false); return; } - var item = _searches.MagicItems[new NadekoRandom().Next(0, _searches.MagicItems.Count)]; + var item = _service.MagicItems[new NadekoRandom().Next(0, _service.MagicItems.Count)]; await Context.Channel.SendConfirmAsync("✨" + item.Name, item.Description).ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Searches/Commands/PokemonSearchCommands.cs b/src/NadekoBot/Modules/Searches/Commands/PokemonSearchCommands.cs index b457b02b..4cdec0c0 100644 --- a/src/NadekoBot/Modules/Searches/Commands/PokemonSearchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/PokemonSearchCommands.cs @@ -12,17 +12,10 @@ namespace NadekoBot.Modules.Searches public partial class Searches { [Group] - public class PokemonSearchCommands : NadekoSubmodule + public class PokemonSearchCommands : NadekoSubmodule { - private readonly SearchesService _searches; - - public Dictionary Pokemons => _searches.Pokemons; - public Dictionary PokemonAbilities => _searches.PokemonAbilities; - - public PokemonSearchCommands(SearchesService searches) - { - _searches = searches; - } + public Dictionary Pokemons => _service.Pokemons; + public Dictionary PokemonAbilities => _service.PokemonAbilities; [NadekoCommand, Usage, Description, Aliases] public async Task Pokemon([Remainder] string pokemon = null) diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs index 30e18523..4ec1a325 100644 --- a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs @@ -15,15 +15,13 @@ namespace NadekoBot.Modules.Searches public partial class Searches { [Group] - public class StreamNotificationCommands : NadekoSubmodule + public class StreamNotificationCommands : NadekoSubmodule { private readonly DbService _db; - private readonly StreamNotificationService _service; - public StreamNotificationCommands(DbService db, StreamNotificationService service) + public StreamNotificationCommands(DbService db) { _db = db; - _service = service; } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index ea2990f5..8c45a953 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -25,17 +25,16 @@ using NadekoBot.DataStructures; namespace NadekoBot.Modules.Searches { - public partial class Searches : NadekoTopLevelModule + public partial class Searches : NadekoTopLevelModule { private readonly IBotCredentials _creds; private readonly IGoogleApiService _google; private readonly SearchesService _searches; - public Searches(IBotCredentials creds, IGoogleApiService google, SearchesService searches) + public Searches(IBotCredentials creds, IGoogleApiService google) { _creds = creds; _google = google; - _searches = searches; } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Utility/Commands/CommandMapCommands.cs b/src/NadekoBot/Modules/Utility/Commands/CommandMapCommands.cs index 03316135..bf79d41a 100644 --- a/src/NadekoBot/Modules/Utility/Commands/CommandMapCommands.cs +++ b/src/NadekoBot/Modules/Utility/Commands/CommandMapCommands.cs @@ -17,15 +17,13 @@ namespace NadekoBot.Modules.Utility public partial class Utility { [Group] - public class CommandMapCommands : NadekoSubmodule + public class CommandMapCommands : NadekoSubmodule { - private readonly CommandMapService _service; private readonly DbService _db; private readonly DiscordSocketClient _client; - public CommandMapCommands(CommandMapService service, DbService db, DiscordSocketClient client) + public CommandMapCommands(DbService db, DiscordSocketClient client) { - _service = service; _db = db; _client = client; } diff --git a/src/NadekoBot/Modules/Utility/Commands/PatreonCommands.cs b/src/NadekoBot/Modules/Utility/Commands/PatreonCommands.cs index 6e287374..940f82b6 100644 --- a/src/NadekoBot/Modules/Utility/Commands/PatreonCommands.cs +++ b/src/NadekoBot/Modules/Utility/Commands/PatreonCommands.cs @@ -13,21 +13,19 @@ namespace NadekoBot.Modules.Utility public partial class Utility { [Group] - public class PatreonCommands : NadekoSubmodule + public class PatreonCommands : NadekoSubmodule { - private readonly PatreonRewardsService _patreon; private readonly IBotCredentials _creds; private readonly BotConfig _config; private readonly DbService _db; private readonly CurrencyService _currency; - public PatreonCommands(PatreonRewardsService p, IBotCredentials creds, BotConfig config, DbService db, CurrencyService currency) + public PatreonCommands(IBotCredentials creds, BotConfig config, DbService db, CurrencyService currency) { _creds = creds; _config = config; _db = db; _currency = currency; - _patreon = p; } [NadekoCommand, Usage, Description, Aliases] @@ -37,7 +35,7 @@ namespace NadekoBot.Modules.Utility { if (string.IsNullOrWhiteSpace(_creds.PatreonAccessToken)) return; - await _patreon.RefreshPledges(true).ConfigureAwait(false); + await _service.RefreshPledges(true).ConfigureAwait(false); await Context.Channel.SendConfirmAsync("👌").ConfigureAwait(false); } @@ -57,7 +55,7 @@ namespace NadekoBot.Modules.Utility int amount = 0; try { - amount = await _patreon.ClaimReward(Context.User.Id).ConfigureAwait(false); + amount = await _service.ClaimReward(Context.User.Id).ConfigureAwait(false); } catch (Exception ex) { @@ -69,7 +67,7 @@ namespace NadekoBot.Modules.Utility await ReplyConfirmLocalized("clpa_success", amount + _config.CurrencySign).ConfigureAwait(false); return; } - var rem = (_patreon.Interval - (DateTime.UtcNow - _patreon.LastUpdate)); + var rem = (_service.Interval - (DateTime.UtcNow - _service.LastUpdate)); var helpcmd = Format.Code(Prefix + "donate"); await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithDescription(GetText("clpa_fail")) diff --git a/src/NadekoBot/Modules/Utility/Commands/Remind.cs b/src/NadekoBot/Modules/Utility/Commands/Remind.cs index e16a0486..e87dcfa9 100644 --- a/src/NadekoBot/Modules/Utility/Commands/Remind.cs +++ b/src/NadekoBot/Modules/Utility/Commands/Remind.cs @@ -16,15 +16,13 @@ namespace NadekoBot.Modules.Utility public partial class Utility { [Group] - public class RemindCommands : NadekoSubmodule + public class RemindCommands : NadekoSubmodule { - private readonly RemindService _service; private readonly DbService _db; private readonly GuildTimezoneService _tz; - public RemindCommands(RemindService service, DbService db, GuildTimezoneService tz) + public RemindCommands(DbService db, GuildTimezoneService tz) { - _service = service; _db = db; _tz = tz; } diff --git a/src/NadekoBot/Modules/Utility/Commands/RepeatCommands.cs b/src/NadekoBot/Modules/Utility/Commands/RepeatCommands.cs index 457e7b67..d7f38e0c 100644 --- a/src/NadekoBot/Modules/Utility/Commands/RepeatCommands.cs +++ b/src/NadekoBot/Modules/Utility/Commands/RepeatCommands.cs @@ -19,15 +19,13 @@ namespace NadekoBot.Modules.Utility public partial class Utility { [Group] - public class RepeatCommands : NadekoSubmodule + public class RepeatCommands : NadekoSubmodule { - private readonly MessageRepeaterService _service; private readonly DiscordSocketClient _client; private readonly DbService _db; - public RepeatCommands(MessageRepeaterService service, DiscordSocketClient client, DbService db) + public RepeatCommands(DiscordSocketClient client, DbService db) { - _service = service; _client = client; _db = db; } diff --git a/src/NadekoBot/Modules/Utility/Commands/StreamRoleCommands.cs b/src/NadekoBot/Modules/Utility/Commands/StreamRoleCommands.cs index 5bfa393b..9b534b12 100644 --- a/src/NadekoBot/Modules/Utility/Commands/StreamRoleCommands.cs +++ b/src/NadekoBot/Modules/Utility/Commands/StreamRoleCommands.cs @@ -8,22 +8,15 @@ namespace NadekoBot.Modules.Utility { public partial class Utility { - public class StreamRoleCommands : NadekoSubmodule + public class StreamRoleCommands : NadekoSubmodule { - private readonly StreamRoleService service; - - public StreamRoleCommands(StreamRoleService service) - { - this.service = service; - } - [NadekoCommand, Usage, Description, Aliases] [RequireBotPermission(GuildPermission.ManageRoles)] [RequireUserPermission(GuildPermission.ManageRoles)] [RequireContext(ContextType.Guild)] public async Task StreamRole(IRole fromRole, IRole addRole) { - this.service.SetStreamRole(fromRole, addRole); + this._service.SetStreamRole(fromRole, addRole); await ReplyConfirmLocalized("stream_role_enabled", Format.Bold(fromRole.ToString()), Format.Bold(addRole.ToString())).ConfigureAwait(false); } @@ -34,7 +27,7 @@ namespace NadekoBot.Modules.Utility [RequireContext(ContextType.Guild)] public async Task StreamRole() { - this.service.StopStreamRole(Context.Guild.Id); + this._service.StopStreamRole(Context.Guild.Id); await ReplyConfirmLocalized("stream_role_disabled").ConfigureAwait(false); } } diff --git a/src/NadekoBot/Modules/Utility/Commands/UnitConversion.cs b/src/NadekoBot/Modules/Utility/Commands/UnitConversion.cs index 1e7f5d22..aafa3b1f 100644 --- a/src/NadekoBot/Modules/Utility/Commands/UnitConversion.cs +++ b/src/NadekoBot/Modules/Utility/Commands/UnitConversion.cs @@ -11,15 +11,8 @@ namespace NadekoBot.Modules.Utility public partial class Utility { [Group] - public class UnitConverterCommands : NadekoSubmodule + public class UnitConverterCommands : NadekoSubmodule { - private readonly ConverterService _service; - - public UnitConverterCommands(ConverterService service) - { - _service = service; - } - [NadekoCommand, Usage, Description, Aliases] public async Task ConvertList() { diff --git a/src/NadekoBot/Modules/Utility/Commands/VerboseCommandErrors.cs b/src/NadekoBot/Modules/Utility/Commands/VerboseCommandErrors.cs index 8ec131d0..db73bdda 100644 --- a/src/NadekoBot/Modules/Utility/Commands/VerboseCommandErrors.cs +++ b/src/NadekoBot/Modules/Utility/Commands/VerboseCommandErrors.cs @@ -8,21 +8,14 @@ namespace NadekoBot.Modules.Utility public partial class Utility { [Group] - public class VerboseCommandErrors : NadekoSubmodule + public class VerboseCommandErrors : NadekoSubmodule { - private readonly VerboseErrorsService _ves; - - public VerboseCommandErrors(VerboseErrorsService ves) - { - _ves = ves; - } - [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequireUserPermission(Discord.GuildPermission.ManageMessages)] public async Task VerboseError() { - var state = _ves.ToggleVerboseErrors(Context.Guild.Id); + var state = _service.ToggleVerboseErrors(Context.Guild.Id); if (state) await ReplyConfirmLocalized("verbose_errors_enabled").ConfigureAwait(false); diff --git a/src/NadekoBot/NadekoBot.csproj b/src/NadekoBot/NadekoBot.csproj index b0d9d8b0..07193a3c 100644 --- a/src/NadekoBot/NadekoBot.csproj +++ b/src/NadekoBot/NadekoBot.csproj @@ -31,8 +31,11 @@ + + + Always @@ -88,8 +91,4 @@ - - - - diff --git a/src/NadekoBot/Services/ServiceProvider.cs b/src/NadekoBot/Services/ServiceProvider.cs index 03eebec6..6e0c642b 100644 --- a/src/NadekoBot/Services/ServiceProvider.cs +++ b/src/NadekoBot/Services/ServiceProvider.cs @@ -4,12 +4,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.Immutable; using System.Reflection; -using Discord.Commands; -using Discord.WebSocket; -using NadekoBot.Services.Database.Models; -using NadekoBot.Services.Impl; using System.Linq; -using NadekoBot.Extensions; using System.Diagnostics; using NLog;