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
1
[Plugin(1, "Extra Macro Component Plugin", "Adds new macro components to the macro builder!")]
2
public class PluginCore : IStartPlugin
3
{
4
/// <summary>
5
/// Should be used to check compatability with the
6
/// current version of the bot.
7
/// </summary>
8
public override void OnLoad(int version, int subversion, int buildversion) { }
9
public override PluginResponse OnEnable(IBotSettings botSettings) {
10
/* Regular plugin content */
11
return base.OnEnable(botSettings);
12
}
13
}
14
15
public class TestMacroComponent : IExternalMacroComponent {
16
17
public TestMacroComponent() {
18
this.Category = MacroComponentCategory.Misc;
19
this.Outputs = new IMacroOutputCollection(
20
new KeyValuePair<string, ExternalMacroOutput>("success", new ExternalMacroOutput("Success", "This output gets called once the call finishes", true)),
21
new KeyValuePair<string, ExternalMacroOutput>("output_internal_name", new ExternalMacroOutput("Error", "This output will never get called", false))
22
);
23
this.Variables = new IMacroVariableCollection(
24
new KeyValuePair<string, ExternalMacroVariable>("variable_internal_name1", new ExternalMacroVariable(typeof(string), "Message", "What message should we send to chat?", "my default message!"))
25
);
26
}
27
28
public override string GetName() {
29
return "Test macro component";
30
}
31
32
public override string GetInternalName() {
33
return "ex:test_macro_component";
34
}
35
36
public override string GetDescription() {
37
return "This is a test macro component";
38
}
39
public override string GetInteractiveDescription() {
40
var variableValue = GetVariable<string>("variable_internal_name1");
41
return
42
string.IsNullOrWhiteSpace(variableValue) ? GetDescription()
43
: quot;I will say {variableValue}.";
44
}
45
46
public override string Execute(IBotContext Context) {
47
Context.Functions.Chat("My message: " + GetVariable<string>("variable_internal_name1"));
48
return "success"; // or return "output_internal_name"
49
}
50
}
Copied!

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:
1
public TestMacroComponent() {
2
...
3
this.Outputs = new IMacroOutputCollection(
4
new KeyValuePair<string, ExternalMacroOutput>("success", new ExternalMacroOutput("Success", "This output gets called once the call finishes", true)),
5
new KeyValuePair<string, ExternalMacroOutput>("output_internal_name", new ExternalMacroOutput("Error", "This output will never get called", false))
6
);
7
...
8
}
Copied!
Copy link
Contents
Outputs