Packages can be loaded/unloaded. IUnloadableService interface added whose method Unload, if service implements it, will be called when the module is unloaded.

This commit is contained in:
Master Kwoth
2017-10-05 00:51:12 +02:00
parent 599245b1ca
commit 33ac43e1b5
74 changed files with 866 additions and 520 deletions

View File

@ -3,6 +3,7 @@ using System.Linq;
using System.Threading.Tasks;
using Discord.Commands;
using NadekoBot.Services;
using NadekoBot.Modules.CustomReactions.Services;
namespace NadekoBot.Common.TypeReaders
{
@ -28,38 +29,38 @@ namespace NadekoBot.Common.TypeReaders
}
}
//todo dependency on the module
//public class CommandOrCrTypeReader : CommandTypeReader
//{
// public override async Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services)
// {
// input = input.ToUpperInvariant();
public class CommandOrCrTypeReader : CommandTypeReader
{
public override async Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services)
{
input = input.ToUpperInvariant();
// var _crs = ((INServiceProvider)services).GetService<CustomReactionsService>();
var _crs = ((INServiceProvider)services).GetService<CustomReactionsService>();
// if (_crs.GlobalReactions.Any(x => x.Trigger.ToUpperInvariant() == input))
// {
// return TypeReaderResult.FromSuccess(new CommandOrCrInfo(input));
// }
// var guild = context.Guild;
// if (guild != null)
// {
// if (_crs.GuildReactions.TryGetValue(guild.Id, out var crs))
// {
// if (crs.Concat(_crs.GlobalReactions).Any(x => x.Trigger.ToUpperInvariant() == input))
// {
// return TypeReaderResult.FromSuccess(new CommandOrCrInfo(input));
// }
// }
// }
if (_crs.GlobalReactions.Any(x => x.Trigger.ToUpperInvariant() == input))
{
return TypeReaderResult.FromSuccess(new CommandOrCrInfo(input));
}
var guild = context.Guild;
if (guild != null)
{
if (_crs.GuildReactions.TryGetValue(guild.Id, out var crs))
{
if (crs.Concat(_crs.GlobalReactions).Any(x => x.Trigger.ToUpperInvariant() == input))
{
return TypeReaderResult.FromSuccess(new CommandOrCrInfo(input));
}
}
}
// var cmd = await base.Read(context, input, services);
// if (cmd.IsSuccess)
// {
// return TypeReaderResult.FromSuccess(new CommandOrCrInfo(((CommandInfo)cmd.Values.First().Value).Name));
// }
// return TypeReaderResult.FromError(CommandError.ParseFailed, "No such command or cr found.");
// }
//}
var cmd = await base.Read(context, input, services);
if (cmd.IsSuccess)
{
return TypeReaderResult.FromSuccess(new CommandOrCrInfo(((CommandInfo)cmd.Values.First().Value).Name));
}
return TypeReaderResult.FromError(CommandError.ParseFailed, "No such command or cr found.");
}
}
public class CommandOrCrInfo
{