Making ignore easier

Discussion about Perl, TCL or Python scripts and C/C++ plugins (using and writing them).

Making ignore easier

Postby Centauri » 18 Jul 2009 20:21

I always thought the way ignore worked was a little cumbersome (using the equivalent of a banmask type 2) and I help other people use x-chat, so today I decided to write a perl script to make this MUCH easier.

The script assumes you want a type 2, and makes special provisions for host addresses ending in .IP (it keeps the whole hostmask after the @)

It also will strip the leading ~ in the user ident when building the mask so that the address changes as follows:
nick!~user@someIRCserver-EEC2AA85.dial1.philadelphia1.level3.net
*!user@*dial1.philadelphia1.level3.net

this script is then loaded and a line is added to the userlist popups as:
name command
ignore ig1 %a

After that, its a simple matter to right click on a nick in the userlist and select ignore ;)

The whole script is 49 lines or so, and I would be happy to put it out there for anyone interested.
Centauri
 
Posts: 5
Joined: 18 Jul 2009 20:04
Location: Texas

Postby LifeIsPain » 19 Jul 2009 00:17

Kind of pointless talking about what you did without an example. Tis better to just post the script to [url]scripts.xchat.org[/url] (assuming you have it hosted in a mostly permanent location, no pastebins) and allow people access even if you aren't around.

That said, the means of stripping out the ~ is inaccurate. You can replace the ~ with a *, but by removing it, the ignore mask no longer works on the intended victim.
User avatar
LifeIsPain
 
Posts: 490
Joined: 25 Aug 2005 06:36

Making ignore easier

Postby Centauri » 19 Jul 2009 00:28

I wasn't sure about the size of posting code: so here it is:

Code: Select all
#!/usr/bin/perl -w

print "loading Centauri's Ignore Script....";
$script_name        = "IggyScript";
$script_version     = "1.0";
$script_description = "Make ignoring easier.";

Xchat::register($script_name,$script_version,$script_description,"");
IRC::add_command_handler("ig1", "ignore");

sub ignore {
   local($nick) = @_;
   IRC::command("/echo '$nick' iggy info");
   while ($nick[length($nick)] eq ' ') {
      chop($nick);
   }
   if ($nick eq "") {
      IRC::command("/echo '$nick' - nothing to ignore");
      return Xchat::EAT_NONE;
   }
   
   my $userinfo = Xchat::user_info($nick);
   $usermask = $userinfo->{host};
   ($usr,$host) = split(/@/,$usermask);
   $l = length($host);
   $t = substr($host,($l-3));
   if ($t eq ".IP") {
      $toss = "";
      $hostkeep = $host;
   } else {
      ($toss,$hostkeep) = split('\.',$host,2);
      $hostkeep = "*$hostkeep";
   }
   if ($usr[0] eq '~') {
      $usr = substr($usr,1);
   }
   $hostmask = "*!$usr" . "@" . "$hostkeep";
   IRC::command("/ignore $hostmask ALL");
   return Xchat::EAT_NONE;
}


removing the 3 lines about the ~ is pretty easy, if that causes problems
Centauri
 
Posts: 5
Joined: 18 Jul 2009 20:04
Location: Texas

Postby LifeIsPain » 19 Jul 2009 01:22

The IRC:: methods are deprecated, and so should not be used in new scripts. Even if it wasn't deprecated, it is better to be consistent throughout the script and use either Xchat:: or IRC::, but not both. The behavior is a little different, but similar.

Your sub is being called by IRC::add_command_handler, but you are using Xchat::EAT_NONE as the return value. This one in particular should be the same. Also, in this case, you would want EAT_ALL or EAT_XCHAT instead of EAT_NONE, as in your version, "ig1" gets sent to the server.

If you do use Xchat::hook_command instead of IRC::add_command_handler, you will note the parameters are different, so your local($nick) = @_; won't work (and any particular reason for using local?).

if ($nick eq "") could just be if (! $nick)

