Skip to content
Valerie Pond edited this page May 23, 2021 · 2 revisions

Hooks



As Valeyard is primarily an IRC client, we call our IRC events using hooks.

Here is an example of the first line you'd need when "hooking in" to a privmsg (which fires on a channel message and a private message). We also use a function and a variable to put the information into that gets sent along with the hook. I commonly use $u to grab the information, and so I will use it in the example below.

hook::func("privmsg", function($u){

Available hooks:

  • "connect" - Fires when the bot successfully connects to the IRC server. Specifically, when the bot receives the numeric 001 from the server. citation.
  • "privmsg" - Fires on a channel message and a private message citation.
  • "notice" - Fires on notices, including server notices, channel or private. citation.
  • "join" - Fires when someone (either the bot or someone else) joins a channel. citation.
  • "part" - Fires when someone (either the bot or someone else) parts a channel. citation.
  • "quit" - Fires when someone (either the bot or someone else) quits and they were from a common channel. citation.
  • "mode" - Fires when a mode is set (either on the bot or in a channel). citation.
  • "ping" Fires when the server sends the bot a PING. citation.
  • "auth" Fires when SASL server tells us we authd correctly. citation.



Commonly passed hook information and how to call it

Following any of these citations will show you what information gets passed to the hook. Examples of information that commonly gets passed in hooks

  • 'nick' - The username which triggered the hook
  • 'ident' - The ident of the nick which triggered the hook
  • 'hostmask' - The hostmask
  • 'dest' - Where it was sent (usually either $me or a channel)
  • 'parc' - the entire command params they sent
  • 'mtags' - the message-tags that were sent along



Earlier, in the hook::func example upstairs, I told you that I like to store this information in the variable $u And so you can call information within the hook as an array, like so:

$u['nick'] $u['dest']

etc. For an example of how to do this, check out this example

Clone this wiki locally