#!/usr/bin/perl -w # noteserv.pl # # This script provides a more user-friendly interface for noteserv, an IRCnet service # brought to you by irc.fu-berlin.de. I didn't like the default lifetime values, # and I didn't want to use a notify for !*@* instead of a simple nickname # notify for . This script provides online help for the most common commands, # logs you in without typing your username and password, uses your personal default # lifetime value for notify and send commands and expands incomplete user masks # ("nick" -> "nick!*@*", "nick!user" -> "nick!user@*", "user@host" -> "*!user@host"). # And, oh, it prevents typing "/quote squery noteserv :blah..." every time. :-) # # Once again: This ONLY WORKS IN IRCNET and in no other IRC networks (as other # IRC admins don't provide a noteserv server)! Got it..? # # Plans: # # - None. Any ideas? Let me know. # # Author: Jonas Pasche . Licensed under the GPL. Have fun. # # Changelog: # # 2001-10-29 * Added /ns as a shortkey for /noteserv # * Implemented reading noteserv.user and noteserv.pass # # ---------------------------------------------------------------------------------------- # Program name and version $NAME = "noteserv"; $VERSION = "0.2"; # Noteserv command... you shouldn't change that $NOTESERV = "/quote squery noteserv :"; # Username and password for noteserv - If you don't have a login already, just try # a username. If it's new, it will be automatically created, and then it's yours :) $USER = `cat noteserv.user`; chomp($USER); $PASS = `cat noteserv.pass`; chomp($PASS); # Default lifetime of notify and send commands $LTSEND = "+7"; $LTNOTIFY = "+0"; # Debugging? $DEBUG = 0; # ---------------------------------------------------------------------------------------- # No configuration needed beyond this point... IRC::print ":: Loading $NAME $VERSION :: Type \"/noteserv login\" to start (you can shorten /noteserv with /ns).\n"; # We definitely need the $USER value, so break the script if we don't have one if( !$USER ) { IRC::print "Error: Please put your username in noteserv.user - noteserv will not be available until you do so.\n"; exit(0); } # Same to $PASS if( !$PASS ) { IRC::print "Error: Please put your password in noteserv.pass - noteserv will not be available until you do so.\n"; exit(0); } # Register the script and the "noteserv" command handler IRC::register ($NAME, $VERSION, "", ""); IRC::add_command_handler("noteserv", "noteserv_command_handler"); IRC::add_command_handler("ns", "noteserv_command_handler"); # Here we go... we only have the "noteserv" handler that manages all stuff sub noteserv_command_handler { # Arguments are in $_[0] - chomp, lowercase, cleanup, build array my $args = shift; chomp $args; $args = lc($args); $args =~ s/\s+/ /g; @args = split(/ /, $args); SWITCH: { if( $args[0] eq "notify" ) { # No additional parameters: List online users if( !$args[1] ) { IRC::print "Debug: " . $NOTESERV . "notify\n" if( $DEBUG ); IRC::command $NOTESERV . "notify"; last SWITCH; } # Did we get lifetime/nickname or just a nickname? # In case of just a nickname we set lifetime to our default if( $args[2] ) { $lifetime = $args[1]; $nickname = $args[2]; } else { $lifetime = $LTNOTIFY; $nickname = $args[1]; } $nickname = nickname_qualify($nickname); IRC::print "Debug: " . $NOTESERV . "notify $lifetime $nickname\n" if( $DEBUG ); IRC::command $NOTESERV . "notify $lifetime $nickname"; last SWITCH; } if( $args[0] eq "send" ) { # We need at least two arguments (user and message) if( !$args[1] ) { IRC::print "Error: \"send\" requires at least the username and the message.\n"; last SWITCH; } # Did we get lifetime/nickname/msg or just nickname/msg? # In case of just a nickname we set lifetime to our default if( $args[3] ) { $lifetime = $args[1]; $nickname = $args[2]; $message = $args[3]; } else { $lifetime = $LTSEND; $nickname = $args[1]; $message = $args[2]; } $nickname = nickname_qualify($nickname); IRC::print "Debug: " . $NOTESERV . "send $lifetime $nickname $message\n" if( $DEBUG ); IRC::command $NOTESERV . "send $lifetime $nickname $message"; last SWITCH; } if( $args[0] eq "login" ) { # Issue a login command with the known user and password IRC::print "Debug: " . $NOTESERV . "login $USER $PASS\n" if( $DEBUG ); IRC::command $NOTESERV . "login $USER $PASS"; last SWITCH; } if( $args[0] eq "status" ) { # Show the status (as which user am I logged in?) IRC::print "Debug: " . $NOTESERV . "status\n" if( $DEBUG ); IRC::command $NOTESERV . "status"; last SWITCH; } if( $args[0] eq "passwd" ) { # Change the password. The script knows the old password for itself. IRC::print "Debug: " . $NOTESERV . "passwd $PASS $args[1]\n" if( $DEBUG ); IRC::command $NOTESERV . "passwd $PASS $args[1]"; last SWITCH; } if( $args[0] eq "lang" ) { # Change the language of the noteserv output IRC::print "Debug: " . $NOTESERV . "lang $args[1]\n" if( $DEBUG ); IRC::command $NOTESERV . "lang $args[1]"; last SWITCH; } if( $args[0] eq "find" ) { # Find users according to a mask IRC::print "Debug: " . $NOTESERV . "find $args[1]\n" if( $DEBUG ); IRC::command $NOTESERV . "find $args[1]"; last SWITCH; } if( $args[0] eq "ls" ) { # List notifies and pending messages IRC::print "Debug: " . $NOTESERV . "ls\n" if( $DEBUG ); IRC::command $NOTESERV . "ls"; last SWITCH; } if( $args[0] eq "rm" ) { # Removes a notify or a pending message IRC::print "Debug: " . $NOTESERV . "rm $args[1]\n" if( $DEBUG ); IRC::command $NOTESERV . "rm $args[1]"; last SWITCH; } if( $args[0] eq "debug" ) { # Internal: Set debugging on or off $DEBUG = $args[1]; IRC::print "Debugging is set to $args[1], thank you.\n"; last SWITCH; } # nothing matched, so give the user some helpful information IRC::print < Changes your password (remember to change in the script) lang [] Change your language ("en" and "de" are available at the moment) User Management find List users that match a pattern with wildcards send [+|-] Send a to offline users (lifetime: "-" for hours, "+" for days) notify [+|-] Get informed if a user is online (lifetime: "-" for hours, "+" for days) Job Management ls List your notifies (with numbers) and pending messages (with letters) rm | Removes the notify or the pending message EOF } return 1; } sub nickname_qualify { # This subroutine expands partial to full user masks: # # nick!user@host -> nick!user@host # nick!user -> nick!user@* # user@host -> *!user@host # nick -> nick!*@* NICK: { if( $_[0] =~ /^.*\!.*\@.*$/ ) { $complete_nickname = $_[0]; last NICK; } if( $_[0] =~ /^.*\!.*$/ ) { $complete_nickname = $_[0] . "\@*"; last NICK; } if( $_[0] =~ /^.*\@.*$/ ) { $complete_nickname = "*!" . $_[0]; last NICK; } $complete_nickname = $_[0] . "!*\@*"; } return $complete_nickname; }