Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestPlugin"/> class.
        /// The plugin constructor can receive services by dependency injection.
        /// </summary>
        public TestPlugin(ICommandService commands, IPermissionService permissions)
        {
            Console.WriteLine("TEST PLUGIN - Constructor");
            commands.RegisterDelegate("ping", ctx => ctx.Respond("pong"));

            permissions.SetDefaultAccess(PermissionModifier.Allow);
            //permissions.GetPermissions("misc", "console").AddExpression(new PermissionExpression("cmd.ping"));
            permissions.SavePermissions();
            commands.AddProcessorStep((ctx, next) =>
            {
                if (ctx.Sender is ConsoleService)
                {
                    var node = $"cmd.{ctx.CommandName}";

                    if (!permissions.IsAllowed("misc", "console", node))
                    {
                        ctx.Respond($"You do not have permission to use this command (node {node}).");
                        return;
                    }
                }

                next(ctx);
            });
        }