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:

  1. With .on(), defines a Trigger and the associated Hook
  2. 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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(**opts) #

[View source]

Instance Method Detail

def docs : Hash(String, String) #

Documentation lines for each hook


[View source]
def handle(msg : String) #

Sugar for #handle that parse the string as a Crirc::Protocol::Message


[View source]
def handle(msg : Crirc::Protocol::Message) #

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 ?)


[View source]
def hooks : Hash(Trigger, Array(Hook)) #

Hooks associated with Trigger


[View source]
def on(command : String = "PRIVMSG", source : HookRule = nil, arguments : HookRule = nil, message : HookRule = nil, doc : Tuple(String, String)? = 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.

  • 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 and match).

[View source]