# This script is for identifying state postal codes.
#
#    !state pa
#
#    This returns the state for the pa postal code
#
#    !pcode pennsylvania
#
#    This returns the postal code for pennsylvania
#
# This script requires you to have the text file "statecodes" in your /home/user/.irssi/ directory
#
# Originally Created On 03.25.04
# 

use Irssi;

$VERSION = "1.0";
%IRSSI = (
    author => 'PrincessLeia2',
    contact => 'lyz@princessleia.com ',
    name => 'stateCodes',
    description => 'script to return state for a given postal code',
    license => 'GNU GPL v2 or later',
    url => 'http://www.princessleia.com'
);

open ( PCODE, "<.irssi/statecodes" )or die "can't open statecodes:$!\n";
 chomp( @statecodes = <PCODE> );
        close PCODE;

sub event_privmsg {
	my ($server, $data) =@_;
	my ($target, $text) = $data =~ /^(\S*)\s:(.*)/;
	return if ( $text !~ /^!/i );

	if ( $text =~ /^!state /i ) {
		my ($code) = $text =~ /!state (.*)/;
	      	foreach $pcode (@statecodes ) {
		       	if ($pcode =~ /^$code: /i)  {
                        	$server->command ( "MSG $target $pcode" );
                        }
		}
	}

	elsif ( $text =~ /^!pcode /i ) {
                my ($state) = $text =~ /!pcode (.*)/;
                foreach $pcode (@statecodes ) {
                       	if ($pcode =~ /^\D\D: $state/i)  {
                        	$server->command ( "MSG $target $pcode" );
                        }
               }
        }
}



Irssi::signal_add('event privmsg', 'event_privmsg');
