Added required parameter to GetService

This commit is contained in:
RogueException
2015-11-09 01:35:02 -04:00
parent 093095e410
commit 2e4f880563
7 changed files with 19 additions and 28 deletions

View File

@@ -2,7 +2,7 @@
{
public static class CommandExtensions
{
public static CommandService Commands(this DiscordClient client)
=> client.GetService<CommandService>();
public static CommandService Commands(this DiscordClient client, bool required = true)
=> client.GetService<CommandService>(required);
}
}

View File

@@ -1,6 +1,4 @@
using System;
namespace Discord.Commands.Permissions.Levels
namespace Discord.Commands.Permissions.Levels
{
public class PermissionLevelChecker : IPermissionChecker
{
@@ -12,10 +10,8 @@ namespace Discord.Commands.Permissions.Levels
internal PermissionLevelChecker(DiscordClient client, int minPermissions)
{
_service = client.GetService<PermissionLevelService>();
_service = client.GetService<PermissionLevelService>(true);
_minPermissions = minPermissions;
if (_service == null)
throw new InvalidOperationException($"{nameof(PermissionLevelService)} must be added to {nameof(DiscordClient)} before this function is called.");
}
public bool CanRun(Command command, User user, Channel channel)

View File

@@ -1,6 +1,4 @@
using System;
namespace Discord.Commands.Permissions.Userlist
namespace Discord.Commands.Permissions.Userlist
{
public class BlacklistChecker : IPermissionChecker
{
@@ -8,9 +6,7 @@ namespace Discord.Commands.Permissions.Userlist
internal BlacklistChecker(DiscordClient client)
{
_service = client.GetService<BlacklistService>();
if (_service == null)
throw new InvalidOperationException($"{nameof(BlacklistService)} must be added to {nameof(DiscordClient)} before this function is called.");
_service = client.GetService<BlacklistService>(true);
}
public bool CanRun(Command command, User user, Channel channel)

View File

@@ -1,6 +1,4 @@
using System;
namespace Discord.Commands.Permissions.Userlist
namespace Discord.Commands.Permissions.Userlist
{
public class WhitelistChecker : IPermissionChecker
{
@@ -8,9 +6,7 @@ namespace Discord.Commands.Permissions.Userlist
internal WhitelistChecker(DiscordClient client)
{
_service = client.GetService<WhitelistService>();
if (_service == null)
throw new InvalidOperationException($"{nameof(WhitelistService)} must be added to {nameof(DiscordClient)} before this function is called.");
_service = client.GetService<WhitelistService>(true);
}
public bool CanRun(Command command, User user, Channel channel)