Country Codes Replacer

By Jethro on May 23, 2010

This is a request by a forum user named CrAnk who asked if it's possible to replace two-letter country codes with their actual country names shown in users addresses. (if shown) I thought I would give it a shot and here is the finished product:

e.g CrAnK (CrAnK@XXXXXXXXXX-***.libero.it)

will result in:

CrAnK (CrAnK@XXXXXXXXXX-***.libero.Italy)

To enable it, initiate the switch via the popups.

I know you may wonder why I use a socket. My main purpose is to borrow the efficiency of socket and pull the country codes into a hash table for later reference, merely for convenience's sake.

UPDATE: Thanks to SnoooP who found a little bug. I have updated the script, along with the add of hsave command when you exit or get disconnected (making it only remove everything completely when you have disabled the script), and a check to see if the script has been turned on already.

on *:start:{ 
  ccload 
}
on *:connect:{ 
  ccload 
}
on *:exit:{
  hsave -o cc cc.hsh
}
on *:disconnect:{
  hsave -o cc cc.hsh
}
alias -l ccload {
  if !$hget(cc) {
    hmake cc 5 
    if $isfile(cc.hsh) {
      .hload cc cc.hsh
    }
  }
}
on *:sockread:cc:{
  var %cc 
  sockread %cc 
  tokenize 32 %cc
  if $rid($1) { 
    sockmark cc $v1 $2- 
  }
  if </PRE> isin %cc { 
    sockclose cc 
  }
  if $sock(cc).mark { 
    write cc.txt $v1
  }
}
on *:sockopen:cc:{
  var %c sockwrite -n cc
  .timercc 1 2 read
  .timerdel 1 3 write -c cc.txt
  %c GET /Generic/countries.htm HTTP/1.1
  %c Host: www.paladinsoftware.com 
  %c $crlf
}
alias -l rid { 
  return $remove($1,<p>,<pre>,<HTML>) 
}
alias -l read { 
  var %r 24 
  while $read(cc.txt,%r) { 
    hadd -m cc $v1
    inc %r 
  } 
}
menu channel,nicklist,menubar,status {
  Enable Country Codes {
    if !$isfile(cc.txt) {
      if $sock(cc) { 
        sockclose cc 
      }
      sockopen cc www.paladinsoftware.com 80
      echo -a * Country Codes have been activated!
    }
    else { 
      echo -a * Country Code was already activated!
    }
  }
  Disable Country Codes { 
    $iif($hget(cc),hfree cc)
    $iif($isfile(cc.txt),.remove cc.txt)
    $iif($isfile(cc.hsh),.remove cc.hsh)
    echo -a * Country Codes have been deactivated! 
  }
}
on !^*:quit:{ cc }
on !^*:join:#:{ cc }
on !^*:part:#:{ cc }
alias -l cc {
  haltdef
  noop $regex($fulladdress,/(.*?\100)/) 
  var %r $regml(1)
  if ($hget(cc)) && ($regex($site,/.*\56(\w{2})$/)) {
    var %q $comchan($nick,0)
    while %q {
      if $me ison $comchan($nick,%q) {
        var %v2 $v2
        if $event == quit {
          echo -bfilmrt %v2 * $+(%r,$regsubex($site,/( $+ $regml(1) $+ )$/,),$&
            $hget(cc,$hfind(cc,$regml(1),1,w))) has quit %v2
        }
        else {
          echo -bfilmrt %v2 * $+(%r,$regsubex($site,/( $+ $regml(1) $+ )$/,),$&
            $hget(cc,$hfind(cc,$regml(1),1,w))) has $iif($event == part,$v1,join) $+ ed %v2
        }
        dec %q
      }
    }
  }
}

Comments

Sign in to comment.
SnoooP   -  Aug 10, 2010

Sorry I have been offline for a few days Jethro, I will have a look now and see how it works.

 Respond  
Jethro   -  Jul 30, 2010

I take that it's working, since you haven't responded. Silence means yes to me.

 Respond  
SnoooP   -  Jul 29, 2010

Awesome i'll check it out now :)

 Respond  
Jethro   -  Jul 28, 2010

Ok thanks to you, SnoooP. I wound up having to rewrite it, and I think I've had it fixed...:P

 Respond  
SnoooP   -  Jul 28, 2010

Indeed. .fr isn't replaced as .france and .star is replaced by, god knows what haha

 Respond  
Jethro   -  Jul 28, 2010

Gee, looks like it's gotten worse than before.

 Respond  
SnoooP   -  Jul 28, 2010
(23:52:10) * Snoopy!Bertrum@989981.965c23.a13d28.ad1 has quit #Paradox
(23:52:10) * Snoopy!Bertrum@teSao Tome and Principe.Sao Tome and Principea has joined #Paradox
(23:52:10) * irc.ParadoxIRC.net sets mode: +v Snoopy
-
Snoopy is Bertrum@test.star * http://IRC-Wiki.org
(23:53:26) * Snoopy!Bertrum@testing.f has joined #Paradox
(23:53:26) * irc.ParadoxIRC.net sets mode: +v Snoopy
-
Snoopy is Bertrum@testing.fr * http://IRC-Wiki.org
 Respond  
Jethro   -  Jul 28, 2010

Ok SnoooP, I've updated the script to make sure it's a two-letter word ending in the vhost to match for the country codes, along with two addition of part and quit event. Let me know if there's any shortcoming that you find.

 Respond  
SnoooP   -  Jul 27, 2010

Jethro another thing, I think you should check that the vhost is like blahblah.XX

(03:52:13) 11 * Tabz!vorpal@fuck.like.a.stArgentina has joined #zeronet
-=-
Tabz is vorpal@fuck.like.a.star 

