Browse Source

Added assembly searching to commands

tags/1.0-rc
RogueException 9 years ago
parent
commit
baf1efb446
2 changed files with 42 additions and 15 deletions
  1. +41
    -14
      src/Discord.Net.Commands/CommandParser.cs
  2. +1
    -1
      src/Discord.Net/Net/Queue/RequestQueue.cs

+ 41
- 14
src/Discord.Net.Commands/CommandParser.cs View File

@@ -12,21 +12,38 @@ namespace Discord.Commands
public string Name { get; }
public IEnumerable<Command> Commands { get; }
internal Module(object module, TypeInfo typeInfo)
internal Module(object parent, TypeInfo typeInfo)
{
List<Command> commands = new List<Command>();
SearchClass(commands);
SearchClass(parent, commands, typeInfo);
Commands = commands;
}

private void SearchClass(List<Command> commands)
private void SearchClass(object parent, List<Command> commands, TypeInfo typeInfo)
{
//TODO: Implement
foreach (var method in typeInfo.DeclaredMethods)
{
if (typeInfo.GetCustomAttribute<CommandAttribute>() != null)
{

}
}
foreach (var type in typeInfo.DeclaredNestedTypes)
{
if (typeInfo.GetCustomAttribute<GroupAttribute>() != null)
{
SearchClass(CommandParser.CreateObject(typeInfo), commands, type);
}
}
}
}
public class Command
{
public string SourceName { get; }

internal Command(TypeInfo typeInfo)
{
}
}

public class CommandParser
@@ -46,7 +63,10 @@ namespace Discord.Commands
{
if (_modules.ContainsKey(module))
throw new ArgumentException($"This module has already been loaded.");
return LoadInternal(module, module.GetType().GetTypeInfo());
var typeInfo = module.GetType().GetTypeInfo();
if (typeInfo.GetCustomAttribute<ModuleAttribute>() == null)
throw new ArgumentException($"Modules must be marked with ModuleAttribute.");
return LoadInternal(module, typeInfo);
}
finally
{
@@ -70,15 +90,7 @@ namespace Discord.Commands
var typeInfo = type.GetTypeInfo();
if (typeInfo.GetCustomAttribute<ModuleAttribute>() != null)
{
var constructor = typeInfo.DeclaredConstructors.Where(x => x.GetParameters().Length == 0).FirstOrDefault();
if (constructor == null)
throw new InvalidOperationException($"Failed to find a valid constructor for \"{typeInfo.FullName}\"");
object module;
try { module = constructor.Invoke(null); }
catch (Exception ex)
{
throw new InvalidOperationException($"Failed to create \"{typeInfo.FullName}\"", ex);
}
var module = CreateObject(typeInfo);
modules.Add(LoadInternal(module, typeInfo));
}
}
@@ -102,5 +114,20 @@ namespace Discord.Commands
_moduleLock.Release();
}
}

internal static object CreateObject(TypeInfo typeInfo)
{
var constructor = typeInfo.DeclaredConstructors.Where(x => x.GetParameters().Length == 0).FirstOrDefault();
if (constructor == null)
throw new InvalidOperationException($"Failed to find a valid constructor for \"{typeInfo.FullName}\"");
try
{
return constructor.Invoke(null);
}
catch (Exception ex)
{
throw new InvalidOperationException($"Failed to create \"{typeInfo.FullName}\"", ex);
}
}
}
}

+ 1
- 1
src/Discord.Net/Net/Queue/RequestQueue.cs View File

@@ -24,7 +24,7 @@ namespace Discord.Net.Queue
_globalLimits = new Dictionary<GlobalBucket, BucketDefinition>
{
//REST
[GlobalBucket.GeneralRest] = new BucketDefinition(0, 0),
[GlobalBucket.GeneralRest] = new BucketDefinition(0, 0), //No Limit
//[GlobalBucket.Login] = new BucketDefinition(1, 1),
[GlobalBucket.DirectMessage] = new BucketDefinition(5, 5),
[GlobalBucket.SendEditMessage] = new BucketDefinition(50, 10),


Loading…
Cancel
Save