module Crirc::Binding::Handler
Overview
This class is designed to be able to automaticaly respond to incoming IRC messages on a set conditions. The flow of this system is the following:
- With
.on()
, defines a Trigger and the associated Hook - Call
.handle()
to process the incoming IRC message.
bot.on("PRIVMSG", message: /^(Hello|Hi)$/) { |msg, data| bot.reply(msg, "Hello !") }
while (incoming_message = io.gets) do
bot.handle(incoming_message)
end
Direct including types
Defined in:
crirc/binding/handler.crConstructors
Instance Method Summary
-
#docs : Hash(String, String)
Documentation lines for each hook
-
#handle(msg : String)
Sugar for
#handle
that parse the string as aCrirc::Protocol::Message
-
#handle(msg : Crirc::Protocol::Message)
Handle one
Message
It goes through the registred hooks, select the one to trigger. -
#hooks : Hash(Trigger, Array(Hook))
Hooks associated with
Trigger
-
#on(command : String = "PRIVMSG", source : HookRule = nil, arguments : HookRule = nil, message : HookRule = nil, doc : Tuple(String, String) | Nil = nil, &hook : Hook)
Register a news Hook that is called when the incoming messages meet a set of conditions: command name (JOIN, PRIVMSG, ...), source, arguments, message.
Constructor Detail
Instance Method Detail
Handle one Message
It goes through the registred hooks, select the one to trigger.
Then, it execute every hooks associated, and send as parameters the current message and the regex match if possible
TODO msg should NEVER be modified in the hook. (copy ? readonly ? struct ?)
Register a news Hook that is called when the incoming messages meet a set of conditions: command name (JOIN, PRIVMSG, ...), source, arguments, message.
- command : Condition that match exactly with the command of the incomming message.
- source : Condition that match with the source of the incomming message.
- arguments : Condition that match with the arguments of the incomming message.
- message : Condition that match with the message of the incomming message.
- doc : Documentation lines (
{short, long}
) - hook : function to call if the conditions are met (with the parameters
message
andmatch
).