star shows as argentina, so maybe have it check that there is a . then two letters before it gives the country code.

 Respond  
SnoooP   -  Jul 27, 2010

Awesome Jethro, truly a great snippet, this is something I can see me using alot haha :x 1 more thing though, maybe an on part and on quit that showed the country code :P

 Respond  
Jethro   -  Jul 27, 2010

Ok, I got ya. I've added it.

 Respond  
SnoooP   -  Jul 27, 2010

Not just the asterix, if you look at the first thing i posted it just says

 (01:07:10) Chelle!supramad01@Chatter-A92EB388.too.secksy.France

That does not specify what channel has been joined. The second part I posted includes an asterix and 'has joined #Chat'

Edit:
This is a clearer example:

(01:50:46) * Snoopy (Bertrum@989981.d5c616.948a24.d4be1c) has joined #Paradox
(01:50:46) * Paradox sets mode: +v Snoopy
(01:50:58) * +Snoopy (Bertrum@989981.d5c616.948a24.d4be1c) Quit (Changing hosts)
(01:50:58) * Snoopy!Bertrum@blahblah.blah.France
(01:50:58) * irc.ParadoxIRC.net sets mode: +v Snoopy
(01:51:08) * +Snoopy (Bertrum@blahblah.blah.fr) Quit (Changing hosts)
(01:51:08) * Snoopy!Bertrum@blahblah.blah.Italy
(01:51:08) * irc.ParadoxIRC.net sets mode: +v Snoopy
(01:51:10) * +Snoopy (Bertrum@blahblah.blah.it) Quit (Changing hosts)
(01:51:10) * Snoopy!Bertrum@blahblah.blah.Ireland
(01:51:10) * irc.ParadoxIRC.net sets mode: +v Snoopy
(01:51:13) * +Snoopy (Bertrum@blahblah.blah.ie) Quit (Changing hosts)
(01:51:13) * Snoopy!Bertrum@blahblah.blah.Colombia
(01:51:13) * irc.ParadoxIRC.net sets mode: +v Snoopy

Notice how it doesn't show "has joined #Paradox" when it replaces the country code, only the first join which isn't a country code shows "has joined #Paradox"

 Respond  
Jethro   -  Jul 27, 2010

You mean to have an asterisk symbol added? If so, I have added it so it simulates the default output.

 Respond  
SnoooP   -  Jul 27, 2010

Also another thing you may want to implement:

(01:07:10) * @Chelle (supramad01@Chatter-A92EB388.too.secksy.fr) has left #Chat
(01:07:10) Chelle!supramad01@Chatter-A92EB388.too.secksy.France

Is how we would see it, so perhaps make it a bit more user friendly so it would instead display as

(01:07:10) * @Chelle (supramad01@Chatter-A92EB388.too.secksy.fr) has left #Chat
(01:07:10) * Chelle!supramad01@Chatter-A92EB388.too.secksy.France has joined #Chat

Other than that I love thise code, 8/10

 Respond  
Jethro   -  Jul 27, 2010

Thank you, Snooop. I have fixed the bug.

 Respond  
SnoooP   -  Jul 27, 2010

I love the idea of this script, this is a problem I noticed.

(22:41:50) * @Adward (IceChat7@Adward.donator.nixtrixirc.net) has left #Chat
(22:41:50) Adward!IceChat7@Adward.donator.nixtrixirc.nEthiopia

A small thing I know but thought i'd mention it

 Respond  
AYEHAN   -  May 27, 2010

awesome buddy .. great job ..

 Respond  
Jethro   -  May 25, 2010

Thank you all for the kind words and encouragement.

 Respond  
napa182   -  May 25, 2010

ah so true +like

 Respond  
Jonesy44   -  May 25, 2010

Aye, +Like it napa, they can't get decreased atleast...

 Respond  
napa182   -  May 25, 2010

nice work Jethro
don't worry too much about score ratings cuz the way it is on here is just flawed
anyways I gave ur snippet an 8

 Respond  
Jonesy44   -  May 25, 2010

Good effort Jethro. I did something a bit like this a while back using a literal $replace identifier, this is definitely more efficient and can be updated with new ones.

Rated 10/10 although i would have put 8/10, i believe your score does not need to be so low because of some moron.

 Respond  
Jethro   -  May 25, 2010

Which brings out my point being, "without posting a comment why he or she thinks this script deserves to be lowered in ratings." If they feel that it's incomplete, they should suggest to me how to improve it so I can refine the script further.

I know there are lots of folks who horse around and randomly lower people snippets for no reason. This happens a lot to FordLawnMower. He makes some great scripts and out of the blue, some people lower the rating of them. Again, no comments posted as to why.

 Respond  
RusselB   -  May 25, 2010

not only a lower rating, but a majorly lower rating. I gave you a 9, so the second rating has to have been a 2, which means that the poster felt your code was incomplete (if they were paying attention to the rating levels).

 Respond  
Jethro   -  May 25, 2010

I agree, RusselB. :-)

Ack, I finally know what is like to have someone lowered the rating of a snippet without posting a comment why he or she thinks this script deserves a low score.

 Respond  
RusselB   -  May 23, 2010

Using the * would mean that the code could be triggered from within a picwin window, but you'd still have to create the window first.

 Respond  
Jethro   -  May 23, 2010

Thank you, RusselB.

I knew I could do it that way, but I was told once by a user named WorldDMT (whom I believe still frequents Hawkee every now and then) who suggested to me that I shouldn't do it with the asterisk symbol, because it could trigger the PicWin. He didn't explain the cause and effect, since he doesn't speak English very well.

 Respond  
RusselB   -  May 23, 2010

You could replace

menu channel,nicklist,menubar,status {

with

menu * {

but other than that, a great script.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.