示例#1
0
        public void RegisterPlugin(Plugin plugin)
        {
            if (PluginCommands.ContainsKey(plugin))
            {
                throw new InvalidOperationException("Plugin is already laoded.");
            }

            var comList = plugin.GetWrappedCommands().ToList();

            CheckDistinct(comList);

            PluginCommands.Add(plugin, comList.AsReadOnly());

            int loaded = 0;

            try
            {
                for (; loaded < comList.Count; loaded++)
                {
                    LoadCommand(comList[loaded]);
                }
            }
            catch             // TODO test
            {
                for (int i = 0; i <= loaded && i < comList.Count; i++)
                {
                    UnloadCommand(comList[i]);
                }
                throw;
            }
        }
示例#2
0
 public void UnregisterPlugin(Plugin plugin)
 {
     if (PluginCommands.TryGetValue(plugin, out IList <BotCommand> commands))
     {
         foreach (var com in commands)
         {
             UnloadCommand(com);
         }
     }
 }
 /// <summary>
 /// Attempts to get a command from this plugin.
 /// </summary>
 /// <param name="command">The command to retrieve.</param>
 /// <returns>The command.</returns>
 public ICommand GetCommand(ICommand command) => PluginCommands?.FirstOrDefault(x => x.CommandTag == command.CommandTag);
 private ICommandResult Plugin_CommandExecutionRequested(IPlugin sender, ICommand requestedCommand, params string[] execArgs)
 {
     return(PluginCommands?
            .FirstOrDefault(x => x.CommandTag.ToLowerInvariant() == requestedCommand.CommandTag.ToLowerInvariant())?
            .Execute(execArgs));
 }
 /// <summary>
 /// Gets a value indicating whether the inheriting plugin contains
 /// a given command.
 /// </summary>
 /// <param name="command">A command to check against.</param>
 /// <returns><code >true</code> if the command was found in this plugin.</returns>
 public bool HasCommand(ICommand command) => PluginCommands?.Count(x => x.CommandTag == command.CommandTag) > 0;