As to your method of substring to get rid of the ~, a simpler method for those three lines would be:
Code: Select all
$usr =~ s/^~//;
or to do it the way I mentioned before
Code: Select all
$usr =~ s/^~/*/;


It would be more efficient to not keep variables inside of double quotes when the quotes aren't necessary. in the case of:
Code: Select all
   $hostmask = "*!$usr" . "@" . "$hostkeep";
the "$hostkeep" really should just be $hostkeep

Hope that make sense to you.
User avatar
LifeIsPain
 
Posts: 490
Joined: 25 Aug 2005 06:36

Making ignore easier

Postby Centauri » 19 Jul 2009 02:00

I was testing this at one point directly in perl at the command line for various testing issues. In particular, the escaping of the @.

during testing, I was finding that "my ($nick)" was acting differently than "local ($nick)". Perhaps it was a part of the entire debugging process ;)

I wasnt aware of the IRC:: variances, thanks.. I'll have to look into that!

This program is still only in stage 1 of the 3 rules of programming:
make it work
make it right
make it fast
Centauri
 
Posts: 5
Joined: 18 Jul 2009 20:04
Location: Texas

Postby Khisanth » 19 Jul 2009 03:52

local is the wrong thing to use 99.99% of the time
0.009% of the time it's correct but it means the program was badly designed
the remaining 0.001% of the time it's actually the right thing to use :)

and those times that it is correct is either when you have to make temporary changes to one of the variables listed in perldoc perlvar or if you are using a module that someone else wrote and the only want to interface with it is package variables(which is what local affects)
Khisanth
 
Posts: 1724
Joined: 10 Jun 2004 05:23

Making ignore easier

Postby Centauri » 19 Jul 2009 15:22

Worked on this last night, and changed the local($nick) = @_ to my ($nick) = @_ along with some other changes.

I also found that those running vhosts required a little more processing in the else clause as follows:

Code: Select all
   $usermask = $userinfo->{host};
   ($usr,$host) = split(/@/,$usermask);
   if (substr($host,-3,3) eq ".IP") {
      $toss = "";
      $hostkeep = $host;
   } else {
      ($toss,$hostkeep) = split('\.',$host,2);
      $fullserv = IRC::get_info(3);
      ($irc,$serv,$typ) = split('\.',$fullserv);
      ($toss2,$throw) = split('-',$toss,2);
      if ($toss2 eq $serv) {
         $hostkeep = "*$hostkeep";
      } else {
         $hostkeep = $host;
      }
   }
   $usr =~ s/^~//;
   $hostmask = "*!$usr" . "@" . "$hostkeep";
   IRC::command("/ignore $hostmask ALL");
   return;


Its now working consistently, and I did try to change some things between IRC:: type functions and XChat:: - but they were not behaving well (or at all) yet. Perhaps some more work on it today.
Centauri
 
Posts: 5
Joined: 18 Jul 2009 20:04
Location: Texas

Postby LifeIsPain » 20 Jul 2009 00:15

Your method of determining masked hosts such as Network-8CBF120A.dip.t-dialin.net based on the connected server is not very consistent. Not always will server name be irc1.network.net. Rizon for instance (which uses Rizon-ABCD1234.network.isp.tld for hosts that resolve) has very few servers that actually say "rizon" in the name (such as irc.cccp-project.net), Efnet is the same way, except it doesn't do masking, but many of these servers don't say efnet either (irc.inet.tele.dk). Even networks that do all use the network name don't always use that form. IRCHighWay uses names such as genesis.ks.us.irchighway.net and further confuses your script with masks such as b7233.3b00fc6.fios.verizon.net.

However masks won't change unless the IP address changes, so I'm not really sure why you care that it is masked anway, the type 2 takes care of it.

As to type 2, type 2 results in:
*!*user@*.host
rather than
*!user@*.host

This handles the ~ issue I was mentioning before.

But good job introducing another IRC:: call there ;)
User avatar
LifeIsPain
 
Posts: 490
Joined: 25 Aug 2005 06:36

Making ignore easier

Postby Centauri » 20 Jul 2009 01:07

I did finally make changes to the code after what you saw for calls to Xchat::hook_command and Xchat::command (after a few cups of coffee) and indeed there are differences in the initial way to extract the passed arguments:
Code: Select all
# IRC::add_command_handler("ig1", "ignore");
Xchat::hook_command("ig1", "ignore");

Code: Select all
# my ($nick) = @_;
 my $nick = $_[0][1];

the commented out one is for the IRC:: method.

Also the Xchat::command
Code: Select all
# IRC::command("/ignore $hostmask ALL");
Xchat::command("ignore $hostmask ALL");


A lot of my scripts are copies from other scripts to start with (older stuff using IRC:: ) then modifed to suit. I suppose I have a new template of examples now ;)

the one I have to tackle when there is LOT of time for is IRC::add_message_handler("PRIVMSG", "privmsg_handler_all"); (in other scripts) as the parameters passed for that particular one seem VERY different. But its all coming along.

the "local" thing I found in another script (not mine originally) and I've changed that one as well to my ($nick)
Centauri
 
Posts: 5
Joined: 18 Jul 2009 20:04
Location: Texas


Return to Scripts and Plugins

Who is online

Users browsing this forum: No registered users and 1 guest