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.
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
data Command
= Command
{ name :: String
, state :: C_State
, auth :: [ACL]
, usage :: String
, desc :: String
, trigger :: [C_Trigger]
, action :: [C_Action] }
deriving (Show,Read)
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.
The State
is going to specify when a Command
needs to be run
depending on whether the bot is being requested directly or not.
Active
Passive
Always
Never
Never
state disallows the
command from ever being run.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.
data ACL
= ACL_N
| ACL_W Authorization
| ACL_M Authorization Authorization
| ACL_S Authorization Authorization Authorization
deriving (Show,Read,Eq)
ACL_N
ACL_W Token
ACL_M Token Token
ACL_S Token Token Token
data Authorization
= Auth_Nick String
| Auth_User String
| Auth_Host String
deriving (Show,Read,Eq)
AUTH_Nick String
AUTH_User String
AUTH_Host String
Usage is a string denoting how the command should be used. The description only ever crops up when the commander asks for help.
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.
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)
AllMessages
FirstWord String
WordPresent String
FollowedBy String String
EntireMessage String
EmptyMessage
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)
KILL
Respond Response_Type [Argument] Destination
ReloadCommands
LogToFile [Argument] [Argument]
HelpCommandList
HelpUsageList
HelpDescriptionList
RunScript String [Argument] Destination
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)
NULL
[]
.SourceUrl
Literal String
String
literally.WordAfter String
[]
if the word is not found.AllWordsAfter String
[]
if not present.FirstChannelMentioned
#
character.Message_Nickname
Message_Username
Message_Channel
Message_Hostname
Message_WholeMessage
Message_AllFields
Bot_Nickname
Bot_OwnerNick
Bot_OwnerUser
Bot_AttChar
Active
comands
along with it's own nickname.Bot_Server
Bot_Port
Bot_Channels
Bot_CommandCount
Bot_CommandDirectory
Bot_ScriptDirectory
Bot_LogDirectory
Bot_DebugLevel
The destination of an IRC Message Response
data Destination
= To_Current
| To_Server
| To_Channel String
deriving (Show,Read)
To_Current
To_Server
To_Channel String