Here is how my bot works.
$MessagePrefix = "#"; //Say # in chat like a command
$FunctionPrefix = "ChatBot_"; //Function names (Shown below)
$ChatBot::Name = "ChatBot"; //Chatbot's name
package ChatBot
{
function NMH_Type::send( %this )
{
%value = %this.getValue();
%length = strLen($MessagePrefix);
if(getSubStr(%value,0,%length) $= $MessagePrefix)
{
%this.setValue("");
%value = getSubStr(%value, %length, strLen(%value));
if(isFunction(%func = $FunctionPrefix @ firstWord(%value)))
{
call(%func,restWords(%value));
}
}
else
{
%this.setValue(%value);
}
parent::send( %this );
}
};
activatePackage(ChatBot);
Put down a function as like
function ChatBot_Hi()
{
commandToServer('messagesent',$ChatBot::Name @ ": Hi!");
}
Say #hi in the chat and the bot will say Hi
Creating a command:
function ChatBot_CommandName(%string)
{
//stuff here
}