QuickStart - mslot/IRCSharp GitHub Wiki

This is the bare minimum for getting the bot up and running.

Downloading

Get the code either by cloning it:

$ git clone git://github.com/mslot/IRCSharp.git

Or by downloading the source:

$ wget https://github.com/mslot/IRCSharp/zipball/master

Configuring the robot

I have made a simple console runner for the bot, located at:

/IRCSharp.ConsoleRunner/

In this directory you will find an App.config where you can configure the name of the bot, which channels to listen on, what server to connect to etc. It should be self-explanatory. When this is done, compile the code, either by running msbuild on the .sln file or open the solution in Visual Studio and compile it. Then it should run.

Extending

It is pretty easy to develop custom commands to the robot. All you have to do is:

  • Create a class library project
  • Add the IRCSharp.Kernel to the projects reference. (remember to compile the source if you have not already done this)
  • Add the IRCSharp.Kernel.Model to projects reference.
  • Make the class implement the IRCSharp.Kernel.UserdefinedCommandBase, class.

A hello world example would be:

namespace UserdefinedCommandExample
{
	[IRCSharp.Kernel.UserdefinedCommand("hello")]
	public class UserdefinedCommandExample : IRCSharp.Kernel.UserdefinedCommandBase
	{
		public override IRCSharp.Kernel.Model.Query.IRCCommandQuery Execute(IRCSharp.Kernel.Model.Query.UserdefinedCommandQuery query)
		{
			//You could use the authenticationProvider to either protect certain users from reading or writing. The default implementation is an XML based user and command list
			//where you can configure user and command authentication and permissions:
			IRCSharp.Kernel.Security.User userWrite;
			base.authenticationProvider.MayUserWriteToCommand(query.From, "hello", out userWrite);
			{

			}

			IRCSharp.Kernel.Security.User userRead;
			base.authenticationProvider.MayUserReadFromCommand(query.From, "hello", out userRead);
			{

			}

			//Execute rights is handled by the system if using the IRCSharp.Kernel.Manager.SecureManager.

			//This is how you get the parameters from the query
			Console.WriteLine("hello from command: " + query.CommandName);
			foreach (string param in query.Parameters)
			{
				Console.WriteLine("param in command: " + param);
			}
			return null;
		}

		public override void Init()
		{
			//here we can run code that should only run once, when the command is initiated. This happens when the bot is starting up.
		}
	}
}

The name of the command is defined by the UserdefinedCommand attribute. The Execute method is the piece of code that is going to be executed when the command is invoked. The prefix for invoking userdefined commands is '!', so this command is going to be invoked like this

!hello arg1 arg2 arg3

Drop the compiled dll in the directory that you have configured in the App.config. Start the bot, and enjoy the wonders of your bot.

This userdefined command example can also be found in the UserdefinedCommandExample project located here, https://github.com/mslot/IRCSharp/tree/master/UserdefinedCommandExample.