Advertisement
swarley

xHilight

Mar 9th, 2012
99
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. my %hilights;
  17.  
  18. sub init {
  19.   open my $fh, '<', (Xchat::get_info('xchatdir') . '/.xhilight');
  20.   my $scope;
  21.  
  22.   while (<$fh>) {
  23.       chomp;
  24.       if (/^\[(.+?)\]$/) {
  25.       my $result = $1;
  26.       $result =~ s/\s+|\t+//g;
  27.       $scope = $result;
  28.       $hilights{$scope} = {};
  29.       next;
  30.       }
  31.       m/^(.+?)=(.+?)$/ or next;
  32.       $1 =~ s/\s+|\t+//g;    
  33.       $hilights{$scope}->{$1} = $2;    
  34.   }
  35. }
  36.  
  37. sub chanhook {
  38.   foreach my $key (keys(%hilights)) {
  39.     $_[0][0] =~ s/\s|\t//g;
  40.     if($_[0][0] eq $key) {
  41.     my $format = $hilights{$key}{ChanMsg};
  42.     return Xchat::EAT_NONE unless $format;
  43.     $format =~ s/\%C/\x03/g;
  44.     $format =~ s/\%B/\x02/g;
  45.     $format =~ s/\%O/\x0f/g;
  46.     if($_[0][2]) {
  47.       $format =~ s/\%prefix\%/$_[0][2]/g;
  48.     }
  49.     else {
  50.       $format =~ s/\%prefix\%//g;  
  51.     }
  52.     $format =~ s/\%nick\%/$key/g;
  53.     $format =~ s/\%div\%/\t/g;
  54.     $format =~ s/\%message\%/$_[0][1]/g;
  55.     Xchat::print( $format );
  56.     return Xchat::EAT_ALL;
  57.     }
  58.   }
  59. }
  60.  
  61. sub actionhook {
  62.   foreach my $key (keys(%hilights)) {
  63.     $_[0][0] =~ s/\s|\t//g;
  64.     if($_[0][0] eq $key) {
  65.     my $format = $hilights{$key}{Action};
  66.     return Xchat::EAT_NONE unless $format;
  67.     $format =~ s/\%C/\x03/g;
  68.     $format =~ s/\%B/\x02/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. sub pvt_hook {
  84.   foreach my $key (keys(%hilights)) {
  85.     $_[0][0] =~ s/\s|\t//g;
  86.     if($_[0][0] eq $key) {
  87.     my $format = $hilights{$key}{PvtMsg};
  88.     return Xchat::EAT_NONE unless $format;
  89.     $format =~ s/\%C/\x03/g;
  90.     $format =~ s/\%B/\x02/g;
  91.     $format =~ s/\%O/\x0f/g;
  92.     $format =~ s/\%nick\%/$key/g;
  93.     $format =~ s/\%div\%/\t/g;
  94.     $format =~ s/\%message\%/$_[0][1]/g;
  95.     Xchat::print( $format );
  96.     return Xchat::EAT_ALL;
  97.     }
  98.   }
  99. }
  100.  
  101. sub notchook {
  102.   foreach my $key (keys(%hilights)) {
  103.     $_[0][0] =~ s/\s|\t//g;
  104.     if($_[0][0] eq $key) {
  105.     my $format = $hilights{$key}{Notice};
  106.     return Xchat::EAT_NONE unless $format;
  107.     $format =~ s/\%C/\x03/g;
  108.     $format =~ s/\%B/\x02/g;
  109.     $format =~ s/\%O/\x0f/g;
  110.     $format =~ s/\%nick\%/$key/g;
  111.     $format =~ s/\%div\%/\t/g;
  112.     $format =~ s/\%message\%/$_[0][1]/g;
  113.     Xchat::print( $format );
  114.     return Xchat::EAT_ALL;
  115.     }
  116.   }
  117. }
  118.  
  119. sub parthook {
  120.   foreach my $key (keys(%hilights)) {
  121.     $_[0][0] =~ s/\s|\t//g;
  122.     if($_[0][0] eq $key) {
  123.     my $format = $hilights{$key}{ChanPart};
  124.     return Xchat::EAT_NONE unless $format;
  125.     $format =~ s/\%C/\x03/g;
  126.     $format =~ s/\%B/\x02/g;
  127.     $format =~ s/\%O/\x0f/g;
  128.     $format =~ s/\%host\%/$_[0][1]/g;
  129.     $format =~ s/\%nick\%/$key/g;
  130.     $format =~ s/\%div\%/\t/g;
  131.     $format =~ s/\%channel\%/$_[0][2]/g;
  132.     defined($_[0][3]) ? $format =~ s/\%message\%/$_[0][3]/g : $format =~ s/\%message\%//g;
  133.     Xchat::print( $format );
  134.     return Xchat::EAT_ALL;
  135.     }
  136.   }
  137. }
  138.  
  139. sub chanmsghilight {
  140.   foreach my $key (keys(%hilights)) {
  141.     $_[0][0] =~ s/\s|\t//g;
  142.     if($_[0][0] eq $key) {
  143.     my $format = $hilights{$key}{ChanMsgHilight};
  144.     return Xchat::EAT_NONE unless $format;
  145.     $format =~ s/\%C/\x03/g;
  146.     $format =~ s/\%B/\x02/g;
  147.     $format =~ s/\%O/\x0f/g;
  148.     $format =~ s/\%message\%/$_[0][1]/g;
  149.     $format =~ s/\%nick\%/$key/g;
  150.     $format =~ s/\%div\%/\t/g;
  151.     defined($_[0][2]) ? $format =~ s/\%prefix\%/$_[0][2]/g : $format =~ s/\%prefix\%//g;
  152.     Xchat::print( $format );
  153.     return Xchat::EAT_ALL;
  154.     }
  155.   }
  156. }
  157.  
  158. sub chanacthilight {
  159.   foreach my $key (keys(%hilights)) {
  160.     $_[0][0] =~ s/\s|\t//g;
  161.     if($_[0][0] eq $key) {
  162.     my $format = $hilights{$key}{ChanActHilight};
  163.     return Xchat::EAT_NONE unless $format;
  164.     $format =~ s/\%C/\x03/g;
  165.     $format =~ s/\%B/\x02/g;
  166.     $format =~ s/\%O/\x0f/g;
  167.     $format =~ s/\%message\%/$_[0][1]/g;
  168.     $format =~ s/\%nick\%/$key/g;
  169.     $format =~ s/\%div\%/\t/g;
  170.     $format =~ s/\%channel\%/$_[0][2]/g;
  171.     defined($_[0][2]) ? $format =~ s/\%prefix\%/$_[0][2]/g : $format =~ s/\%prefix\%//g;
  172.     Xchat::print( $format );
  173.     return Xchat::EAT_ALL;
  174.     }
  175.   }
  176. }
  177.  
  178. sub join_chan {
  179.   foreach my $key (keys(%hilights)) {
  180.     $_[0][0] =~ s/\s|\t//g;
  181.     if($_[0][0] eq $key) {
  182.     my $format = $hilights{$key}{JoinChan};
  183.     return Xchat::EAT_NONE unless $format;
  184.     $format =~ s/\%C/\x03/g;
  185.     $format =~ s/\%B/\x02/g;
  186.     $format =~ s/\%O/\x0f/g;
  187.     $format =~ s/\%host%/$_[0][2]/g;
  188.     $format =~ s/\%nick\%/$key/g;
  189.     $format =~ s/\%div\%/\t/g;
  190.     $format =~ s/\%channel\%/$_[0][1]/g;
  191.     Xchat::print( $format );
  192.     return Xchat::EAT_ALL;
  193.     }
  194.   }
  195. }
  196.  
  197. sub quit_msg {
  198.   foreach my $key (keys(%hilights)) {
  199.     $_[0][0] =~ s/\s|\t//g;
  200.     if($_[0][0] eq $key) {
  201.     my $format = $hilights{$key}{Quit};
  202.     return Xchat::EAT_NONE unless $format;
  203.     $format =~ s/\%C/\x03/g;
  204.     $format =~ s/\%B/\x02/g;
  205.     $format =~ s/\%O/\x0f/g;
  206.     $format =~ s/\%host%/$_[0][2]/g;
  207.     $format =~ s/\%nick\%/$key/g;
  208.     $format =~ s/\%div\%/\t/g;
  209.     $format =~ s/\%message\%/$_[0][1]/g;
  210.     Xchat::print( $format );
  211.     return Xchat::EAT_ALL;
  212.     }
  213.   }
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement