Add a source type to not command hooks

This commit is contained in:
Zontreck 2020-06-02 08:32:33 -07:00
parent a50237304d
commit fe628b0a9d
3 changed files with 23 additions and 7 deletions

View file

@ -7,6 +7,10 @@ namespace Bot.NonCommands
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class NotCommand : Attribute
{
/// <summary>
/// Defaults to all except action
/// </summary>
public MessageHandler.Destinations SourceType = MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_CONSOLE_INFO | MessageHandler.Destinations.DEST_DISCORD | MessageHandler.Destinations.DEST_GROUP | MessageHandler.Destinations.DEST_LOCAL;
public NotCommand()
{
// Not Command, this just marks a class

View file

@ -24,14 +24,26 @@ namespace Bot.NonCommands
NotCommand[] nc = (NotCommand[])mi.GetCustomAttributes(typeof(NotCommand), false);
if (nc.Length>0)
{
ThreadStart work = delegate
bool OK = false;
foreach(NotCommand nx in nc)
{
if (nx.SourceType.HasFlag(sourceLoc))
{
OK = true;
}
}
if (OK)
{
ThreadStart work = delegate
{
mi.Invoke(Activator.CreateInstance(mi.DeclaringType), new object[] { request, agentKey, agentName, sourceLoc, originator });
};
Thread T = new Thread(work);
T.Start();
mi.Invoke(Activator.CreateInstance(mi.DeclaringType), new object[] { request, agentKey, agentName, sourceLoc, originator });
};
Thread T = new Thread(work);
T.Start();
}
}
}