Showtitle Irssi Bot Script

Showtitle is an Irssi script that scans the current private, public or action message for a string matching a URL specification. If it finds one, it then tries to get the beginning of the URL contents in order to parse out the <title></title> tag, and then attempts to show it either to the channel, or to the script user.

Showtitle is an active bot script, i.e, it responds to certain types of text on channels it is listening on.

The channel text to invoke showtitle commands is "!st" at the beginning of the line.

!st subcommands:

listen (on|off|list)

Determines whether showtitle will be listening to a particular channel.

filter (add|delete|list|help)

Modifies the filters for the current chatnet/channel. If no filters are specified, and listening is on for this chatnet/channel, then all URL title are sent to the channel. Filters are pass filters, rather than no-pass filters, i.e. they determine what is allowed to send to the channel.

user (add|delete|request [address]|list|help)

Deal with eligible users for managing the showtitle bot. Eligible users are determined by the address part of their hostmask.

help

send general help to calling user.

UI Commands

These commands are available to the user running the showtitle script.

/stuser (add|delete|list)

modify user list

/stfilter (add|delete|list)

modify filter list

/stlisten (on|off|list)

modify listening list

/stignore (on|off|list)

Completely ignore any ^! input from the channel. This has the effect of essentially hiding showtitle from anyone attempting to determine if there are any bots listening

/stsave

save current configuration

/ststatus

show current status across all chatnets/channels

/stdebug [on|off]

turns debugging for showtitle script on or off, or reports status


Internal Documentation

Global Declarations

The following globals are used to enable useful error messages from deep inside some of the functions.

Utility Routines

DebugPrint

Print a message to the current window with some debugging information if $debug is true.

irssi_safe

Prepare a message for output to Irssi by making sure anything needed is escaped. Currently, that's only the percent sign (%).

shownotice

Nicely format a string to show up on the user's current window

showerror

Nicely format an error messge string to show up on the user's current window

say_message

Say a message to the specified server/channel

me_action

send an action message to the current chatnet/channel

printOnThisWindow

send a string to the current window

lc_irc

convert the passed string to lower case, special for irc

uc_irc

convert the passed string to upper case, special for irc

Database handling functions

do_listen

Process a listen database entry

do_filter

process the filter database entry

do_user

process a user database entry

do_ignore

process an ignore database entry

syntax_error

Report a syntax error reading and processing the database

%parse_database

An associative array containing a jump table to handle each database entry type. Structure is:

read_database

reads and processes the various entries in the database

write_database

Writing the database to file

append_to_database

Append an entry to the database

URL Processing

is_html

Retrieve the header of the given URL to see if it contains HTML code

grab_page


get the page for the specified URL -- possibly only a fragment

description:

Uses curl (command line version) to pull over the contents of the specified URL. The curl command is set to be silent, unless the command fails. Other parameters to the curl command include the output file name, the user agent string, a connect timeout and a max timeout, and to follow relocation headers (302s) from the web server.

get_title

Pull the title from the contents and clean it up

find_url

Extract the url from the message text

find_url will match on the text for various URL schemes (currently only supporting FTP and HTTP). In addition, if the bareword "www" precedes a triple-word, it is treated as an HTTP URL and modified accordingly.

pass_filter

Check to see if the url passes various filters

showtitle

Main logic of the script -- display the title of a given URL on either the target's channel, or to the user's screen

showtitle checks the message to see if it contains a valid URL string (currently only ftp: and http: are supported). showtitle will also match if the string begins with "www". It then checks to see if the URL contains an HTML content type.

Command Processing

is_validuser

Checks to see if calling user is in the list of valid users

process_listen

Process an !st listen on/off request

show_listen

List the current channels being listened to for urls

listen_help

    Provide help to the calling user, sent as private message.

show_listen_status

Show whether the current chatnet/channel is being listened to

add_filter

Add a filter to the current channel. Filters are treated as regexes. If a filter is specified as "qr/.../", then it will be evaled as is, if it isn't, then "qr/" and "/" will be wrapped around what ever is given.

delete_filter

Deletes a given filter. Filters are regexes. If a filter is specifed with "qr/.../" then it is used as is. Otherwise "qr/" and "/" are wrapped around teh filter text and it is evaled.

show_filters

Give a list of filters on the current channel

filter_help

Send help messages to calling nick as private messages

show_filter_status

Show what the current filter status is on channel (on or off)

add_user

Add a user to the authorized users list for this channel

delete_user

Remove a user to the authorized users list for this channel

list_users

Show the current set of authorized users for the chatnet/channel

user_request

Send a user request to the owner of the bot to add to authorized users

user_help

Send help info to requesting user as private messages

show_user_status

Say whether the requesting user is an authorized user or not

showtitle_help

Send help info to requesting user as private messages

parse_command jump table

A jump table to determine which subroutine to use to process the command

process_command

process the command given with the st trigger

ignored

returns true if the current chatnet/channel is being ignored

sig_showtitle

Process the signals from a channel for showtitle requests and URLs

sig_own_showtitle

Process the signals from self for showtitle requests and URLs

UI commands

cmd_stuser

Dispatch the appropriate user command.

cmd_stuser uses the Irssi::command_runsub to dispatch the appropriate subcommand based on the first word in the $data string. Commands include:

cmd_stuser_add

Add a user to the authorized user list for a given channel and chatnet

The user can specify the user to add as:

/stuser add [[[chatnet] channel] hostmask]

cmd_stuser_delete

Delete a user based on chatnet, channel and/or hostmask

The user can specify the user to delete as:

/stuser delete [[[chatnet] channel] hostmask]

cmd_stuser_list

List the current set of users

cmd_stfilter

Dispatch the appropriate filter command.

cmd_stfilter uses the Irssi::command_runsub to dispatch the appropriate subcommand based on the first word in the $data string. Commands include:

cmd_stfilter_add

Add a filter to the authorized filter list for a given channel and chatnet

The user can specify the filter to add as:

/stfilter add [[[chatnet] channel] hostmask] [qr/]regex[/]

cmd_stfilter_delete

Delete a filter to the authorized filter list for a given channel and chatnet

The user can specify the filter to delete as:

/stfilter delete [[[chatnet] channel] hostmask] [qr/]regex[/]

cmd_stfilter_list

List the current set of filters

cmd_stlisten

Dispatch the appropriate listen command.

cmd_stlisten uses the Irssi::command_runsub to dispatch the appropriate subcommand based on the first word in the $data string. Commands include:

cmd_stlisten_on

Turn on listening for the specified chatnet/channel

The user can specify the listen channel as:

/stlisten on [[chatnet] channel]

cmd_stlisten_off

Turn off listening on the specified chatnet/channel

The user can specify the filter to delete as:

/stlisten off [[chatnet] channel]

cmd_stlisten_list

List the channels being listened to

cmd_stignore

Dispatch the appropriate ignore command.

cmd_stignore uses the Irssi::command_runsub to dispatch the appropriate subcommand based on the first word in the $data string. Commands include:

cmd_stignore_on

Turn on ignore for a given chatnet/channel

The user can specify the filter to delete as:

/stignore on [[chatnet] channel]

cmd_stignore_off

Stop ignoring a given chatnet/channel

The user can specify the filter to delete as:

/stignore off [[chatnet] channel]

cmd_stignore_list

Show the channels being ignored

cmd_save

Save the database

cmd_ststatus

Give a current status of everything.

cmd_debug

Turn debugging on or off

Usage: /stdebug [on|off]

on - turn on debugging

off - turn off debugging

omitted - show current debugging status