Sirc::Util - Utility sirc functions
# sirc functions use Sirc::Util ':sirc'; # overrides: addhelp $cmd, $usage_line, $rest; timer $delay, $code_string_or_ref, [$reference]; # user messages arg_count_error undef, $want, [@arg]; # or 1st arg $name tell_error $msg; tell_question $msg; xtell $msg; # miscellaneous $pattern = ban_pattern $nick, $user, $host; $boolean = by_server [$who, $user, $host]; eval_this $code, [@arg]; eval_verbose $name, code$, [@arg]; $boolean = have_ops $channel; $boolean = have_ops_q $channel; $boolean = ieq $a, $b; $re = mask_to_re $mask; $unused_timer = newtimer; optional_channel or return; $boolean = plausible_channel $channel; $boolean = plausible_nick $nick; $arg = xgetarg; $restricted = xrestrict; # /settables settable name, $var_ref, $setter_ref; settable_boolean $name, $var_ref, [$validate_ref]; settable_int $name, $var_ref, [$validate_ref]; settable_str $name, $var_ref, [$validate_ref]; # hooks add_hook_type $name; add_hook $name, $code; run_hook $name, [@arg];
This module provides a bunch of utility functions for sirc.
It also allows you to import from it all of the standard sirc API functions, so that you can more simply write your script as a module.
Nothing is exported by default.
You can import the standard SIRC API functions individually or, using the tag :sirc, as a group. The available functions are:
accept addcmd addhelp addhook addset connect deltimer describe docommand doset dosplat dostatus eq getarg getuserline getuserpass listen load me msg newfh notice print remhook remsel resolve say sl tell timer userhost yetonearg
Some of these are actually enhanced versions of the routines that sirc provides, see below for information about them.
These functions provide for a few standard message forms which are shown to the user via main::tell().
This prints an error appropriate to an incorrect number of arguments. name is the name to report as having been invoked incorrectly. If it's undef (which is the usual case) it's set to the caller's function name. want is how many arguments were desired and the remaining arg arguments are the arguments which were actually received.
undef
This formats msg as an error message and passes it to main::tell. It's appropriate for errors caused by the system or an invalid invocation of your code.
This formats msg as an error message for something the user did wrong. The message is passed to main::tell.
This is just main::tell "*** $msg".
main::tell "*** $msg"
These are some functions which don't fall nicely into groups like those following do.
This is an enhanced version of sirc's addcmd(). It lets you define commands whose names contain non-alphanumeric characters.
This is an enhanced version of sirc's addhelp(). It arranges for the new command to appear in the master help list.
Additionally, there's a new 3-arg syntax. When called with 2 args it uses the regular addhelp() command. I hate the way this makes you hardcode the standard form for help info, though, so I added the second form. This form takes the usage info which appears after the command as its first arg, and the bulk of the help as its 3rd arg.
This returns a pattern suitable for banning the given nick, user and host.
The current implementation is this: Any nick is always matched. If the user has a ~ at the start (that is, it didn't come from identd) all user names are matched, else just the one given matches. If the host is an IP address, it bans a class C sized chunk of IP space, otherwise part of it is wildcarded (how much depends on how many parts it has).
For example:
qw(Nick user 1.2.3.4) *!user@1.2.3.* qw(Nick ~user 1.2.3.4) *!*@1.2.3.* qw(Nick user host.foo.com) *!user@*.foo.com qw(Nick ~user host.foo.com) *!*@*.foo.com qw(Nick user foo.com) *!user@*foo.com qw(Nick ~user foo.com) *!*@*foo.com
If the given who, user, host corresponds to a server rather than a user, return the server name, else return undef. If these aren't specified the global $::who, $::user, and $::host are used, which is what you usually want anyway.
This evals code with arg as arguments. The code can be either a code reference or a string. In either case the args will be available in @_. The return value is whatever the code returns. $@ will be set if an exception was raised.
This is like eval_this except that if an exception is raised it is passed along to tell_error (with a message indicating it's from name).
This function returns true if you have ops on the specified channel. If you don\'t have ops it prints an error message and returns false.
This is like have_ops except that no message is printed, it just returns true or false depending on whether you have ops on the specified channel.
This sub returns true if its two args are eq, ignoring case.
Convert the given "mask" (an IRC-style glob pattern) to a regular expression. The only special characters in IRC masks are * and ? (there's no way to escape one of these). The returned pattern always matches case insensitively and is anchored at the front and back (as IRC does it).
*
?
This sub examines $::args to see if the first word in it looks like a channel. If it doesn't then $::talkchannel is inserted there. If there was no channel present and you're not on a channel then an error message is printed and false is returned, otherwise true is returned.
Here's a replacement for /names which runs /names for your current channel if you don't provide any args.
sub main::cmd_names { optional_channel or return; docommand "/names $::args"; } addcmd 'names';
Return an unused timer number.
This returns true if channel is syntactically valid as a channel name.
This returns true if nick is syntactically valid as a nick name. Originally I used the RFC 1459 definition here, but that turns out to be no longer valid. I don't know what definition modern IRC servers are using. This sub allows characters in the range [!-~].
This is an enhanced version of sirc's timer(). It allows you to use a code reference as the code arg.
This is like main::getarg, but it returns the new argument (in addition to setting $::newarg).
This just returns $::restrict.
These commands provide a simplified interface to adding /set variables.
This sub adds a user-settable option. name is its name, var-ref is a reference to the place it will be stored, and setter-ref is a reference to code to validate and save new values. The code will be called as $rsetter-($rvar, $name, $value)>. $name will be in upper case. The code needs to set both $$rvar and $::set{$name}. (The values in %set are user-visible.)
$rsetter-
This adds a /settable boolean called name. var-ref is a reference to the scalar which will store the value.
validate-ref, if provided, will be called to validate a new value is legal. It will receive both the name and the new value (as a boolean, not as the user typed it) as arguments. It should return a boolean to indicate whether the value is okay.
This function adds a /settable integer called name. var-ref is a reference to the scalar which will store the value.
validate-ref, if provided, will be called to validate a new value is legal. It will receive both the name and the new value as arguments. Before it is called the new value will have been vetted for number-hood. It should return a boolean to indicate whether the value is okay.
This function adds a /settable called name. var-ref is a reference to the scalar which will store the value.
validate-ref, if provided, will be called to validate the a new value is legal. It will receive both the name and the new value as arguments. It should return a boolean to indicate whether the value is okay.
Sirc::Util provides functionality for creating, adding code to and running hooks.
This creates a new hook called name.
Add code to the name hook. The name must already have been created with add_hook_type(). The code can be either a string or a code reference.
Run the name hook, passing the args to each hook member via @_.
Check CPAN or http://www.argon.org/~roderick/ for the latest version.
Roderick Schertler <roderick@argon.org>
sirc(1), perl(1), Sirc::Chantrack(3pm).
To install Sirc::URL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sirc::URL
CPAN shell
perl -MCPAN -e shell install Sirc::URL
For more information on module installation, please visit the detailed CPAN module installation guide.