MrRacoon / RaBot

Modular Haskell IRC Bot Framework
Other
2 stars 0 forks source link

RaBot

Modular IRC Bot Framework

I wrote this framework, while working at the Computer Action Team at Portland State University. Mainly for fun and practice.

The idea is that all of the commands get loaded from the command directory at runtime, and can be reloaded at anytime in the bot's lifespan. The syntax adheres to typical Haskell syntax.

Make a Bot

Use your package manager of choice to install the haskell platform if you don't already have it. The platform includes Haskell's awesome module manager cabal which we'll need later. The following example is for use on debian systems.

sudo apt-get install haskell-platform

Now, RaBot requires two modules to run, one for regex, and the other to handle Unicode -> utf8. Use cabal to install the following packages like so.

cabal update
cabal install regex-tdfa
cabal install hxt-unicode
cabal install quickcheck 

Now we're set to build RaBot!

Get the source code from GitHub.

git clone https://github.com/MrRacoon/RaBot

compile and go!

cd RaBot
ghc --make Main.hs -o RaBot
./RaBot

Commands

data Command  
    = Command   
    { name    :: String   
    , state   :: C_State   
    , auth    :: [ACL]
    , usage   :: String
    , desc    :: String
    , trigger :: [C_Trigger]
    , action  :: [C_Action] }
  deriving (Show,Read)

Name

The name of the command comes into play whenever command help is requested. If this field is ommited using the empty string, "" help information will not be displayed.

State

The State is going to specify when a Command needs to be run depending on whether the bot is being requested directly or not.

Auth

In order to ensure that only the people you want executing certain commands, are the only people executing commnds, there is a basic authorization framework.

Authorization Levels

data ACL 
    = ACL_N
    | ACL_W Authorization 
    | ACL_M Authorization Authorization
    | ACL_S Authorization Authorization Authorization
  deriving (Show,Read,Eq)

Authorization Token Types

data Authorization 
    = Auth_Nick String
    | Auth_User String
    | Auth_Host String
  deriving (Show,Read,Eq)

Usage

Usage is a string denoting how the command should be used. The description only ever crops up when the commander asks for help.

Desc

The description is a description of the command and like the usage field only ever crops up when the commander requests for a description of the various commands.

Trigger

The triggers are used to trigger a command based off the content of the message field in a message over IRC.

data C_Trigger 
    = AllMessages
    | FirstWord String
    | WordPresent String
    | FollowedBy String String
    | EntireMessage String
    | EmptyMessage
  deriving (Show,Read,Eq)

Action

Actions are run for every Command that is triggered successfully.

data C_Action
    = KILL
    | Respond Response_Type [Argument] Destination
    | ReloadCommands
    | LogToFile [Argument] [Argument]
    | HelpCommandList
    | HelpUsageList
    | HelpDescriptionList
    | RunScript String [Argument] Destination
  deriving (Show,Read)

Arguments

Arguments are tokens that will resolve to strings based on the state of the bot at the given time in which they are resolved.

data Argument
    = NULL
    | SourceUrl
    | Literal String
    | WordAfter String
    | AllWordsAfter String
    | FirstChannelMentioned
    | Message_Nickname
    | Message_Username
    | Message_Channel
    | Message_Hostname
    | Message_WholeMessage
    | Message_AllFields
    | Bot_Nickname
    | Bot_OwnerNick
    | Bot_OwnerUser
    | Bot_AttChar
    | Bot_Server
    | Bot_Port
    | Bot_Channels
    | Bot_CommandCount
    | Bot_CommandDirectory
    | Bot_ScriptDirectory
    | Bot_LogDirectory
    | Bot_DebugLevel
  deriving (Show,Read)

Destination

The destination of an IRC Message Response

data Destination
    = To_Current
    | To_Server
    | To_Channel String
  deriving (Show,Read)