Skip to content
shiftkey edited this page Jan 11, 2012 · 4 revisions

Want to start writing your own extensions to JibbR?

Two steps:

  • Create a new Class Library project under the Extensions folder - name it whatever you want

  • Add a class which implements one of the extension points.

As you see below the implementatio of HelloSprocket is done by inheriting the CommandSprocket. This is a sprocket that is made for sending commands to your bot.

The SupportedInitiators are which words should initiating the command when the bot detects a message in the chatroom. The SupportedCommands is the commands you can add after the initiator. So to describe how this actually works here is a small chat sample.

Me: hello you

Bot: Hello Me

public class HelloSprocket : CommandSprocket
{
    public override IEnumerable<string> SupportedInitiators
    {
        get { yield return "hello"; }
    }

    public override IEnumerable<string> SupportedCommands
    {
        get { yield return "you"; }
    }

public override bool ExecuteCommand()
{
        Bot.Say(string.Format("Hello {0}", Message.Sender), Message.Receiver);
        return true;
    }
}

An alternative sprocket could be used to performing periodic tasks. The IAnnounce interface requires an extension declare how often it needs to run, and what code to run. The extension receives the active Bot as a way of interacting with the current set of rooms (if necessary).

public class EchoAnnouncement : IAnnounce
{
    public TimeSpan Interval
    {
        get { return TimeSpan.FromMinutes(5); }
    }

    public void Execute(Bot bot)
    {
        // TODO: something smarter
        foreach (var room in bot.Rooms)
        {
            bot.Say("Hello world!", room);
        }
    }
}

We're using MEF to wire up components at runtime. You don't need to modify the console runner code to add your extension - a post-build step will search the Extensions folder for all assemblies and copy them across.

Clone this wiki locally