Advertisement
swarley

xHilight

Mar 9th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use Xchat ':all';
  2. use warnings;
  3. use strict;
  4.  
  5. Xchat::register('xHilight', '0.1', 'Script made for Tabibibles', &init);
  6. Xchat::hook_print('Channel Message', 'chanhook');
  7. Xchat::hook_print('Channel Action', 'actionhook');
  8. Xchat::hook_print('Channel Msg Hilight', 'chanmsghilight');
  9. Xchat::hook_print('Channel Action Hilight', 'chanacthilight');
  10. Xchat::hook_print('Private Action to Dialog', 'actionhook');
  11. Xchat::hook_print('Private Message to Dialog', 'pvt_hook');
  12. Xchat::hook_print('Notice', 'notchook');
  13. Xchat::hook_print('Part', 'parthook');
  14. Xchat::hook_print('Part with Reason', 'parthook');
  15. Xchat::hook_print('Join', 'join_chan');
  16. Xchat::hook_command('xrefresh', 'xrefresh');
  17.  
  18. my %hilights;
  19.  
  20. sub init {
  21.   open my $fh, '<', (Xchat::get_info('xchatdir') . '/.xhilight');
  22.   my $scope;
  23.  
  24.   while (<$fh>) {
  25.       chomp;
  26.       if (/^\[(.+?)\]$/) {
  27.       my $result = $1;
  28.       $result =~ s/\s+|\t+//g;
  29.       $scope = $result;
  30.       $hilights{$scope} = {};
  31.       next;
  32.       }
  33.       m/^(.+?)=(.+?)$/ or next;
  34.       $1 =~ s/\s+|\t+//g;    
  35.       $hilights{$scope}->{$1} = $2;    
  36.   }
  37.   close $fd;
  38. }
  39.  
  40. sub xrefresh {
  41.     open my $fh, '<', (Xchat::get_info('xchatdir') . '/.xhilight');
  42.   my $scope;
  43.  
  44.   while (<$fh>) {
  45.       chomp;
  46.       if (/^\[(.+?)\]$/) {
  47.       my $result = $1;
  48.       $result =~ s/\s+|\t+//g;
  49.       $scope = $result;
  50.       $hilights{$scope} = {};
  51.       next;
  52.       }
  53.       m/^(.+?)=(.+?)$/ or next;
  54.       $1 =~ s/\s+|\t+//g;    
  55.       $hilights{$scope}->{$1} = $2;    
  56.   }
  57.   close $fh;
  58.   Xchat::print("xHilight refreshed");
  59. }
  60. sub chanhook {
  61.   foreach my $key (keys(%hilights)) {
  62.     $_[0][0] =~ s/\s|\t//g;
  63.     if($_[0][0] eq $key) {
  64.     my $format = $hilights{$key}{ChanMsg};
  65.     return Xchat::EAT_NONE unless $format;
  66.     $format =~ s/\%C/\x03/g;
  67.     $format =~ s/\%B/\x02/g;
  68.     $format =~ s/\%O/\x0f/g;
  69.     if($_[0][2]) {
  70.       $format =~ s/\%prefix\%/$_[0][2]/g;
  71.     }
  72.     else {
  73.       $format =~ s/\%prefix\%//g;  
  74.     }
  75.     $format =~ s/\%nick\%/$key/g;
  76.     $format =~ s/\%div\%/\t/g;
  77.     $format =~ s/\%message\%/$_[0][1]/g;
  78.     Xchat::print( $format );
  79.     return Xchat::EAT_ALL;
  80.     }
  81.   }
  82. }
  83.  
  84. sub actionhook {
  85.   foreach my $key (keys(%hilights)) {
  86.     $_[0][0] =~ s/\s|\t//g;
  87.     if($_[0][0] eq $key) {
  88.     my $format = $hilights{$key}{Action};
  89.     return Xchat::EAT_NONE unless $format;
  90.     $format =~ s/\%C/\x03/g;
  91.     $format =~ s/\%B/\x02/g;
  92.     if($_[0][2]) {
  93.       $format =~ s/\%prefix\%/$_[0][2]/g;
  94.     }
  95.     else {
  96.       $format =~ s/\%prefix\%//g;  
  97.     }
  98.     $format =~ s/\%nick\%/$key/g;
  99.     $format =~ s/\%div\%/\t/g;
  100.     $format =~ s/\%message\%/$_[0][1]/g;
  101.     Xchat::print( $format );
  102.     return Xchat::EAT_ALL;
  103.     }
  104.   }
  105. }
  106. sub pvt_hook {
  107.   foreach my $key (keys(%hilights)) {
  108.     $_[0][0] =~ s/\s|\t//g;
  109.     if($_[0][0] eq $key) {
  110.     my $format = $hilights{$key}{PvtMsg};
  111.     return Xchat::EAT_NONE unless $format;
  112.     $format =~ s/\%C/\x03/g;
  113.     $format =~ s/\%B/\x02/g;
  114.     $format =~ s/\%O/\x0f/g;
  115.     $format =~ s/\%nick\%/$key/g;
  116.     $format =~ s/\%div\%/\t/g;
  117.     $format =~ s/\%message\%/$_[0][1]/g;
  118.     Xchat::print( $format );
  119.     return Xchat::EAT_ALL;
  120.     }
  121.   }
  122. }
  123.  
  124. sub notchook {
  125.   foreach my $key (keys(%hilights)) {
  126.     $_[0][0] =~ s/\s|\t//g;
  127.     if($_[0][0] eq $key) {
  128.     my $format = $hilights{$key}{Notice};
  129.     return Xchat::EAT_NONE unless $format;
  130.     $format =~ s/\%C/\x03/g;
  131.     $format =~ s/\%B/\x02/g;
  132.     $format =~ s/\%O/\x0f/g;
  133.     $format =~ s/\%nick\%/$key/g;
  134.     $format =~ s/\%div\%/\t/g;
  135.     $format =~ s/\%message\%/$_[0][1]/g;
  136.     Xchat::print( $format );
  137.     return Xchat::EAT_ALL;
  138.     }
  139.   }
  140. }
  141.  
  142. sub parthook {
  143.   foreach my $key (keys(%hilights)) {
  144.     $_[0][0] =~ s/\s|\t//g;
  145.     if($_[0][0] eq $key) {
  146.     my $format = $hilights{$key}{ChanPart};
  147.     return Xchat::EAT_NONE unless $format;
  148.     $format =~ s/\%C/\x03/g;
  149.     $format =~ s/\%B/\x02/g;
  150.     $format =~ s/\%O/\x0f/g;
  151.     $format =~ s/\%host\%/$_[0][1]/g;
  152.     $format =~ s/\%nick\%/$key/g;
  153.     $format =~ s/\%div\%/\t/g;
  154.     $format =~ s/\%channel\%/$_[0][2]/g;
  155.     defined($_[0][3]) ? $format =~ s/\%message\%/$_[0][3]/g : $format =~ s/\%message\%//g;
  156.     Xchat::print( $format );
  157.     return Xchat::EAT_ALL;
  158.     }
  159.   }
  160. }
  161.  
  162. sub chanmsghilight {
  163.   foreach my $key (keys(%hilights)) {
  164.     $_[0][0] =~ s/\s|\t//g;
  165.     if($_[0][0] eq $key) {
  166.     my $format = $hilights{$key}{ChanMsgHilight};
  167.     return Xchat::EAT_NONE unless $format;
  168.     $format =~ s/\%C/\x03/g;
  169.     $format =~ s/\%B/\x02/g;
  170.     $format =~ s/\%O/\x0f/g;
  171.     $format =~ s/\%message\%/$_[0][1]/g;
  172.     $format =~ s/\%nick\%/$key/g;
  173.     $format =~ s/\%div\%/\t/g;
  174.     defined($_[0][2]) ? $format =~ s/\%prefix\%/$_[0][2]/g : $format =~ s/\%prefix\%//g;
  175.     Xchat::print( $format );
  176.     return Xchat::EAT_ALL;
  177.     }
  178.   }
  179. }
  180.  
  181. sub chanacthilight {
  182.   foreach my $key (keys(%hilights)) {
  183.     $_[0][0] =~ s/\s|\t//g;
  184.     if($_[0][0] eq $key) {
  185.     my $format = $hilights{$key}{ChanActHilight};
  186.     return Xchat::EAT_NONE unless $format;
  187.     $format =~ s/\%C/\x03/g;
  188.     $format =~ s/\%B/\x02/g;
  189.     $format =~ s/\%O/\x0f/g;
  190.     $format =~ s/\%message\%/$_[0][1]/g;
  191.     $format =~ s/\%nick\%/$key/g;
  192.     $format =~ s/\%div\%/\t/g;
  193.     $format =~ s/\%channel\%/$_[0][2]/g;
  194.     defined($_[0][2]) ? $format =~ s/\%prefix\%/$_[0][2]/g : $format =~ s/\%prefix\%//g;
  195.     Xchat::print( $format );
  196.     return Xchat::EAT_ALL;
  197.     }
  198.   }
  199. }
  200.  
  201. sub join_chan {
  202.   foreach my $key (keys(%hilights)) {
  203.     $_[0][0] =~ s/\s|\t//g;
  204.     if($_[0][0] eq $key) {
  205.     my $format = $hilights{$key}{JoinChan};
  206.     return Xchat::EAT_NONE unless $format;
  207.     $format =~ s/\%C/\x03/g;
  208.     $format =~ s/\%B/\x02/g;
  209.     $format =~ s/\%O/\x0f/g;
  210.     $format =~ s/\%host%/$_[0][2]/g;
  211.     $format =~ s/\%nick\%/$key/g;
  212.     $format =~ s/\%div\%/\t/g;
  213.     $format =~ s/\%channel\%/$_[0][1]/g;
  214.     Xchat::print( $format );
  215.     return Xchat::EAT_ALL;
  216.     }
  217.   }
  218. }
  219.  
  220. sub quit_msg {
  221.   foreach my $key (keys(%hilights)) {
  222.     $_[0][0] =~ s/\s|\t//g;
  223.     if($_[0][0] eq $key) {
  224.     my $format = $hilights{$key}{Quit};
  225.     return Xchat::EAT_NONE unless $format;
  226.     $format =~ s/\%C/\x03/g;
  227.     $format =~ s/\%B/\x02/g;
  228.     $format =~ s/\%O/\x0f/g;
  229.     $format =~ s/\%host%/$_[0][2]/g;
  230.     $format =~ s/\%nick\%/$key/g;
  231.     $format =~ s/\%div\%/\t/g;
  232.     $format =~ s/\%message\%/$_[0][1]/g;
  233.     Xchat::print( $format );
  234.     return Xchat::EAT_ALL;
  235.     }
  236.   }
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement