Removed DiscordBotClient, moved to CommandsPlugin
This commit is contained in:
@@ -46,11 +46,11 @@
|
||||
<Compile Include="..\Discord.Net.Commands\CommandParser.cs">
|
||||
<Link>CommandParser.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Discord.Net.Commands\DiscordBotClient.cs">
|
||||
<Link>DiscordBotClient.cs</Link>
|
||||
<Compile Include="..\Discord.Net.Commands\CommandsPlugin.cs">
|
||||
<Link>CommandsPlugin.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Discord.Net.Commands\DiscordBotClient.Events.cs">
|
||||
<Link>DiscordBotClient.Events.cs</Link>
|
||||
<Compile Include="..\Discord.Net.Commands\CommandsPlugin.Events.cs">
|
||||
<Link>CommandsPlugin.Events.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -71,13 +71,13 @@ namespace Discord.Commands
|
||||
}
|
||||
public sealed class CommandGroupBuilder
|
||||
{
|
||||
private readonly DiscordBotClient _client;
|
||||
private readonly CommandsPlugin _plugin;
|
||||
private readonly string _prefix;
|
||||
private int _defaultMinPermissions;
|
||||
|
||||
internal CommandGroupBuilder(DiscordBotClient client, string prefix, int defaultMinPermissions)
|
||||
internal CommandGroupBuilder(CommandsPlugin plugin, string prefix, int defaultMinPermissions)
|
||||
{
|
||||
_client = client;
|
||||
_plugin = plugin;
|
||||
_prefix = prefix;
|
||||
_defaultMinPermissions = defaultMinPermissions;
|
||||
}
|
||||
@@ -89,7 +89,7 @@ namespace Discord.Commands
|
||||
|
||||
public CommandGroupBuilder CreateCommandGroup(string cmd, Action<CommandGroupBuilder> config = null)
|
||||
{
|
||||
config(new CommandGroupBuilder(_client, _prefix + ' ' + cmd, _defaultMinPermissions));
|
||||
config(new CommandGroupBuilder(_plugin, _prefix + ' ' + cmd, _defaultMinPermissions));
|
||||
return this;
|
||||
}
|
||||
public CommandBuilder CreateCommand()
|
||||
@@ -98,7 +98,7 @@ namespace Discord.Commands
|
||||
{
|
||||
var command = new Command(cmd != "" ? _prefix + ' ' + cmd : _prefix);
|
||||
command.MinPerms = _defaultMinPermissions;
|
||||
_client._commands.Add(command);
|
||||
_plugin._commands.Add(command);
|
||||
return new CommandBuilder(command);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Discord.Commands;
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Discord
|
||||
namespace Discord.Commands
|
||||
{
|
||||
public class PermissionException : Exception { public PermissionException() : base("User does not have permission to run this command.") { } }
|
||||
public class CommandEventArgs
|
||||
@@ -38,7 +37,7 @@ namespace Discord
|
||||
Exception = ex;
|
||||
}
|
||||
}
|
||||
public partial class DiscordBotClient : DiscordClient
|
||||
public partial class CommandsPlugin
|
||||
{
|
||||
public event EventHandler<CommandEventArgs> RanCommand;
|
||||
private void RaiseRanCommand(CommandEventArgs args)
|
||||
@@ -1,13 +1,13 @@
|
||||
using Discord.Commands;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord
|
||||
namespace Discord.Commands
|
||||
{
|
||||
/// <summary> A Discord.Net client with extensions for handling common bot operations like text commands. </summary>
|
||||
public partial class DiscordBotClient : DiscordClient
|
||||
public partial class CommandsPlugin
|
||||
{
|
||||
internal List<Command> _commands;
|
||||
private Func<User, Server, int> _getPermissions;
|
||||
|
||||
public IEnumerable<Command> Commands => _commands;
|
||||
|
||||
@@ -16,24 +16,27 @@ namespace Discord
|
||||
public bool RequireCommandCharInPublic { get; set; }
|
||||
public bool RequireCommandCharInPrivate { get; set; }
|
||||
|
||||
public DiscordBotClient(DiscordClientConfig config = null, Func<User, Server, int> getPermissions = null)
|
||||
: base(config)
|
||||
public CommandsPlugin(Func<User, Server, int> getPermissions = null)
|
||||
{
|
||||
_getPermissions = getPermissions;
|
||||
_commands = new List<Command>();
|
||||
|
||||
CommandChar = '~';
|
||||
UseCommandChar = true;
|
||||
CommandChar = '/';
|
||||
UseCommandChar = false;
|
||||
RequireCommandCharInPublic = true;
|
||||
RequireCommandCharInPrivate = true;
|
||||
}
|
||||
|
||||
MessageCreated += async (s, e) =>
|
||||
public void Install(DiscordClient client)
|
||||
{
|
||||
client.MessageCreated += async (s, e) =>
|
||||
{
|
||||
//If commands aren't being used, don't bother processing them
|
||||
if (_commands.Count == 0)
|
||||
return;
|
||||
|
||||
//Ignore messages from ourselves
|
||||
if (e.Message.UserId == CurrentUserId)
|
||||
if (e.Message.UserId == client.CurrentUserId)
|
||||
return;
|
||||
|
||||
//Check for the command character
|
||||
@@ -87,7 +90,7 @@ namespace Discord
|
||||
newArgs[j] = args[j + cmd.Parts.Length];
|
||||
|
||||
//Check Permissions
|
||||
int permissions = getPermissions != null ? getPermissions(e.Message.User, e.Message.Channel?.Server) : 0;
|
||||
int permissions = _getPermissions != null ? _getPermissions(e.Message.User, e.Message.Channel?.Server) : 0;
|
||||
var eventArgs = new CommandEventArgs(e.Message, cmd, msg, permissions, newArgs);
|
||||
if (permissions < cmd.MinPerms)
|
||||
{
|
||||
Reference in New Issue
Block a user