More refactoring

This commit is contained in:
Master Kwoth 2017-07-15 18:34:34 +02:00
parent b3243eb0e9
commit 4e11a6c8bc
39 changed files with 174 additions and 284 deletions

View File

@ -12,16 +12,14 @@ using NadekoBot.Services.Administration;
namespace NadekoBot.Modules.Administration
{
public partial class Administration : NadekoTopLevelModule
public partial class Administration : NadekoTopLevelModule<AdministrationService>
{
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);
}
}

View File

@ -12,15 +12,13 @@ namespace NadekoBot.Modules.Administration
public partial class Administration
{
[Group]
public class AutoAssignRoleCommands : NadekoSubmodule
public class AutoAssignRoleCommands : NadekoSubmodule<AutoAssignRoleService>
{
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]

View File

@ -10,15 +10,13 @@ namespace NadekoBot.Modules.Administration
public partial class Administration
{
[Group]
public class GameChannelCommands : NadekoSubmodule
public class GameChannelCommands : NadekoSubmodule<GameVoiceChannelService>
{
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]

View File

@ -18,14 +18,12 @@ namespace NadekoBot.Modules.Administration
{
[Group]
[NoPublicBot]
public class LogCommands : NadekoSubmodule
public class LogCommands : NadekoSubmodule<LogCommandService>
{
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:

View File

@ -11,14 +11,12 @@ namespace NadekoBot.Modules.Administration
public partial class Administration
{
[Group]
public class MuteCommands : NadekoSubmodule
public class MuteCommands : NadekoSubmodule<MuteService>
{
private readonly MuteService _service;
private readonly DbService _db;
public MuteCommands(MuteService service, DbService db)
public MuteCommands(DbService db)
{
_service = service;
_db = db;
}

View File

@ -11,16 +11,14 @@ namespace NadekoBot.Modules.Administration
public partial class Administration
{
[Group]
public class PlayingRotateCommands : NadekoSubmodule
public class PlayingRotateCommands : NadekoSubmodule<PlayingRotateService>
{
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]

View File

@ -15,15 +15,13 @@ namespace NadekoBot.Modules.Administration
public partial class Administration
{
[Group]
public class ProtectionCommands : NadekoSubmodule
public class ProtectionCommands : NadekoSubmodule<ProtectionService>
{
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;
}

View File

@ -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<PruneService>
{
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);
}
}
}

View File

@ -15,14 +15,12 @@ namespace NadekoBot.Modules.Administration
public partial class Administration
{
[Group]
public class SlowModeCommands : NadekoSubmodule
public class SlowModeCommands : NadekoSubmodule<SlowmodeService>
{
private readonly SlowmodeService _service;
private readonly DbService _db;
public SlowModeCommands(SlowmodeService service, DbService db)
public SlowModeCommands(DbService db)
{
_service = service;
_db = db;
}

View File

@ -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<SelfService>
{
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;

View File

@ -11,14 +11,12 @@ namespace NadekoBot.Modules.Administration
public partial class Administration
{
[Group]
public class ServerGreetCommands : NadekoSubmodule
public class ServerGreetCommands : NadekoSubmodule<GreetSettingsService>
{
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);

View File

@ -13,15 +13,8 @@ namespace NadekoBot.Modules.Administration
public partial class Administration
{
[Group]
public class TimeZoneCommands : NadekoSubmodule
public class TimeZoneCommands : NadekoSubmodule<GuildTimezoneService>
{
private readonly GuildTimezoneService _service;
public TimeZoneCommands(GuildTimezoneService service)
{
_service = service;
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Timezones(int page = 1)

View File

@ -15,15 +15,13 @@ namespace NadekoBot.Modules.Administration
public partial class Administration
{
[Group]
public class UserPunishCommands : NadekoSubmodule
public class UserPunishCommands : NadekoSubmodule<UserPunishService>
{
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]

View File

@ -16,14 +16,12 @@ namespace NadekoBot.Modules.Administration
public partial class Administration
{
[Group]
public class VcRoleCommands : NadekoSubmodule
public class VcRoleCommands : NadekoSubmodule<VcRoleService>
{
private readonly VcRoleService _service;
private readonly DbService _db;
public VcRoleCommands(VcRoleService service, DbService db)
public VcRoleCommands(DbService db)
{
_service = service;
_db = db;
}

View File

@ -15,14 +15,12 @@ namespace NadekoBot.Modules.Administration
public partial class Administration
{
[Group]
public class VoicePlusTextCommands : NadekoSubmodule
public class VoicePlusTextCommands : NadekoSubmodule<VplusTService>
{
private readonly VplusTService _service;
private readonly DbService _db;
public VoicePlusTextCommands(VplusTService service, DbService db)
public VoicePlusTextCommands(DbService db)
{
_service = service;
_db = db;
}

View File

@ -12,19 +12,17 @@ using NadekoBot.Services.CustomReactions;
namespace NadekoBot.Modules.CustomReactions
{
public class CustomReactions : NadekoTopLevelModule
public class CustomReactions : NadekoTopLevelModule<CustomReactionsService>
{
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<CustomReaction>()).Where(cr => cr != null).ToArray();
customReactions = _service.GuildReactions.GetOrAdd(Context.Guild.Id, Array.Empty<CustomReaction>()).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;

View File

@ -11,15 +11,13 @@ namespace NadekoBot.Modules.Games
public partial class Games
{
[Group]
public class CleverBotCommands : NadekoSubmodule
public class CleverBotCommands : NadekoSubmodule<ChatterBotService>
{
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<ChatterBotSession> throwaway))
if (_service.ChatterBotGuilds.TryRemove(channel.Guild.Id, out Lazy<ChatterBotSession> throwaway))
{
using (var uow = _db.UnitOfWork)
{
@ -40,7 +38,7 @@ namespace NadekoBot.Modules.Games
return;
}
_games.ChatterBotGuilds.TryAdd(channel.Guild.Id, new Lazy<ChatterBotSession>(() => new ChatterBotSession(Context.Guild.Id), true));
_service.ChatterBotGuilds.TryAdd(channel.Guild.Id, new Lazy<ChatterBotSession>(() => new ChatterBotSession(Context.Guild.Id), true));
using (var uow = _db.UnitOfWork)
{

View File

@ -11,15 +11,13 @@ namespace NadekoBot.Modules.Games
public partial class Games
{
[Group]
public class PollCommands : NadekoSubmodule
public class PollCommands : NadekoSubmodule<PollService>
{
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);
}
}

View File

@ -9,14 +9,12 @@ using NadekoBot.Services.Games;
namespace NadekoBot.Modules.Games
{
public partial class Games : NadekoTopLevelModule
public partial class Games : NadekoTopLevelModule<GamesService>
{
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)

View File

@ -15,7 +15,7 @@ using NadekoBot.Services.Help;
namespace NadekoBot.Modules.Help
{
public class Help : NadekoTopLevelModule
public class Help : NadekoTopLevelModule<HelpService>
{
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());

View File

@ -21,22 +21,20 @@ using NadekoBot.Services.Impl;
namespace NadekoBot.Modules.Music
{
[NoPublicBot]
public class Music : NadekoTopLevelModule
public class Music : NadekoTopLevelModule<MusicService>
{
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;

View File

@ -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<SearchesService>
{
private static readonly ConcurrentDictionary<ulong, Timer> _autoHentaiTimers = new ConcurrentDictionary<ulong, Timer>();
private static readonly ConcurrentHashSet<ulong> _hentaiBombBlacklist = new ConcurrentHashSet<ulong>();
private readonly SearchesService _service;
public NSFW(SearchesService service)
{
_service = service;
}
private async Task InternalHentai(IMessageChannel channel, string tag, bool noError)
{

View File

@ -131,7 +131,21 @@ namespace NadekoBot.Modules
}
}
public abstract class NadekoTopLevelModule<TService> : 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<TService> : NadekoTopLevelModule<TService> where TService : INService
{
protected NadekoSubmodule() : base(false)
{

View File

@ -13,15 +13,13 @@ using NadekoBot.Services.Permissions;
namespace NadekoBot.Modules.Permissions
{
public partial class Permissions : NadekoTopLevelModule
public partial class Permissions : NadekoTopLevelModule<PermissionService>
{
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]

View File

@ -12,16 +12,14 @@ using NadekoBot.Services.Pokemon;
namespace NadekoBot.Modules.Pokemon
{
public class Pokemon : NadekoTopLevelModule
public class Pokemon : NadekoTopLevelModule<PokemonService>
{
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;

View File

@ -15,15 +15,8 @@ namespace NadekoBot.Modules.Searches
public partial class Searches
{
[Group]
public class AnimeSearchCommands : NadekoSubmodule
public class AnimeSearchCommands : NadekoSubmodule<AnimeSearchService>
{
private readonly AnimeSearchService _service;
public AnimeSearchCommands(AnimeSearchService service)
{
_service = service;
}
[NadekoCommand, Usage, Description, Aliases]
[Priority(0)]
public async Task Mal([Remainder] string name)

View File

@ -14,14 +14,8 @@ namespace NadekoBot.Modules.Searches
public partial class Searches
{
[Group]
public class JokeCommands : NadekoSubmodule
public class JokeCommands : NadekoSubmodule<SearchesService>
{
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);
}

View File

@ -12,17 +12,10 @@ namespace NadekoBot.Modules.Searches
public partial class Searches
{
[Group]
public class PokemonSearchCommands : NadekoSubmodule
public class PokemonSearchCommands : NadekoSubmodule<SearchesService>
{
private readonly SearchesService _searches;
public Dictionary<string, SearchPokemon> Pokemons => _searches.Pokemons;
public Dictionary<string, SearchPokemonAbility> PokemonAbilities => _searches.PokemonAbilities;
public PokemonSearchCommands(SearchesService searches)
{
_searches = searches;
}
public Dictionary<string, SearchPokemon> Pokemons => _service.Pokemons;
public Dictionary<string, SearchPokemonAbility> PokemonAbilities => _service.PokemonAbilities;
[NadekoCommand, Usage, Description, Aliases]
public async Task Pokemon([Remainder] string pokemon = null)

View File

@ -15,15 +15,13 @@ namespace NadekoBot.Modules.Searches
public partial class Searches
{
[Group]
public class StreamNotificationCommands : NadekoSubmodule
public class StreamNotificationCommands : NadekoSubmodule<StreamNotificationService>
{
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]

View File

@ -25,17 +25,16 @@ using NadekoBot.DataStructures;
namespace NadekoBot.Modules.Searches
{
public partial class Searches : NadekoTopLevelModule
public partial class Searches : NadekoTopLevelModule<SearchesService>
{
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]

View File

@ -17,15 +17,13 @@ namespace NadekoBot.Modules.Utility
public partial class Utility
{
[Group]
public class CommandMapCommands : NadekoSubmodule
public class CommandMapCommands : NadekoSubmodule<CommandMapService>
{
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;
}

View File

@ -13,21 +13,19 @@ namespace NadekoBot.Modules.Utility
public partial class Utility
{
[Group]
public class PatreonCommands : NadekoSubmodule
public class PatreonCommands : NadekoSubmodule<PatreonRewardsService>
{
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"))

View File

@ -16,15 +16,13 @@ namespace NadekoBot.Modules.Utility
public partial class Utility
{
[Group]
public class RemindCommands : NadekoSubmodule
public class RemindCommands : NadekoSubmodule<RemindService>
{
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;
}

View File

@ -19,15 +19,13 @@ namespace NadekoBot.Modules.Utility
public partial class Utility
{
[Group]
public class RepeatCommands : NadekoSubmodule
public class RepeatCommands : NadekoSubmodule<MessageRepeaterService>
{
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;
}

View File

@ -8,22 +8,15 @@ namespace NadekoBot.Modules.Utility
{
public partial class Utility
{
public class StreamRoleCommands : NadekoSubmodule
public class StreamRoleCommands : NadekoSubmodule<StreamRoleService>
{
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);
}
}

View File

@ -11,15 +11,8 @@ namespace NadekoBot.Modules.Utility
public partial class Utility
{
[Group]
public class UnitConverterCommands : NadekoSubmodule
public class UnitConverterCommands : NadekoSubmodule<ConverterService>
{
private readonly ConverterService _service;
public UnitConverterCommands(ConverterService service)
{
_service = service;
}
[NadekoCommand, Usage, Description, Aliases]
public async Task ConvertList()
{

View File

@ -8,21 +8,14 @@ namespace NadekoBot.Modules.Utility
public partial class Utility
{
[Group]
public class VerboseCommandErrors : NadekoSubmodule
public class VerboseCommandErrors : NadekoSubmodule<VerboseErrorsService>
{
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);

View File

@ -31,8 +31,11 @@
<ItemGroup>
<Compile Remove="data\**\*;credentials.json" />
<Compile Remove="Modules\Music\Classes\**" />
<Compile Remove="Modules\Utility\Models\**" />
<EmbeddedResource Remove="Modules\Music\Classes\**" />
<EmbeddedResource Remove="Modules\Utility\Models\**" />
<None Remove="Modules\Music\Classes\**" />
<None Remove="Modules\Utility\Models\**" />
<None Update="credentials_example.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
@ -88,8 +91,4 @@
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Modules\Music\Classes\" />
</ItemGroup>
</Project>

View File

@ -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;