Comment on page

Macro Component Additions

Plugins can also add custom components to the macro builder. Regular plugin api functions can be used within the Execute method. This page describes how to make a plugin that registers new components.
PluginCore.cs
[Plugin(1, "Extra Macro Component Plugin", "Adds new macro components to the macro builder!")]
public class PluginCore : IStartPlugin
{
/// <summary>
/// Should be used to check compatability with the
/// current version of the bot.
/// </summary>
public override void OnLoad(int version, int subversion, int buildversion) { }
public override PluginResponse OnEnable(IBotSettings botSettings) {
/* Regular plugin content */
return base.OnEnable(botSettings);
}
}
public class TestMacroComponent : IExternalMacroComponent {
public TestMacroComponent() {
this.Category = MacroComponentCategory.Misc;
this.Outputs = new IMacroOutputCollection(
new KeyValuePair<string, ExternalMacroOutput>("success", new ExternalMacroOutput("Success", "This output gets called once the call finishes", true)),
new KeyValuePair<string, ExternalMacroOutput>("output_internal_name", new ExternalMacroOutput("Error", "This output will never get called", false))
);
this.Variables = new IMacroVariableCollection(
new KeyValuePair<string, ExternalMacroVariable>("variable_internal_name1", new ExternalMacroVariable(typeof(string), "Message", "What message should we send to chat?", "my default message!"))
);
}
public override string GetName() {
return "Test macro component";
}
public override string GetInternalName() {
return "ex:test_macro_component";
}
public override string GetDescription() {
return "This is a test macro component";
}
public override string GetInteractiveDescription() {
var variableValue = GetVariable<string>("variable_internal_name1");
return
string.IsNullOrWhiteSpace(variableValue) ? GetDescription()
: $"I will say {variableValue}.";
}
public override string Execute(IBotContext Context) {
Context.Functions.Chat("My message: " + GetVariable<string>("variable_internal_name1"));
return "success"; // or return "output_internal_name"
}
}

Outputs

Macro component outputs
Outputs refer to possible paths that the macro component will lead to. The execute method should return a name of one of the registered outputs. These should be registered in the constructor, as can be seen here:
public TestMacroComponent() {
...
this.Outputs = new IMacroOutputCollection(
new KeyValuePair<string, ExternalMacroOutput>("success", new ExternalMacroOutput("Success", "This output gets called once the call finishes", true)),
new KeyValuePair<string, ExternalMacroOutput>("output_internal_name", new ExternalMacroOutput("Error", "This output will never get called", false))
);
...
}