ChatCommands: Output now supports RazorEngine

Depreciated as of r273
Bot# now implements the RazorEngine. This means plugins can use it to do advanced template-based text formatting. This can either be done manually by the plugin author (example: Need to iterate through a couple entries, and add a complex piece of text generated from each of these objects), or it can be done using the ChatCommandHandlers implementation.
Here’s an example implementation of the latter, taken directly from the TestPlugin:

        [Command("test5"), CommandPermission(AccessLevel.Other), Description("This is a test of the RazorEngine implementation")]
        [TemplateString("Hello, @Model.Name! This is a RazorEngine test. Time&date now: @Model.Date @Model.Time. Rawr!")]
        public object ChatCommandTest5()
            return new {
                Name = ChatCommand.This.Raw.SenderName,
                Date = DateTime.Now.ToShortDateString(),
                Time = DateTime.Now.ToShortTimeString()            

I’ll get to the RazorEngine-specific explanation soon, but I’ll start with the beginning.
[Command(“test5”)] tells the ChatCommandHandler that this method will handle the chatcommand ‘test5’. [CommandPermission(AccessLevel.Other)] tells the ChatCommandHandler what access level is required, by default, in order to execute this chat command. This may be overridden by the bot administrator at any time. [Description(“text”)] is quite self-explanatory. The help system use this text to describe the command to the user. [TemplateString(“text”)] is the RazorEngine template string, which will be passed to the RazorEngine along with the returned object.

If the template is complex, it may clutter the code to have it inline like this. Luckily, you can point to a template file instead, as the following example shows:

        [Command("test6"), CommandPermission(AccessLevel.Other), Description("This is a test of the RazorEngine implementation")]
        public object ChatCommandTest6()
            return new
                CharacterName = ChatCommand.This.Raw.SenderName,
                CharacterID = ChatCommand.This.Raw.Sender

Depreciated as of r273

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s