# This script is for identifying internet country codes.
#
#    !country us
#
#    This returns the country for the .us domain
#
#    !code united states
#
#    This returns the country code for the united states
#
# This script requires you to have the text file "countrycodes" in your /home/user/.irssi/ directory
#
# Originally Created On 03.24.04
# 

use Irssi;

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

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

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

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


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